public override void OnInspectorGUI() { SequenceInspector sequenceInspector = target as SequenceInspector; Sequence sequence = sequenceInspector.sequence; if (sequence == null) { return; } FungusScript fungusScript = sequence.GetFungusScript(); SequenceEditor sequenceEditor = Editor.CreateEditor(sequence) as SequenceEditor; sequenceEditor.DrawSequenceGUI(fungusScript); DestroyImmediate(sequenceEditor); Command inspectCommand = null; if (fungusScript.selectedCommands.Count == 1) { inspectCommand = fungusScript.selectedCommands[0]; } if (Application.isPlaying && inspectCommand != null && inspectCommand.parentSequence != sequence) { Repaint(); return; } if (inspectCommand != null) { CommandEditor commandEditor = Editor.CreateEditor(inspectCommand) as CommandEditor; commandEditor.DrawCommandInspectorGUI(); DestroyImmediate(commandEditor); } Repaint(); }
void DrawSequenceView(FungusScript fungusScript) { GUILayout.Space(5); fungusScript.commandScrollPos = GUILayout.BeginScrollView(fungusScript.commandScrollPos); EditorGUILayout.BeginVertical(); GUILayout.Box("Sequence", GUILayout.ExpandWidth(true)); GUILayout.BeginHorizontal(); if (fungusScript.selectedSequence == null) { GUILayout.FlexibleSpace(); } if (GUILayout.Button(fungusScript.selectedSequence == null ? "Create Sequence" : "Create", fungusScript.selectedSequence == null ? EditorStyles.miniButton : EditorStyles.miniButtonLeft)) { Sequence newSequence = fungusScript.CreateSequence(fungusScript.scriptScrollPos); Undo.RegisterCreatedObjectUndo(newSequence, "New Sequence"); fungusScript.selectedSequence = newSequence; fungusScript.selectedCommand = null; } if (fungusScript.selectedSequence == null) { GUILayout.FlexibleSpace(); } if (fungusScript.selectedSequence != null) { if (GUILayout.Button("Delete", EditorStyles.miniButtonMid)) { Undo.DestroyObjectImmediate(fungusScript.selectedSequence.gameObject); fungusScript.selectedSequence = null; fungusScript.selectedCommand = null; } if (GUILayout.Button("Duplicate", EditorStyles.miniButtonRight)) { GameObject copy = GameObject.Instantiate(fungusScript.selectedSequence.gameObject) as GameObject; copy.transform.parent = fungusScript.transform; copy.transform.hideFlags = HideFlags.HideInHierarchy; copy.name = fungusScript.selectedSequence.name; Sequence sequenceCopy = copy.GetComponent <Sequence>(); sequenceCopy.nodeRect.x += sequenceCopy.nodeRect.width + 10; Undo.RegisterCreatedObjectUndo(copy, "Duplicate Sequence"); fungusScript.selectedSequence = sequenceCopy; fungusScript.selectedCommand = null; } } GUILayout.EndHorizontal(); if (fungusScript.selectedSequence != null) { EditorGUILayout.Separator(); SequenceEditor sequenceEditor = Editor.CreateEditor(fungusScript.selectedSequence) as SequenceEditor; sequenceEditor.DrawSequenceGUI(fungusScript); DestroyImmediate(sequenceEditor); GUILayout.FlexibleSpace(); } EditorGUILayout.EndVertical(); GUILayout.EndScrollView(); }