예제 #1
0
        //========ID================================
        /// <summary>
        /// 通过ID获取节点引用
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public NodeModifier GetNextNodeByID(int id)
        {
            if (_id == id)
            {
                return(this);
            }

            for (int i = 0; i < _nextNodeList.Count; i++)
            {
                NodeModifier node = _nextNodeList[i];
                if (node == null)
                {
                    continue;
                }
                //if (IsParent(node)) continue;
                if (node.Parent != this)
                {
                    continue;
                }
                if (CompareNodeID(node, id))
                {
                    return(node);
                }

                NodeModifier node2 = node.GetNextNodeByID(id);
                if (node2 != null)
                {
                    return(node2);
                }
            }

            return(null);
        }
예제 #2
0
 /// <summary>
 /// 添加一个子节点
 /// </summary>
 /// <param name="next"></param>
 public void AddNextNode(NodeModifier next)
 {
     if (!_nextNodeList.Contains(next))
     {
         _nextNodeList.Add(next);
     }
 }
예제 #3
0
        protected override EnumResult OnUpdate()
        {
            if (_contenNodeList.Count == 0)
            {
                return(EnumResult.Success);
            }
            for (int i = 0; i < _contenNodeList.Count; i++)
            {
                if (i >= _contenNodeList.Count)
                {
                    break;
                }
                EnumResult result = _contenNodeList[i].Tick(this);

                if (result != EnumResult.Running)
                {
                    if (i >= _contenNodeList.Count)
                    {
                        break;
                    }
                    NodeModifier node = _contenNodeList[i];

                    if (result == EnumResult.Failed)
                    {
                        switch (node.RunMode)
                        {
                        case EnumRunMode.UntilSuccess:
                            continue;

                        case EnumRunMode.ReturnParentNode:
                            _toRemoveNode.Add(node);
                            _toAddNode.Add(node.Parent);
                            continue;

                        case EnumRunMode.StopNodeList:
                            _toRemoveNode.Add(node);
                            continue;
                        }
                    }

                    _toRemoveNode.Add(node);

                    //单独处理Decorator节点运行
                    //if (node is Decorator)
                    //{
                    //    //NodeModifier child = System.Array.Find<NodeModifier>(node.NextNodes, (n) => n.Parent == node);
                    //    //if (child != null)
                    //    //    _toAddNode.Add(child);
                    //    (node as Decorator).GetNextNodesFromDecorator(_toAddNode);
                    //}
                    //else
                    node.GetNextNodes(_toAddNode);
                }
            }

            ProcessNode();

            return(EnumResult.Running);
        }
예제 #4
0
 private bool CompareNodeID(NodeModifier node, int id)
 {
     if (node == null)
     {
         return(false);
     }
     return(node._id == id);
 }
예제 #5
0
        public override void GetNextNodes(List <NodeModifier> nodes)
        {
            NodeModifier node = _nextNodeList.Find(n => n.Parent == this);

            if (node != null)
            {
                nodes.Add(node);
            }
        }
예제 #6
0
 public static bool SetParent(NodeModifier node, NodeModifier parentNode)
 {
     if (node.CanSetParent(parentNode))
     {
         node.RemoveFromContent();
         node.DeleteParent();
         node.SetParent(parentNode);
         return(true);
     }
     return(false);
 }
예제 #7
0
        //Static=============================================
        //以下静态方法将会同时处理设置中的各项引用、依赖关系
        //<<<===============================================
        public static void Delete(NodeModifier node)
        {
            NodeModifier[] nodes = node.NextNodes;
            for (int i = 0; i < nodes.Length; i++)
            {
                node.Remove(nodes[i]);
            }

            node.DeleteParent();
            node.RemoveFromContent();
        }
예제 #8
0
        /// <summary>
        /// 删除其父节点
        /// </summary>
        public void DeleteParent()
        {
            if (_lastNode == null)
            {
                return;
            }
            _lastNode.Remove(this);
            _lastNode = null;

            DeleteSingleConnectChildNode();
        }
예제 #9
0
 /// <summary>
 /// 是否属于自身的父节点
 /// </summary>
 /// <param name="node">可能是父节点的节点</param>
 /// <returns></returns>
 public bool IsParent(NodeModifier node)
 {
     if (_lastNode == null)
     {
         return(false);
     }
     if (_lastNode == node)
     {
         return(true);
     }
     return(_lastNode.IsParent(node));
 }
예제 #10
0
 /// <summary>
 /// 父节点转化为Layer,即层级数(用于保存)
 /// </summary>
 /// <param name="parent"></param>
 /// <param name="layer"></param>
 /// <returns></returns>
 public int ParentToLayer(NodeModifier parent, int layer = 0)
 {
     layer++;
     if (this == parent)
     {
         return(layer);
     }
     if (_lastNode == null)
     {
         return(0);
     }
     return(_lastNode.ParentToLayer(parent, layer));
 }
예제 #11
0
        public override void GetNextNodes(List <NodeModifier> nodes)
        {
            if (_tempIndex > _nextNodeList.Count - 1)
            {
                return;
            }
            NodeModifier node = _nextNodeList[_tempIndex];

            if (node != null)
            {
                nodes.Add(node);
            }
        }
예제 #12
0
        public virtual void Deserialize(BinaryReader r)
        {
            UnityEngine.JsonUtility.FromJsonOverwrite(r.ReadString(), this);
            int count = r.ReadInt32();

            for (int i = 0; i < count; i++)
            {
                //int layer = r.ReadInt32();
                int          id           = r.ReadInt32();
                bool         isSingleNode = r.ReadBoolean();
                NodeModifier node;
                if (isSingleNode)
                {
                    node = GetContent().GetNodeByID(id);// GetTopParent().GetNextNodeByID(id);//LayerToParent(layer);
                    if (node != null)
                    {
                        _nextNodeList.Add(node);
                    }
                    else
                    {
                        GetContent().OnNodeLoaded += (con) =>
                        {
                            NodeModifier child = con.GetNodeByID(id);
                            if (child != null)
                            {
                                _nextNodeList.Add(child);
                            }
                        }
                    };
                }
                else
                {
                    string fullName = r.ReadString();
                    node = ReflectionHelper.CreateInstance <NodeModifier>(fullName);
                    if (node == null)
                    {
#if UNITY_EDITOR
                        UnityEngine.Debug.LogError("Error: The Mission Node [" + fullName + "] Was Lost!");
#endif
                        //return;
                        node = ReflectionHelper.CreateInstance <NodeModifier>("CryDialog.Runtime._MissingNode");
                    }

                    SetParent(node, this);
                    node.Deserialize(r);
                }
            }

            OnLoaded(r);
        }
예제 #13
0
 /// <summary>
 /// 若为容器,获取该容器中指定ID节点
 /// </summary>
 /// <param name="id"></param>
 /// <returns></returns>
 public NodeModifier GetNodeByID(int id)
 {
     for (int i = 0; i < _contenNodeList.Count; i++)
     {
         if (_contenNodeList[i]._id == id)
         {
             return(_contenNodeList[i]);
         }
         NodeModifier node = _contenNodeList[i].GetNextNodeByID(id);
         if (node != null)
         {
             return(node);
         }
     }
     return(null);
 }
예제 #14
0
 /// <summary>
 /// 将节点添加至该容器。注意:不会更改节点本身容器数据!
 /// 使用节点SetContent代替
 /// </summary>
 /// <param name="node"></param>
 /// <returns></returns>
 public bool AddContentNode(NodeModifier node)
 {
     if (_contenNodeList.Contains(node) || node == null)
     {
         return(false);
     }
     //不允许已运行节点的子节点添加
     //for (int i = 0; i < _contenNodeList.Count; i++)
     //{
     //    if (_contenNodeList[i].IsChild(node)) return false;
     //}
     _contenNodeList.Add(node);
     OnAddedContentNode(node);
     //node.SetContent(this);
     return(true);
 }
예제 #15
0
 /// <summary>
 /// 是否可以将指定节点设置为自身的父节点
 /// </summary>
 /// <param name="node"></param>
 /// <returns></returns>
 public bool CanSetParent(NodeModifier node)
 {
     if (node == this)
     {
         return(false);
     }
     if (node.IsChild(this, false))
     {
         return(false);
     }
     if (node.IsParent(this))
     {
         return(false);
     }
     return(true);
 }
예제 #16
0
        protected void RemoveChild(NodeContent content, NodeModifier node)
        {
            if (content.RemoveContenNode(node))
            {
                node.ForceStop();
            }

            NodeModifier[] nodes = node.NextNodes;
            for (int i = 0; i < nodes.Length; i++)
            {
                if (nodes[i].Parent != node)
                {
                    continue;
                }
                RemoveChild(content, nodes[i]);
            }
        }
예제 #17
0
        //Save
        protected override void OnSaved(BinaryWriter w)
        {
            base.OnSaved(w);

            bool running = _running;//_tempNodeList != null;

            //if (running) running = _tempNodeList.Length > 0;

            w.Write(running);
            if (running)
            {
                //Save Oringin Node
                //处于正在运行节点,保存初始节点及当前运行节点ID
                w.Write(_tempNodeList.Length);
                for (int i = 0; i < _tempNodeList.Length; i++)
                {
                    NodeModifier node = _tempNodeList[i];
                    System.Type  type = node.GetType();

                    w.Write(type.FullName);
                    node.Serialize(w);
                }

                w.Write(_contenNodeList.Count);
                for (int i = 0; i < _contenNodeList.Count; i++)
                {
                    w.Write(_contenNodeList[i]._id);
                }
            }
            else
            {
                //未运行节点,直接保存当前节点即可
                w.Write(_contenNodeList.Count);
                for (int i = 0; i < _contenNodeList.Count; i++)
                {
                    NodeModifier node = _contenNodeList[i];
                    System.Type  type = node.GetType();

                    w.Write(type.FullName);
                    node.Serialize(w);
                }
            }
        }
예제 #18
0
        //Save===========================================

        public virtual void Serialize(BinaryWriter w)
        {
            w.Write(UnityEngine.JsonUtility.ToJson(this));
            w.Write(_nextNodeList.Count);
            for (int i = 0; i < _nextNodeList.Count; i++)
            {
                NodeModifier node = _nextNodeList[i];
                w.Write(node._id);//(ParentToLayer(node));
                bool isSingleNode = node.Parent != this;
                w.Write(isSingleNode);
                if (!isSingleNode)
                {
                    w.Write(node.GetType().FullName);
                    node.Serialize(w);
                }
            }

            OnSaved(w);
        }
예제 #19
0
 /// <summary>
 /// 是否是属于该节点的子节点,将检查所有的链表
 /// </summary>
 /// <param name="node"></param>
 /// <param name="includeSingleNode">是否包括单方面链接的节点(父级具有子级,子级不具有父级)</param>
 /// <returns></returns>
 public bool IsChild(NodeModifier node, bool includeSingleNode = true)
 {
     if (includeSingleNode)
     {
         if (node._lastNode != this)
         {
             return(false);
         }
     }
     if (_nextNodeList.Contains(node))
     {
         return(true);
     }
     for (int i = 0; i < _nextNodeList.Count; i++)
     {
         if (_nextNodeList[i].IsChild(node))
         {
             return(true);
         }
     }
     return(false);
 }
예제 #20
0
        protected override void OnLoaded(BinaryReader r)
        {
            //清空当前容器节点,避免被重复添加
            _contenNodeList.Clear();

            base.OnLoaded(r);
            bool running = r.ReadBoolean();

            //恢复初始节点
            int count = r.ReadInt32();

            for (int i = 0; i < count; i++)
            {
                string       fullName = r.ReadString();
                NodeModifier node     = ReflectionHelper.CreateInstance <NodeModifier>(fullName);
                if (node == null)
                {
                    node = ReflectionHelper.CreateInstance <NodeModifier>("CryDialog.Runtime._MissingNode");
                    //It's mission
                    //return;
                }
                node.SetContent(this);
                node.Deserialize(r);
                NodeModifier.SetContent(node, this);
            }

            if (running)
            {
                //恢复运行节点(以ID为主)
                count = r.ReadInt32();
                List <NodeModifier> runningNode = new List <NodeModifier>();
                for (int i = 0; i < count; i++)
                {
                    for (int j = 0; j < _contenNodeList.Count; j++)
                    {
                        NodeModifier node = _contenNodeList[j].GetNextNodeByID(r.ReadInt32());
                        if (node != null)
                        {
                            runningNode.Add(node);
                            break;
                        }
                    }
                }

                //装填缓存节点
                _tempNodeList = _contenNodeList.ToArray();

                //移除初始节点
                for (int i = 0; i < _tempNodeList.Length; i++)
                {
                    RemoveContenNode(_tempNodeList[i]);
                }

                //重新加入已运行节点
                for (int i = 0; i < runningNode.Count; i++)
                {
                    AddContentNode(runningNode[i]);
                }
            }

            if (OnNodeLoaded != null)
            {
                OnNodeLoaded.Invoke(this);
            }
        }
예제 #21
0
 protected virtual void OnAddedContentNode(NodeModifier node)
 {
 }
예제 #22
0
 /// <summary>
 /// 删除一个节点
 /// </summary>
 public bool RemoveContenNode(NodeModifier node)
 {
     return(_contenNodeList.Remove(node));
 }
예제 #23
0
 /// <summary>
 ///设置父节点
 /// </summary>
 /// <param name="node"></param>
 public void SetParent(NodeModifier node)
 {
     node.AddNextNode(this);
     _lastNode = node;
 }
예제 #24
0
 /// <summary>
 /// 删除指定子节点
 /// </summary>
 /// <param name="node"></param>
 public void Remove(NodeModifier node)
 {
     _nextNodeList.Remove(node);
 }
예제 #25
0
 public static void SetContent(NodeModifier node, NodeContent content)
 {
     node.RemoveFromContent();
     node.DeleteParent();
     node.SetContent(content);
 }
예제 #26
0
 /// <summary>
 /// 获取指定节点的父节点是自身,并且指定节点并非子节点的父节点的子节点
 /// </summary>
 /// <param name="node"></param>
 /// <returns></returns>
 public NodeModifier[] GetNextNodes(NodeModifier node)
 {
     return(_nextNodeList.FindAll((n) => !node.IsParent(n) && n.Parent == node).ToArray());
 }
예제 #27
0
 public static void SetToDefaltContent(NodeModifier node)
 {
     SetContent(node, node.GetContent());
 }