コード例 #1
0
        /// <summary>
        /// Take the Top node and make it the left or right child.
        /// Take the left or right child and make it top node.
        /// </summary>
        /// <param name="side"></param>
        /// <param name="meta"></param>
        /// <returns></returns>
        private NodeMeta RotateToChild(Side side, NodeMeta meta)
        {
            var otherSide = OtherSide(side);

            // Three nodes to rotate
            Node oldParent = meta.Node;
            Node newParent = oldParent[otherSide];
            Node child     = newParent[side];

            newParent[side] = oldParent;
            //            newParent[otherSide] = oldParent[otherSide];
            oldParent[otherSide] = child;

            NodeMeta grandParentMeta = meta.ParentMeta;

            if (grandParentMeta == null)
            {
                SetRoot(newParent);
            }
            else
            {
                Node grandParent = grandParentMeta.Node;
                grandParent[meta.SideFromParent] = newParent;
            }

            return(grandParentMeta);
        }
コード例 #2
0
        private NodeMeta Remove(NodeMeta meta)
        {
            Node node  = meta.Node;
            Side side  = Side.Left;
            Node child = node[side];

            if (child == null)
            {
                side  = Side.Right;
                child = node[side];
            }
            if (child == null)
            {
                // adjust color through parent.
                if (node.Color == Color.Black)
                {
                    // Black-Black
                    var sentinel = new SentinelNode();
                    meta.ParentMeta.Node[meta.SideFromParent] = sentinel;
                    var sentinelMeta = new NodeMeta(meta.ParentMeta, sentinel, meta.SideFromParent, meta.Sibling);
                    return(sentinelMeta);
                }
                else
                {
                    // Red with Black Parent. Done.
                    meta.ParentMeta.Node[meta.SideFromParent] = null;
                    return(null);
                }
            }
            else
            {
                NodeMeta leaf = SwapWithAdjacent(meta, side);
                return(Remove(leaf));
            }
        }
コード例 #3
0
ファイル: GraphDesigner.cs プロジェクト: HusKka/NiuNiu
        private void CreateNode()
        {
            NodeMeta         nodeProto = BTEditor.Instance.GetComponent <BTNodeInfoComponent>().GetNodeMeta(BTEditor.Instance.selectNodeName);
            BehaviorNodeData nodeData  = BTEditor.Instance.CreateNode(nodeProto.name);

            CreateNode(nodeData, MousePosToGraphPos(mMousePos));
        }
コード例 #4
0
ファイル: BTNodeInfoComponent.cs プロジェクト: ajue/ETGame
        public NodeMeta GetNodeMeta(string nodeName)
        {
            NodeMeta nodeMeta = null;

            this.nameNodeMetas.TryGetValue(nodeName, out nodeMeta);
            return(nodeMeta);
        }
コード例 #5
0
ファイル: GraphDesigner.cs プロジェクト: ycllz/Egametang
        private void CreateNode()
        {
            NodeMeta         nodeProto = BTEntity.Instance.GetNodeMeta(BTEntity.Instance.selectNodeName);
            BehaviorNodeData nodeData  = BTEntity.Instance.CreateNode((int)BTEntity.Instance.CurTree.Id, nodeProto.name);

            CreateNode(nodeData, MousePosToGraphPos(mMousePos));
        }
コード例 #6
0
 public NodeMeta(NodeMeta parentMeta, Node node, Side sideFromParent, Node sibling)
 {
     this.ParentMeta     = parentMeta;
     this.Node           = node;
     this.SideFromParent = sideFromParent;
     this.Sibling        = sibling;
 }
コード例 #7
0
        private NodeMeta RotateToGrandChild(Side side, NodeMeta meta)
        {
            var otherSide = OtherSide(side);

            // Three nodes to rotate
            Node oldParent = meta.Node;
            Node newParent = oldParent[otherSide][side];
            Node child     = newParent[side];


            newParent[side]      = oldParent;
            newParent[otherSide] = oldParent[otherSide];
            oldParent[otherSide] = child;

            oldParent[otherSide] = child;
            newParent[side]      = oldParent;

            NodeMeta parentMeta = meta.ParentMeta;

            if (parentMeta == null)
            {
                _root           = newParent;
                newParent.Color = Color.Black;
            }
            else
            {
                Node nextLevelUp = parentMeta.Node;
                nextLevelUp[meta.ParentMeta.SideFromParent] = newParent;
            }

            return(parentMeta);
        }
コード例 #8
0
ファイル: GraphDesigner.cs プロジェクト: HusKka/NiuNiu
        //有待优化
        private void ChangeNodeType(object obj)
        {
            string           nodeType  = (string)obj;
            NodeMeta         nodeProto = BTEditor.Instance.GetComponent <BTNodeInfoComponent>().GetNodeMeta(nodeType);
            BehaviorNodeData nodeData  = BTEditor.Instance.CreateNode(nodeProto.name);
            NodeDesigner     oldNode   = mSelectedNode;
            NodeDesigner     newNode   = new NodeDesigner(nodeData);

            if (oldNode == RootNode)
            {
                newNode.NodeData.Id = RootNode.NodeData.Id;
                RootNode            = newNode;
                BehaviorTreeData oldTree = BTEditor.Instance.CurTree;
                BehaviorTreeData newTree = new BehaviorTreeData()
                {
                    classify = oldTree.classify,
                    Root     = nodeData
                };
                BTEditor.Instance.CurTree = newTree;
            }
            else
            {
                int idx = oldNode.Parent.Children.IndexOf(oldNode);
                oldNode.Parent.AddChild(newNode, idx);
                oldNode.Parent.RemoveChild(oldNode);
            }

            foreach (NodeDesigner child in oldNode.Children)
            {
                newNode.AddChild(child);
            }
            BTEditor.Instance.ResetTreeId();
            Game.EventSystem.Run(EventIdType.BehaviorTreeAfterChangeNodeType);
        }
コード例 #9
0
ファイル: GraphDesigner.cs プロジェクト: HusKka/NiuNiu
 private static int CompareShowName(NodeMeta nodeType1, NodeMeta nodeType2)
 {
     if (string.IsNullOrEmpty(nodeType1.name) || string.IsNullOrEmpty(nodeType2.name))
     {
         Log.Error("字符串输入参数有误");
     }
     return(String.CompareOrdinal(nodeType1.name, nodeType2.name));
 }
コード例 #10
0
ファイル: GraphDesigner.cs プロジェクト: ycllz/Egametang
        public void onCreateNode(params object[] list)
        {
            string  name = (string)list[0];
            Vector2 pos  = (Vector2)list[1];

            NodeMeta         nodeProto = BTEntity.Instance.GetNodeMeta(name);
            BehaviorNodeData nodeData  = BTEntity.Instance.CreateNode((int)BTEntity.Instance.CurTree.Id, nodeProto.name);

            CreateNode(nodeData, pos);
        }
コード例 #11
0
ファイル: GraphDesigner.cs プロジェクト: HusKka/NiuNiu
        public void onCreateNode(params object[] list)
        {
            string  nodeName = (string)list[0];
            Vector2 pos      = (Vector2)list[1];

            NodeMeta         nodeProto = BTEditor.Instance.GetComponent <BTNodeInfoComponent>().GetNodeMeta(nodeName);
            BehaviorNodeData nodeData  = BTEditor.Instance.CreateNode(nodeProto.name);

            CreateNode(nodeData, pos);
        }
コード例 #12
0
 /// <summary>
 /// Additional public method overload to simplify node meta creation
 /// </summary>
 public void AddChildComposite(RobotChassis value, string containerName)
 {
   var meta = new NodeMeta
   {
     Name = Guid.NewGuid().ToString(),
     GroupName = GROUP_NAME,
     DisplayName = containerName
   };
   base.AddChildComposite(value, meta);
 }
コード例 #13
0
        private NodeMeta GetNodeMeta(T node)
        {
            NodeMeta metaData = null;

            if (!this.metaData.TryGetValue(node, out metaData))
            {
                metaData = new NodeMeta(node);
                this.metaData.Add(node, metaData);
            }

            return(metaData);
        }
コード例 #14
0
        private NodeMeta GetFillData(T node)
        {
            NodeMeta nodeMeta = null;

            if (!fillData.TryGetValue(node, out nodeMeta))
            {
                nodeMeta       = new NodeMeta(node);
                fillData[node] = nodeMeta;
            }

            return(nodeMeta);
        }
コード例 #15
0
 public void Delete(int value)
 {
     if (root == null)
     {
         // Do nothing. Not found.
     }
     else
     {
         var meta    = new NodeMeta(root);
         var removed = Remove(meta, value);
         BalanceTree(removed);
     }
 }
コード例 #16
0
        private void RemoveDoubleBlack(NodeMeta meta)
        {
            Node node = meta.Node;

            if (node is SentinelNode)
            {
                meta.ParentMeta.Node[meta.SideFromParent] = null;
            }
            else
            {
                node.Color = Color.Black;
            }
        }
コード例 #17
0
        private NodeMeta Adjacent(Side side, NodeMeta meta)
        {
            Node node         = meta.Node;
            Side otherSide    = OtherSide(side);
            var  adjacent     = node[side];
            var  adjacentMeta = new NodeMeta(meta, adjacent, side, node[otherSide]);

            for (Node iter = adjacent; iter != null; iter = iter[otherSide])
            {
                adjacent     = iter;
                adjacentMeta = new NodeMeta(meta, adjacent, side, node[side]);
            }
            return(adjacentMeta);
        }
コード例 #18
0
        /// <summary>
        /// Building Field2 Node
        /// </summary>
        /// <param name="displayName">Optional, defaults to field's property name when empty or null</param>
        /// <returns>Value Node for Field2 </returns>
        public Node BuildNode_Field2(string displayName = null)
        {
            NodeMeta meta = new NodeMeta(BuildNodeId_Field2());

            SetCommonAttributes(meta);
            if (string.IsNullOrWhiteSpace(displayName))
            {
                displayName =
                    GetNodeIdCodes(_nodeIdField)
                    .Aggregate("Field2", (current, code) => current + " " + code);
            }
            meta.Name = displayName;
            return(Node.NewValue(meta, ValueSource.Entity, Convert.ToDecimal(_field2)));
        }
コード例 #19
0
        private void AddNeighbours(NodeMeta nodeMeta)
        {
            foreach (var pathfindingNode in nodeMeta.Node.GetNeighbours())
            {
                var neighbour = (T)pathfindingNode;

                NodeMeta neighNodeMeta = GetFillData(neighbour);
                if (!frontier.Contains(neighNodeMeta) && traverser.CanTraverse(neighNodeMeta.Node))
                {
                    neighNodeMeta.GCost = nodeMeta.GCost + traverser.GetTraverseCost(nodeMeta.Node, neighNodeMeta.Node);
                    frontier.Add(neighNodeMeta);
                }
            }
        }
コード例 #20
0
        public void Insert(int value)
        {
            var newNode = new Node(value);

            if (root == null)
            {
                SetRoot(newNode);
            }
            else
            {
                var meta = new NodeMeta(root);
                Insert(meta, newNode);
            }
        }
コード例 #21
0
        private void Insert(NodeMeta meta, Node newNode)
        {
            var  node  = meta.Node;
            Side side  = newNode.Value < node.Value ? Side.Left : Side.Right;
            Node child = node[side];

            if (child == null)
            {
                node[side] = newNode;
                BalanceTree(new NodeMeta(meta, newNode, side, node[OtherSide(side)]));
            }
            else
            {
                Insert(new NodeMeta(meta, child, side, node[OtherSide(side)]), newNode);
            }
        }
コード例 #22
0
ファイル: NodeMetaHelper.cs プロジェクト: AlunWorker/ET-
        public static Dictionary <string, NodeMeta> ExportToDict()
        {
            Dictionary <string, NodeMeta> name2NodeProtoDict = new Dictionary <string, NodeMeta>();
            List <Type> types = Game.EventSystem.GetTypes();

            foreach (Type type in types)
            {
                NodeMeta proto = GetNodeTypeProtoFromType(type);
                if (proto == null)
                {
                    continue;
                }
                name2NodeProtoDict.Add(proto.name, proto);
            }
            return(name2NodeProtoDict);
        }
コード例 #23
0
        public static Dictionary <string, NodeMeta> ExportToDict()
        {
            Dictionary <string, NodeMeta> name2NodeProtoDict = new Dictionary <string, NodeMeta>();

            Type[] types = DllHelper.GetMonoTypes();
            foreach (Type type in types)
            {
                NodeMeta proto = GetNodeTypeProtoFromType(type);
                if (proto == null)
                {
                    continue;
                }
                name2NodeProtoDict.Add(proto.name, proto);
            }
            return(name2NodeProtoDict);
        }
コード例 #24
0
        private NodeMeta SwapWithAdjacent(NodeMeta meta, Side side)
        {
            Side     otherSide    = OtherSide(side);
            NodeMeta adjacentMeta = Adjacent(side, meta);
            Node     adjacent     = adjacentMeta.Node;
            Node     toBeReplaced = meta.Node;


            Node adjacentParent = adjacentMeta.ParentMeta.Node;

            adjacentParent[otherSide] = adjacent[side];

            // Swap the nodes.
            // Cache the children of item to be replaced.
            Node child = adjacent[side];

            // Adjacent takes place of node to be removed.
            meta.ReplaceNode(adjacent);
            meta.ParentMeta.Node[meta.SideFromParent] = adjacent;
            adjacent[side]      = toBeReplaced[side];
            adjacent[otherSide] = toBeReplaced[otherSide];

            // Put node to be replaced in adjacent spot
            adjacentParent[otherSide] = toBeReplaced;
            toBeReplaced[side]        = child;
            toBeReplaced[otherSide]   = null; // This is null, that is how we know it is the leaf
            adjacentMeta.ReplaceNode(toBeReplaced);

            // Swap the color
            Color temp = toBeReplaced.Color;

            toBeReplaced.Color = adjacent.Color;
            adjacent.Color     = temp;

            if (child == null)
            {
                // We have found the node to remove. Replace it with a sentinal
                SentinelNode sentinel = new SentinelNode(toBeReplaced.Color);
                adjacentParent[otherSide] = sentinel;
                return(new NodeMeta(adjacentMeta.ParentMeta, sentinel, adjacentMeta.SideFromParent, adjacentMeta.Sibling));
            }
            else
            {
                return(SwapWithAdjacent(adjacentMeta, side));
            }
        }
コード例 #25
0
        public Path <T> GetPath(T startNode, T endNode, ITraverser <T> traverser)
        {
            if (startNode == endNode)
            {
                return(new Path <T>(new List <T>()
                {
                    startNode
                }));
            }

            this.startNode = startNode;
            this.endNode   = endNode;
            this.traverser = traverser;

            closedList.Clear();
            openList.Clear();

            var startNodeMeta = GetNodeMeta(startNode);

            startNodeMeta.GCost = 0.0f;

            openList.Add(startNodeMeta);

            while (true)
            {
                if (openList.Count == 0)
                {
                    return(Path <T> .Empty);  // No path exists
                }

                current = openList[openList.Count - 1];
                openList.Remove(current);

                if (current.Node == endNode)
                {
                    return(Backtrack());    // Path discovered
                }

                if (!closedList.Contains(current))
                {
                    closedList.Add(current);
                    AddNeighboursToOpen();
                }
            }
        }
コード例 #26
0
        private void Remove(NodeMeta meta, int value)
        {
            Node node = meta.Node;

            if (node.Value == value)
            {
                Side side  = Side.Left;
                Node child = node[side];
                if (child == null)
                {
                    side  = Side.Right;
                    child = node[side];
                }
                if (child == null)
                {
                    meta.ParentMeta.Node[meta.SideFromParent] = null;
                    // adjust color through parent.
                    if (node.Color == Color.Black && meta.ParentMeta.Node.Color == Color.Black)
                    {
                        meta.ParentMeta.Node.Color = Color.DoubleBlack;
                        BalanceTree(meta.ParentMeta);
                    }
                }
                else
                {
                    NodeMeta childMetaData = SwapWithAdjacent(meta, side);
                    BalanceTree(childMetaData);
                }
            }
            else
            {
                Side side       = value < node.Value ? Side.Left : Side.Right;
                Side otherSidde = OtherSide(side);
                Node next       = node[side];
                if (next == null)
                {
                    throw new InvalidOperationException("Value not found.");
                }
                Remove(new NodeMeta(meta, next, side, node[otherSidde]), value);
            }
        }
コード例 #27
0
        public void RemoveUnusedArgs(NodeProto nodeProto)
        {
            NodeMeta      proto      = this.GetComponent <BTNodeInfoComponent>().GetNodeMeta(nodeProto.Name);
            List <string> unUsedList = new List <string>();

            foreach (KeyValuePair <string, object> item in nodeProto.Args.Dict())
            {
                if (!proto.new_args_desc.Exists(a => (a.name == item.Key)))
                {
                    unUsedList.Add(item.Key);
                }
            }
            foreach (string item in unUsedList)
            {
                nodeProto.Args.Remove(item);
            }
            for (int i = 0; i < nodeProto.children.Count; i++)
            {
                RemoveUnusedArgs(nodeProto.children[i]);
            }
        }
コード例 #28
0
        private void AddToOpen(T node)
        {
            NodeMeta target = GetNodeMeta(node);

            if (traverser.CanTraverse(node) || node == endNode)
            {
                float gCost = current.GCost + traverser.GetTraverseCost(current.Node, node);
                if (!closedList.Contains(target) && !openList.Contains(target))
                {
                    target.Parent = current.Node;
                    target.HCost  = Vector3.Distance(node.Position, endNode.Position);
                    target.GCost  = gCost;
                    openList.Add(target);
                }
                else if (target.GCost > gCost)
                {
                    target.Parent = current.Node;
                    target.GCost  = gCost;
                }
            }
        }
コード例 #29
0
        public List <string> Filter(List <string> list, string text)
        {
            List <string> result1 = new List <string>();
            string        selectType;

            if (mEnumNodeTypeSelection == 0)
            {
                selectType = "All";
                result1    = list;
            }
            else
            {
                selectType = Enum.GetName(typeof(NodeClassifyType), mEnumNodeTypeSelection - 1);
                foreach (string name in list)
                {
                    NodeMeta proto = BTEntity.Instance.GetNodeMeta(name);
                    if (selectType == proto.classify)
                    {
                        result1.Add(name);
                    }
                }
            }

            if (string.IsNullOrEmpty(text))
            {
                return(result1);
            }

            List <string> result2 = new List <string>();

            foreach (string name in result1)
            {
                NodeMeta proto = BTEntity.Instance.GetNodeMeta(name);
                if (name.ToUpper().Contains(text.ToUpper()) || proto.describe.ToUpper().Contains(text.ToUpper()))
                {
                    result2.Add(name);
                }
            }
            return(result2);
        }
コード例 #30
0
        private void DrawAllValue(NodeMeta proto)
        {
            List <NodeFieldDesc> paramFieldList  = GetFieldDescList(proto.new_args_desc, typeof(NodeFieldAttribute));
            List <NodeFieldDesc> inputFieldList  = GetFieldDescList(proto.new_args_desc, typeof(NodeInputAttribute));
            List <NodeFieldDesc> outputFieldList = GetFieldDescList(proto.new_args_desc, typeof(NodeOutputAttribute));

            mFoldParam = EditorGUILayout.Foldout(mFoldParam, "参数");
            if (mFoldParam)
            {
                DrawProp(proto.name, paramFieldList, NodeParamType.None);
            }
            mFoldInput = EditorGUILayout.Foldout(mFoldInput, "输入");
            if (mFoldInput)
            {
                DrawProp(proto.name, inputFieldList, NodeParamType.Input);
            }
            mFoldOutput = EditorGUILayout.Foldout(mFoldOutput, "输出");
            if (mFoldOutput)
            {
                DrawProp(proto.name, outputFieldList, NodeParamType.Output);
            }
        }