Browse Source

Added Up, Down, Delete, Copy, Paste buttons

master
chrisgregan 11 years ago
parent
commit
ff26e90891
  1. 59
      Assets/Fungus/Editor/FungusScript/FungusCommandEditor.cs
  2. 2
      Assets/Fungus/Editor/FungusScript/FungusEditorWindow.cs
  3. 31
      Assets/Fungus/Editor/FungusScript/FungusScriptEditor.cs
  4. 3
      Assets/Fungus/VisualScripting/FungusScript.cs
  5. 2
      Assets/Fungus/VisualScripting/Sequence.cs
  6. BIN
      Assets/Shuttle/ShuttleGame.unity

59
Assets/Fungus/Editor/FungusScript/FungusCommandEditor.cs

@ -1,4 +1,5 @@
using UnityEditor; using UnityEditor;
using UnityEditorInternal;
using UnityEngine; using UnityEngine;
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
@ -22,11 +23,55 @@ namespace Fungus.Script
public override void OnInspectorGUI() public override void OnInspectorGUI()
{ {
FungusCommand t = target as FungusCommand;
Rect rect = EditorGUILayout.BeginVertical(); 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<FungusCommand>(fungusScript.copyCommand, t.gameObject);
}
}
}
if (GUILayout.Button("Delete"))
{
Undo.DestroyObjectImmediate(t);
return;
}
GUILayout.EndHorizontal();
EditorGUILayout.Separator();
DrawCommandInspectorGUI(); DrawCommandInspectorGUI();
FungusCommand t = target as FungusCommand; EditorGUILayout.Separator();
if (t != null) if (t != null)
{ {
if (t.errorMessage.Length > 0) if (t.errorMessage.Length > 0)
@ -53,6 +98,18 @@ namespace Fungus.Script
{ {
DrawDefaultInspector(); DrawDefaultInspector();
} }
T CopyComponent<T>(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;
}
} }
} }

2
Assets/Fungus/Editor/FungusScript/FungusEditorWindow.cs

@ -62,6 +62,8 @@ namespace Fungus.Script
return; return;
} }
EditorUtility.SetDirty(fungusScript);
if (Event.current.button == 0 && if (Event.current.button == 0 &&
Event.current.type == EventType.MouseDown) Event.current.type == EventType.MouseDown)
{ {

31
Assets/Fungus/Editor/FungusScript/FungusScriptEditor.cs

@ -64,11 +64,18 @@ namespace Fungus.Script
GUILayout.EndHorizontal(); GUILayout.EndHorizontal();
EditorGUILayout.Separator(); EditorGUILayout.Separator();
GUI.backgroundColor = Color.yellow;
GUILayout.Box("Sequence Editor", GUILayout.ExpandWidth(true)); GUILayout.Box("Sequence Editor", GUILayout.ExpandWidth(true));
GUI.backgroundColor = Color.white;
GUILayout.BeginHorizontal(); GUILayout.BeginHorizontal();
if (GUILayout.Button("New")) if (t.selectedSequence == null)
{
GUILayout.FlexibleSpace();
}
if (GUILayout.Button("Create"))
{ {
GameObject go = new GameObject("Sequence"); GameObject go = new GameObject("Sequence");
go.transform.parent = t.transform; go.transform.parent = t.transform;
@ -82,6 +89,11 @@ namespace Fungus.Script
return; return;
} }
if (t.selectedSequence == null)
{
GUILayout.FlexibleSpace();
}
if (t.selectedSequence != null) if (t.selectedSequence != null)
{ {
if (GUILayout.Button("Delete")) if (GUILayout.Button("Delete"))
@ -111,6 +123,10 @@ namespace Fungus.Script
if (t.selectedSequence != null) if (t.selectedSequence != null)
{ {
DrawSequenceGUI(t.selectedSequence); DrawSequenceGUI(t.selectedSequence);
EditorGUILayout.Separator();
DrawAddCommandGUI(t.selectedSequence);
} }
serializedObject.ApplyModifiedProperties(); serializedObject.ApplyModifiedProperties();
@ -120,7 +136,7 @@ namespace Fungus.Script
{ {
EditorGUI.BeginChangeCheck(); 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); string sequenceDescription = EditorGUILayout.TextField(new GUIContent("Description", "Sequence description displayed in editor window"), sequence.description);
EditorGUILayout.Separator(); EditorGUILayout.Separator();
@ -137,7 +153,7 @@ namespace Fungus.Script
FungusCommand[] commands = sequence.GetComponents<FungusCommand>(); FungusCommand[] commands = sequence.GetComponents<FungusCommand>();
foreach (FungusCommand command in commands) foreach (FungusCommand command in commands)
{ {
if (GUILayout.Button(command.GetCommandTitle())) if (GUILayout.Button(command.GetCommandTitle(), GUILayout.ExpandWidth(true)))
{ {
command.expanded = !command.expanded; command.expanded = !command.expanded;
} }
@ -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() public void DrawVariablesGUI()
{ {
serializedObject.Update(); serializedObject.Update();

3
Assets/Fungus/VisualScripting/FungusScript.cs

@ -18,6 +18,9 @@ namespace Fungus.Script
[System.NonSerialized] [System.NonSerialized]
public Sequence executingSequence; public Sequence executingSequence;
[System.NonSerialized]
public FungusCommand copyCommand;
public Sequence selectedSequence; public Sequence selectedSequence;
public bool startAutomatically = false; public bool startAutomatically = false;

2
Assets/Fungus/VisualScripting/Sequence.cs

@ -12,7 +12,7 @@ namespace Fungus.Script
public class Sequence : MonoBehaviour public class Sequence : MonoBehaviour
{ {
[HideInInspector] [HideInInspector]
public Rect nodeRect = new Rect(10, 10, 100, 100); public Rect nodeRect = new Rect(10, 10, 100, 40);
[HideInInspector] [HideInInspector]
public string description = ""; public string description = "";

BIN
Assets/Shuttle/ShuttleGame.unity

Binary file not shown.
Loading…
Cancel
Save