2
0

Program.cs 5.4 KB

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