Example #1
0
        // DeselectNode cannot be called here
        // void OnLostFocus()
        // {
        //     // DeselectNode();
        // }

        private void UpdateSelection()
        {
            MonoBehaviourTree prevMBT = currentMBT;

            if (!this.locked && Selection.activeGameObject != null)
            {
                currentMBT = Selection.activeGameObject.GetComponent <MonoBehaviourTree>();
                // If new selection is null then restore previous one
                if (currentMBT == null)
                {
                    currentMBT = prevMBT;
                }
            }
            if (currentMBT != prevMBT)
            {
                // Get new editor for new MBT
                Editor.CreateCachedEditor(currentMBT, null, ref currentMBTEditor);
            }
            if (currentMBT != null)
            {
                currentNodes = currentMBT.GetComponents <Node>();
                // Ensure there is no error when node script is missing
                for (int i = 0; i < currentNodes.Length; i++)
                {
                    currentNodes[i].children.RemoveAll(item => item == null);
                }
            }
            else
            {
                currentNodes = new Node[0];
                // Unlock when there is nothing to display
                this.locked = false;
            }
        }
Example #2
0
        void OnSelectionChange()
        {
            MonoBehaviourTree previous = currentMBT;

            UpdateSelection();
            // Reset workspace position only when selection changed
            if (previous != currentMBT)
            {
                workspaceOffset = Vector2.zero;
            }
            Repaint();
        }
Example #3
0
        void OnEnable()
        {
            // Set hide flags in case object was duplicated or turned into prefab
            if (target == null)
            {
                return;
            }
            MonoBehaviourTree mbt = (MonoBehaviourTree)target;

            // Sample one component and check if its hidden. Hide all nodes if sample is visible.
            if (mbt.TryGetComponent <Node>(out Node n) && n.hideFlags != HideFlags.HideInInspector)
            {
                Node[] nodes = mbt.GetComponents <Node>();
                for (int i = 0; i < nodes.Length; i++)
                {
                    nodes[i].hideFlags = HideFlags.HideInInspector;
                }
            }
        }
Example #4
0
        public override void OnInspectorGUI()
        {
            // Destroy previous editor
            if (nodeEditor != null)
            {
                DestroyImmediate(nodeEditor);
            }

            InitStyle();

            DrawDefaultInspector();
            GUILayout.Space(5);

            if (GUILayout.Button("Open editor"))
            {
                BehaviourTreeWindow.OpenEditor();
            }

            EditorGUILayout.Space();

            MonoBehaviourTree mbt    = ((MonoBehaviourTree)target);
            bool renderNodeInspector = mbt.selectedEditorNode != null;

            EditorGUILayout.BeginFoldoutHeaderGroup(renderNodeInspector, "Node inspector", foldStyle);
            EditorGUILayout.Space(1);
            if (renderNodeInspector)
            {
                EditorGUILayout.BeginHorizontal(boxStyle);
                GUILayout.Space(3);
                EditorGUILayout.BeginVertical();
                GUILayout.Space(5);
                nodeEditor = Editor.CreateEditor(mbt.selectedEditorNode);
                nodeEditor.OnInspectorGUI();
                GUILayout.Space(5);
                EditorGUILayout.EndVertical();
                EditorGUILayout.EndHorizontal();
            }
            EditorGUILayout.EndFoldoutHeaderGroup();
            EditorGUILayout.Space();
        }