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.
78 lines
1.6 KiB
78 lines
1.6 KiB
10 years ago
|
using UnityEditor;
|
||
|
using UnityEditorInternal;
|
||
|
using UnityEngine;
|
||
|
using System;
|
||
|
using System.Collections;
|
||
|
using System.Collections.Generic;
|
||
|
using System.Linq;
|
||
|
|
||
|
namespace Fungus
|
||
|
{
|
||
10 years ago
|
[CustomEditor (typeof(Label))]
|
||
|
public class LabelEditor : CommandEditor
|
||
10 years ago
|
{
|
||
10 years ago
|
protected SerializedProperty keyProp;
|
||
|
|
||
10 years ago
|
static public void LabelField(SerializedProperty property,
|
||
|
GUIContent labelText,
|
||
10 years ago
|
Block block)
|
||
10 years ago
|
{
|
||
|
List<string> labelKeys = new List<string>();
|
||
|
List<Label> labelObjects = new List<Label>();
|
||
|
|
||
|
labelKeys.Add("<None>");
|
||
|
labelObjects.Add(null);
|
||
|
|
||
|
Label selectedLabel = property.objectReferenceValue as Label;
|
||
|
|
||
|
int index = 0;
|
||
|
int selectedIndex = 0;
|
||
10 years ago
|
foreach (Command command in block.commandList)
|
||
10 years ago
|
{
|
||
|
Label label = command as Label;
|
||
|
if (label == null)
|
||
|
{
|
||
|
continue;
|
||
|
}
|
||
|
|
||
|
labelKeys.Add(label.key);
|
||
|
labelObjects.Add(label);
|
||
|
|
||
|
index++;
|
||
|
|
||
|
if (label == selectedLabel)
|
||
|
{
|
||
|
selectedIndex = index;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
selectedIndex = EditorGUILayout.Popup(labelText.text, selectedIndex, labelKeys.ToArray());
|
||
|
|
||
|
property.objectReferenceValue = labelObjects[selectedIndex];
|
||
|
}
|
||
10 years ago
|
|
||
|
protected virtual void OnEnable()
|
||
|
{
|
||
|
keyProp = serializedObject.FindProperty("key");
|
||
|
}
|
||
|
|
||
|
public override void DrawCommandGUI()
|
||
|
{
|
||
|
Label t = target as Label;
|
||
|
|
||
10 years ago
|
Flowchart flowchart = t.GetFlowchart();
|
||
|
if (flowchart == null)
|
||
10 years ago
|
{
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
serializedObject.Update();
|
||
|
|
||
|
EditorGUILayout.PropertyField(keyProp);
|
||
10 years ago
|
keyProp.stringValue = flowchart.GetUniqueLabelKey(keyProp.stringValue, t);
|
||
10 years ago
|
|
||
|
serializedObject.ApplyModifiedProperties();
|
||
|
}
|
||
10 years ago
|
}
|
||
|
|
||
|
}
|