Program.cs 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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. * @{
  9. */
  10. /** @defgroup GUI-Editor GUI
  11. *
  12. */
  13. /** @defgroup Input-Editor Input
  14. *
  15. */
  16. /** @defgroup General General
  17. *
  18. */
  19. /** @defgroup Inspectors Inspectors
  20. *
  21. */
  22. /** @defgroup Script Script
  23. *
  24. */
  25. /** @defgroup Tests Tests
  26. *
  27. */
  28. /** @defgroup Utility-Editor Utility
  29. *
  30. */
  31. /** @defgroup Window Window
  32. *
  33. */
  34. /** @defgroup Windows Windows
  35. * @{
  36. */
  37. /** @defgroup Build Build
  38. *
  39. */
  40. /** @defgroup Inspector Inspector
  41. *
  42. */
  43. /** @defgroup Library Library
  44. *
  45. */
  46. /** @defgroup Scene-Editor Scene
  47. * @{
  48. */
  49. /** @defgroup Gizmos Gizmos
  50. *
  51. */
  52. /** @defgroup Handles Handles
  53. *
  54. */
  55. /** @} */
  56. /** @defgroup Settings Settings
  57. *
  58. */
  59. /** @} */
  60. /** @} */
  61. /** @cond Interop */
  62. /// <summary>
  63. /// Entry point to the editor.
  64. /// </summary>
  65. class Program
  66. {
  67. private static EditorApplication app;
  68. /// <summary>
  69. /// Called by the runtime whenever the editor assembly is loaded. This means initially when editor is started
  70. /// and every time assembly refresh occurs.
  71. /// </summary>
  72. static void OnInitialize()
  73. {
  74. app = new EditorApplication();
  75. }
  76. /// <summary>
  77. /// Called by the runtime when the editor is first started. Called after <see cref="OnInitialize"/>.
  78. /// </summary>
  79. static void OnEditorStartUp()
  80. {
  81. if (EditorSettings.AutoLoadLastProject)
  82. {
  83. string projectPath = EditorSettings.LastOpenProject;
  84. if (EditorApplication.IsValidProject(projectPath))
  85. EditorApplication.LoadProject(projectPath);
  86. else
  87. ProjectWindow.Open();
  88. }
  89. else
  90. ProjectWindow.Open();
  91. CodeEditorType activeCodeEditor = (CodeEditorType)EditorSettings.GetInt(SettingsWindow.ActiveCodeEditorKey, (int) CodeEditorType.None);
  92. CodeEditorType[] availableEditors = CodeEditor.AvailableEditors;
  93. if (Array.Exists(availableEditors, x => x == activeCodeEditor))
  94. CodeEditor.ActiveEditor = activeCodeEditor;
  95. else
  96. {
  97. if (availableEditors.Length > 0)
  98. CodeEditor.ActiveEditor = availableEditors[0];
  99. }
  100. }
  101. /// <summary>
  102. /// Called 60 times per second by the runtime.
  103. /// </summary>
  104. static void OnEditorUpdate()
  105. {
  106. app.OnEditorUpdate();
  107. }
  108. /// <summary>
  109. /// Attempts to save the current scene, and keeps retrying if failed or until user cancels.
  110. /// </summary>
  111. static void TrySaveScene()
  112. {
  113. Action success = () =>
  114. {
  115. EditorApplication.SaveProject();
  116. EditorApplication.Quit();
  117. };
  118. EditorApplication.SaveScene(success, TrySaveScene);
  119. }
  120. /// <summary>
  121. /// Called when the user requests that the editor shuts down. You must manually close the editor from this
  122. /// method if you choose to accept the users request.
  123. /// </summary>
  124. static void OnEditorQuitRequested()
  125. {
  126. Action<DialogBox.ResultType> dialogCallback =
  127. (result) =>
  128. {
  129. if (result == DialogBox.ResultType.Yes)
  130. TrySaveScene();
  131. else if (result == DialogBox.ResultType.No)
  132. {
  133. EditorApplication.SaveProject();
  134. EditorApplication.Quit();
  135. }
  136. };
  137. if (EditorApplication.IsSceneModified())
  138. {
  139. DialogBox.Open("Warning", "You current scene has modifications. Do you wish to save them first?",
  140. DialogBox.Type.YesNoCancel, dialogCallback);
  141. }
  142. else
  143. {
  144. EditorApplication.SaveProject();
  145. EditorApplication.Quit();
  146. }
  147. }
  148. }
  149. /** @endcond */
  150. }