Beispiel #1
0
        public static void ShowGo()
        {
            TextNewECtrl window = ScriptableObject.CreateInstance <TextNewECtrl>();

            if (Instance == null)
            {
                Instance = new RunTimeNodesManager();
            }
            InitCtrl(window);

            foreach (GameObject go in Selection.gameObjects)
            {
                string path = AssetDatabase.GetAssetPath(go);
                try
                {
                    BehaviorTreeConfig config = go.GetComponent <BehaviorTreeConfig>();
                    if (config == null)
                    {
                        Log.Debug($"{go.name}不是行为树");
                        continue;
                    }
                    Instance.InitBeTree(config.RootNodeProto, path, go.GetInstanceID());
                    window.SetName(Path.GetFileNameWithoutExtension(path));
                }
                catch (Exception err)
                {
                    BehaviourTreeDebugPanel.Error(Instance._curOpenningCtrl, $"打开行为树失败:{path}-> {err}");
                }
            }
        }
        public void OnGUI()
        {
            _oldType = EditorDataFields.EditorDataField("旧的类型", _oldType);
            _newType = EditorDataFields.EditorDataField("新的类型", _newType);

            if (string.IsNullOrEmpty(_oldType) || string.IsNullOrEmpty(_newType))
            {
                return;
            }

            using (new EditorHorizontalLayout("Box"))
            {
                if (GUILayout.Button("替换客户端"))
                {
                    EditorUtility.DisplayDialog("错误", "功能未实现", "关闭");
                }

                if (GUILayout.Button("替换服务器"))
                {
                    if (!EditorUtility.DisplayDialog("警告", "修改后不能够回退,是否确认修改", "OK", "CANCEL"))
                    {
                        return;
                    }
                    string   path  = EditorTreeConfigHelper.Instance.Config.ServersPath;
                    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);
                            p = TypeReplace(_oldType, _newType, p);
                            reader.Close();
                            StreamWriter writer = new StreamWriter(file);
                            writer.Write(MongoHelper.ToJson(p));
                            writer.Close();
                        }
                        catch (Exception err)
                        {
                            BehaviourTreeDebugPanel.Error($"文件({file})无法解析成行为树");
                            Log.Error(err);
                        }
                    }

                    EditorUtility.DisplayDialog("信息", "替换完成", "OK");
                }
            }
        }
Beispiel #3
0
 private void OpenTree(string path)
 {
     using (StreamReader rd = new StreamReader(path))
     {
         string text = rd.ReadToEnd();
         try
         {
             string fileName = Path.GetFileNameWithoutExtension(path);
             Instance.InitBeTree(MongoHelper.FromJson <NodeProto>(text), path, fileName.GetHashCode());
         }
         catch (Exception err)
         {
             BehaviourTreeDebugPanel.Error(_curOpenningCtrl, $"打开行为树失败:{path}-> {err}");
         }
     }
 }
Beispiel #4
0
        public static void ShowGo(string path)
        {
            TextNewECtrl window = ScriptableObject.CreateInstance <TextNewECtrl>();

            if (Instance == null)
            {
                Instance = new RunTimeNodesManager();
            }

            InitCtrl(window);
            try
            {
                Instance.CreateNewTree(path);
            }
            catch (Exception err)
            {
                BehaviourTreeDebugPanel.Error(Instance._curOpenningCtrl, $"打开行为树失败:{path}-> {err}");
            }
        }
Beispiel #5
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);
        }
        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);
            }
        }