Browse Source
Use label to specify a location in a command list, and the jump to command to move execution to that point.master
chrisgregan
10 years ago
8 changed files with 125 additions and 7 deletions
@ -0,0 +1,32 @@
|
||||
using UnityEditor; |
||||
using UnityEngine; |
||||
using System.Collections; |
||||
using System.Collections.Generic; |
||||
|
||||
namespace Fungus |
||||
{ |
||||
[CustomEditor (typeof(Jump))] |
||||
public class JumpEditor : CommandEditor |
||||
{ |
||||
protected SerializedProperty targetLabelProp; |
||||
|
||||
protected virtual void OnEnable() |
||||
{ |
||||
targetLabelProp = serializedObject.FindProperty("targetLabel"); |
||||
} |
||||
|
||||
public override void DrawCommandGUI() |
||||
{ |
||||
serializedObject.Update(); |
||||
|
||||
Jump t = target as Jump; |
||||
|
||||
LabelEditor.LabelField(targetLabelProp, |
||||
new GUIContent("Target Label", "Label to jump to"), |
||||
t.parentSequence); |
||||
|
||||
serializedObject.ApplyModifiedProperties(); |
||||
} |
||||
} |
||||
|
||||
} |
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2 |
||||
guid: c1fd0ccd416054df994af1949fa6fce3 |
||||
MonoImporter: |
||||
serializedVersion: 2 |
||||
defaultReferences: [] |
||||
executionOrder: 0 |
||||
icon: {instanceID: 0} |
||||
userData: |
@ -0,0 +1,53 @@
|
||||
using UnityEditor; |
||||
using UnityEditorInternal; |
||||
using UnityEngine; |
||||
using System; |
||||
using System.Collections; |
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
|
||||
namespace Fungus |
||||
{ |
||||
public class LabelEditor |
||||
{ |
||||
|
||||
static public void LabelField(SerializedProperty property, |
||||
GUIContent labelText, |
||||
Sequence sequence) |
||||
{ |
||||
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; |
||||
foreach (Command command in sequence.commandList) |
||||
{ |
||||
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]; |
||||
} |
||||
} |
||||
|
||||
} |
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2 |
||||
guid: 788b0e4d9a7584649a4c608bbacc8ada |
||||
MonoImporter: |
||||
serializedVersion: 2 |
||||
defaultReferences: [] |
||||
executionOrder: 0 |
||||
icon: {instanceID: 0} |
||||
userData: |
Loading…
Reference in new issue