- Home /
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();
}
}
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
Your answer
Follow this Question
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
Hint at Inspector variables that have tooltips 0 Answers
Recreate default editor look manually without base.OnInspectorGUI [UnityEditor] 2 Answers
GUIStyle doesn't work when renamed. What to do here? 1 Answer