void OnEnable()
        {
            BonsaiPreferences.Instance = BonsaiPreferences.LoadDefaultPreferences();
            BonsaiEditor.FetchBehaviourNodes();

            Editor = new BonsaiEditor();
            Viewer = new BonsaiViewer();
            Saver  = new BonsaiSaver();

            Saver.SaveMessage += (sender, message) => ShowNotification(new GUIContent(message));

            Editor.Viewer                   = Viewer;
            Editor.Input.SaveRequest       += (s, e) => Save();
            Editor.CanvasChanged           += (s, e) => Repaint();
            Editor.Input.MouseDown         += (s, e) => Repaint();
            Editor.Input.MouseUp           += (s, e) => Repaint();
            Editor.EditorMode.ValueChanged += (s, mode) => { EditorMode = mode; };

            EditorApplication.playModeStateChanged    += PlayModeStateChanged;
            AssemblyReloadEvents.beforeAssemblyReload += BeforeAssemblyReload;
            Selection.selectionChanged += SelectionChanged;

            BuildCanvas();
            Editor.EditorMode.Value = BonsaiEditor.Mode.Edit;
            SwitchToViewModeIfRequired();
        }
        void OnEnable()
        {
            BonsaiPreferences.Instance = BonsaiPreferences.LoadDefaultPreferences();
            BonsaiEditor.FetchBehaviourNodes();

            Editor = new BonsaiEditor();
            Viewer = new BonsaiViewer();
            Saver  = new BonsaiSaver();

            Saver.SaveMessage += (sender, message) => ShowNotification(new GUIContent(message));

            Editor.Viewer                   = Viewer;
            Editor.Input.SaveRequest       += (s, e) => Save();
            Editor.CanvasChanged           += (s, e) => Repaint();
            Editor.Input.MouseDown         += (s, e) => Repaint();
            Editor.Input.MouseUp           += (s, e) => Repaint();
            Editor.EditorMode.ValueChanged += (s, mode) => { EditorMode = mode; };

            EditorApplication.playModeStateChanged += PlayModeStateChanged;

            BuildCanvas();

            // Always start in edit mode.
            //
            // The only way it can be in view mode is if the window is
            // already opened and the user selects a game object with a
            // behaviour tree component.
            Editor.EditorMode.Value = BonsaiEditor.Mode.Edit;
        }
        // Creates an editor node.
        private BonsaiNode CreateEditorNode(Type behaviourType)
        {
            var prop = BonsaiEditor.GetNodeTypeProperties(behaviourType);
            var tex  = BonsaiPreferences.Texture(prop.texName);
            var node = AddEditorNode(prop.hasOutput, tex);

            return(node);
        }
        private void PopulateTypeConversions(GenericMenu menu, BonsaiNode node)
        {
            Type coreType       = BonsaiEditor.CoreType(node.Behaviour);
            var  behaviourTypes = BonsaiEditor.RegisteredBehaviourNodeTypes;

            foreach (Type subclass in behaviourTypes.Where(t => t.IsSubclassOf(coreType) && !t.IsAbstract))
            {
                menu.AddItem(new GUIContent("Change Type/" + subclass.Name), false, () =>
                {
                    EditorChangeNodeType.ChangeType(node, subclass);
                    TypeChanged?.Invoke(this, node);
                });
            }
        }
Esempio n. 5
0
        void OnEnable()
        {
            GUIScaleUtility.CheckInit();

            editor        = new BonsaiEditor();
            editor.window = this;
            BonsaiEditor.FetchBehaviourNodes();

            inputHandler = new BonsaiInputHandler(this);
            saveManager  = new BonsaiSaveManager(this);

            buildCanvas();

            // Always start in edit mode.
            //
            // The only way it can be in view mode is if the window is
            // already opened and the user selects a game object with a
            // behaviour tree component.
            _mode = Mode.Edit;
        }
Esempio n. 6
0
        // Creates an editor node.
        private BonsaiNode createEditorNode(Type behaviourType)
        {
            string texName = null;

            var prop = BonsaiEditor.GetNodeTypeProperties(behaviourType);
            var node = addEditorNode(prop.bCreateInput, prop.bCreateOutput, prop.bCanHaveMultipleChildren);

            texName = prop.texName;
            var tex = BonsaiResources.GetTexture(texName);

            // Failed to find texture, set default.
            if (tex == null)
            {
                tex = BonsaiResources.GetTexture("Play");
            }

            node.iconTex = BonsaiResources.GetTexture(texName);

            return(node);
        }
Esempio n. 7
0
        private static Texture NodeIcon(Type behaviourType)
        {
            var prop = BonsaiEditor.GetNodeTypeProperties(behaviourType);

            return(BonsaiPreferences.Texture(prop.texName));
        }