protected IEnumerator Run(InstructionStore variables, InstructionGraphNode root, string source) { _rootStore = variables; StartRunning(root, source); GoTo(root, source); while (ShouldContinue()) { var frame = SetupFrame(_nextNode); _nextNode.Reset(); if (frame.Node != null) { _callstack.Push(frame); yield return(ProcessFrame(frame)); } if (_shouldBreak) { HandleBreak(); _shouldBreak = false; } if (_shouldExit) { _shouldExit = false; break; } } _callstack.Clear(); _nextNode.Reset(); }
protected IEnumerator Run(InstructionStore variables, InstructionGraphNode root, string source) { StartRunning(root, source); var rootThis = variables.This; _rootStore = variables; GoTo(root, _rootStore.This, source); while (ShouldContinue()) { var frame = SetupFrame(_nextNode); _nextNode.Node = null; if (frame.Node != null) { _callstack.Push(frame); _rootStore.ChangeThis(frame.This); yield return(ProcessFrame(frame)); } if (_shouldBreak) { HandleBreak(); _shouldBreak = false; } } _callstack.Clear(); variables.ChangeThis(rootThis); }
public override void SetConnection(ConnectionData connection, InstructionGraphNode target) { foreach (var node in Connections) { if (node.Name == connection.Name) { node.Node = target; } } }
private void StartRunning(InstructionGraphNode root, string source) { _currentBranch = source; DebugState = PlaybackState.Running; if (IsDebugLoggingEnabled) { Debug.LogFormat(this, "(Frame {0}) Instruction Graph {1}: running branch '{2}'", Time.frameCount, name, source); } }
private bool IsNodeInStack(InstructionGraphNode node) { foreach (var frame in _callstack) { if (frame.Node == node) { return(true); } } return(false); }
public void GoTo(InstructionGraphNode node, string name) { switch (node) { case ILoopNode loop: _nextNode.Type = NodeType.Loop; break; case ISequenceNode sequence: _nextNode.Type = NodeType.Sequence; break; default: _nextNode.Type = NodeType.Normal; break; } _nextNode.Node = node; _nextNode.Source = name; }
public bool IsInCallStack(InstructionGraphNode node, string source) { if (_callstack.Count > 0) { foreach (var frame in _callstack) { if (frame.Node == node && frame.Source == source) { return(true); } } } return(false); }
public void ApplyConnection(object obj, InstructionGraphNode target) { var field = obj.GetType().GetField(Field, BindingFlags.Instance | BindingFlags.Public); if (field != null) { if (field.FieldType == typeof(InstructionGraphNode)) { field.SetValue(obj, target); } else if (field.FieldType == typeof(InstructionGraphNodeDictionary)) { var dictionary = field.GetValue(obj) as InstructionGraphNodeDictionary; if (dictionary.ContainsKey(FieldKey)) { dictionary[FieldKey] = target; } else { Debug.LogErrorFormat(_missingKeyError, Field, target.name); } } else if (field.FieldType == typeof(InstructionGraphNodeList)) { var list = field.GetValue(obj) as InstructionGraphNodeList; if (FieldIndex >= 0 && FieldIndex < list.Count) { list[FieldIndex] = target; } else { Debug.LogErrorFormat(_missingIndexError, Field, Target.Node.name); } } else { Debug.LogErrorFormat(_missingFieldError, Field, Target.Node.name); } } else { Debug.LogErrorFormat(_missingFieldError, Field, Target.Node.name); } }
public override void SetConnection(ConnectionData connection, InstructionGraphNode target) { if (connection.Field == nameof(Buttons)) { foreach (var button in Buttons) { if ((button.Type == InputNodeButton.ButtonType.Key && button.Key.ToString() == connection.FieldKey) || button.Name == connection.FieldKey) { button.OnSelected = target; return; } } } else { base.SetConnection(connection, target); } }
public override void SetConnection(ConnectionData connection, InstructionGraphNode target) { if (connection.Field == nameof(Items)) { foreach (var item in Items) { if (item.Id == connection.FieldKey) { item.OnSelected = target; return; } } } else { base.SetConnection(connection, target); } }
public ConnectionData(string field, string key, int index, InstructionGraphNode from, InstructionGraphNode to, int fromIndex) { Field = field; FieldKey = key; FieldIndex = index; From = from; FromIndex = fromIndex; To = to; if (index >= 0) { Name = string.Format("{0} {1}", field, index); } else if (!string.IsNullOrEmpty(key)) { Name = string.Format("{0} {1}", field, key); } else { Name = field; } }
public int IsInCallStack(InstructionGraphNode node) { if (_callstack.Count > 0) { foreach (var frame in _callstack) { if (frame.Node == node) { if (frame.Type != NodeType.Normal) { return(frame.Iteration + 1); } else { return(0); } } } } return(-1); }
public void Reset() { Iteration = 0; Node = null; }
public void AddConnection(string name, int index, InstructionGraphNode to) { Connections.Add(new ConnectionData(name, null, index, Node, to, Connections.Count)); UpdateBounds(); }
public void AddConnection(string name, string key, InstructionGraphNode to) { Connections.Add(new ConnectionData(name, key, -1, Node, to, Connections.Count)); UpdateBounds(); }
public NodeData(InstructionGraphNode node) { Node = node; UpdateBounds(); }
public virtual void SetConnection(ConnectionData connection, InstructionGraphNode target) { connection.ApplyConnection(this, target); }
public void GoTo(InstructionGraphNode node, string name, int index) { var source = string.Format("{0} {1}", name, index); GoTo(node, source); }
public void GoTo(InstructionGraphNode node, object thisObject, string name, string key) { var source = string.Format("{0} {1}", name, key); GoTo(node, thisObject, source); }
public bool IsExecuting(InstructionGraphNode node) { return(_callstack.Count > 0 && _callstack.Peek().Node == node); }
private void StartRunning(InstructionGraphNode root, string source) { }