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(); }
static bool OpenCanvasAsset(int instanceID, int line) { var tree = EditorUtility.InstanceIDToObject(instanceID) as BehaviourTree; BonsaiWindow w = OpenTree(tree); if (w) { // If a tree asset was created but has no blackboard, add one upon opening. // This is for convenience. BonsaiSaver.AddBlackboardIfMissing(tree); w.SwitchToViewModeIfRequired(); } return(w); }
private void CreateNew() { QuickSave(); SetTree(BonsaiSaver.CreateBehaviourTree()); ShowNotification(new GUIContent("New Tree Created")); }