Ejemplo n.º 1
0
        public override void OnGUI()
        {
            FTGraph self = (FTGraph)target;

            DrawToolBar();
            DrawDebugInfo();
        }
Ejemplo n.º 2
0
        private void ExportJson(FTGraph btGraph, List <string> paths, string filename)
        {
            // if (btGraph == null)
            // {
            //     Debug.Log("BT-- ExportJson failed because BTGraph is null");
            //     return;
            // }

            // // check root node
            // if (btGraph.root == null)
            // {
            //     EditorUtility.DisplayDialog("Warning", "Cant find any root node.", "OK");
            //     return;
            // }

            // // check dead loop
            // if (BTEditorUtils.CheckExistDeadLoop(btGraph.root))
            // {
            //     EditorUtility.DisplayDialog("Error", "Export failed, Your father is still your father.", "OK");
            //     return;
            // }

            // B3TreeData b3TreeData = BTEditorUtils.ToB3TreeData(btGraph);
            // if (b3TreeData == null)
            // {
            //     Debug.LogError("Failed export bt json, because ToB3TreeData return null");
            //     return;
            // }

            // System.Text.StringBuilder sb = new System.Text.StringBuilder();
            // JsonWriter jw = new JsonWriter(sb);
            // jw.PrettyPrint = true;
            // LitJson.JsonMapper.ToJson(b3TreeData, jw);

            // for (int i = 0; i < paths.Count; ++i)
            // {
            //     string fullpath = Path.GetFullPath(paths[i] + "/" + filename + ".json");

            //     if (File.Exists(fullpath))
            //     {
            //         Game.EditorUtils.Checkout(new List<string>() { fullpath });
            //         // NOTE:
            //         // because we cant get Checkout callback, so directly change file attribute
            //         File.SetAttributes(fullpath, File.GetAttributes(fullpath) & ~FileAttributes.ReadOnly );
            //         File.WriteAllText(fullpath, sb.ToString());
            //     }
            //     else
            //     {
            //         File.WriteAllText(fullpath, sb.ToString());
            //         Game.EditorUtils.Add(new List<string>() { fullpath });
            //     }

            //     Debugger.Log($"Success Export AI Json {fullpath}");
            // }

            // AssetDatabase.Refresh();
        }
Ejemplo n.º 3
0
        private void FindFTNode(string nodeName)
        {
            if (string.IsNullOrEmpty(nodeName))
            {
                return;
            }

            FTGraph gp = (FTGraph)target;

            if (gp == null || gp.nodes.Count == 0)
            {
                return;
            }

            int nodeCount = gp.nodes.Count;
            int startIdx  = Mathf.Min(lastFindIdx + 1, nodeCount);

            string nodeNameLower = nodeName.ToLower();

            for (int i = 0; i < nodeCount; ++i)
            {
                int idx = (startIdx + i) % nodeCount;
                if (idx < 0 || idx >= nodeCount)
                {
                    break;
                }

                Node nd = gp.nodes[idx];
                if ((nd is FTNode) == false)
                {
                    continue;
                }

                if (nd.name.ToLower() == nodeNameLower)
                {
                    lastFindIdx = idx;
                    FocusOnFTNode(nd as FTNode);
                    break;
                }
            }
        }
Ejemplo n.º 4
0
 private void OnEnable()
 {
     btGraph = (FTGraph)target;
 }
Ejemplo n.º 5
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);
        }