예제 #1
0
        public static NodeParam GetNodeParam(Type nodeType, int nodeID, int srcTreeID, bool isClient)
        {
            NodeParam p = default(NodeParam);

            TryGetNodeParam(nodeType, nodeID, srcTreeID, isClient, out p);
            return(p);
        }
예제 #2
0
        private NodeParam NodeParamClone(NodeParam src)
        {
            NodeParam p = new NodeParam()
            {
                NodeType      = src.NodeType,
                NodeDesc      = src.NodeDesc,
                NodeClassType = src.NodeClassType,
                Parent        = src.Parent,
                NodeID        = ++_maxID,
                SrcTreeID     = _treeID
            };

            foreach (ParamInfo pi in src.Fields)
            {
                p.Fields.Add(pi.Clone());
            }

            foreach (ParamInfoOutput pi in src.Outputs)
            {
                p.Outputs.Add(pi.Clone(p));
            }

            foreach (ParamInfoInput input in src.Inputs)
            {
                p.Inputs.Add(input.Clone());
            }

            _id2Node.Add(p.NodeID, p);
            foreach (NodeParam child in src.ChildrenList)
            {
                NodeParam cloneChild = NodeParamClone(child);
                cloneChild.SetParent(p);
            }
            return(p);
        }
예제 #3
0
        public bool CopyChild(NodeParam newRoot, NodeParam target)
        {
            NodeParam        rootParent = newRoot.Parent;
            NodeClassifyType rootType   = newRoot.NodeClassType;

            if (rootType == NodeClassifyType.Action || rootType == NodeClassifyType.Condition || rootType == NodeClassifyType.DataTransform)
            {
                return(false);
            }
            while (rootParent != null)
            {
                if (rootParent == target)
                {
                    return(false);
                }
                rootParent = rootParent.Parent;
            }

            NodeParam newNode = NodeParamClone(target);

            newNode.SetParent(newRoot);
            InitNodeOutputAvailable();

            return(true);
        }
예제 #4
0
        private void CutAndCopy(BeTreeNode arg1, BeTreeNode arg2)
        {
            RunTimeNodeData data1 = _datas[arg1.SrcTreeID];
            RunTimeNodeData data2 = _datas[arg2.SrcTreeID];

            NodeParam root = data1.GetNodeParam(arg1.NodeID);
            NodeParam copy = data2.GetNodeParam(arg2.NodeID);

            if (!data1.CopyChild(root, copy))
            {
                return;
            }
            data2.DeleteNode(copy.NodeID);

            if (data1 == data2)
            {
                _id2Windows[data1.ID].Canvas.RefreshNodeParam(data1.Root);
                SetNodeShowValue(data1.ID);
            }
            else
            {
                _id2Windows[data1.ID].Canvas.RefreshNodeParam(data1.Root);
                _id2Windows[data2.ID].Canvas.RefreshNodeParam(data2.Root);
                SetNodeShowValue(data1.ID);
                SetNodeShowValue(data2.ID);
            }
        }
예제 #5
0
        private static NodeParam NodeParamClone(NodeParam src, int nodeID, int srcTreeID)
        {
            NodeParam p = new NodeParam()
            {
                NodeType      = src.NodeType,
                NodeDesc      = src.NodeDesc,
                NodeClassType = src.NodeClassType,
                NodeID        = nodeID,
                SrcTreeID     = srcTreeID
            };

            foreach (var item in src.Fields)
            {
                p.Fields.Add(item.Clone());
            }

            foreach (var item in src.Inputs)
            {
                p.Inputs.Add(item.Clone());
            }

            foreach (var item in src.Outputs)
            {
                p.Outputs.Add(item.Clone(p));
            }

            return(p);
        }
예제 #6
0
        private NodeParam CreateEmptyNode(int nodeID)
        {
            NodeParam param = NodeInfoManager.GetErrorParam(nodeID, _treeID);

            _id2Node.Add(nodeID, param);
            return(param);
        }
예제 #7
0
        private NodeParam CreateNodeParam(Type nodeType, int nodeID)
        {
            NodeParam param = NodeInfoManager.GetNodeParam(nodeType, nodeID, _treeID, _isClient);

            _id2Node.Add(nodeID, param);
            return(param);
        }
 /// <summary>
 /// 刷新一个节点(没有层级关系)
 /// </summary>
 /// <param name="node"></param>
 /// <param name="param"></param>
 public static void RefreshBTNWithParam(this BeTreeNode node, NodeParam param)
 {
     _dict.Remove(node.NodeID);
     node.SrcTreeID = param.SrcTreeID;
     node.NodeID    = param.NodeID;
     _dict.Add(node.NodeID, node);
 }
예제 #9
0
        public bool Replace(int srcNodeID, Type rpType)
        {
            NodeParam param   = _id2Node[srcNodeID];
            NodeParam rpParam = NodeInfoManager.GetNodeParam(rpType, 0, 0, _isClient);

            param.Replace(rpParam);
            return(true);
        }
예제 #10
0
        private void OnNodeClick(BeTreeNode node)
        {
            int             index = node.SrcTreeID;
            RunTimeNodeData data  = _datas[index];
            NodeParam       param = data.GetNodeParam(node.NodeID);

            _curOpenningCtrl.Canvas.ShowDetialPanel(param, data.GetParamOutput(param));
        }
예제 #11
0
        public void AddChild(int nodeID, Type childType)
        {
            NodeParam param  = CreateNodeParam(childType);
            NodeParam parent = _id2Node[nodeID];

            param.SetParent(parent);
            InitNodeOutputAvailable();
        }
예제 #12
0
 public void SetNodeShowValue(int id)
 {
     _id2Windows[id].Canvas.ForeachNode(node =>
     {
         int index            = node.SrcTreeID;
         RunTimeNodeData data = _datas[index];
         NodeParam param      = data[node.NodeID];
         node.NodeTypeSet(param);
     });
 }
        /// <summary>
        /// 创建一个节点(没有层级关系)
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        private static BeTreeNode CreateBTN(this NodeParam param)
        {
            BeTreeNode btn = NodeFactoryXML.CreateEditorControl <BeTreeNode>();

            btn.SrcTreeID    = param.SrcTreeID;
            btn.NodeID       = param.NodeID;
            btn.ChildrenShow = param.IsShowChild;
            btn.Active       = param.IsShow;
            _dict.Add(btn.NodeID, btn);
            return(btn);
        }
예제 #14
0
        public void DeleteNode(int nodeID)
        {
            NodeParam node = _id2Node[nodeID];

            if (node == _root)
            {
                return;
            }
            RemoveNode(nodeID);

            InitNodeOutputAvailable();
        }
        public ParamInfoOutput Clone(NodeParam newParam)
        {
            ParamInfoOutput p = new ParamInfoOutput()
            {
                OutputFieldName = OutputFieldName,
                Desc            = Desc,
                OutputType      = OutputType,
                OutputName      = OutputName,
            };

            p.SrcParam = newParam;
            return(p);
        }
예제 #16
0
        public bool Insert(NodeParam node, NodeParam insertNode)
        {
            if (insertNode.Parent != node.Parent || insertNode.Parent == null)
            {
                return(false);
            }

            int index = node.Parent.ChildrenList.IndexOf(node);

            insertNode.InsertParent(insertNode.Parent, index);
            InitNodeOutputAvailable();
            return(true);
        }
예제 #17
0
        public void InitBehaviourTree(NodeParam param)
        {
            Dictionary <int, BeTreeNode> id2Node;

            if (!_srcNode.TryGetValue(param.SrcTreeID, out id2Node))
            {
                id2Node = new Dictionary <int, BeTreeNode>();
                _srcNode.Add(param.SrcTreeID, id2Node);
            }
            BeTreeNode node = NodeParamCreatorHelper.CreateTree(param, this, id2Node);

            NodeList.Add(node.SrcTreeID, node);
            ReCalculateNode();
        }
예제 #18
0
        public void ShowDetialPanel(NodeParam param, NodeParamIOData infos)
        {
            BeTreeNode node = _srcNode[param.SrcTreeID][param.NodeID];

            if (!NodeSelectedPanel.Active && !SelectedNode(GetBtnFromParam(param)))
            {
                DetialPanel.Hide();
                return;
            }
            Vector2 pos = node.LocalPosition + NodePanels.LocalPosition + new Vector2(node.Size.x, 0);

            DetialPanel.LocalPosition      = pos;
            DetialBackground.LocalPosition = pos;
            NodeSelectedPanel.Active       = false;
            DetialPanel.Show(param, infos);
        }
예제 #19
0
        public void InitNodeOutputAvailable()
        {
            _infoDatas.Clear();
            NodeParamIOData   initData  = new NodeParamIOData();
            Stack <NodeParam> nodeStack = new Stack <NodeParam>();

            nodeStack.Push(_root);

            while (nodeStack.Count > 0)
            {
                NodeParam node = nodeStack.Pop();

                foreach (ParamInfoInput input in node.Inputs)
                {
                    List <ParamInfoOutput> ps = initData[input.InputType];
                    if (ps == null || input.Input != null && !ps.Contains(input.Input))
                    {
                        input.Input = null;
                    }

                    if (!string.IsNullOrEmpty(input.SrcInputStr) && input.Input == null)
                    {
                        foreach (var p in ps)
                        {
                            if (p.OutputName == input.SrcInputStr)
                            {
                                input.Input = p;
                                break;
                            }
                        }
                    }
                }

                _infoDatas.Add(node, initData.Clone());

                foreach (ParamInfoOutput paramInfo in node.Outputs)
                {
                    initData.AddParam(paramInfo.OutputType, paramInfo);
                }

                for (int i = node.ChildrenList.Count - 1; i >= 0; --i)
                {
                    nodeStack.Push(node.ChildrenList[i]);
                }
            }
        }
예제 #20
0
        private void RemoveNode(int id)
        {
            NodeParam         node  = _id2Node[id];
            Queue <NodeParam> queue = new Queue <NodeParam>();

            queue.Enqueue(node);
            while (queue.Count > 0)
            {
                NodeParam n = queue.Dequeue();
                n.SetParent(null);
                _id2Node.Remove(n.NodeID);
                foreach (NodeParam child in n.ChildrenList)
                {
                    queue.Enqueue(child);
                }
            }
            node.SetParent(null);
        }
        public void Show(NodeParam node, NodeParamIOData infos)
        {
            GUI.FocusControl("强制测试用名");
            Active = true;
            _node  = node;
            _infos = infos;

            _outputs.Clear();
            _typeIndexSelection.Clear();
            _typeIndexShow.Clear();

            foreach (ParamInfoInput pair in _node.Inputs)
            {
                List <ParamInfoOutput> outputs;
                if (!_outputs.TryGetValue(pair.InputType, out outputs))
                {
                    outputs = _infos[pair.InputType];
                    _outputs.Add(pair.InputType, outputs);
                }

                List <string> shows = new List <string>();
                foreach (ParamInfoOutput output in outputs)
                {
                    shows.Add($"{output.OutputName}");
                }

                if (shows.Count > 0)
                {
                    if (pair.Input != null)
                    {
                        int index = outputs.IndexOf(pair.Input);
                        _typeIndexSelection.Add(pair, index);
                    }
                    else
                    {
                        shows.Insert(0, NONE_SELECTED);
                        _typeIndexSelection.Add(pair, 0);
                    }
                    _typeIndexShow.Add(pair, shows.ToArray());
                }
            }
        }
예제 #22
0
        private void Show()
        {
            while (_selectionButtons.Count < _showStr.Length)
            {
                _selectionButtons.Add(CreateButton(_selectionButtons.Count));
            }

            for (int i = 0; i < _selectionButtons.Count; ++i)
            {
                EditorButton button = _selectionButtons[i];
                if (_showStr.Length <= i)
                {
                    button.Active = false;
                    continue;
                }
                button.Active = true;
                NodeParam str = _showStr[i];
                button.Content = str;
            }
        }
        public static BeTreeNode CreateTree(NodeParam root, TreeNodeCanvas canvas, Dictionary <int, BeTreeNode> dict)
        {
            _canvas = canvas;
            _dict   = dict;

            List <int> ids = new List <int>(dict.Keys);

            foreach (int id in ids)
            {
                dict[id].RemoveBTN();
            }

            Queue <NodeParam> queue = new Queue <NodeParam>();

            queue.Enqueue(root);
            BeTreeNode rootNode = null;

            while (queue.Count > 0)
            {
                NodeParam  p    = queue.Dequeue();
                BeTreeNode pBtn = p.CreateBTN();
                pBtn.DeployNodeEvent();
                if (p.Parent == null)
                {
                    rootNode = pBtn;
                    rootNode.SetParent(canvas.NodePanels);
                }
                else
                {
                    dict[p.Parent.NodeID].AddChild(pBtn, _canvas.NodePanels);
                }

                foreach (NodeParam child in p.ChildrenList)
                {
                    queue.Enqueue(child);
                }
            }

            return(rootNode);
        }
        public void NodeTypeSet(NodeParam param)
        {
            _param = param;

            if (EditorTreeConfigHelper.Instance.Config.ShowTreeID)
            {
                NodeIDText.Content = $"{param.NodeID}({param.SrcTreeID})";
            }
            else
            {
                NodeIDText.Content = $"{param.NodeID}";
            }
            TypeName.Content = param.NodeType.Name;
            TypeDesc.Content = param.NodeDesc;

            switch (param.NodeClassType)
            {
            case NodeClassifyType.Action:
            case NodeClassifyType.Condition:
            case NodeClassifyType.DataTransform:
                ShowCloseFlag.Active = false;
                BgImg.Bg             = LeafNode;
                break;

            case NodeClassifyType.Composite:
            case NodeClassifyType.Decorator:
                ShowCloseFlag.Active = true;
                BgImg.Bg             = NoneLeaf;
                break;

            case NodeClassifyType.Root:
                ShowCloseFlag.Active = true;
                BgImg.Bg             = RootNode;
                break;
            }

            ErrorCheck();
        }
예제 #25
0
        private bool SaveCheck()
        {
            Queue <NodeParam> queue = new Queue <NodeParam>();

            queue.Enqueue(Root);
            while (queue.Count > 0)
            {
                NodeParam p = queue.Dequeue();
                foreach (var input in p.Inputs)
                {
                    if (input.Input == null)
                    {
                        BehaviourTreeDebugPanel.Error($"{p.NodeID}的输入不能为空");
                        return(false);
                    }
                }

                foreach (var child in p.ChildrenList)
                {
                    queue.Enqueue(child);
                }
            }
            return(true);
        }
예제 #26
0
        public void Replace(NodeParam newParam)
        {
            TypeDesc      = newParam.TypeDesc;
            NodeType      = newParam.NodeType;
            NodeClassType = newParam.NodeClassType;

            Fields.Clear();
            foreach (ParamInfo info in newParam.Fields)
            {
                Fields.Add(info.Clone());
            }

            Inputs.Clear();
            foreach (ParamInfoInput input in newParam.Inputs)
            {
                Inputs.Add(input.Clone());
            }

            Outputs.Clear();
            foreach (ParamInfoOutput output in newParam.Outputs)
            {
                Outputs.Add(output.Clone(this));
            }
        }
예제 #27
0
 public BeTreeNode GetBtnFromParam(NodeParam param)
 {
     return(_srcNode[param.SrcTreeID][param.NodeID]);
 }
예제 #28
0
 public void SetParent(NodeParam root)
 {
     Parent?._childList.Remove(this);
     Parent = root;
     root?._childList.Add(this);
 }
예제 #29
0
 public void InsertParent(NodeParam root, int index)
 {
     Parent?._childList.Remove(this);
     Parent = root;
     root?._childList.Insert(index, this);
 }
        public void OnGUI()
        {
            _name = EditorDataFields.EditorDataField("名字", _name);

            using (new EditorHorizontalLayout())
            {
                if (GUILayout.Button("搜索客户端"))
                {
                    bool get = false;
                    _goes.Clear();
                    _files.Clear();
                    foreach (NodeParam param in _nodes)
                    {
                        if (param.NodeType.Name == _name)
                        {
                            get       = true;
                            _selected = param;
                            break;
                        }
                    }

                    if (get)
                    {
                        List <string> paths = EditorResHelper.GetAllPath("Assets", true);
                        foreach (string path in paths)
                        {
                            GameObject         go     = AssetDatabase.LoadAssetAtPath <GameObject>(path);
                            BehaviorTreeConfig config = go.GetComponent <BehaviorTreeConfig>();
                            if (!config)
                            {
                                continue;
                            }

                            NodeProto         p     = config.RootNodeProto;
                            Stack <NodeProto> stack = new Stack <NodeProto>();
                            stack.Push(p);

                            while (stack.Count > 0)
                            {
                                NodeProto node = stack.Pop();
                                if (node.Name == _name)
                                {
                                    _goes.Add(go);
                                    break;
                                }

                                foreach (NodeProto child in node.Children)
                                {
                                    stack.Push(child);
                                }
                            }
                        }
                    }
                    else
                    {
                        _selected = null;
                    }
                }
                if (GUILayout.Button("搜索服务器"))
                {
                    string path = EditorTreeConfigHelper.Instance.Config.ServersPath;
                    bool   get  = false;
                    _goes.Clear();
                    _files.Clear();
                    foreach (NodeParam param in _nodes)
                    {
                        if (param.NodeType.Name == _name)
                        {
                            get       = true;
                            _selected = param;
                            break;
                        }
                    }

                    if (get)
                    {
                        string[] files = Directory.GetFiles(path, "*.txt");
                        foreach (string file in files)
                        {
                            try
                            {
                                StreamReader      reader = new StreamReader(file);
                                string            data   = reader.ReadToEnd();
                                NodeProto         p      = MongoHelper.FromJson <NodeProto>(data);
                                Queue <NodeProto> queue  = new Queue <NodeProto>();
                                queue.Enqueue(p);
                                while (queue.Count > 0)
                                {
                                    NodeProto node = queue.Dequeue();
                                    if (node.Name == _name)
                                    {
                                        _files.Add(file);
                                        break;
                                    }

                                    foreach (NodeProto child in node.Children)
                                    {
                                        queue.Enqueue(child);
                                    }
                                }
                            }
                            catch (Exception err)
                            {
                                BehaviourTreeDebugPanel.Error($"文件({file})无法解析成行为树");
                                Log.Error(err);
                            }
                        }
                    }
                }
            }

            if (_selected == null)
            {
                EditorGUILayout.LabelField("请输入节点名称,不需要命名空间");
                return;
            }
            if (_goes.Count > 0)
            {
                EditorDataFields.EditorListDataField(_goes, 20);
            }
            else if (_files.Count > 0)
            {
                EditorDataFields.EditorListDataField(_files, 20);
            }
        }