Exemplo n.º 1
0
        private void SelectBehaviorBrain()
        {
            GUIContent content = new GUIContent(BehaviorTreeEditor.active != null ? BehaviorTreeEditor.active.name : "[None Selected]");
            float      width   = EditorStyles.toolbarDropDown.CalcSize(content).x;

            width = Mathf.Clamp(width, 100f, width);
            if (GUILayout.Button(content, EditorStyles.toolbarDropDown, GUILayout.Width(width)))
            {
                GenericMenu menu = new GenericMenu();
                if (BehaviorTreeEditor.active != null)
                {
                    SelectBehaviorBrainMenu(BehaviorTreeEditor.active, ref menu);
                }

                menu.AddItem(new GUIContent("[Craete New]"), false, delegate()
                {
                    BehaviorTree bt = AssetCreator.CreateAsset <BehaviorTree>(true);
                    if (bt != null)
                    {
                        bt.Name = bt.name;

                        Root root   = BehaviorTreeEditorUtility.AddNode <Root>(BehaviorTreeEditor.center, bt);
                        bt.rootNode = root;
                        root.Name   = "Root";

                        AssetDatabase.SaveAssets();
                        BehaviorTreeEditor.SelectBehaviorTrees(bt);
                    }
                });
                menu.ShowAsContext();
            }
        }
Exemplo n.º 2
0
 public static void EndInspectorGUI(UnityEngine.Object obj)
 {
     GUILayout.EndVertical();
     if (GUI.changed)
     {
         EditorUtility.SetDirty(obj);
         BehaviorTreeEditor.RepaintAll();
     }
 }
Exemplo n.º 3
0
 private void SelectBehaviorBrainMenu(BehaviorTree bt, ref GenericMenu menu)
 {
     if (bt != null)
     {
         GUIContent content = new GUIContent(bt.name);
         menu.AddItem(content, false, delegate()
         {
             BehaviorTreeEditor.SelectBehaviorTrees(bt);
         });
     }
 }
Exemplo n.º 4
0
        protected override void OnEnable()
        {
            base.OnEnable();
            BehaviorTreeEditor.instance = this;
            if (_mainToolBar == null)
            {
                _mainToolBar = new MainToolBar();
            }

            _isViewCenter = true;
            EditorApplication.playmodeStateChanged += OnPlayModeStateChanged;
        }
Exemplo n.º 5
0
 private void Update()
 {
     if (BehaviorTreeEditor.active != null && BehaviorTreeEditor.activeGameObject != null)
     {
         if (EditorApplication.isPlaying)
         {
             _debugProgress += Time.unscaledDeltaTime * 2.5f;
             if (_debugProgress >= 1)
             {
                 _debugProgress = 0;
             }
             BehaviorTreeEditor.RepaintAll();
         }
     }
 }
Exemplo n.º 6
0
 private void SelectGameObject()
 {
     if (GUILayout.Button(BehaviorTreeEditor.activeGameObject != null ? BehaviorTreeEditor.activeGameObject.name : "[None Selected]", EditorStyles.toolbarDropDown, GUILayout.Width(100)))
     {
         GenericMenu  toolsMenu = new GenericMenu();
         List <Brain> brains    = BehaviorTreeEditorUtility.FindInScene <Brain>();
         foreach (Brain brain in brains)
         {
             GameObject gameObject = brain.gameObject;
             toolsMenu.AddItem(new GUIContent(gameObject.name), false, delegate()
             {
                 BehaviorTreeEditor.SelectGameObject(gameObject);
             });
         }
         toolsMenu.ShowAsContext();
     }
 }
Exemplo n.º 7
0
        public static void SelectGameObject(GameObject gameObject)
        {
            if (BehaviorTreeEditor.instance == null)
            {
                return;
            }

            if (gameObject != null)
            {
                Brain brain = gameObject.GetComponent <Brain>();
                BehaviorTreeEditor.instance._brain = brain;
                if (brain != null && brain.behaviorTree != null)
                {
                    BehaviorTreeEditor.instance._activeGameObject = gameObject;
                    BehaviorTreeEditor.SelectBehaviorTrees(brain.behaviorTree);
                }
            }
        }
Exemplo n.º 8
0
 private void OnPlayModeStateChanged()
 {
     if (EditorApplication.isPlayingOrWillChangePlaymode)
     {
         if (_activeGameObject != null)
         {
             _brain = activeGameObject.GetComponent <Brain>();
             if (_brain != null && _brain.behaviorTree != null)
             {
                 SelectBehaviorTrees(_brain.behaviorTree);
             }
         }
         _selection.Clear();
         _decoratorSelection.Clear();
         _serviceSelection.Clear();
         UpdateUnitySelection();
     }
     BehaviorTreeEditor.RepaintAll();
 }
Exemplo n.º 9
0
        private static void DrawDecorators(Node node, ref float height)
        {
            for (int i = 0; i < node.decorators.Length; i++)
            {
                Decorator decorator = node.decorators[i];

                Rect decoratorRect = node.position;
                decoratorRect.xMin += 7;
                decoratorRect.xMax -= 7;
                decoratorRect.yMin  = height;
                decoratorRect.yMax  = height + 32 + GetCommentHeight(decorator.comment);

                GUIStyle decoratorStyle = BehaviorTreeEditorStyles.GetNodeStyle((int)NodeColor.Blue, BehaviorTreeEditor.CompareSelectedDecorators(decorator));
                if (EditorApplication.isPlaying)
                {
                    decoratorStyle = BehaviorTreeEditorStyles.GetNodeStyle(BehaviorTreeEditor.CheckThisDecoratorClosed(decorator) ? (int)NodeColor.Red : (int)NodeColor.Blue, BehaviorTreeEditor.CompareSelectedDecorators(decorator));
                }
                GUI.Box(decoratorRect, "", decoratorStyle);

                Rect decoratorIconRect = node.position;
                decoratorIconRect.x = node.position.xMin + 7;
                decoratorIconRect.y = height - 1;
                GUI.Label(decoratorIconRect, decoratorIcon);

                Rect decoratorNameRect = node.position;
                decoratorNameRect.x = node.position.xMin + 42;
                decoratorNameRect.y = height + 5;
                GUI.Label(decoratorNameRect, "<color=white>" + decorator.Name + "</color>", BehaviorTreeEditorStyles.nodeBoxNameNormalStyle);

                GUIContent decoratorCommentContent = new GUIContent(decorator.comment);
                Rect       decoratorCommentRect    = node.position;
                decoratorCommentRect.x     = node.position.xMin + 7;
                decoratorCommentRect.y     = height + 30;
                decoratorCommentRect.width = BehaviorTreeEditorStyles.nodeBoxCommentStyle.CalcSize(decoratorCommentContent).x + 10;
                GUI.Label(decoratorCommentRect, "<color=white>" + decorator.comment + "</color>", BehaviorTreeEditorStyles.nodeBoxCommentStyle);

                height += decoratorRect.yMax - decoratorRect.yMin + 5;
            }
        }
Exemplo n.º 10
0
        public static BehaviorTreeEditor ShowEditorWindow()
        {
            BehaviorTreeEditor window = EditorWindow.GetWindow <BehaviorTreeEditor>("BT Editor");

            return(window);
        }
Exemplo n.º 11
0
 private void OnSelectionChange()
 {
     // This code is borrowed from ICode(https://www.assetstore.unity3d.com/en/#!/content/13761)
     BehaviorTreeEditor.SelectGameObject(Selection.activeGameObject);
 }
Exemplo n.º 12
0
        protected override void OnEnable()
        {
            base.OnEnable();
            BehaviorTreeEditor.instance = this;
            if (_mainToolBar == null)
                _mainToolBar = new MainToolBar();

            _isViewCenter = true;
            EditorApplication.playmodeStateChanged += OnPlayModeStateChanged;
        }
Exemplo n.º 13
0
        private static void DrawServices(Node node, float height)
        {
            if (node is Composite)
            {
                Composite composite = node as Composite;
                for (int i = 0; i < composite.services.Length; i++)
                {
                    Service service = composite.services[i];

                    Rect serviceRect = node.position;
                    serviceRect.xMin += 7 + 13;
                    serviceRect.xMax -= 7;
                    serviceRect.yMin  = height;
                    serviceRect.yMax  = height + 32 + GetCommentHeight(service.comment);
                    GUIStyle serviceStyle = BehaviorTreeEditorStyles.GetNodeStyle((int)NodeColor.Aqua, BehaviorTreeEditor.CompareSelectedServices(service));
                    GUI.Box(serviceRect, "", serviceStyle);

                    Rect serviceIconRect = node.position;
                    serviceIconRect.x = node.position.xMin + 7 + 13;
                    serviceIconRect.y = height - 1;
                    GUI.Label(serviceIconRect, serviceIcon);

                    Rect serviceNameRect = node.position;
                    serviceNameRect.x = node.position.xMin + 42 + 13;
                    serviceNameRect.y = height + 5;
                    GUI.Label(serviceNameRect, "<color=white>" + service.Name + "</color>", BehaviorTreeEditorStyles.nodeBoxNameNormalStyle);

                    GUIContent serviceCommentContent = new GUIContent(service.comment);
                    Rect       serviceCommentRect    = node.position;
                    serviceCommentRect.x     = node.position.xMin + 7 + 13;
                    serviceCommentRect.y     = height + 30;
                    serviceCommentRect.width = BehaviorTreeEditorStyles.nodeBoxCommentStyle.CalcSize(serviceCommentContent).x + 10;
                    GUI.Label(serviceCommentRect, "<color=white>" + service.comment + "</color>", BehaviorTreeEditorStyles.nodeBoxCommentStyle);
                }
            }
        }
Exemplo n.º 14
0
 public static void OpenEditorWindow()
 {
     BehaviorTreeEditor.ShowEditorWindow();
 }