2
0

Program.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. using System;
  4. using System.Collections.Generic;
  5. using BansheeEngine;
  6. namespace BansheeEditor
  7. {
  8. /// <summary>
  9. /// Entry point to the editor.
  10. /// </summary>
  11. class Program
  12. {
  13. private static EditorApplication app;
  14. /// <summary>
  15. /// Called by the runtime whenever the editor assembly is loaded. This means initially when editor is started
  16. /// and every time assembly refresh occurs.
  17. /// </summary>
  18. static void OnInitialize()
  19. {
  20. app = new EditorApplication();
  21. }
  22. /// <summary>
  23. /// Called by the runtime when the editor is first started. Called after <see cref="OnInitialize"/>.
  24. /// </summary>
  25. static void OnEditorStartUp()
  26. {
  27. if (EditorSettings.AutoLoadLastProject)
  28. {
  29. string projectPath = EditorSettings.LastOpenProject;
  30. if (EditorApplication.IsValidProject(projectPath))
  31. EditorApplication.LoadProject(projectPath);
  32. else
  33. ProjectWindow.Open();
  34. }
  35. else
  36. ProjectWindow.Open();
  37. CodeEditorType activeCodeEditor = (CodeEditorType)EditorSettings.GetInt(SettingsWindow.ActiveCodeEditorKey, (int) CodeEditorType.None);
  38. CodeEditorType[] availableEditors = CodeEditor.AvailableEditors;
  39. if (Array.Exists(availableEditors, x => x == activeCodeEditor))
  40. CodeEditor.ActiveEditor = activeCodeEditor;
  41. else
  42. {
  43. if (availableEditors.Length > 0)
  44. CodeEditor.ActiveEditor = availableEditors[0];
  45. }
  46. }
  47. /// <summary>
  48. /// Called 60 times per second by the runtime.
  49. /// </summary>
  50. static void OnEditorUpdate()
  51. {
  52. app.OnEditorUpdate();
  53. }
  54. /// <summary>
  55. /// Attempts to save the current scene, and keeps retrying if failed or until user cancels.
  56. /// </summary>
  57. static void TrySaveScene()
  58. {
  59. Action success = () =>
  60. {
  61. EditorApplication.SaveProject();
  62. EditorApplication.Quit();
  63. };
  64. EditorApplication.SaveScene(success, TrySaveScene);
  65. }
  66. /// <summary>
  67. /// Called when the user requests that the editor shuts down. You must manually close the editor from this
  68. /// method if you choose to accept the users request.
  69. /// </summary>
  70. static void OnEditorQuitRequested()
  71. {
  72. Action<DialogBox.ResultType> dialogCallback =
  73. (result) =>
  74. {
  75. if (result == DialogBox.ResultType.Yes)
  76. TrySaveScene();
  77. else if (result == DialogBox.ResultType.No)
  78. {
  79. EditorApplication.SaveProject();
  80. EditorApplication.Quit();
  81. }
  82. };
  83. if (EditorApplication.IsSceneModified())
  84. {
  85. DialogBox.Open("Warning", "You current scene has modifications. Do you wish to save them first?",
  86. DialogBox.Type.YesNoCancel, dialogCallback);
  87. }
  88. else
  89. {
  90. EditorApplication.SaveProject();
  91. EditorApplication.Quit();
  92. }
  93. }
  94. }
  95. }