Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by hypnoslave · Feb 20, 2014 at 04:19 AM · editorimporting assetsimporting textures

Finding and changing the import settings on specific textures.

Hi there!

I have a number of texture assets in my project with their "Texture Type" in the inspector set to GUI. I would like to create a script that finds any texture, anywhere in my assets folder that's marked as "GUI", set it to be marked as "Advanced", and switch "Bypass sRGB Sampling" to off.

Here's what I have so far:

 using UnityEngine;
 using UnityEditor;
 public class UpdateGUITextures : EditorWindow {
     
     [MenuItem ("Custom/Update GUI Textures")]
     static void Init () {
         Object[] tex = Resources.FindObjectsOfTypeAll(typeof(Texture2D)) as Object[];
 
         foreach(Texture2D t in tex){
             string path = AssetDatabase.GetAssetPath(t);
             if(path != "" && !path.Contains(".ttf")){
                 TextureImporter textureImporter = AssetImporter.GetAtPath(path) as TextureImporter;
                 if(textureImporter.textureType == TextureImporterType.GUI){
                     textureImporter.textureType = TextureImporterType.Advanced;
                     textureImporter.linearTexture = false;
                 }
             }
         }
     }
     
 }


I'm getting some odd behaviour. First, it's grabbing a LOT of assets, not just Texture2Ds. It looks like it's grabbing everything in the scene as well, which is why I'm checking if the path != "". Also, if I get it to Debug.Log out a list of assets if their import type is set to GUI, it doesn't look like it's getting them all - textures that have their type set to GUI but their compression format set to something other than Compressed, for example, don't appear to be in the list (after a superficial check)

Any advice here would be greatly appreciated!

EDIT: a bit of an update here -- It does seem to be working in some places, but I often have to run it several times and It's hard to determine which texture it'll fix and which it won't. It may also only load textures that are referenced in the currently loaded scene as well ????? Enlighten me someone!

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by flamy · Feb 20, 2014 at 04:46 AM

 public class AutoTextureSettingChanger : AssetPostprocessor  {
 
     
         void OnPreprocessTexture () {
         TextureImporter importer= (TextureImporter)assetImporter;
             
 
         if( importer.textureType== TextureImporterType.GUI)
         {
         
              importer.textureFormat=TextureImporterFormat.AutomaticTruecolor;
     
              importer.textureType=TextureImporterType.Advanced;
              importer.mipmapEnabled = false;
         
     //    importer.ClearPlatformTextureSettings("Android");
     //    importer.ClearPlatformTextureSettings("Web");
     //    importer.ClearPlatformTextureSettings("Standalone");
     //    importer.ClearPlatformTextureSettings("iOS");
              Debug.Log(importer.assetPath+ "     Settings changed");
         }
    }
 
 }



Keep this file inside the Editor Folder and re import the folder containing all the textures, the textures with GUI selected will be converted to Advanced...

Note: After doing that make sure you comment out the function or delete the class, otherwise when ever you set a texture to GUI, it will revert back to advanced.

Extra note: If you want this to be an utility, have menu that sets an EditorPrefs key to certain values and check for the key too while remporting

 if( importer.textureType== TextureImporterType.GUI  && EditorPrefs.GetBool("GUIUpdateFlag")== true)
 {
 }



 [MenuItem ("Custom/Update GUI Textures Flag")]
 static void Init () {
     
   if(EditorPrefs.GetBool("GUIUpdateFlag"))
   {
       EditorPrefs.SetBool("GUIUpdateFlag",false);
   }
   else
   {
       EditorPrefs.SetBool("GUIUpdateFlag",true);
   }
  

 }
Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image hypnoslave · Feb 20, 2014 at 08:10 PM 0
Share

Awesome, thanks for the assist. Oddly, it never occurred to me to check the textureType inside OnPreprocessTexture. Good idea. thanks again!

avatar image flamy · Feb 21, 2014 at 04:57 AM 0
Share

glad that it helped :)

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

19 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Problem with importing objects to 3d unity 0 Answers

I have an asset that is around 3.10GB so imported it to Unity. but take forever to import my full day waste on it 0 Answers

Import obj and mtl file with more textures than one? 0 Answers

Queue method to be called after asset processor is done 0 Answers

Script for locating missing files? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges