예제 #1
0
        private void SelectBehaviorBrain()
        {
            GUIContent content = new GUIContent(BehaviorTreesEditor.active != null ? BehaviorTreesEditor.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 (BehaviorTreesEditor.active != null)
                {
                    SelectBehaviorBrainMenu(BehaviorTreesEditor.active, ref menu);
                }

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

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

                        AssetCreator.SaveAIAsset();
                        BehaviorTreesEditor.SelectBehaviorTrees(bt);
                    }
                });
                menu.ShowAsContext();
            }
        }
 public static void EndInspectorGUI(UnityEngine.Object obj)
 {
     GUILayout.EndVertical();
     if (GUI.changed)
     {
         EditorUtility.SetDirty(obj);
         BehaviorTreesEditor.RepaintAll();
     }
 }
예제 #3
0
 private void SelectBehaviorBrainMenu(BehaviorTrees bt, ref GenericMenu menu)
 {
     if (bt != null)
     {
         GUIContent content = new GUIContent(bt.name);
         menu.AddItem(content, false, delegate()
         {
             BehaviorTreesEditor.SelectBehaviorTrees(bt);
         });
     }
 }
예제 #4
0
        protected override void OnEnable()
        {
            base.OnEnable();
            BehaviorTreesEditor.instance = this;
            if (_mainToolBar == null)
            {
                _mainToolBar = new MainToolBar();
            }

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

            if (gameObject != null)
            {
                Brain brain = gameObject.GetComponent <Brain>();
                BehaviorTreesEditor.instance._brain = brain;
                if (brain != null && brain.behaviorTrees != null)
                {
                    BehaviorTreesEditor.instance._activeGameObject = gameObject;
                    BehaviorTreesEditor.SelectBehaviorTrees(brain.behaviorTrees);
                }
            }
        }
예제 #8
0
 private void OnPlayModeStateChanged()
 {
     if (EditorApplication.isPlayingOrWillChangePlaymode)
     {
         if (_activeGameObject != null)
         {
             _brain = activeGameObject.GetComponent <Brain>();
             if (_brain != null && _brain.behaviorTrees != null)
             {
                 SelectBehaviorTrees(_brain.behaviorTrees);
             }
         }
         _selection.Clear();
         _decoratorSelection.Clear();
         _serviceSelection.Clear();
         UpdateUnitySelection();
     }
     BehaviorTreesEditor.RepaintAll();
 }
예제 #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 = BehaviorTreesEditorStyles.GetNodeStyle((int)NodeColor.Blue, BehaviorTreesEditor.CompareSelectedDecorators(decorator));
                if (EditorApplication.isPlaying)
                {
                    decoratorStyle = BehaviorTreesEditorStyles.GetNodeStyle(BehaviorTreesEditor.CheckThisDecoratorClosed(decorator) ? (int)NodeColor.Red : (int)NodeColor.Blue, BehaviorTreesEditor.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>", BehaviorTreesEditorStyles.nodeBoxNameNormalStyle);

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

                height += decoratorRect.yMax - decoratorRect.yMin + 5;
            }
        }
예제 #10
0
파일: Menu.cs 프로젝트: yabos/SaveTheQueen
 public static void OpenEditorWindow()
 {
     BehaviorTreesEditor.ShowEditorWindow();
 }
예제 #11
0
        public static BehaviorTreesEditor ShowEditorWindow()
        {
            BehaviorTreesEditor window = EditorWindow.GetWindow <BehaviorTreesEditor>("BT Editor");

            return(window);
        }
예제 #12
0
 private void OnSelectionChange()
 {
     // This code is borrowed from ICode(https://www.assetstore.unity3d.com/en/#!/content/13761)
     BehaviorTreesEditor.SelectGameObject(Selection.activeGameObject);
 }
예제 #13
0
        private static void DrawNode(Node node, bool selected, Texture2D iconImage, int boxColor)
        {
            float sharedHeight = node.position.yMin + 15;

            DrawDecorators(node, ref sharedHeight);

            Rect insideMainNode = node.position;

            insideMainNode.xMin += 7;
            insideMainNode.xMax -= 7;
            insideMainNode.yMin  = sharedHeight;
            insideMainNode.yMax  = sharedHeight + 32 + GetCommentHeight(node.comment);

            GUIStyle insideMainNodeStyle = BehaviorTreesEditorStyles.GetNodeStyle(boxColor, false);

            if (EditorApplication.isPlaying)
            {
                if (node is Task)
                {
                    Task t = node as Task;
                    insideMainNodeStyle = BehaviorTreesEditorStyles.GetNodeStyle(
                        BehaviorTreesEditor.CheckThisTaskClosed(t) ? (int)NodeColor.Yellow : boxColor, BehaviorTreesEditor.CheckThisTaskClosed(t));
                }
            }
            GUI.Box(insideMainNode, "", insideMainNodeStyle);

            int?myIndex = BehaviorTreesEditorUtility.GetMyIndex(node);

            if (myIndex != null && circleIcon != null)
            {
                float circleIconWidth  = circleIcon.width * 1.1f;
                float circleIconHeight = circleIcon.height * 1.1f;
                Rect  indexRect        = new Rect(insideMainNode.xMax - circleIconWidth / 2f + 12, insideMainNode.yMin - circleIconHeight / 2f, circleIconWidth, circleIconHeight);
                GUI.DrawTexture(indexRect, circleIcon);
                indexRect.xMin -= 2;
                indexRect.yMin -= 2;
                GUI.Label(indexRect, "<color=black>" + (myIndex + 1).ToString() + "</color>", BehaviorTreesEditorStyles.nodeIndexLabel);
            }

            Rect iconRect = node.position;

            iconRect.x = node.position.xMin + 7;
            iconRect.y = sharedHeight - 1;
            GUI.Label(iconRect, iconImage);

            Rect nameRect = node.position;

            nameRect.x = node.position.xMin + 42;
            nameRect.y = sharedHeight + 5;

            GUI.Label(nameRect, "<color=white>" + node.Name + "</color>", BehaviorTreesEditorStyles.nodeBoxNameNormalStyle);

            GUIContent commentContent = new GUIContent(node.comment);
            Rect       commentRect    = node.position;

            commentRect.x     = node.position.xMin + 7;
            commentRect.y     = sharedHeight + 30;
            commentRect.width = BehaviorTreesEditorStyles.nodeBoxCommentStyle.CalcSize(commentContent).x + 10;
            GUI.Label(commentRect, "<color=white>" + node.comment + "</color>", BehaviorTreesEditorStyles.nodeBoxCommentStyle);

            sharedHeight += insideMainNode.yMax - insideMainNode.yMin + 5;
            DrawServices(node, sharedHeight);
        }
예제 #14
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 = BehaviorTreesEditorStyles.GetNodeStyle((int)NodeColor.Aqua, BehaviorTreesEditor.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>", BehaviorTreesEditorStyles.nodeBoxNameNormalStyle);

                    GUIContent serviceCommentContent = new GUIContent(service.comment);
                    Rect       serviceCommentRect    = node.position;
                    serviceCommentRect.x     = node.position.xMin + 7 + 13;
                    serviceCommentRect.y     = height + 30;
                    serviceCommentRect.width = BehaviorTreesEditorStyles.nodeBoxCommentStyle.CalcSize(serviceCommentContent).x + 10;
                    GUI.Label(serviceCommentRect, "<color=white>" + service.comment + "</color>", BehaviorTreesEditorStyles.nodeBoxCommentStyle);

                    height += serviceRect.yMax - serviceRect.yMin + 5;
                }
            }
        }