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
3
Question by karl_ · Mar 31, 2011 at 10:11 PM · editortextureeditor-scripting

Custom Inspector Element on Texture Importer?

I'm trying to get a custom editor to show up in the inspector for textures. If I use

@CustomEditor(TextureImporter) 

it overwrites the Texture Importer settings. How would I go about attaching this to the inspector for images?

alt text

Comment
Add comment · Show 1
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 numberkruncher · Dec 02, 2013 at 09:07 AM 0
Share

I agree, it would be useful if there was a way to daisy-chain some custom controls after/before the default editor. This is quite an old question, but there still doesn't appear to be a way to do this.

2 Replies

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

Answer by Statement · Apr 04, 2011 at 01:08 AM

ext!


@CustomEditor(TextureImporter) class Texture2DEditor extends Editor {

 var drawDefaultInspector : boolean;
 var drawExtendedInspector : boolean;

 function OnInspectorGUI() {
     GUI.enabled = true;

     drawDefaultInspector = GUILayout.Toggle(drawDefaultInspector, "Default Inspector", EditorStyles.toolbarDropDown);
     if (drawDefaultInspector) DrawDefaultInspector(); 
     drawExtendedInspector = GUILayout.Toggle(drawExtendedInspector, "Extended Inspector", EditorStyles.toolbarDropDown);
     if (drawExtendedInspector) DrawExtendedInspector();
 }

 function DrawExtendedInspector() {
     GUILayout.Label("Hello OnInspectorGUI!");
 }       

}


Note that you have to redo the upper portion, I was unable to draw the built in inspector. I also tried Texture2D editors but they didn't work well either (check answer revision history). I checked out the built in texture inspector in UnityEditor.dll, but it uses internal functions that are inaccessible. You might be able to use reflection to invoke them but if I remember correctly, they have application security that deny those operations so you're out of luck if that is the case. Anyhow, it's the best I can give.

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 Statement · Apr 04, 2011 at 11:39 AM 1
Share

I have spent some time trying to rebuild the original TextureImporterInspector using reflector so we could reuse its original GUI. This was not an easy task, and one have to rebuild several classes. I'm currently at 1100 lines of code and there's still tons missing. What's more is everywhere they make use of internal members to key classes, so, I highly doubt you'll ever be able to get the standard gui + extended gui this way. I'll investigate another route though, just got an idea.

avatar image Statement · Apr 04, 2011 at 12:09 PM 1
Share

I had an idea to add a custom asset object to the texture in an AssetPostprocessor and create an inspector for that object type. However, it doesn't seem to work. $$anonymous$$aybe I'm doing something wrong, or it can't be done. Warning: Don't try to save any asset in AssetPostprocessor or you'll get caught in a loop. I also tried to create a menu item that would add this whenever the user chose to, to break free of the loop. But then the default texture importer seems to overwrite any changes, and I still won't get the object in inspector. I'm thinking this is a dead route.

avatar image
3

Answer by Statement · Apr 04, 2011 at 12:36 PM

I came to the conclusion that you can't easily do this. A much easier approach would be to make another editor window that sits next to your inspector. I know it's not ideal but I think it's the best we can do until Unity Technologies open up more customization options for inspectors. The script is very minimal at its current state but you should be able to extend it to fit your likings.


alt text


class TextureInspector extends EditorWindow { var scrollView : Vector2;

 @MenuItem("Window/Texture Inspector")
 static function OpenWindow() {
     var window : TextureInspector = EditorWindow.GetWindow (TextureInspector);
     window.title = "T2D Inspector";
 }

 function OnGUI() {
     var textures = Selection.GetFiltered(Texture2D, SelectionMode.Assets);
     scrollView = GUILayout.BeginScrollView(scrollView);
     GUILayout.Label ("Selected Textures", EditorStyles.boldLabel);
     for (var texture : Texture2D in textures) {
         EditorGUILayout.InspectorTitlebar(true, texture);
         DrawInspector(texture);
     }
     GUILayout.EndScrollView();
     Repaint();
 }

 function DrawInspector(texture : Texture2D) {
     GUILayout.Label("Add your custom inspection here");
 }

}

Comment
Add comment · 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

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

1 Person is following this question.

avatar image

Related Questions

Can you set Read/Write on an image in an Editor Script? 1 Answer

EditorWindow texture effected by Playmode Color Tint 1 Answer

Editor class "Texture Importer" question (applying settings to multiple texture assets). 2 Answers

AssetBundle to prefab => meshes/textures missing 1 Answer

Editor Script Selection thinks Sprites are Texture2Ds. 2 Answers


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