void UpdateIndentLevels(Sequence sequence) { int indentLevel = 0; foreach(Command command in sequence.commandList) { indentLevel += command.GetPreIndent(); command.indentLevel = Math.Max(indentLevel, 0); indentLevel += command.GetPostIndent(); } }
public static 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]; }
public virtual void ExecuteSequence(Sequence s) { OnExit(); if (parentSequence != null) { FungusScript fungusScript = parentSequence.GetFungusScript(); // Record the currently selected sequence because Stop() will clear it. Sequence selectedSequence = fungusScript.selectedSequence; parentSequence.Stop(); if (fungusScript != null) { // If the executing sequence is currently selected then follow the execution // onto the next sequence in the inspector. if (selectedSequence == parentSequence) { fungusScript.selectedSequence = s; } fungusScript.ExecuteSequence(s); } } }
/** * Start running the Fungus Script by executing a specific child sequence. */ public void ExecuteSequence(Sequence sequence) { // Sequence must be a child of the parent Fungus Script if (sequence == null || sequence.transform.parent != transform) { return; } executingSequence = sequence; selectedSequence = sequence; sequence.ExecuteNextCommand(); }
void ShowCommandMenu(int index, Sequence sequence) { GenericMenu commandMenu = new GenericMenu(); // Build menu list List<System.Type> menuTypes = EditorExtensions.FindDerivedTypes(typeof(Command)).ToList(); foreach(System.Type type in menuTypes) { object[] attributes = type.GetCustomAttributes(false); foreach (object obj in attributes) { CommandInfoAttribute infoAttr = obj as CommandInfoAttribute; if (infoAttr != null) { SetCommandOperation commandOperation = new SetCommandOperation(); commandOperation.sequence = sequence; commandOperation.commandType = type; commandOperation.index = index; commandMenu.AddItem (new GUIContent (infoAttr.Category + "/" + infoAttr.CommandName), false, Callback, commandOperation); } } } commandMenu.ShowAsContext(); }
void DrawConnections(FungusScript fungusScript, Sequence sequence, bool highlightedOnly) { if (sequence == null) { return; } List<Sequence> connectedSequences = new List<Sequence>(); bool sequenceIsSelected = (fungusScript.selectedSequence == sequence); foreach (Command command in sequence.commandList) { bool commandIsSelected = (fungusScript.selectedCommand == command); bool highlight = command.IsExecuting() || (sequenceIsSelected && commandIsSelected); if (highlightedOnly && !highlight || !highlightedOnly && highlight) { continue; } connectedSequences.Clear(); command.GetConnectedSequences(ref connectedSequences); foreach (Sequence sequenceB in connectedSequences) { if (sequenceB == null || sequenceB.GetFungusScript() != fungusScript) { continue; } DrawRectConnection(sequence.nodeRect, sequenceB.nodeRect, highlight); } } }
/** * Called when the command is deleted from a sequence in the editor. */ public virtual void OnCommandRemoved(Sequence parentSequence) { }
/** * Called when the new command is added to a sequence in the editor. */ public virtual void OnCommandAdded(Sequence parentSequence) { }
public virtual void ExecuteSequence(Sequence s) { OnExit(); Sequence sequence = GetSequence(); if (sequence != null) { sequence.Stop(); FungusScript fungusScript = sequence.GetFungusScript(); if (fungusScript != null) { fungusScript.ExecuteSequence(s); } } }
static public Sequence SequenceField(Rect position, GUIContent nullLabel, FungusScript fungusScript, Sequence sequence) { if (fungusScript == null) { return null; } Sequence result = sequence; // Build dictionary of child sequences List<GUIContent> sequenceNames = new List<GUIContent>(); int selectedIndex = 0; sequenceNames.Add(nullLabel); Sequence[] sequences = fungusScript.GetComponentsInChildren<Sequence>(); for (int i = 0; i < sequences.Length; ++i) { sequenceNames.Add(new GUIContent(sequences[i].name)); if (sequence == sequences[i]) { selectedIndex = i + 1; } } selectedIndex = EditorGUI.Popup(position, selectedIndex, sequenceNames.ToArray()); if (selectedIndex == 0) { result = null; // Option 'None' } else { result = sequences[selectedIndex - 1]; } return result; }