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. 35
      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 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<FungusCommand>(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>(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;
}
EditorUtility.SetDirty(fungusScript);
if (Event.current.button == 0 &&
Event.current.type == EventType.MouseDown)
{

35
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<FungusCommand>();
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();

3
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;

2
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 = "";

BIN
Assets/Shuttle/ShuttleGame.unity

Binary file not shown.
Loading…
Cancel
Save