예제 #1
0
        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();
        }
예제 #2
0
        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);
        }
예제 #3
0
 public override void SetConnection(ConnectionData connection, InstructionGraphNode target)
 {
     foreach (var node in Connections)
     {
         if (node.Name == connection.Name)
         {
             node.Node = target;
         }
     }
 }
예제 #4
0
        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);
            }
        }
예제 #5
0
        private bool IsNodeInStack(InstructionGraphNode node)
        {
            foreach (var frame in _callstack)
            {
                if (frame.Node == node)
                {
                    return(true);
                }
            }

            return(false);
        }
예제 #6
0
        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;
        }
예제 #7
0
        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);
        }
예제 #8
0
            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);
                }
            }
예제 #9
0
 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);
     }
 }
예제 #10
0
 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);
     }
 }
예제 #11
0
            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;
                }
            }
예제 #12
0
        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);
        }
예제 #13
0
 public void Reset()
 {
     Iteration = 0;
     Node      = null;
 }
예제 #14
0
 public void AddConnection(string name, int index, InstructionGraphNode to)
 {
     Connections.Add(new ConnectionData(name, null, index, Node, to, Connections.Count));
     UpdateBounds();
 }
예제 #15
0
 public void AddConnection(string name, string key, InstructionGraphNode to)
 {
     Connections.Add(new ConnectionData(name, key, -1, Node, to, Connections.Count));
     UpdateBounds();
 }
예제 #16
0
 public NodeData(InstructionGraphNode node)
 {
     Node = node;
     UpdateBounds();
 }
예제 #17
0
 public virtual void SetConnection(ConnectionData connection, InstructionGraphNode target)
 {
     connection.ApplyConnection(this, target);
 }
예제 #18
0
        public void GoTo(InstructionGraphNode node, string name, int index)
        {
            var source = string.Format("{0} {1}", name, index);

            GoTo(node, source);
        }
예제 #19
0
        public void GoTo(InstructionGraphNode node, object thisObject, string name, string key)
        {
            var source = string.Format("{0} {1}", name, key);

            GoTo(node, thisObject, source);
        }
예제 #20
0
 public bool IsExecuting(InstructionGraphNode node)
 {
     return(_callstack.Count > 0 && _callstack.Peek().Node == node);
 }
예제 #21
0
 private void StartRunning(InstructionGraphNode root, string source)
 {
 }