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(); }
// 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); }); } }
private static Texture NodeIcon(Type behaviourType) { var prop = BonsaiEditor.GetNodeTypeProperties(behaviourType); return(BonsaiPreferences.Texture(prop.texName)); }