EditorApplication.cs 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Runtime.CompilerServices;
  4. using System.IO;
  5. using BansheeEngine;
  6. namespace BansheeEditor
  7. {
  8. /// <summary>
  9. /// Available tools in the scene view.
  10. /// </summary>
  11. public enum SceneViewTool
  12. {
  13. View,
  14. Move,
  15. Rotate,
  16. Scale
  17. }
  18. /// <summary>
  19. /// Pivot mode used by the scene view tools.
  20. /// </summary>
  21. public enum HandlePivotMode
  22. {
  23. Center,
  24. Pivot
  25. }
  26. /// <summary>
  27. /// Coordinate mode used by the scene view tools.
  28. /// </summary>
  29. public enum HandleCoordinateMode
  30. {
  31. Local,
  32. World
  33. }
  34. /// <summary>
  35. /// Manages various generic and global settings relating to the editor.
  36. /// </summary>
  37. public class EditorApplication
  38. {
  39. /// <summary>
  40. /// Determines the active tool shown in the scene view.
  41. /// </summary>
  42. public static SceneViewTool ActiveSceneTool
  43. {
  44. get { return EditorSettings.ActiveSceneTool; }
  45. set { EditorSettings.ActiveSceneTool = value; }
  46. }
  47. /// <summary>
  48. /// Determines the coordinate mode used by the tools in the scene view.
  49. /// </summary>
  50. public static HandleCoordinateMode ActiveCoordinateMode
  51. {
  52. get { return EditorSettings.ActiveCoordinateMode; }
  53. set { EditorSettings.ActiveCoordinateMode = value; }
  54. }
  55. /// <summary>
  56. /// Determines the pivot mode used by the tools in the scene view.
  57. /// </summary>
  58. public static HandlePivotMode ActivePivotMode
  59. {
  60. get { return EditorSettings.ActivePivotMode; }
  61. set { EditorSettings.ActivePivotMode = value; }
  62. }
  63. /// <summary>
  64. /// Camera used for rendering the scene view.
  65. /// </summary>
  66. public static Camera SceneViewCamera
  67. {
  68. get { return EditorWindow.GetWindow<SceneWindow>().Camera; }
  69. }
  70. /// <summary>
  71. /// Absolute path to the folder containing the currently open project.
  72. /// </summary>
  73. public static string ProjectPath { get { return Internal_GetProjectPath(); } }
  74. /// <summary>
  75. /// Name of the currently open project.
  76. /// </summary>
  77. public static string ProjectName { get { return Internal_GetProjectName(); } }
  78. /// <summary>
  79. /// Checks is any project currently loaded.
  80. /// </summary>
  81. public static bool IsProjectLoaded { get { return Internal_GetProjectLoaded(); } }
  82. /// <summary>
  83. /// Determines is the game currently running in the editor, or is it stopped or paused. Setting this value to false
  84. /// will stop the game, but if you just want to pause it use <see cref="IsPaused"/> property.
  85. /// </summary>
  86. public static bool IsPlaying
  87. {
  88. get { return Internal_GetIsPlaying(); }
  89. set { Internal_SetIsPlaying(value); }
  90. }
  91. /// <summary>
  92. /// Determines if the game is currently running in the editor, but paused. If the game is stopped and not running
  93. /// this will return false. If the game is not running and this is enabled, the game will start running but be
  94. /// immediately paused.
  95. /// </summary>
  96. public static bool IsPaused
  97. {
  98. get { return Internal_GetIsPaused(); }
  99. set { Internal_SetIsPaused(value); }
  100. }
  101. /// <summary>
  102. /// Returns the path where the script compiler is located at.
  103. /// </summary>
  104. internal static string CompilerPath { get { return Internal_GetCompilerPath(); } }
  105. /// <summary>
  106. /// Returns the path to the folder where the builtin script assemblies are located at.
  107. /// </summary>
  108. internal static string BuiltinAssemblyPath { get { return Internal_GetBuiltinAssemblyPath(); } }
  109. /// <summary>
  110. /// Returns the path to the folder where the custom script assemblies are located at.
  111. /// </summary>
  112. internal static string ScriptAssemblyPath { get { return Internal_GetScriptAssemblyPath(); } }
  113. /// <summary>
  114. /// Returns the path to the folder where the .NET framework assemblies are located at.
  115. /// </summary>
  116. internal static string FrameworkAssemblyPath { get { return Internal_GetFrameworkAssemblyPath(); } }
  117. /// <summary>
  118. /// Name of the builtin assembly containing engine specific types.
  119. /// </summary>
  120. internal static string EngineAssemblyName { get { return Internal_GetEngineAssemblyName(); } }
  121. /// <summary>
  122. /// Name of the builtin assembly containing editor specific types.
  123. /// </summary>
  124. internal static string EditorAssemblyName { get { return Internal_GetEditorAssemblyName(); } }
  125. /// <summary>
  126. /// Name of the custom assembly compiled from non-editor scripts within the project.
  127. /// </summary>
  128. internal static string ScriptGameAssemblyName { get { return Internal_GetScriptGameAssemblyName(); } }
  129. /// <summary>
  130. /// Name of the custom assembly compiled from editor scripts within the project.
  131. /// </summary>
  132. internal static string ScriptEditorAssemblyName { get { return Internal_GetScriptEditorAssemblyName(); } }
  133. private static EditorApplication instance;
  134. private static FolderMonitor monitor;
  135. private static ScriptCodeManager codeManager;
  136. private static HashSet<string> dirtyResources = new HashSet<string>();
  137. private static bool sceneDirty;
  138. private static bool unitTestsExecuted;
  139. /// <summary>
  140. /// Constructs a new editor application. Called at editor start-up by the runtime.
  141. /// </summary>
  142. internal EditorApplication()
  143. {
  144. instance = this;
  145. codeManager = new ScriptCodeManager();
  146. // Register controls
  147. InputConfiguration inputConfig = VirtualInput.KeyConfig;
  148. inputConfig.RegisterButton(SceneCamera.MoveForwardBinding, ButtonCode.W);
  149. inputConfig.RegisterButton(SceneCamera.MoveBackBinding, ButtonCode.S);
  150. inputConfig.RegisterButton(SceneCamera.MoveLeftBinding, ButtonCode.A);
  151. inputConfig.RegisterButton(SceneCamera.MoveRightBinding, ButtonCode.D);
  152. inputConfig.RegisterButton(SceneCamera.MoveForwardBinding, ButtonCode.Up);
  153. inputConfig.RegisterButton(SceneCamera.MoveBackBinding, ButtonCode.Down);
  154. inputConfig.RegisterButton(SceneCamera.MoveLeftBinding, ButtonCode.Left);
  155. inputConfig.RegisterButton(SceneCamera.MoveRightBinding, ButtonCode.Right);
  156. inputConfig.RegisterButton(SceneCamera.FastMoveBinding, ButtonCode.LeftShift);
  157. inputConfig.RegisterButton(SceneCamera.RotateBinding, ButtonCode.MouseRight);
  158. inputConfig.RegisterAxis(SceneCamera.HorizontalAxisBinding, InputAxis.MouseX);
  159. inputConfig.RegisterAxis(SceneCamera.VerticalAxisBinding, InputAxis.MouseY);
  160. inputConfig.RegisterButton(SceneWindow.ToggleProfilerOverlayBinding, ButtonCode.P, ButtonModifier.CtrlAlt);
  161. inputConfig.RegisterButton(SceneWindow.ViewToolBinding, ButtonCode.Q);
  162. inputConfig.RegisterButton(SceneWindow.MoveToolBinding, ButtonCode.W);
  163. inputConfig.RegisterButton(SceneWindow.RotateToolBinding, ButtonCode.E);
  164. inputConfig.RegisterButton(SceneWindow.ScaleToolBinding, ButtonCode.R);
  165. inputConfig.RegisterButton(SceneWindow.DuplicateBinding, ButtonCode.D, ButtonModifier.Ctrl);
  166. if (IsProjectLoaded)
  167. {
  168. monitor = new FolderMonitor(ProjectLibrary.ResourceFolder);
  169. monitor.OnAdded += OnAssetModified;
  170. monitor.OnRemoved += OnAssetModified;
  171. monitor.OnModified += OnAssetModified;
  172. }
  173. }
  174. /// <summary>
  175. /// Triggered when the folder monitor detects an asset in the monitored folder was modified.
  176. /// </summary>
  177. /// <param name="path">Path to the modified file or folder.</param>
  178. private static void OnAssetModified(string path)
  179. {
  180. ProjectLibrary.Refresh(path);
  181. }
  182. /// <summary>
  183. /// Called 60 times per second by the runtime.
  184. /// </summary>
  185. internal void OnEditorUpdate()
  186. {
  187. ProjectLibrary.Update();
  188. codeManager.Update();
  189. }
  190. /// <summary>
  191. /// Creates a new empty scene.
  192. /// </summary>
  193. [MenuItem("File/New Scene", 10051, true)]
  194. private static void NewScene()
  195. {
  196. LoadScene(null);
  197. }
  198. /// <summary>
  199. /// Opens a dialog that allows the user to select a new prefab to load as the current scene. If current scene
  200. /// is modified the user is offered a chance to save it.
  201. /// </summary>
  202. [MenuItem("File/Open Scene", ButtonModifier.Ctrl, ButtonCode.L, 10050)]
  203. private static void LoadScene()
  204. {
  205. string[] scenePaths;
  206. if (BrowseDialog.OpenFile(ProjectLibrary.ResourceFolder, "", false, out scenePaths))
  207. {
  208. if (scenePaths.Length > 0)
  209. LoadScene(scenePaths[0]);
  210. }
  211. }
  212. /// <summary>
  213. /// Opens a dialog to allows the user to select a location where to save the current scene. If scene was previously
  214. /// saved it is instead automatically saved at the last location.
  215. /// </summary>
  216. public static void SaveScene(Action onSuccess = null, Action onFailure = null)
  217. {
  218. if (!string.IsNullOrEmpty(Scene.ActiveSceneUUID))
  219. {
  220. string scenePath = ProjectLibrary.GetPath(Scene.ActiveSceneUUID);
  221. SaveScene(scenePath);
  222. if (onSuccess != null)
  223. onSuccess();
  224. }
  225. else
  226. SaveSceneAs(onSuccess, onFailure);
  227. }
  228. /// <summary>
  229. /// Opens a dialog to allows the user to select a location where to save the current scene.
  230. /// </summary>
  231. public static void SaveSceneAs(Action onSuccess = null, Action onFailure = null)
  232. {
  233. string scenePath = "";
  234. if (BrowseDialog.SaveFile(ProjectLibrary.ResourceFolder, "*.prefab", out scenePath))
  235. {
  236. if (!PathEx.IsPartOf(scenePath, ProjectLibrary.ResourceFolder))
  237. {
  238. DialogBox.Open("Error", "The location must be inside the Resources folder of the project.",
  239. DialogBox.Type.OK,
  240. x =>
  241. {
  242. if (onFailure != null)
  243. onFailure();
  244. });
  245. }
  246. else
  247. {
  248. // TODO - If path points to an existing non-scene asset or folder I should delete it otherwise
  249. // Internal_SaveScene will silently fail.
  250. scenePath += ".prefab";
  251. SaveScene(scenePath);
  252. }
  253. }
  254. else
  255. {
  256. // User canceled, so technically a success
  257. if (onSuccess != null)
  258. onSuccess();
  259. }
  260. }
  261. /// <summary>
  262. /// Loads a prefab as the current scene at the specified path. If current scene is modified the user is offered a
  263. /// chance to save it.
  264. /// </summary>
  265. /// <param name="path">Path to a valid prefab relative to the resource folder. If path is empty a brand new
  266. /// scene will be loaded.</param>
  267. public static void LoadScene(string path)
  268. {
  269. Action<string> continueLoad =
  270. (scenePath) =>
  271. {
  272. if (string.IsNullOrEmpty(path))
  273. Scene.Clear();
  274. else
  275. Scene.Load(path);
  276. SetSceneDirty(false);
  277. ProjectSettings.LastOpenScene = scenePath;
  278. ProjectSettings.Save();
  279. };
  280. Action<DialogBox.ResultType> dialogCallback =
  281. (result) =>
  282. {
  283. if (result == DialogBox.ResultType.Yes)
  284. {
  285. SaveScene();
  286. continueLoad(path);
  287. }
  288. else if (result == DialogBox.ResultType.No)
  289. continueLoad(path);
  290. };
  291. if (IsSceneModified())
  292. {
  293. DialogBox.Open("Warning", "You current scene has modifications. Do you wish to save them first?",
  294. DialogBox.Type.YesNoCancel, dialogCallback);
  295. }
  296. else
  297. continueLoad(path);
  298. }
  299. /// <summary>
  300. /// Saves the currently loaded scene to the specified path.
  301. /// </summary>
  302. /// <param name="path">Path relative to the resource folder. This can be the path to the existing scene
  303. /// prefab if it just needs updating. </param>
  304. public static void SaveScene(string path)
  305. {
  306. Internal_SaveScene(path);
  307. ProjectLibrary.Refresh(true);
  308. SetSceneDirty(false);
  309. }
  310. /// <summary>
  311. /// Checks does the folder at the provieded path contain a valid project.
  312. /// </summary>
  313. /// <param name="path">Absolute path to the root project folder.</param>
  314. /// <returns>True if the folder contains a valid project.</returns>
  315. public static bool IsValidProject(string path)
  316. {
  317. return Internal_IsValidProject(path);
  318. }
  319. /// <summary>
  320. /// Contains a new project in the provided folder.
  321. /// </summary>
  322. /// <param name="path">Absolute path to the folder to create the project in. Name of this folder will be used as the
  323. /// project's name.</param>
  324. public static void CreateProject(string path)
  325. {
  326. Internal_CreateProject(path);
  327. }
  328. /// <summary>
  329. /// Wrapper for menu items for <see cref="SaveScene(Action, Action)"/> method
  330. /// </summary>
  331. [MenuItem("File/Save Scene", ButtonModifier.Ctrl, ButtonCode.S, 10049)]
  332. [ToolbarItem("Save Scene", ToolbarIcon.SaveScene, "", 1998)]
  333. private static void SaveSceneMenu()
  334. {
  335. SaveScene();
  336. }
  337. /// <summary>
  338. /// Wrapper for menu items for <see cref="SaveSceneAs(Action, Action)"/> method
  339. /// </summary>
  340. [MenuItem("File/Save Scene As", 10048)]
  341. private static void SaveSceneAsMenu()
  342. {
  343. SaveSceneAs();
  344. }
  345. /// <summary>
  346. /// Opens a Project Window allowing you to browse for or create a project.
  347. /// </summary>
  348. [MenuItem("File/Open Project", 10100)]
  349. [ToolbarItem("Open Project", ToolbarIcon.OpenProject, "", 2000)]
  350. public static void BrowseForProject()
  351. {
  352. ProjectWindow.Open();
  353. }
  354. /// <summary>
  355. /// Saves all data in the currently open project.
  356. /// </summary>
  357. [MenuItem("File/Save Project", 10099)]
  358. [ToolbarItem("Save Project", ToolbarIcon.SaveProject, "", 1999)]
  359. public static void SaveProject()
  360. {
  361. foreach (var resourceUUID in dirtyResources)
  362. {
  363. string path = ProjectLibrary.GetPath(resourceUUID);
  364. Resource resource = ProjectLibrary.Load<Resource>(path);
  365. if(resource != null)
  366. ProjectLibrary.Save(resource);
  367. }
  368. dirtyResources.Clear();
  369. SetStatusProject(false);
  370. Internal_SaveProject();
  371. }
  372. /// <summary>
  373. /// Loads the project at the specified path. This method executes asynchronously.
  374. /// </summary>
  375. /// <param name="path">Absolute path to the project's root folder.</param>
  376. public static void LoadProject(string path)
  377. {
  378. if (IsProjectLoaded && path == ProjectPath)
  379. return;
  380. if (!Internal_IsValidProject(path))
  381. {
  382. Debug.LogWarning("Provided path: \"" + path + "\" is not a valid project.");
  383. return;
  384. }
  385. if (IsProjectLoaded)
  386. UnloadProject();
  387. Internal_LoadProject(path); // Triggers Internal_OnProjectLoaded when done
  388. }
  389. /// <summary>
  390. /// Closes the editor.
  391. /// </summary>
  392. public static void Quit()
  393. {
  394. Internal_Quit();
  395. }
  396. /// <summary>
  397. /// Toggles an existing toolbar button into an on or off state which changes the visuals of the button.
  398. /// </summary>
  399. /// <param name="name">Name of the existing button to toggle</param>
  400. /// <param name="on">True to toggle on, false to toggle off (default)</param>
  401. public static void ToggleToolbarItem(string name, bool on)
  402. {
  403. Internal_ToggleToolbarItem(name, on);
  404. }
  405. /// <summary>
  406. /// Opens a file or a folder in the default external application.
  407. /// </summary>
  408. /// <param name="path">Absolute path to the file or folder to open.</param>
  409. public static void OpenExternally(string path)
  410. {
  411. Internal_OpenExternally(path);
  412. }
  413. /// <summary>
  414. /// Marks a resource as dirty so that it may be saved the next time the project is saved. Optionally you may also
  415. /// call <see cref="ProjectLibrary.Save"/> to save it immediately.
  416. /// </summary>
  417. /// <param name="resource">Resource to mark as dirty</param>
  418. public static void SetDirty(Resource resource)
  419. {
  420. if (resource == null)
  421. return;
  422. SetStatusProject(true);
  423. dirtyResources.Add(resource.UUID);
  424. }
  425. /// <summary>
  426. /// Marks the current scene as dirty.
  427. /// </summary>
  428. public static void SetSceneDirty()
  429. {
  430. SetSceneDirty(true);
  431. }
  432. /// <summary>
  433. /// Marks the current scene as clean or dirty.
  434. /// </summary>
  435. /// <param name="dirty">Should the scene be marked as clean or dirty.</param>
  436. internal static void SetSceneDirty(bool dirty)
  437. {
  438. sceneDirty = dirty;
  439. SetStatusScene(Scene.ActiveSceneName, dirty);
  440. if (!dirty)
  441. dirtyResources.Remove(Scene.ActiveSceneUUID);
  442. }
  443. /// <summary>
  444. /// Checks is the specific resource dirty and needs saving.
  445. /// </summary>
  446. /// <param name="resource">Resource to check.</param>
  447. /// <returns>True if the resource requires saving, false otherwise.</returns>
  448. public static bool IsDirty(Resource resource)
  449. {
  450. return dirtyResources.Contains(resource.UUID);
  451. }
  452. /// <summary>
  453. /// Unloads the currently loaded project. Offers the user a chance to save the current scene if it is modified.
  454. /// Automatically saves all project data before unloading.
  455. /// </summary>
  456. private static void UnloadProject()
  457. {
  458. Action continueUnload =
  459. () =>
  460. {
  461. Scene.Clear();
  462. if (monitor != null)
  463. {
  464. monitor.Destroy();
  465. monitor = null;
  466. }
  467. LibraryWindow window = EditorWindow.GetWindow<LibraryWindow>();
  468. if(window != null)
  469. window.Reset();
  470. SetSceneDirty(false);
  471. Internal_UnloadProject();
  472. SetStatusProject(false);
  473. };
  474. Action<DialogBox.ResultType> dialogCallback =
  475. (result) =>
  476. {
  477. if (result == DialogBox.ResultType.Yes)
  478. SaveScene();
  479. continueUnload();
  480. };
  481. if (IsSceneModified())
  482. {
  483. DialogBox.Open("Warning", "You current scene has modifications. Do you wish to save them first?",
  484. DialogBox.Type.YesNoCancel, dialogCallback);
  485. }
  486. else
  487. continueUnload();
  488. }
  489. /// <summary>
  490. /// Reloads all script assemblies in case they were modified. This action is delayed and will be executed
  491. /// at the beginning of the next frame.
  492. /// </summary>
  493. public static void ReloadAssemblies()
  494. {
  495. Internal_ReloadAssemblies();
  496. }
  497. /// <summary>
  498. /// Changes the scene displayed on the status bar.
  499. /// </summary>
  500. /// <param name="name">Name of the scene.</param>
  501. /// <param name="modified">Whether to display the scene as modified or not.</param>
  502. private static void SetStatusScene(string name, bool modified)
  503. {
  504. Internal_SetStatusScene(name, modified);
  505. }
  506. /// <summary>
  507. /// Changes the project state displayed on the status bar.
  508. /// </summary>
  509. /// <param name="modified">Whether to display the project as modified or not.</param>
  510. private static void SetStatusProject(bool modified)
  511. {
  512. Internal_SetStatusProject(modified);
  513. }
  514. /// <summary>
  515. /// Displays or hides the "compilation in progress" visual on the status bar.
  516. /// </summary>
  517. /// <param name="compiling">True to display the visual, false otherwise.</param>
  518. internal static void SetStatusCompiling(bool compiling)
  519. {
  520. Internal_SetStatusCompiling(compiling);
  521. }
  522. /// <summary>
  523. /// Checks did we make any modifications to the scene since it was last saved.
  524. /// </summary>
  525. /// <returns>True if the scene was never saved, or was modified after last save.</returns>
  526. public static bool IsSceneModified()
  527. {
  528. return sceneDirty;
  529. }
  530. /// <summary>
  531. /// Runs a single frame of the game and pauses it. If the game is not currently running it will be started.
  532. /// </summary>
  533. public static void FrameStep()
  534. {
  535. Internal_FrameStep();
  536. }
  537. /// <summary>
  538. /// Executes any editor-specific unit tests. This should be called after a project is loaded if possible.
  539. /// </summary>
  540. private static void RunUnitTests()
  541. {
  542. #if DEBUG
  543. Internal_RunUnitTests();
  544. #endif
  545. }
  546. /// <summary>
  547. /// Triggered by the runtime when <see cref="LoadProject"/> method completes.
  548. /// </summary>
  549. private static void Internal_OnProjectLoaded()
  550. {
  551. SetStatusProject(false);
  552. if (!unitTestsExecuted)
  553. {
  554. RunUnitTests();
  555. unitTestsExecuted = true;
  556. }
  557. if (!IsProjectLoaded)
  558. {
  559. ProjectWindow.Open();
  560. return;
  561. }
  562. string projectPath = ProjectPath;
  563. RecentProject[] recentProjects = EditorSettings.RecentProjects;
  564. bool foundPath = false;
  565. for (int i = 0; i < recentProjects.Length; i++)
  566. {
  567. if (PathEx.Compare(recentProjects[i].path, projectPath))
  568. {
  569. recentProjects[i].accessTimestamp = (ulong)DateTime.Now.Ticks;
  570. EditorSettings.RecentProjects = recentProjects;
  571. foundPath = true;
  572. break;
  573. }
  574. }
  575. if (!foundPath)
  576. {
  577. List<RecentProject> extendedRecentProjects = new List<RecentProject>();
  578. extendedRecentProjects.AddRange(recentProjects);
  579. RecentProject newProject = new RecentProject();
  580. newProject.path = projectPath;
  581. newProject.accessTimestamp = (ulong)DateTime.Now.Ticks;
  582. extendedRecentProjects.Add(newProject);
  583. EditorSettings.RecentProjects = extendedRecentProjects.ToArray();
  584. }
  585. EditorSettings.LastOpenProject = projectPath;
  586. EditorSettings.Save();
  587. ProjectLibrary.Refresh();
  588. monitor = new FolderMonitor(ProjectLibrary.ResourceFolder);
  589. monitor.OnAdded += OnAssetModified;
  590. monitor.OnRemoved += OnAssetModified;
  591. monitor.OnModified += OnAssetModified;
  592. if (!string.IsNullOrWhiteSpace(ProjectSettings.LastOpenScene))
  593. {
  594. Scene.Load(ProjectSettings.LastOpenScene);
  595. SetSceneDirty(false);
  596. }
  597. }
  598. /// <summary>
  599. /// Triggered by the runtime when the user clicks on the status bar.
  600. /// </summary>
  601. private static void Internal_OnStatusBarClicked()
  602. {
  603. EditorWindow.OpenWindow<ConsoleWindow>();
  604. }
  605. [MethodImpl(MethodImplOptions.InternalCall)]
  606. private static extern void Internal_SetStatusScene(string name, bool modified);
  607. [MethodImpl(MethodImplOptions.InternalCall)]
  608. private static extern void Internal_SetStatusProject(bool modified);
  609. [MethodImpl(MethodImplOptions.InternalCall)]
  610. private static extern void Internal_SetStatusCompiling(bool compiling);
  611. [MethodImpl(MethodImplOptions.InternalCall)]
  612. private static extern string Internal_GetProjectPath();
  613. [MethodImpl(MethodImplOptions.InternalCall)]
  614. private static extern string Internal_GetProjectName();
  615. [MethodImpl(MethodImplOptions.InternalCall)]
  616. private static extern bool Internal_GetProjectLoaded();
  617. [MethodImpl(MethodImplOptions.InternalCall)]
  618. private static extern string Internal_GetCompilerPath();
  619. [MethodImpl(MethodImplOptions.InternalCall)]
  620. private static extern string Internal_GetBuiltinAssemblyPath();
  621. [MethodImpl(MethodImplOptions.InternalCall)]
  622. private static extern string Internal_GetScriptAssemblyPath();
  623. [MethodImpl(MethodImplOptions.InternalCall)]
  624. private static extern string Internal_GetFrameworkAssemblyPath();
  625. [MethodImpl(MethodImplOptions.InternalCall)]
  626. private static extern string Internal_GetEngineAssemblyName();
  627. [MethodImpl(MethodImplOptions.InternalCall)]
  628. private static extern string Internal_GetEditorAssemblyName();
  629. [MethodImpl(MethodImplOptions.InternalCall)]
  630. private static extern string Internal_GetScriptGameAssemblyName();
  631. [MethodImpl(MethodImplOptions.InternalCall)]
  632. private static extern string Internal_GetScriptEditorAssemblyName();
  633. [MethodImpl(MethodImplOptions.InternalCall)]
  634. private static extern string Internal_SaveScene(string path);
  635. [MethodImpl(MethodImplOptions.InternalCall)]
  636. private static extern bool Internal_IsValidProject(string path);
  637. [MethodImpl(MethodImplOptions.InternalCall)]
  638. private static extern void Internal_SaveProject();
  639. [MethodImpl(MethodImplOptions.InternalCall)]
  640. private static extern void Internal_LoadProject(string path);
  641. [MethodImpl(MethodImplOptions.InternalCall)]
  642. private static extern void Internal_UnloadProject();
  643. [MethodImpl(MethodImplOptions.InternalCall)]
  644. private static extern void Internal_CreateProject(string path);
  645. [MethodImpl(MethodImplOptions.InternalCall)]
  646. private static extern void Internal_ReloadAssemblies();
  647. [MethodImpl(MethodImplOptions.InternalCall)]
  648. private static extern void Internal_OpenExternally(string path);
  649. [MethodImpl(MethodImplOptions.InternalCall)]
  650. private static extern void Internal_RunUnitTests();
  651. [MethodImpl(MethodImplOptions.InternalCall)]
  652. private static extern void Internal_Quit();
  653. [MethodImpl(MethodImplOptions.InternalCall)]
  654. private static extern void Internal_ToggleToolbarItem(string name, bool on);
  655. [MethodImpl(MethodImplOptions.InternalCall)]
  656. private static extern bool Internal_GetIsPlaying();
  657. [MethodImpl(MethodImplOptions.InternalCall)]
  658. private static extern void Internal_SetIsPlaying(bool value);
  659. [MethodImpl(MethodImplOptions.InternalCall)]
  660. private static extern bool Internal_GetIsPaused();
  661. [MethodImpl(MethodImplOptions.InternalCall)]
  662. private static extern void Internal_SetIsPaused(bool value);
  663. [MethodImpl(MethodImplOptions.InternalCall)]
  664. private static extern void Internal_FrameStep();
  665. }
  666. }