Browse Source

Updated Sequence editor to use serialised property

master
chrisgregan 11 years ago
parent
commit
c8c2846808
  1. BIN
      Assets/Example/Scenes/Example.unity
  2. 2
      Assets/Fungus/FungusScript/Editor/FungusScriptEditor.cs
  3. 4
      Assets/Fungus/FungusScript/Editor/FungusScriptWindow.cs
  4. 33
      Assets/Fungus/FungusScript/Editor/SequenceEditor.cs
  5. 3
      Assets/Fungus/FungusScript/Scripts/Sequence.cs

BIN
Assets/Example/Scenes/Example.unity

Binary file not shown.

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

@ -48,8 +48,6 @@ namespace Fungus.Script
} }
} }
EditorGUI.BeginChangeCheck();
EditorGUILayout.PropertyField(stepTimeProp, new GUIContent("Step Time", "Minimum time to execute each step")); EditorGUILayout.PropertyField(stepTimeProp, new GUIContent("Step Time", "Minimum time to execute each step"));
SequenceEditor.SequenceField(startSequenceProp, SequenceEditor.SequenceField(startSequenceProp,

4
Assets/Fungus/FungusScript/Editor/FungusScriptWindow.cs

@ -132,7 +132,7 @@ namespace Fungus.Script
{ {
Sequence sequence = sequences[i]; Sequence sequence = sequences[i];
float titleWidth = windowStyle.CalcSize(new GUIContent(sequence.name)).x; float titleWidth = windowStyle.CalcSize(new GUIContent(sequence.sequenceName)).x;
float windowWidth = Mathf.Max (titleWidth + 10, 100); float windowWidth = Mathf.Max (titleWidth + 10, 100);
if (fungusScript.selectedSequence == sequence || if (fungusScript.selectedSequence == sequence ||
@ -302,7 +302,7 @@ namespace Fungus.Script
GUILayout.BeginVertical(); GUILayout.BeginVertical();
GUILayout.FlexibleSpace(); GUILayout.FlexibleSpace();
GUILayout.Label(sequence.name, labelStyle); GUILayout.Label(sequence.sequenceName, labelStyle);
GUILayout.FlexibleSpace(); GUILayout.FlexibleSpace();
GUILayout.EndVertical(); GUILayout.EndVertical();

33
Assets/Fungus/FungusScript/Editor/SequenceEditor.cs

@ -12,6 +12,15 @@ namespace Fungus.Script
[CustomEditor (typeof(Sequence))] [CustomEditor (typeof(Sequence))]
public class SequenceEditor : Editor public class SequenceEditor : Editor
{ {
SerializedProperty sequenceNameProp;
SerializedProperty descriptionProp;
void OnEnable()
{
sequenceNameProp = serializedObject.FindProperty("sequenceName");
descriptionProp = serializedObject.FindProperty("description");
}
public void DrawSequenceGUI(FungusScript fungusScript) public void DrawSequenceGUI(FungusScript fungusScript)
{ {
if (fungusScript.selectedSequence == null) if (fungusScript.selectedSequence == null)
@ -23,25 +32,10 @@ namespace Fungus.Script
Sequence sequence = fungusScript.selectedSequence; Sequence sequence = fungusScript.selectedSequence;
EditorGUI.BeginChangeCheck(); EditorGUILayout.PropertyField(sequenceNameProp);
EditorGUILayout.PropertyField(descriptionProp);
string name = EditorGUILayout.TextField(new GUIContent("Name", "Name of sequence displayed in editor window"), sequence.name);
string desc = EditorGUILayout.TextField(new GUIContent("Description", "Sequence description displayed in editor window"), sequence.description);
EditorGUILayout.Separator(); EditorGUILayout.Separator();
if (name != sequence.name)
{
// The name is the gameobject name, so have to undo seperately
Undo.RecordObject(sequence.gameObject, "Set Sequence Name");
sequence.name = name;
}
if (desc != sequence.description)
{
Undo.RecordObject(sequence, "Set Sequence Description");
sequence.description = desc;
}
UpdateIndentLevels(sequence); UpdateIndentLevels(sequence);
@ -52,6 +46,7 @@ namespace Fungus.Script
if (Application.isPlaying) if (Application.isPlaying)
{ {
serializedObject.ApplyModifiedProperties();
return; return;
} }
@ -81,6 +76,7 @@ namespace Fungus.Script
GUILayout.Label("New Command"); GUILayout.Label("New Command");
GUILayout.FlexibleSpace(); GUILayout.FlexibleSpace();
// We should probably use SerializedProperty for the category & command index but there's no real benefit to doing so
int selectedCategoryIndex = EditorGUILayout.Popup(fungusScript.selectedCommandCategoryIndex, categories.ToArray()); int selectedCategoryIndex = EditorGUILayout.Popup(fungusScript.selectedCommandCategoryIndex, categories.ToArray());
List<string> commandNames = new List<string>(); List<string> commandNames = new List<string>();
@ -127,6 +123,7 @@ namespace Fungus.Script
if (fungusScript.selectedSequence == null || if (fungusScript.selectedSequence == null ||
selectedType == null) selectedType == null)
{ {
serializedObject.ApplyModifiedProperties();
return; return;
} }

3
Assets/Fungus/FungusScript/Scripts/Sequence.cs

@ -15,6 +15,9 @@ namespace Fungus.Script
[HideInInspector] [HideInInspector]
public Rect nodeRect = new Rect(10, 10, 100, 40); public Rect nodeRect = new Rect(10, 10, 100, 40);
[HideInInspector]
public string sequenceName = "";
[HideInInspector] [HideInInspector]
public string description = ""; public string description = "";

Loading…
Cancel
Save