• 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
Question by JAAMY · Jun 06, 2018 at 08:54 PM · ioseditor-scriptingeditorguieditorguilayouteditor scripting

Custom Inspector and ExposedRefreces

Hi.

I'm Trying to write my custom inspector, every thing is fine and I can make right field for different type of variables I have in the main script.


But in Main script I have a field which is Exposed Reference

 public ExposedReference<GameObject> relativeToWhat;




How can I make a field for it in OnInspectorGUI ? I tried EditorGUILayout.ObjectField and some other things but I couldn't use them.


By the way if there is no way to do so, Is there any way that I can tell OnInspectorGUI to draw only a specific Part of Default Inspector ? only a specific part of Base.OnInspectorGUI()?

Or if again there Is no way, Is there any way that I can make a gameobject field in custom inspector script and some how handle it in My Main Code ? for example converting or resolving them ? I'm new to exposed References.


And My Main Script doesn't implements Monobehaviour and it is inheriting from TrackAsset Actually I'm creating my own type of playables for timeline.


Here is also put my Custom Editor script up to here Although it is not needed.

Thanks.

 using UnityEditor;
 using UnityEditor.AnimatedValues;
 using UnityEngine;
 
 [CustomEditor(typeof(MagneticTweenTrack))]
 public class MagneticTweenTrackDrawer : Editor
 {
 
     AnimBool animBoolShowUnParentingSettings = new AnimBool(false);
     AnimBool animBoolShowFallowOffset = new AnimBool(true);
     AnimBool animBoolShowRelativeSettings = new AnimBool(false);
 
     public override void OnInspectorGUI()
     {
         MagneticTweenTrack targetTrack = target as MagneticTweenTrack;
         if (targetTrack == null)
             return;
 
         targetTrack.animationClipTrackWillHaveChangesDurringPlayMode = EditorGUILayout.ToggleLeft("Any Change During PlayMode ?", targetTrack.animationClipTrackWillHaveChangesDurringPlayMode);
 
         EditorGUILayout.Space();
         EditorGUILayout.Space();
         EditorGUILayout.HelpBox("Change below values only if you know what are you doing. First read Documentations and then use bellow Parts", MessageType.None, true);
         EditorGUILayout.Space();
 
         EditorGUILayout.LabelField("Parent Mangement Settings", EditorStyles.boldLabel);
 
 
         animBoolShowUnParentingSettings.valueChanged.AddListener(Repaint);
 
         animBoolShowUnParentingSettings.target = EditorGUILayout.ToggleLeft("Use UnParenting ?", targetTrack.useUnParenting);
         targetTrack.useUnParenting = animBoolShowUnParentingSettings.target;
 
         if (EditorGUILayout.BeginFadeGroup(animBoolShowUnParentingSettings.faded))
         {
             EditorGUI.indentLevel++;
             targetTrack.revertToPreviousStatusAfterTimelineFinished = EditorGUILayout.ToggleLeft("Revert to Previous Status ?", targetTrack.revertToPreviousStatusAfterTimelineFinished);
 
             animBoolShowFallowOffset.valueChanged.AddListener(Repaint);
             //entegaMMM
             animBoolShowFallowOffset.target = EditorGUILayout.ToggleLeft("Make Parent to Follow Child ?", targetTrack.inTimelineDurationParentFollowChild);
             targetTrack.inTimelineDurationParentFollowChild = animBoolShowFallowOffset.target;
             if (EditorGUILayout.BeginFadeGroup(animBoolShowFallowOffset.faded))
             {
                 EditorGUI.indentLevel++;
                 EditorGUI.indentLevel++;
                 targetTrack.followOffsetPosition = EditorGUILayout.Vector3Field("Follow Offset Position", targetTrack.followOffsetPosition);
                 targetTrack.followOffsetRotation = EditorGUILayout.Vector3Field("Follow Offset Rotation", targetTrack.followOffsetRotation);
                 EditorGUI.indentLevel--;
                 EditorGUI.indentLevel--;
             }
 
             EditorGUILayout.EndFadeGroup();
             EditorGUI.indentLevel--;
         }
 
         EditorGUILayout.EndFadeGroup();
 
         EditorGUILayout.Space();
         EditorGUILayout.Space();
 
         EditorGUILayout.LabelField("Relative Mode Settings", EditorStyles.boldLabel);
 
         animBoolShowRelativeSettings.valueChanged.AddListener(Repaint);
         animBoolShowRelativeSettings.target = EditorGUILayout.ToggleLeft("Is it Relative ?", targetTrack.isRelative);
         targetTrack.isRelative = animBoolShowRelativeSettings.target;
         if (EditorGUILayout.BeginFadeGroup(animBoolShowRelativeSettings.faded))
         {
             EditorGUI.indentLevel++;
             //
             // Here i am stuck with making a field for my exposed Refrence
          //   targetTrack.relativeToWhat = EditorGUILayout.ObjectField("Relative to what ?",targetTrack.relativeToWhatGameObject, typeof(ExposedReference<GameObject>), true) as ExposedReference<GameObject>;
             
             EditorGUI.indentLevel--;
         }
 
         EditorGUILayout.EndFadeGroup();
 
     }
 }





Comment

People who like this

0 Show 0
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

Answer by SolutionStudios · Jun 19, 2020 at 03:04 PM

Sorry for replying to a very old question, but I had the same issue and found the best you can do is use EditorGUILayout.PropertyField.

https://docs.unity3d.com/ScriptReference/EditorGUILayout.PropertyField.html

Comment

People who like this

0 Show 0 · 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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

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

Track when the value is changed and get it 0 Answers

Text in custom editor is displayed/rendered with boxes around characters... 2 Answers

How to modify child class's enum depending on value of parent enum in custom editor,Custom editor to modify nested classes enum options 1 Answer

Hint at Inspector variables that have tooltips 0 Answers

Recreate default editor look manually without base.OnInspectorGUI [UnityEditor] 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