- Home /
Is there a way to draw on the scene view from an asset being inspected by the Inspector?
I've been working on Timeline since the last 2017.1 beta and I've wanted to do some stuff for a particular type of clip. To be more specific, I want to draw an editable line in the scene view when I have a clip of that type selected. The problem is, Timeline clips live inside Timeline Assets, which are not instantiated as part of a Scene, so OnSceneGUI doesn't get called.
[CustomEditor(typeof(EnemyMovementClip))]
public class EnemyMovementClipEditor : Editor {
public override void OnInspectorGUI()
{
//A bunch of stuff that works as intended...
//But that does not.
if (pathMode.enumValueIndex == (int)EnemyMovementBehaviour.PathMode.Linear)
{
Handles.BeginGUI();
Handles.color = Color.green;
behaviour.startingPosition = Handles.DoPositionHandle(behaviour.startingPosition, Quaternion.identity);
behaviour.endingPosition = Handles.DoPositionHandle(behaviour.endingPosition, Quaternion.identity);
Handles.DrawLine(behaviour.startingPosition, behaviour.endingPosition);
Handles.EndGUI();
}
}
private void OnSceneGUI()
{
//Doesn't get called since the object isn't in scene
if (pathMode.enumValueIndex == (int)EnemyMovementBehaviour.PathMode.Linear)
{
Handles.BeginGUI();
Handles.color = Color.green;
behaviour.startingPosition = Handles.DoPositionHandle(behaviour.startingPosition, Quaternion.identity);
behaviour.endingPosition = Handles.DoPositionHandle(behaviour.endingPosition, Quaternion.identity);
Handles.DrawLine(behaviour.startingPosition, behaviour.endingPosition);
Handles.EndGUI();
}
}
}
Is there a way to draw on the scene view form OnInspectorGUI? Or any other way to do what I want, really. I'd very much like to be able to do that kind of thing in a general case, for various previewing purposes.
Your answer
Follow this Question
Related Questions
Callback when custom PropertyAttribute changes 0 Answers
Align text into PropertyField 1 Answer
GUILayout.BeginHorizontal sluggish in custom inspector 0 Answers
OnInspectorGUI - Using the default Object Selection popup. 1 Answer
Using a CustomEditor in the inspector and also seeing normal inspector fields 1 Answer