コード例 #1
0
            public static SettingsProvider CreateZSBTSettingsProvider()
            {
                var provider = new SettingsProvider("Project/Zetan Studio/ZSBTSettingsUIElementsSettings", SettingsScope.Project)
                {
                    label           = "行为树编辑器",
                    activateHandler = (searchContext, rootElement) =>
                    {
                        SerializedObject serializedObject = new SerializedObject(BehaviourTreeSettings.GetOrCreate());

                        Label title = new Label()
                        {
                            text = "行为树编辑器设置"
                        };
                        title.AddToClassList("title");
                        rootElement.Add(title);

                        var properties = new VisualElement()
                        {
                            style = { flexDirection = FlexDirection.Column }
                        };
                        properties.AddToClassList("property-list");
                        rootElement.Add(properties);

                        properties.Add(new InspectorElement(serializedObject));

                        rootElement.Bind(serializedObject);
                    },
                };

                return(provider);
            }
コード例 #2
0
        public static void CreateWindow()
        {
            BehaviourTreeEditor wnd = GetWindow <BehaviourTreeEditor>();

            wnd.minSize      = BehaviourTreeSettings.GetOrCreate().minWindowSize;
            wnd.titleContent = new GUIContent("行为树编辑器");
        }
コード例 #3
0
 private void OnSelectionChange()
 {
     settings = settings ? settings : BehaviourTreeSettings.GetOrCreate();
     if (settings.changeOnSelected)
     {
         ChangeTreeBySelection();
     }
 }
コード例 #4
0
        private void UpdateAssetDropdown()
        {
            if (assetsMenu == null)
            {
                return;
            }
            settings = settings ? settings : BehaviourTreeSettings.GetOrCreate();
            var behaviourTrees = ZetanUtility.Editor.LoadAssets <BehaviourTree>();

            for (int i = assetsMenu.menu.MenuItems().Count - 1; i > 0; i--)
            {
                assetsMenu.menu.RemoveItemAt(i);
            }
            if (!Application.isPlaying && tree && tree.IsRuntime)
            {
                assetsMenu.menu.InsertAction(1, "保存到本地", (a) => { SaveToLocal("new behaviour tree"); });
            }
            if (behaviourTrees.Count > 0)
            {
                assetsMenu.menu.AppendSeparator();
            }
            int counter = 1;

            behaviourTrees.ForEach(tree =>
            {
                if (tree)
                {
                    assetsMenu.menu.AppendAction($"本地/[{counter}] {tree.name} ({ZetanUtility.Editor.GetDirectoryName(tree).Replace("\\", "/").Replace("Assets/", "").Replace("/", "\u2215")})", (a) =>
                    {
                        EditorApplication.delayCall += () =>
                        {
                            latestGo = null;
                            SelectTree(tree);
                        };
                    });
                    counter++;
                }
            });
            counter = 1;
            foreach (var exe in FindObjectsOfType <BehaviourExecutor>(true))
            {
                if (exe.Behaviour)
                {
                    assetsMenu.menu.AppendAction($"场景/[{counter}] {exe.gameObject.name} ({exe.gameObject.GetPath().Replace("/", "\u2215")})", (a) =>
                    {
                        EditorApplication.delayCall += () =>
                        {
                            latestGo = exe.gameObject;
                            SelectTree(exe.Behaviour);
                        };
                    });
                    counter++;
                }
            }
        }
コード例 #5
0
        public static void CreateWindow(BehaviourTree tree)
        {
            if (!tree)
            {
                return;
            }
            BehaviourTreeEditor wnd = GetWindow <BehaviourTreeEditor>();

            wnd.minSize            = BehaviourTreeSettings.GetOrCreate().minWindowSize;
            wnd.titleContent       = new GUIContent("行为树编辑器");
            Selection.activeObject = tree;
            wnd.ChangeTreeBySelection();
        }
コード例 #6
0
        public static void CreateWindow(BehaviourExecutor executor)
        {
            if (!executor)
            {
                return;
            }
            BehaviourTreeEditor wnd = GetWindow <BehaviourTreeEditor>();

            wnd.minSize                = BehaviourTreeSettings.GetOrCreate().minWindowSize;
            wnd.titleContent           = new GUIContent("行为树编辑器");
            Selection.activeGameObject = executor.gameObject;
            EditorGUIUtility.PingObject(executor);
            wnd.ChangeTreeBySelection(executor);
        }
コード例 #7
0
        private void CreateNewTree(string assetName)
        {
            BehaviourTree tree = ZetanUtility.Editor.SaveFilePanel(CreateInstance <BehaviourTree>, assetName, ping: true, select: true);

            if (tree)
            {
                serializedTree = new SerializedObject(tree);
                UpdateVariables();
                Selection.activeObject = tree;
                EditorGUIUtility.PingObject(tree);
                settings = settings ? settings : BehaviourTreeSettings.GetOrCreate();
                if (!settings.changeOnSelected)
                {
                    ChangeTreeBySelection();
                }
            }
        }
コード例 #8
0
        private void CreateVariableScript()
        {
            var    settings = BehaviourTreeSettings.GetOrCreate();
            string path     = $"{settings.newVarScriptFolder}/{ScriptTemplate.Variable.folder}";

            if (path.EndsWith("/"))
            {
                path = path.Substring(0, path.Length - 1);
            }

            UnityEngine.Object script = AssetDatabase.LoadAssetAtPath(path, typeof(UnityEngine.Object));
            Selection.activeObject = script;
            EditorGUIUtility.PingObject(script);

            string templatePath = AssetDatabase.GetAssetPath(ScriptTemplate.Variable.templateFile);

            ProjectWindowUtil.CreateScriptAssetFromTemplateFile(templatePath, ScriptTemplate.Variable.fileName);
        }
コード例 #9
0
        public BehaviourTreeView()
        {
            Insert(0, new GridBackground());

            this.AddManipulator(new ContentZoomer());
            this.AddManipulator(new ContentDragger());
            this.AddManipulator(new SelectionDragger());
            this.AddManipulator(new RectangleSelector());

            settings = BehaviourTreeSettings.GetOrCreate();
            var styleSheet = settings.treeUss;

            styleSheets.Add(styleSheet);

            Undo.undoRedoPerformed        += OnUndoRedo;
            runtimeUndo.onRecordsChanged  += OnUndoRecordsChanged;
            runtimeUndo.undoRedoPerformed += OnRuntimeUndoRedo;
        }
コード例 #10
0
        public NodeEditor(Node node, Action <NodeEditor> onSelected, Action <NodeEditor> onUnselected,
                          Action <NodeEditor, Vector2> onSetPosition) : base(AssetDatabase.GetAssetPath(BehaviourTreeSettings.GetOrCreate().nodeUxml))
        {
            this.node          = node;
            this.onSelected    = onSelected;
            this.onUnselected  = onUnselected;
            this.onSetPosition = onSetPosition;
            viewDataKey        = node.guid;
            Type type = node.GetType();

            title = type.Name + (node.IsRuntime ? "(R)" : string.Empty);
            var attr = type.GetCustomAttribute <NodeDescriptionAttribute>();

            if (attr != null)
            {
                tooltip = attr.description;
            }
            else
            {
                tooltip = string.Empty;
            }

            style.left = node._position.x;
            style.top  = node._position.y;

            des = this.Q <Label>("description");

            abort   = this.Q <Label>("abort");
            repeat  = this.Q <Label>("repeat");
            invalid = this.Q <Label>("invalid");

            InitInput();
            InitOutput();
            InitClasses();
            UpdateStates();
            UpdateAbortType();
        }
コード例 #11
0
        public void CreateGUI()
        {
            try
            {
                settings = settings ? settings : BehaviourTreeSettings.GetOrCreate();

                VisualElement root = rootVisualElement;

                var visualTree = settings.treeUxml;
                visualTree.CloneTree(root);

                var styleSheet = settings.treeUss;
                root.styleSheets.Add(styleSheet);

                treeView = root.Q <BehaviourTreeView>();
                treeView.nodeSelectedCallback       = OnNodeSelected;
                treeView.nodeUnselectedCallback     = OnNodeUnselected;
                treeView.undoRecordsChangedCallback = UpdateUndoEnable;

                inspectorTaber = root.Q <TabbedBar>("inspector-tab");
                inspectorTaber.Refresh(new string[] { "检视器", "快速插入" }, OnInspectorTab, 4);
                inspectorLabel         = root.Q <Label>("inspector-label");
                showInspector          = true;
                inspectorView          = root.Q <InspectorView>();
                variables              = root.Q <IMGUIContainer>("variables");
                variables.onGUIHandler = DrawVariables;

                assetsMenu = root.Q <ToolbarMenu>("assets");
                assetsMenu.menu.AppendAction("新建", (a) => CreateNewTree("new behaviour tree"));
                exeMenu = root.Q <ToolbarMenu>("exe-select");
                UpdateAssetDropdown();

                treeName = root.Q <Label>("tree-name");

                variableTaber = root.Q <TabbedBar>("variable-tab");
                variableTaber.Refresh(new string[] { "共享变量", "全局变量" }, OnVariableTab, 4);
                serializedGlobal = new SerializedObject(Application.isPlaying && BehaviourManager.Instance ? BehaviourManager.Instance.GlobalVariables : ZetanUtility.Editor.LoadAsset <GlobalVariables>());

                undo          = root.Q <ToolbarButton>("undo");
                undo.clicked += OnUndoClick;
                redo          = root.Q <ToolbarButton>("redo");
                redo.clicked += OnRedoClick;
                UpdateUndoVisible();
                UpdateUndoEnable();

                inspectorTaber.SetSelected(1);
                variableTaber.SetSelected(1);

                if (tree == null)
                {
                    ChangeTreeBySelection();
                }
                else
                {
                    SelectTree(tree);
                }
            }
            catch (Exception e)
            {
                Debug.LogException(e);
            }
        }