You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
77 lines
1.7 KiB
77 lines
1.7 KiB
10 years ago
|
using UnityEditor;
|
||
|
using UnityEngine;
|
||
|
using System.Collections;
|
||
|
using System.Collections.Generic;
|
||
|
|
||
10 years ago
|
namespace Fungus.Script
|
||
10 years ago
|
{
|
||
10 years ago
|
|
||
10 years ago
|
[CustomEditor (typeof(Sequence))]
|
||
|
public class SequenceEditor : Editor
|
||
10 years ago
|
{
|
||
10 years ago
|
static public Sequence SequenceField(GUIContent label, FungusScript fungusScript, Sequence sequence)
|
||
10 years ago
|
{
|
||
10 years ago
|
if (fungusScript == null)
|
||
|
{
|
||
|
return null;
|
||
|
}
|
||
10 years ago
|
|
||
10 years ago
|
Sequence result = sequence;
|
||
|
|
||
|
// Build dictionary of child sequences
|
||
|
List<GUIContent> sequenceNames = new List<GUIContent>();
|
||
|
|
||
|
int selectedIndex = 0;
|
||
|
sequenceNames.Add(new GUIContent("<None>"));
|
||
|
Sequence[] sequences = fungusScript.GetComponentsInChildren<Sequence>();
|
||
|
for (int i = 0; i < sequences.Length; ++i)
|
||
10 years ago
|
{
|
||
10 years ago
|
sequenceNames.Add(new GUIContent(sequences[i].name));
|
||
|
|
||
|
if (sequence == sequences[i])
|
||
|
{
|
||
|
selectedIndex = i + 1;
|
||
|
}
|
||
10 years ago
|
}
|
||
10 years ago
|
|
||
|
selectedIndex = EditorGUILayout.Popup(label, selectedIndex, sequenceNames.ToArray());
|
||
|
if (selectedIndex == 0)
|
||
|
{
|
||
|
result = null; // Option 'None'
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
result = sequences[selectedIndex - 1];
|
||
|
}
|
||
|
|
||
|
return result;
|
||
10 years ago
|
}
|
||
10 years ago
|
|
||
10 years ago
|
static public string VariableField(GUIContent label, FungusScript fungusScript, string variableKey, ref VariableType variableType)
|
||
10 years ago
|
{
|
||
10 years ago
|
List<string> keys = new List<string>();
|
||
|
keys.Add("<None>");
|
||
|
int index = 0;
|
||
|
for (int i = 0; i < fungusScript.variables.Count; ++i)
|
||
10 years ago
|
{
|
||
10 years ago
|
Variable v = fungusScript.variables[i];
|
||
|
keys.Add(v.key);
|
||
|
if (v.key == variableKey &&
|
||
|
index == 0)
|
||
|
{
|
||
|
index = i + 1;
|
||
|
}
|
||
10 years ago
|
}
|
||
10 years ago
|
|
||
|
int newIndex = EditorGUILayout.Popup(label.text, index, keys.ToArray());
|
||
|
|
||
|
if (newIndex > 0)
|
||
|
{
|
||
|
variableType = fungusScript.variables[newIndex - 1].type;
|
||
|
}
|
||
|
|
||
|
return keys[newIndex];
|
||
10 years ago
|
}
|
||
|
}
|
||
10 years ago
|
|
||
10 years ago
|
}
|