Browse Source

Custom SequenceField property drop down menu

master
chrisgregan 11 years ago
parent
commit
93cd5bc520
  1. 14
      Assets/Fungus/Editor/SequenceControllerEditor.cs
  2. 38
      Assets/Fungus/Editor/SequenceEditor.cs
  3. 12
      Assets/Fungus/VisualScripting/Sequence.cs

14
Assets/Fungus/Editor/SequenceControllerEditor.cs

@ -9,7 +9,19 @@ public class SequenceControllerEditor : Editor
{
public override void OnInspectorGUI()
{
DrawDefaultInspector();
SequenceController t = target as SequenceController;
t.stepTime = EditorGUILayout.FloatField("Step Time", t.stepTime);
t.startSequence = SequenceEditor.SequenceField("Start Sequence", t, t.startSequence);
if (t.startSequence == null)
{
GUIStyle style = new GUIStyle(GUI.skin.label);
style.normal.textColor = new Color(1,0,0);
EditorGUILayout.LabelField(new GUIContent("Error: Please select a Start Sequence"), style);
}
GUILayout.BeginHorizontal();
GUILayout.FlexibleSpace();
if (GUILayout.Button("Open Fungus Editor"))

38
Assets/Fungus/Editor/SequenceEditor.cs

@ -7,4 +7,42 @@ using Fungus;
[CustomEditor (typeof(Sequence))]
public class SequenceEditor : Editor
{
static public Sequence SequenceField(string label, SequenceController sequenceController, Sequence sequence)
{
if (sequenceController == null)
{
return null;
}
Sequence result = sequence;
// Build dictionary of child sequences
List<string> sequenceNames = new List<string>();
int selectedIndex = 0;
sequenceNames.Add("None");
Sequence[] sequences = sequenceController.GetComponentsInChildren<Sequence>();
for (int i = 0; i < sequences.Length; ++i)
{
sequenceNames.Add(sequences[i].name);
if (sequence == sequences[i])
{
selectedIndex = i + 1;
}
}
selectedIndex = EditorGUILayout.Popup("Start Sequence", selectedIndex, sequenceNames.ToArray());
if (selectedIndex == 0)
{
result = null; // Option 'None'
}
else
{
result = sequences[selectedIndex - 1];
}
return result;
}
}

12
Assets/Fungus/VisualScripting/Sequence.cs

@ -24,16 +24,22 @@ namespace Fungus
public virtual void Start()
{
// Populate sequenceController reference
sequenceController = GetSequenceController();
}
public SequenceController GetSequenceController()
{
SequenceController sc = null;
Transform parent = transform.parent;
while (parent != null)
{
sequenceController = parent.gameObject.GetComponent<SequenceController>();
if (sequenceController != null)
sc = parent.gameObject.GetComponent<SequenceController>();
if (sc != null)
{
break;
}
}
return sc;
}
public bool HasError()

Loading…
Cancel
Save