From ff26e90891c3de8c5b4ba16b68b9d0032c88ada8 Mon Sep 17 00:00:00 2001 From: chrisgregan Date: Wed, 13 Aug 2014 14:53:16 +0100 Subject: [PATCH] Added Up, Down, Delete, Copy, Paste buttons --- .../FungusScript/FungusCommandEditor.cs | 59 +++++++++++++++++- .../Editor/FungusScript/FungusEditorWindow.cs | 2 + .../Editor/FungusScript/FungusScriptEditor.cs | 35 +++++++++-- Assets/Fungus/VisualScripting/FungusScript.cs | 3 + Assets/Fungus/VisualScripting/Sequence.cs | 2 +- Assets/Shuttle/ShuttleGame.unity | Bin 81628 -> 81628 bytes 6 files changed, 94 insertions(+), 7 deletions(-) diff --git a/Assets/Fungus/Editor/FungusScript/FungusCommandEditor.cs b/Assets/Fungus/Editor/FungusScript/FungusCommandEditor.cs index d410f314..002abb90 100644 --- a/Assets/Fungus/Editor/FungusScript/FungusCommandEditor.cs +++ b/Assets/Fungus/Editor/FungusScript/FungusCommandEditor.cs @@ -1,4 +1,5 @@ using UnityEditor; +using UnityEditorInternal; using UnityEngine; using System.Collections; using System.Collections.Generic; @@ -22,11 +23,55 @@ namespace Fungus.Script public override void OnInspectorGUI() { + FungusCommand t = target as FungusCommand; + Rect rect = EditorGUILayout.BeginVertical(); + GUILayout.BeginHorizontal(); + + if (GUILayout.Button("Up")) + { + UnityEditorInternal.ComponentUtility.MoveComponentUp(t); + } + if (GUILayout.Button("Down")) + { + UnityEditorInternal.ComponentUtility.MoveComponentDown(t); + } + + GUILayout.FlexibleSpace(); + + FungusScript fungusScript = t.GetFungusScript(); + + if (fungusScript != null) + { + if (GUILayout.Button("Copy")) + { + fungusScript.copyCommand = t; + } + + if (fungusScript.copyCommand != null) + { + if (GUILayout.Button("Paste")) + { + CopyComponent(fungusScript.copyCommand, t.gameObject); + } + } + } + + if (GUILayout.Button("Delete")) + { + Undo.DestroyObjectImmediate(t); + return; + } + + GUILayout.EndHorizontal(); + + EditorGUILayout.Separator(); + DrawCommandInspectorGUI(); - FungusCommand t = target as FungusCommand; + EditorGUILayout.Separator(); + if (t != null) { if (t.errorMessage.Length > 0) @@ -53,6 +98,18 @@ namespace Fungus.Script { DrawDefaultInspector(); } + + T CopyComponent(T original, GameObject destination) where T : Component + { + System.Type type = original.GetType(); + Component copy = Undo.AddComponent(destination, type); + System.Reflection.FieldInfo[] fields = type.GetFields(); + foreach (System.Reflection.FieldInfo field in fields) + { + field.SetValue(copy, field.GetValue(original)); + } + return copy as T; + } } } diff --git a/Assets/Fungus/Editor/FungusScript/FungusEditorWindow.cs b/Assets/Fungus/Editor/FungusScript/FungusEditorWindow.cs index f9b08489..67dcc700 100755 --- a/Assets/Fungus/Editor/FungusScript/FungusEditorWindow.cs +++ b/Assets/Fungus/Editor/FungusScript/FungusEditorWindow.cs @@ -62,6 +62,8 @@ namespace Fungus.Script return; } + EditorUtility.SetDirty(fungusScript); + if (Event.current.button == 0 && Event.current.type == EventType.MouseDown) { diff --git a/Assets/Fungus/Editor/FungusScript/FungusScriptEditor.cs b/Assets/Fungus/Editor/FungusScript/FungusScriptEditor.cs index de04dac0..cad8111f 100644 --- a/Assets/Fungus/Editor/FungusScript/FungusScriptEditor.cs +++ b/Assets/Fungus/Editor/FungusScript/FungusScriptEditor.cs @@ -64,11 +64,18 @@ namespace Fungus.Script GUILayout.EndHorizontal(); EditorGUILayout.Separator(); + GUI.backgroundColor = Color.yellow; GUILayout.Box("Sequence Editor", GUILayout.ExpandWidth(true)); - + GUI.backgroundColor = Color.white; + GUILayout.BeginHorizontal(); - if (GUILayout.Button("New")) + if (t.selectedSequence == null) + { + GUILayout.FlexibleSpace(); + } + + if (GUILayout.Button("Create")) { GameObject go = new GameObject("Sequence"); go.transform.parent = t.transform; @@ -82,6 +89,11 @@ namespace Fungus.Script return; } + if (t.selectedSequence == null) + { + GUILayout.FlexibleSpace(); + } + if (t.selectedSequence != null) { if (GUILayout.Button("Delete")) @@ -111,6 +123,10 @@ namespace Fungus.Script if (t.selectedSequence != null) { DrawSequenceGUI(t.selectedSequence); + + EditorGUILayout.Separator(); + + DrawAddCommandGUI(t.selectedSequence); } serializedObject.ApplyModifiedProperties(); @@ -120,7 +136,7 @@ namespace Fungus.Script { EditorGUI.BeginChangeCheck(); - string sequenceName = EditorGUILayout.TextField(new GUIContent("Name", "Name of sequence displayed in editor window"), sequence.name); + string sequenceName = EditorGUILayout.TextField(new GUIContent("Sequence Name", "Name of sequence displayed in editor window"), sequence.name); string sequenceDescription = EditorGUILayout.TextField(new GUIContent("Description", "Sequence description displayed in editor window"), sequence.description); EditorGUILayout.Separator(); @@ -137,11 +153,11 @@ namespace Fungus.Script FungusCommand[] commands = sequence.GetComponents(); foreach (FungusCommand command in commands) { - if (GUILayout.Button(command.GetCommandTitle())) + if (GUILayout.Button(command.GetCommandTitle(), GUILayout.ExpandWidth(true))) { command.expanded = !command.expanded; } - + if (command.expanded) { Editor commandEditor = Editor.CreateEditor(command); @@ -150,6 +166,15 @@ namespace Fungus.Script } } + public void DrawAddCommandGUI(Sequence sequence) + { + // FungusScript t = target as FungusScript; + + GUI.backgroundColor = Color.yellow; + GUILayout.Box("Add Command", GUILayout.ExpandWidth(true)); + GUI.backgroundColor = Color.white; + } + public void DrawVariablesGUI() { serializedObject.Update(); diff --git a/Assets/Fungus/VisualScripting/FungusScript.cs b/Assets/Fungus/VisualScripting/FungusScript.cs index 0e9ea2cc..87a3a577 100644 --- a/Assets/Fungus/VisualScripting/FungusScript.cs +++ b/Assets/Fungus/VisualScripting/FungusScript.cs @@ -18,6 +18,9 @@ namespace Fungus.Script [System.NonSerialized] public Sequence executingSequence; + [System.NonSerialized] + public FungusCommand copyCommand; + public Sequence selectedSequence; public bool startAutomatically = false; diff --git a/Assets/Fungus/VisualScripting/Sequence.cs b/Assets/Fungus/VisualScripting/Sequence.cs index febe58be..4aa1e174 100644 --- a/Assets/Fungus/VisualScripting/Sequence.cs +++ b/Assets/Fungus/VisualScripting/Sequence.cs @@ -12,7 +12,7 @@ namespace Fungus.Script public class Sequence : MonoBehaviour { [HideInInspector] - public Rect nodeRect = new Rect(10, 10, 100, 100); + public Rect nodeRect = new Rect(10, 10, 100, 40); [HideInInspector] public string description = ""; diff --git a/Assets/Shuttle/ShuttleGame.unity b/Assets/Shuttle/ShuttleGame.unity index 416b784d5e30df2e1fd4d9c2474b8b94fd3a7a5d..0b019652fe2f5185b155fad75288cc6352ae14c2 100644 GIT binary patch delta 81 zcmV-X0IvVs{RG_o1c0;wP6P#*LD0;yw^IZGCl~=&w|g7`{SKFeD*+gncq;)6mz*mB n+5wQacPs%x0+tg22$$pr0T8#)E&(P71&~1ifTy?nH38uW+1?y+ delta 78 zcmV-U0I~nv{RG_o1c0;wP6P!ULeR{rw^IZGCl~=(w|g7`{SE=@mu)KnBbS^j0onnG kw|6W7K?0Mo{Ro%v9swA)*e(Gc2L)h3006VM`!xaK2%z~Kod5s;