Пример #1
0
 private void CheckFTNodeValid()
 {
     if (_FTNode == null)
     {
         _FTNode = target as FTNode;
     }
 }
Пример #2
0
        private static bool _CheckExistDeadLoop(FTNode fromNode, List <FTNode> checkedNodes)
        {
            if (IsLeafNode(fromNode))
            {
                return(false);
            }

            for (int i = 0; i < fromNode.ChildCount; ++i)
            {
                var ch = fromNode.GetChildNode(i);
                if (ch == null)
                {
                    continue;
                }

                if (checkedNodes.Contains(ch))
                {
                    Debug.Log("BT-- exist dead loop at loop > " + ch.id + " - " + ch.name);
                    return(true);
                }

                List <FTNode> ncheckedNodes = new List <FTNode>();
                ncheckedNodes.AddRange(checkedNodes);
                ncheckedNodes.Add(ch);
                if (_CheckExistDeadLoop(ch, ncheckedNodes))
                {
                    return(true);
                }
            }
            return(false);
        }
Пример #3
0
        public static bool IsLeafNode(FTNode node)
        {
            var lcategory = node.category.ToLower();

            if (lcategory == BTDef.B3_CATEGORY_ACTION || lcategory == BTDef.B3_CATEGORY_CONDITION)
            {
                return(true);
            }
            return(false);
        }
Пример #4
0
        public static bool CheckExistDeadLoop(FTNode fromNode)
        {
            if (fromNode == null)
            {
                return(false);
            }

            List <FTNode> checkedNodes = new List <FTNode>();

            checkedNodes.Add(fromNode);
            return(_CheckExistDeadLoop(fromNode, checkedNodes));
        }
Пример #5
0
        // because always change connection, refresh is one safe way before get
        private void RefreshConnectNode()
        {
            NodePort port = node.GetOutputPort(portName);

            if (port == null || port.Connection == null)
            {
                _connectNode = null;
            }
            else
            {
                _connectNode = (FTNode)port.Connection.node;
            }
        }
Пример #6
0
        // private void InitWithFTNode(TBTTreeNode tFTNode, Dictionary<string, FTNode> mapping)
        // {
        //     FTNode FTNode = null;
        //     if (mapping.TryGetValue(tFTNode.FTNodeId, out FTNode))
        //         FTNode.TFTNode = tFTNode;
        //     else
        //         Debug.LogError("cant InitWithFTNode with id > " + tFTNode.FTNodeId);

        //     for (int i = 0; i < tFTNode.GetChildCount(); ++i)
        //     {
        //         TBTTreeNode subTFTNode = tFTNode.GetChild<TBTTreeNode>(i);
        //         InitWithFTNode(subTFTNode, mapping);
        //     }
        // }

        public bool IsExistFTNode(string FTNodeId)
        {
            for (int i = 0; i < nodes.Count; ++i)
            {
                if ((nodes[i] is FTNode) == false)
                {
                    continue;
                }

                FTNode FTNode = nodes[i] as FTNode;
                if (FTNode.id == FTNodeId)
                {
                    return(true);
                }
            }
            return(false);
        }
Пример #7
0
        // public void SetRoot(FTNode node)
        // {
        //     if (root != null)
        //     {
        //         root.IsRoot = false;
        //     }
        //     root = node;
        // }

        // public void UnsetRoot(FTNode node)
        // {
        //     // Only unset when the state passed is the same as the current one.
        //     if (node == root)
        //     {
        //         root = null;
        //     }
        // }

        // runtime mode
        public void InitWithBTTree(FSM.StateMachine tree)
        {
            Dictionary <string, FTNode> mapping = new Dictionary <string, FTNode>();

            for (int i = 0; i < nodes.Count; ++i)
            {
                if ((nodes[i] is FTNode) == false)
                {
                    continue;
                }

                FTNode FTNode = nodes[i] as FTNode;
                mapping[FTNode.id] = FTNode;
            }

            // InitWithFTNode(tree, mapping);
        }
Пример #8
0
        private void AddFTNode(string nodeName, Vector2 gpos)
        {
            var nodeCfg = BTEditorDefine.GetFTNodeCfg(nodeName);

            if (nodeCfg == null)
            {
                Debug.LogError("Failed to AddFTNode because cant find FTNodeCfg > " + nodeName);
                return;
            }

            FTNode node = (FTNode)CreateNode(typeof(FTNode), gpos);

            NodeEditorWindow.current.AutoConnect(node);
            node.InitWhenAddFromGraph(nodeCfg);

            FocusOnFTNode(node);
        }
Пример #9
0
 private void FocusOnFTNode(FTNode node)
 {
     Selection.activeObject             = node;
     NodeEditorWindow.current.panOffset = -node.position;
     NodeEditorWindow.current.zoom      = 1f;
 }
Пример #10
0
        public static B3TreeData ToB3TreeData(FTGraph btGraph)
        {
            if (btGraph == null)
            {
                Debug.LogError("cant ToB3TreeData because btGraph is null");
                return(null);
            }

            B3TreeData b3Tree = new B3TreeData();

            b3Tree.id = btGraph.id;
            // b3Tree.root = btGraph.root.id;
            b3Tree.title = btGraph.title;
            // b3Tree.description = btGraph.description;

            for (int i = 0; i < btGraph.nodes.Count; ++i)
            {
                if ((btGraph.nodes[i] is FTNode) == false)
                {
                    continue;
                }

                FTNode FTNode = (FTNode)btGraph.nodes[i];

                B3NodeInfo b3NodeInfo = new B3NodeInfo();

                if (b3Tree.nodes.ContainsKey(FTNode.id))
                {
                    UnityEditor.EditorUtility.DisplayDialog("Error", $"CHECK: exist same id AI node > {FTNode.id} - {FTNode.name}", "OK");
                    return(null);
                }

                b3Tree.nodes[FTNode.id] = b3NodeInfo;

                Dictionary <string, object> dictNode = new Dictionary <string, object>();
                b3NodeInfo.id       = FTNode.id;
                b3NodeInfo.name     = FTNode.name;
                b3NodeInfo.category = FTNode.category;
                // b3NodeInfo.description = FTNode.description;
                // b3NodeInfo.display["x"] = (int)FTNode.position.x;
                // b3NodeInfo.display["y"] = (int)FTNode.position.y;

                if (FTNode.properties != null)
                {
                    for (int j = 0; j < FTNode.properties.Count; ++j)
                    {
                        FTNodeProperty prop = FTNode.properties[j];
                        b3NodeInfo.properties.Add(prop.Key, prop.Value);
                    }
                }

                for (int j = 0; j < FTNode.ChildCount; ++j)
                {
                    FTNode childFTNode = FTNode.GetChildNode(j);
                    if (childFTNode == null)
                    {
                        UnityEditor.EditorUtility.DisplayDialog("Error", $"CHECK: exist null child AI node > {FTNode.id} - {FTNode.name}", "OK");
                        return(null);
                    }
                    if (btGraph.IsExistFTNode(childFTNode.id) == false)
                    {
                        UnityEditor.EditorUtility.DisplayDialog("Error", $"CHECK: cant find child AI node > {FTNode.id} - {FTNode.name} - child: {childFTNode.id}", "OK");
                        return(null);
                    }
                    b3NodeInfo.children.Add(childFTNode.id);
                }
            }

            // custom value
            // b3Tree.display.camera_x = 960;
            // b3Tree.display.camera_y = 508;
            // b3Tree.display.camera_z = 1;

            return(b3Tree);
        }
Пример #11
0
 private void OnEnable()
 {
     FTNode = (FTNode)target;
 }
Пример #12
0
        // Transition
        // public

        public FTConnection(FTNode node, string portName)
        {
            this.node     = node;
            this.portName = portName;
            RefreshConnectNode();
        }