Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 JanZagar · Dec 27, 2018 at 12:44 PM · inspectoreditor-scriptingcustom editoreditorguicustom inspector

Custom inspector editor - how to put new editor fields in a specific place

Hi everyone :)

I'm trying to get new editor fields when a bool is checked in the inspector. While I did manage to do that, I don't know how to make it show right below the boolean you had to check and not at the bottom of the inspector.

Here is my code:

 override public void OnInspectorGUI()
 {
     base.OnInspectorGUI ();

     var myScript = target as CardAsset;

     if (myScript.KillEffect) {
         Debug.Log ("KillEffect is true");

         EditorGUILayout.LabelField ("TEST");
     }
 }

Any help is really appreciated :)

Comment
Add comment · Show 4
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 Vega4Life · Dec 27, 2018 at 01:30 PM 0
Share

You are saying it's showing at the bottom because there are more inspector variables from your other script?

avatar image JanZagar Vega4Life · Dec 27, 2018 at 02:28 PM 0
Share

Yes. base.OnInspectorGUI (); is where all others variables are co$$anonymous$$g (from my ScriptableObject). I would like to put the new label between existing vars and i don't know how

avatar image Vega4Life JanZagar · Dec 27, 2018 at 02:35 PM 2
Share

In this case, your custom editor is going to have to show those other variables, ins$$anonymous$$d of doing a DrawDefaultInspector(); Its more work.. I can show you an example if you wish.

avatar image TreyH · Dec 27, 2018 at 02:38 PM 2
Share

I don't think you can insert a single field into an existing inspector GUI. You only have access to its base.OnInspectorGUI() as you've seen, which just draws the entire default inspector block.

I think you will have to make a custom inspector for that type (which it seems like you're doing already) and just create those other fields yourself.

1 Reply

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

Answer by Vega4Life · Dec 27, 2018 at 03:08 PM

For fun I made an example on how to make what you want. Two scripts. To see how it works, copy these scripts and put the Example script on a gameObject. Then toggle the boolean.


     using UnityEngine;
 
     // Nothing special here, just a script with some exposed inspector variables
     public class Example : MonoBehaviour
     {
         [SerializeField] bool boolVariable;
         [SerializeField] float floatVariable;
         [SerializeField] int intVariable;
     }


Here is the custom editor for the above script that will put a label underneath the bool property if true


     using UnityEngine;
     using UnityEditor;
 
 
     [CustomEditor(typeof(Example))]
     public class CustomExample : Editor
     {
         SerializedProperty boolProperty;
         SerializedProperty floatProperty;
         SerializedProperty intProperty;
 
 
         void OnEnable()
         {
             boolProperty = serializedObject.FindProperty("boolVariable");
             floatProperty = serializedObject.FindProperty("floatVariable");
             intProperty = serializedObject.FindProperty("intVariable");
         }
 
 
         public override void OnInspectorGUI()
         {
             serializedObject.Update();
 
             EditorGUILayout.Space();
 
             boolProperty.boolValue = EditorGUILayout.Toggle(boolProperty.displayName, boolProperty.boolValue);
 
             if (boolProperty.boolValue)
             {
                 OnBoolPropertyTrue();
             }
 
             floatProperty.floatValue = EditorGUILayout.FloatField(floatProperty.displayName, floatProperty.floatValue);
             intProperty.intValue = EditorGUILayout.IntField(intProperty.displayName, intProperty.intValue);
 
             serializedObject.ApplyModifiedProperties();
         }
 
 
         void OnBoolPropertyTrue()
         {
             EditorGUILayout.LabelField("I AM BELOW THE BOOL PROPERTY NOW");
         }
     }



I hope this helps!


Comment
Add comment · Show 5 · 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 JanZagar · Dec 27, 2018 at 03:39 PM 0
Share

Huge thanks. You are awesome <3

avatar image Vega4Life JanZagar · Dec 27, 2018 at 03:43 PM 0
Share

Sure. Good luck!

avatar image JanZagar Vega4Life · Dec 27, 2018 at 10:29 PM 0
Share

Hey Vega4Life. $$anonymous$$ind telling me something? Why do you use serializedObject.Update(); with the lower case? If I use the upper case like this SerializedObject.Update(); I get errors. (I was trying to use the upper case because the official documentation uses the upper case)

Show more comments

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

112 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 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 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 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 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 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

How to Hide/Show List or Array in the inspector based on a variable? 0 Answers

Inspector Overlapping Text Label at a Position 1 Answer

Trying to create Custom Inspector Labels and I get erros 0 Answers

How can i get SerializedProperty from UnityEvent which in List. Sorry for my Eng. 2 Answers

Custom Inspector "Multi-object editing not supported" 4 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