Browse Source

Pick variable from popup in SetVariable

master
chrisgregan 11 years ago
parent
commit
e7afa36bc5
  1. 46
      Assets/Fungus/Editor/SetVariableCommandEditor.cs
  2. 15
      Assets/Fungus/VisualScripting/FungusCommand.cs

46
Assets/Fungus/Editor/SetVariableCommandEditor.cs

@ -1,6 +1,7 @@
using UnityEditor;
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
[CustomEditor (typeof(SetVariableCommand))]
public class SetVariableCommandEditor : FungusCommandEditor
@ -9,7 +10,48 @@ public class SetVariableCommandEditor : FungusCommandEditor
{
SetVariableCommand t = target as SetVariableCommand;
t.variableKey = EditorGUILayout.TextField(new GUIContent("Variable Key", "The name of the variable to set"), t.variableKey);
t.booleanValue = EditorGUILayout.Toggle(new GUIContent("Boolean Value", "The boolean value to set the variable with"), t.booleanValue);
SequenceController sc = t.GetParentSequenceController();
if (sc == null)
{
return;
}
int index = -1;
List<string> keys = new List<string>();
for (int i = 0; i < sc.variables.Count; ++i)
{
Variable v = sc.variables[i];
keys.Add(v.key);
if (v.key == t.variableKey &&
index == -1)
{
index = i;
}
}
index = EditorGUILayout.Popup("Variable", index, keys.ToArray());
Variable variable = sc.variables[index];
t.variableKey = variable.key;
switch (variable.type)
{
case VariableType.Boolean:
t.booleanValue = EditorGUILayout.Toggle(new GUIContent("Boolean Value", "The boolean value to set the variable with"), t.booleanValue);
break;
case VariableType.Integer:
t.integerValue = EditorGUILayout.IntField(new GUIContent("Integer Value", "The integer value to set the variable with"), t.integerValue);
break;
case VariableType.Float:
t.floatValue = EditorGUILayout.FloatField(new GUIContent("Float Value", "The float value to set the variable with"), t.floatValue);
break;
case VariableType.String:
t.stringValue = EditorGUILayout.TextField(new GUIContent("String Value", "The string value to set the variable with"), t.stringValue);
break;
}
}
}

15
Assets/Fungus/VisualScripting/FungusCommand.cs

@ -7,7 +7,7 @@ using System.Collections.Generic;
namespace Fungus
{
[RequireComponent(typeof(Sequence))]
public class FungusCommand : MonoBehaviour
{
[HideInInspector]
@ -22,17 +22,24 @@ namespace Fungus
public virtual void Start()
{
parentSequence = GetComponent<Sequence>();
parentSequenceController = GetParentSequenceController();
}
public SequenceController GetParentSequenceController()
{
SequenceController sc = null;
// Populate sequenceController reference
Transform parent = transform.parent;
while (parent != null)
{
parentSequenceController = parent.gameObject.GetComponent<SequenceController>();
if (parentSequenceController != null)
sc = parent.gameObject.GetComponent<SequenceController>();
if (sc != null)
{
break;
}
parent = parent.transform.parent;
}
return sc;
}
public bool IsExecuting()

Loading…
Cancel
Save