Browse Source

Converted SequenceField to use SerializedProperty

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

BIN
Assets/Example/Scenes/Example.unity

Binary file not shown.

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

@ -11,29 +11,35 @@ namespace Fungus.Script
[CustomEditor (typeof(AddOption))]
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()
{
serializedObject.Update();
AddOption t = target as AddOption;
EditorGUI.BeginChangeCheck();
string optionText = EditorGUILayout.TextField(new GUIContent("Option Text", "Text to display on the option button."),
t.optionText);
EditorGUILayout.PropertyField(optionTextProp, new GUIContent("Option Text", "Text to display on the option button."));
Sequence targetSequence = SequenceEditor.SequenceField(new GUIContent("Target Sequence", "Sequence to execute when this option is selected by the player."),
new GUIContent("<Continue>"),
t.GetFungusScript(),
t.targetSequence);
SequenceEditor.SequenceField(targetSequenceProp,
new GUIContent("Target Sequence", "Sequence to execute when this option is selected by the player."),
new GUIContent("<Continue>"),
t.GetFungusScript());
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())
{
Undo.RecordObject(t, "Set Add Option");
t.optionText = optionText;
t.targetSequence = targetSequence;
t.hideOnSelected = hideOnSelected;
}
serializedObject.ApplyModifiedProperties();
}
}

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

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

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

@ -10,6 +10,21 @@ namespace Fungus.Script
[CustomEditor (typeof(FungusScript))]
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()
{
Repaint();
@ -17,12 +32,9 @@ namespace Fungus.Script
public override void OnInspectorGUI()
{
FungusScript t = target as FungusScript;
serializedObject.Update();
if (t != null)
{
t.transform.hideFlags = HideFlags.None;
}
FungusScript t = target as FungusScript;
if (Application.isPlaying)
{
@ -38,12 +50,13 @@ namespace Fungus.Script
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"));
SequenceEditor.SequenceField(startSequenceProp,
new GUIContent("Start Sequence", "Sequence to be executed when controller starts."),
new GUIContent("<None>"),
t);
Sequence startSequence = SequenceEditor.SequenceField(new GUIContent("Start Sequence", "Sequence to be executed when controller starts."),
new GUIContent("<None>"),
t,
t.startSequence);
if (t.startSequence == null)
{
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);
}
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);
if (EditorGUI.EndChangeCheck())
{
Undo.RecordObject(t, "Set Fungus Script");
t.stepTime = stepTime;
t.startSequence = startSequence;
t.startAutomatically = startAutomatically;
t.colorCommands = colorCommands;
}
EditorGUILayout.PropertyField(colorCommandsProp, new GUIContent("Color Commands", "Display commands using colors in editor window."));
EditorGUILayout.Separator();
@ -86,18 +90,17 @@ namespace Fungus.Script
EditorGUILayout.Separator();
DrawVariablesGUI();
serializedObject.ApplyModifiedProperties();
}
public void DrawVariablesGUI()
{
serializedObject.Update();
FungusScript t = target as FungusScript;
ReorderableListGUI.Title("Variables");
SerializedProperty variablesProperty = serializedObject.FindProperty("variables");
FungusVariableListAdaptor adaptor = new FungusVariableListAdaptor(variablesProperty, 0);
FungusVariableListAdaptor adaptor = new FungusVariableListAdaptor(variablesProp, 0);
ReorderableListControl.DrawControlFromState(adaptor, null, ReorderableListFlags.DisableContextMenu | ReorderableListFlags.HideAddButton);
GUILayout.BeginHorizontal();
@ -115,8 +118,6 @@ namespace Fungus.Script
menu.ShowAsContext ();
}
GUILayout.EndHorizontal();
serializedObject.ApplyModifiedProperties();
}
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)
{
return null;
return;
}
Sequence result = sequence;
Sequence sequence = property.objectReferenceValue as Sequence;
// Build dictionary of child sequences
List<GUIContent> sequenceNames = new List<GUIContent>();
@ -196,14 +196,14 @@ namespace Fungus.Script
selectedIndex = EditorGUILayout.Popup(label, selectedIndex, sequenceNames.ToArray());
if (selectedIndex == 0)
{
result = null; // Option 'None'
sequence = null; // Option 'None'
}
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)

Loading…
Cancel
Save