Exemplo n.º 1
0
        void DrawVariables()
        {
            EditorGUILayout.BeginHorizontal(EditorStyles.toolbar);
            GUILayout.FlexibleSpace();

            if (GUILayout.Button("+", EditorStyles.toolbarButton, GUILayout.Width(20)))
            {
                _nodeCanvas.canvasState.tree.CreateVariable("NewVariable");
            }

            EditorGUILayout.EndHorizontal();

            variableScroll = EditorGUILayout.BeginScrollView(variableScroll);
            string[] variables = _nodeCanvas.canvasState.tree.VariableNames;

            for (int i = 0; i < variables.Length; i++)
            {
                EditorGUILayout.BeginHorizontal();

                string newName = EditorGUILayout.TextField(variables[i], EditorStyles.textField);

                if (newName != variables[i] && newName != "")
                {
                    RenameVariable(variables[i], newName);
                }

                if (GUI.changed)
                {
                    BehaviourEditorWindow.RepaintWindow();
                }

                if (GUILayout.Button("-", EditorStyles.miniButton))
                {
                    if (EditorUtility.DisplayDialog("Delete " + variables[i], "Are you sure you want to delete this variable?", "Yes", "No"))
                    {
                        _nodeCanvas.canvasState.tree.DeleteVariable(variables[i]);
                    }
                }

                EditorGUILayout.EndHorizontal();
            }
            EditorGUILayout.EndScrollView();

            if (redrawInspector || Event.current.keyCode == KeyCode.Return)
            {
                redrawInspector = false;
                GUI.FocusControl(null);
                BehaviourEditorWindow.editor.Repaint();
            }
        }
Exemplo n.º 2
0
        public static void OpenWindow()
        {
            editor                = GetWindow <BehaviourEditorWindow>();
            editor.minSize        = new Vector2(600, 300);
            editor.titleContent   = new GUIContent("Behaviour Editor");
            editor._curWindowSize = editor.position.size;
            editor._menuRect      = editor.GetMenuRect();

            nodeCanvas    = new NodeCanvas(editor.GetCanvasRect());
            nodeInspector = new NodeInspector(editor.GetInspectorRect(), nodeCanvas);

            Selection.selectionChanged += TryLoadSelectedAsset;

            NodeFactory.FetchNodes();
            NodePanelFactory.FetchCustomPanels();
            CustomFieldDrawerManager.FetchCustomFieldDrawers();

            // tries to load the selected asset if it is a behaviour tree when the window is open
            // and also when the assembly is reloaded
            TryLoadSelectedAsset();
        }
Exemplo n.º 3
0
        private static void TryLoadSelectedAsset()
        {
            UnityEngine.Object activeObject = Selection.activeObject;

            if (Selection.activeObject == null)
            {
                return;
            }

            if (Selection.activeObject.GetType() == typeof(BehaviourTree))
            {
                nodeCanvas.Load((BehaviourTree)Selection.activeObject);
                BehaviourEditorWindow.RepaintWindow();
            }
            else if (Selection.activeObject is GameObject)
            {
                var controller = ((GameObject)activeObject).GetComponent <BehaviourController>();
                if (controller == null)
                {
                    return;
                }

                if (Application.isPlaying)
                {
                    nodeCanvas.LoadBehaviourController(controller);
                }
                else
                {
                    var tree = controller.behaviourTree;
                    if (tree == null)
                    {
                        return;
                    }

                    nodeCanvas.Load(tree);
                    BehaviourEditorWindow.RepaintWindow();
                }
            }
        }