예제 #1
0
        void OnEnable()
        {
            //BonsaiPreferences.Current = 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.OnEditorModeChanged += (s, mode) => { EditorMode = mode; };

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

            BuildCanvas();
            Editor.EditorMode = BonsaiEditor.Mode.Edit;
            SwitchToViewModeIfRequired();
        }
예제 #2
0
        // 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);
        }
예제 #3
0
        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);
                });
            }
        }
예제 #4
0
        private static Texture NodeIcon(Type behaviourType)
        {
            var prop = BonsaiEditor.GetNodeTypeProperties(behaviourType);

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