Browse Source

Converted SequenceField to use SerializedProperty

master
chrisgregan 11 years ago
parent
commit
2279376b27
  1. BIN
      Assets/Example/Scenes/Example.unity
  2. 32
      Assets/Fungus/Dialog/Editor/AddOptionEditor.cs
  3. 22
      Assets/Fungus/FungusScript/Editor/CallEditor.cs
  4. 53
      Assets/Fungus/FungusScript/Editor/FungusScriptEditor.cs
  5. 12
      Assets/Fungus/FungusScript/Editor/SequenceEditor.cs

BIN
Assets/Example/Scenes/Example.unity

Binary file not shown.

32
Assets/Fungus/Dialog/Editor/AddOptionEditor.cs

@ -11,29 +11,35 @@ namespace Fungus.Script
[CustomEditor (typeof(AddOption))] [CustomEditor (typeof(AddOption))]
public class AddOptionEditor : FungusCommandEditor public class AddOptionEditor : FungusCommandEditor
{ {
SerializedProperty optionTextProp;
SerializedProperty hideOnSelectedProp;
SerializedProperty targetSequenceProp;
void OnEnable()
{
optionTextProp = serializedObject.FindProperty("optionText");
hideOnSelectedProp = serializedObject.FindProperty("hideOnSelected");
targetSequenceProp = serializedObject.FindProperty("targetSequence");
}
public override void DrawCommandGUI() public override void DrawCommandGUI()
{ {
serializedObject.Update();
AddOption t = target as AddOption; AddOption t = target as AddOption;
EditorGUI.BeginChangeCheck(); EditorGUI.BeginChangeCheck();
string optionText = EditorGUILayout.TextField(new GUIContent("Option Text", "Text to display on the option button."), EditorGUILayout.PropertyField(optionTextProp, new GUIContent("Option Text", "Text to display on the option button."));
t.optionText);
Sequence targetSequence = SequenceEditor.SequenceField(new GUIContent("Target Sequence", "Sequence to execute when this option is selected by the player."), SequenceEditor.SequenceField(targetSequenceProp,
new GUIContent("Target Sequence", "Sequence to execute when this option is selected by the player."),
new GUIContent("<Continue>"), new GUIContent("<Continue>"),
t.GetFungusScript(), t.GetFungusScript());
t.targetSequence);
bool hideOnSelected = EditorGUILayout.Toggle(new GUIContent("Hide On Selected", "Hide this option forever once the player has selected it."), t.hideOnSelected); EditorGUILayout.PropertyField(hideOnSelectedProp, new GUIContent("Hide On Selected", "Hide this option forever once the player has selected it."));
if (EditorGUI.EndChangeCheck()) serializedObject.ApplyModifiedProperties();
{
Undo.RecordObject(t, "Set Add Option");
t.optionText = optionText;
t.targetSequence = targetSequence;
t.hideOnSelected = hideOnSelected;
}
} }
} }

22
Assets/Fungus/FungusScript/Editor/CallEditor.cs

@ -8,8 +8,17 @@ namespace Fungus.Script
[CustomEditor (typeof(Call))] [CustomEditor (typeof(Call))]
public class CallEditor : FungusCommandEditor public class CallEditor : FungusCommandEditor
{ {
SerializedProperty targetSequenceProp;
void OnEnable()
{
targetSequenceProp = serializedObject.FindProperty("targetSequence");
}
public override void DrawCommandGUI() public override void DrawCommandGUI()
{ {
serializedObject.Update();
Call t = target as Call; Call t = target as Call;
FungusScript fungusScript = t.GetFungusScript(); FungusScript fungusScript = t.GetFungusScript();
@ -18,15 +27,12 @@ namespace Fungus.Script
return; return;
} }
Sequence targetSequence = SequenceEditor.SequenceField(new GUIContent("Target Sequence", "Sequence to call"), SequenceEditor.SequenceField(targetSequenceProp,
new GUIContent("Target Sequence", "Sequence to call"),
new GUIContent("<Continue>"), new GUIContent("<Continue>"),
fungusScript, fungusScript);
t.targetSequence);
if (targetSequence != t.targetSequence) serializedObject.ApplyModifiedProperties();
{
Undo.RecordObject(t, "Set Target Sequence");
t.targetSequence = targetSequence;
}
} }
} }

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

@ -10,6 +10,21 @@ namespace Fungus.Script
[CustomEditor (typeof(FungusScript))] [CustomEditor (typeof(FungusScript))]
public class FungusScriptEditor : Editor public class FungusScriptEditor : Editor
{ {
SerializedProperty stepTimeProp;
SerializedProperty startSequenceProp;
SerializedProperty startAutomaticallyProp;
SerializedProperty colorCommandsProp;
SerializedProperty variablesProp;
void OnEnable()
{
stepTimeProp = serializedObject.FindProperty("stepTime");
startSequenceProp = serializedObject.FindProperty("startSequence");
startAutomaticallyProp = serializedObject.FindProperty("startAutomatically");
colorCommandsProp = serializedObject.FindProperty("colorCommands");
variablesProp = serializedObject.FindProperty("variables");
}
public void OnInspectorUpdate() public void OnInspectorUpdate()
{ {
Repaint(); Repaint();
@ -17,12 +32,9 @@ namespace Fungus.Script
public override void OnInspectorGUI() public override void OnInspectorGUI()
{ {
FungusScript t = target as FungusScript; serializedObject.Update();
if (t != null) FungusScript t = target as FungusScript;
{
t.transform.hideFlags = HideFlags.None;
}
if (Application.isPlaying) if (Application.isPlaying)
{ {
@ -38,12 +50,13 @@ namespace Fungus.Script
EditorGUI.BeginChangeCheck(); EditorGUI.BeginChangeCheck();
float stepTime = EditorGUILayout.FloatField(new GUIContent("Step Time", "Minimum time to execute each step"), t.stepTime); EditorGUILayout.PropertyField(stepTimeProp, new GUIContent("Step Time", "Minimum time to execute each step"));
Sequence startSequence = SequenceEditor.SequenceField(new GUIContent("Start Sequence", "Sequence to be executed when controller starts."), SequenceEditor.SequenceField(startSequenceProp,
new GUIContent("Start Sequence", "Sequence to be executed when controller starts."),
new GUIContent("<None>"), new GUIContent("<None>"),
t, t);
t.startSequence);
if (t.startSequence == null) if (t.startSequence == null)
{ {
GUIStyle style = new GUIStyle(GUI.skin.label); GUIStyle style = new GUIStyle(GUI.skin.label);
@ -51,18 +64,9 @@ namespace Fungus.Script
EditorGUILayout.LabelField(new GUIContent("Error: Please select a Start Sequence"), style); EditorGUILayout.LabelField(new GUIContent("Error: Please select a Start Sequence"), style);
} }
bool startAutomatically = EditorGUILayout.Toggle(new GUIContent("Start Automatically", "Start this Fungus Script when the scene starts."), t.startAutomatically); EditorGUILayout.PropertyField(startAutomaticallyProp, new GUIContent("Start Automatically", "Start this Fungus Script when the scene starts."));
bool colorCommands = EditorGUILayout.Toggle(new GUIContent("Color Commands", "Display commands using colors in editor window."), t.colorCommands); EditorGUILayout.PropertyField(colorCommandsProp, new GUIContent("Color Commands", "Display commands using colors in editor window."));
if (EditorGUI.EndChangeCheck())
{
Undo.RecordObject(t, "Set Fungus Script");
t.stepTime = stepTime;
t.startSequence = startSequence;
t.startAutomatically = startAutomatically;
t.colorCommands = colorCommands;
}
EditorGUILayout.Separator(); EditorGUILayout.Separator();
@ -86,18 +90,17 @@ namespace Fungus.Script
EditorGUILayout.Separator(); EditorGUILayout.Separator();
DrawVariablesGUI(); DrawVariablesGUI();
serializedObject.ApplyModifiedProperties();
} }
public void DrawVariablesGUI() public void DrawVariablesGUI()
{ {
serializedObject.Update();
FungusScript t = target as FungusScript; FungusScript t = target as FungusScript;
ReorderableListGUI.Title("Variables"); ReorderableListGUI.Title("Variables");
SerializedProperty variablesProperty = serializedObject.FindProperty("variables"); FungusVariableListAdaptor adaptor = new FungusVariableListAdaptor(variablesProp, 0);
FungusVariableListAdaptor adaptor = new FungusVariableListAdaptor(variablesProperty, 0);
ReorderableListControl.DrawControlFromState(adaptor, null, ReorderableListFlags.DisableContextMenu | ReorderableListFlags.HideAddButton); ReorderableListControl.DrawControlFromState(adaptor, null, ReorderableListFlags.DisableContextMenu | ReorderableListFlags.HideAddButton);
GUILayout.BeginHorizontal(); GUILayout.BeginHorizontal();
@ -115,8 +118,6 @@ namespace Fungus.Script
menu.ShowAsContext (); menu.ShowAsContext ();
} }
GUILayout.EndHorizontal(); GUILayout.EndHorizontal();
serializedObject.ApplyModifiedProperties();
} }
void AddVariable<T>(object obj) where T : FungusVariable void AddVariable<T>(object obj) where T : FungusVariable

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

@ -168,14 +168,14 @@ namespace Fungus.Script
} }
} }
static public Sequence SequenceField(GUIContent label, GUIContent nullLabel, FungusScript fungusScript, Sequence sequence) static public void SequenceField(SerializedProperty property, GUIContent label, GUIContent nullLabel, FungusScript fungusScript)
{ {
if (fungusScript == null) if (fungusScript == null)
{ {
return null; return;
} }
Sequence result = sequence; Sequence sequence = property.objectReferenceValue as Sequence;
// Build dictionary of child sequences // Build dictionary of child sequences
List<GUIContent> sequenceNames = new List<GUIContent>(); List<GUIContent> sequenceNames = new List<GUIContent>();
@ -196,14 +196,14 @@ namespace Fungus.Script
selectedIndex = EditorGUILayout.Popup(label, selectedIndex, sequenceNames.ToArray()); selectedIndex = EditorGUILayout.Popup(label, selectedIndex, sequenceNames.ToArray());
if (selectedIndex == 0) if (selectedIndex == 0)
{ {
result = null; // Option 'None' sequence = null; // Option 'None'
} }
else else
{ {
result = sequences[selectedIndex - 1]; sequence = sequences[selectedIndex - 1];
} }
return result; property.objectReferenceValue = sequence;
} }
static public Sequence SequenceField(Rect position, GUIContent nullLabel, FungusScript fungusScript, Sequence sequence) static public Sequence SequenceField(Rect position, GUIContent nullLabel, FungusScript fungusScript, Sequence sequence)

Loading…
Cancel
Save