Program.cs 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. using System;
  4. using bs;
  5. namespace bs.Editor
  6. {
  7. /** @addtogroup BansheeEditor
  8. * Scripting API available in editor only, mainly used for extending the editor in various ways.
  9. * @{
  10. */
  11. /** @defgroup General General
  12. * Various functionality that doesn't fit into any other category.
  13. */
  14. /** @defgroup GUI-Editor GUI
  15. * Editor specific GUI elements.
  16. */
  17. /** @defgroup Input-Editor Input
  18. * %Input handling for editor only (not affected by game pauses).
  19. */
  20. /** @defgroup Inspectors Inspectors
  21. * Implementations of inspectors for various engine types.
  22. */
  23. /** @defgroup Settings Settings
  24. * Editor and project settings, and related window.
  25. */
  26. /** @defgroup Script Script
  27. * Script code management and compilation.
  28. */
  29. /** @defgroup Tests Tests
  30. * Editor only unit tests
  31. */
  32. /** @defgroup Utility-Editor Utility
  33. * Various utility functionality.
  34. */
  35. /** @defgroup Window Window
  36. * Interface and tools for creating custom editor windows.
  37. */
  38. /** @defgroup Windows Windows
  39. * Implementations of various editor windows (for example Scene, Game, Library).
  40. * @{
  41. */
  42. /** @defgroup AnimationEditor Animation Editor
  43. * Animation editor window and related functionality.
  44. */
  45. /** @defgroup Build Build
  46. * Build editor window and build manager.
  47. */
  48. /** @defgroup Inspector Inspector
  49. * Interface and utilities needed for implementing custom inspectors.
  50. */
  51. /** @defgroup Library Library
  52. * Managment of resources in the project (loading, saving, creating, querying, etc.).
  53. */
  54. /** @defgroup Scene-Editor Scene
  55. * Scene editor window and related functionality.
  56. * @{
  57. */
  58. /** @defgroup Gizmos Gizmos
  59. * Interface for creating custom gizmos.
  60. */
  61. /** @defgroup Handles Handles
  62. * Interface for creating custom handles (2D/3D tools).
  63. */
  64. /** @} */
  65. /** @} */
  66. /** @} */
  67. /** @cond Interop */
  68. /// <summary>
  69. /// Entry point to the editor.
  70. /// </summary>
  71. class Program
  72. {
  73. private static EditorApplication app;
  74. private static bool delayQuit;
  75. /// <summary>
  76. /// Called by the runtime whenever the editor assembly is loaded. This means initially when editor is started
  77. /// and every time assembly refresh occurs.
  78. /// </summary>
  79. static void OnInitialize()
  80. {
  81. app = new EditorApplication();
  82. }
  83. /// <summary>
  84. /// Called by the runtime when the editor is first started. Called after <see cref="OnInitialize"/>.
  85. /// </summary>
  86. static void OnEditorStartUp()
  87. {
  88. if (EditorSettings.AutoLoadLastProject)
  89. {
  90. string projectPath = EditorSettings.LastOpenProject;
  91. if (EditorApplication.IsValidProject(projectPath))
  92. EditorApplication.LoadProject(projectPath);
  93. else
  94. ProjectWindow.Open();
  95. }
  96. else
  97. ProjectWindow.Open();
  98. CodeEditorType activeCodeEditor = (CodeEditorType)EditorSettings.GetInt(SettingsWindow.ActiveCodeEditorKey, (int) CodeEditorType.None);
  99. CodeEditorType[] availableEditors = CodeEditor.AvailableEditors;
  100. if (Array.Exists(availableEditors, x => x == activeCodeEditor))
  101. CodeEditor.ActiveEditor = activeCodeEditor;
  102. else
  103. {
  104. if (availableEditors.Length > 0)
  105. CodeEditor.ActiveEditor = availableEditors[0];
  106. }
  107. }
  108. /// <summary>
  109. /// Called 60 times per second by the runtime.
  110. /// </summary>
  111. static void OnEditorUpdate()
  112. {
  113. if (delayQuit && !ProjectLibrary.ImportInProgress)
  114. {
  115. ConfirmImportInProgressWindow.Hide();
  116. EditorApplication.SaveProject();
  117. EditorApplication.Quit();
  118. delayQuit = false;
  119. }
  120. app.OnEditorUpdate();
  121. }
  122. /// <summary>
  123. /// Called when the user requests that the editor shuts down. You must manually close the editor from this
  124. /// method if you choose to accept the users request.
  125. /// </summary>
  126. static void OnEditorQuitRequested()
  127. {
  128. if (delayQuit)
  129. return;
  130. EditorApplication.AskToSaveSceneAndContinue(
  131. () =>
  132. {
  133. if (ProjectLibrary.ImportInProgress)
  134. {
  135. ConfirmImportInProgressWindow.Show();
  136. delayQuit = true;
  137. }
  138. else
  139. {
  140. EditorApplication.SaveProject();
  141. EditorApplication.Quit();
  142. }
  143. });
  144. }
  145. }
  146. /** @endcond */
  147. }