EditorApplication.cs 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Runtime.CompilerServices;
  4. using BansheeEngine;
  5. namespace BansheeEditor
  6. {
  7. public enum SceneViewTool
  8. {
  9. View,
  10. Move,
  11. Rotate,
  12. Scale
  13. }
  14. public enum HandlePivotMode
  15. {
  16. Center,
  17. Pivot
  18. }
  19. public enum HandleCoordinateMode
  20. {
  21. Local,
  22. World
  23. }
  24. public enum EditorPlatformType
  25. {
  26. Windows
  27. }
  28. public class EditorApplication
  29. {
  30. public static SceneViewTool ActiveSceneTool
  31. {
  32. get { return EditorSettings.ActiveSceneTool; }
  33. set { EditorSettings.ActiveSceneTool = value; }
  34. }
  35. public static HandleCoordinateMode ActiveCoordinateMode
  36. {
  37. get { return EditorSettings.ActiveCoordinateMode; }
  38. set { EditorSettings.ActiveCoordinateMode = value; }
  39. }
  40. public static HandlePivotMode ActivePivotMode
  41. {
  42. get { return EditorSettings.ActivePivotMode; }
  43. set { EditorSettings.ActivePivotMode = value; }
  44. }
  45. public static Camera SceneViewCamera
  46. {
  47. get { return EditorWindow.GetWindow<SceneWindow>().GetCamera(); }
  48. }
  49. public static EditorPlatformType EditorPlatform
  50. {
  51. get { return EditorPlatformType.Windows; } // TODO - Set this properly once we have support for more platforms
  52. }
  53. public static string ProjectPath { get { return Internal_GetProjectPath(); } }
  54. public static string ProjectName { get { return Internal_GetProjectName(); } }
  55. internal static string CompilerPath { get { return Internal_GetCompilerPath(); } }
  56. internal static string BuiltinAssemblyPath { get { return Internal_GetBuiltinAssemblyPath(); } }
  57. internal static string ScriptAssemblyPath { get { return Internal_GetScriptAssemblyPath(); } }
  58. internal static string FrameworkAssemblyPath { get { return Internal_GetFrameworkAssemblyPath(); } }
  59. internal static string EngineAssembly { get { return Internal_GetEngineAssemblyName(); } }
  60. internal static string EditorAssembly { get { return Internal_GetEditorAssemblyName(); } }
  61. internal static string ScriptGameAssembly { get { return Internal_GetScriptGameAssemblyName(); } }
  62. internal static string ScriptEditorAssembly { get { return Internal_GetScriptEditorAssemblyName(); } }
  63. private static EditorApplication instance;
  64. private FolderMonitor monitor;
  65. // DEBUG ONLY
  66. Debug_Component1 dbgComponent;
  67. // END DEBUG ONLY
  68. internal EditorApplication()
  69. {
  70. instance = this;
  71. // Register controls
  72. InputConfiguration inputConfig = VirtualInput.KeyConfig;
  73. inputConfig.RegisterButton(SceneCamera.MoveForwardBinding, ButtonCode.W);
  74. inputConfig.RegisterButton(SceneCamera.MoveBackBinding, ButtonCode.S);
  75. inputConfig.RegisterButton(SceneCamera.MoveLeftBinding, ButtonCode.A);
  76. inputConfig.RegisterButton(SceneCamera.MoveRightBinding, ButtonCode.D);
  77. inputConfig.RegisterButton(SceneCamera.MoveForwardBinding, ButtonCode.Up);
  78. inputConfig.RegisterButton(SceneCamera.MoveBackBinding, ButtonCode.Down);
  79. inputConfig.RegisterButton(SceneCamera.MoveLeftBinding, ButtonCode.Left);
  80. inputConfig.RegisterButton(SceneCamera.MoveRightBinding, ButtonCode.Right);
  81. inputConfig.RegisterButton(SceneCamera.FastMoveBinding, ButtonCode.LeftShift);
  82. inputConfig.RegisterButton(SceneCamera.RotateBinding, ButtonCode.MouseRight);
  83. inputConfig.RegisterAxis(SceneCamera.HorizontalAxisBinding, InputAxis.MouseX);
  84. inputConfig.RegisterAxis(SceneCamera.VerticalAxisBinding, InputAxis.MouseY);
  85. inputConfig.RegisterButton(SceneWindow.ToggleProfilerOverlayBinding, ButtonCode.P, ButtonModifier.CtrlAlt);
  86. ProjectLibrary.Refresh();
  87. monitor = new FolderMonitor(ProjectLibrary.ResourceFolder);
  88. monitor.OnAdded += OnAssetModified;
  89. monitor.OnRemoved += OnAssetModified;
  90. monitor.OnModified += OnAssetModified;
  91. // DEBUG ONLY
  92. //SceneObject newDbgObject = new SceneObject("NewDbgObject");
  93. //dbgComponent = newDbgObject.AddComponent<Debug_Component1>();
  94. //newDbgObject.AddComponent<Debug_Component2>();
  95. //SceneObject gizmoDbgObject = new SceneObject("GizmoDebug");
  96. // gizmoDbgObject.AddComponent<DbgGizmoComponent>();
  97. //ProgressBar.Show("Test", 0.5f);
  98. //ColorPicker.Show();
  99. // DEBUG ONLY END
  100. }
  101. private void OnAssetModified(string path)
  102. {
  103. ProjectLibrary.Refresh(path);
  104. }
  105. internal void OnEditorUpdate()
  106. {
  107. ProjectLibrary.Update();
  108. // DEBUG ONLY
  109. //if (dbgComponent != null)
  110. // dbgComponent.intArray[0] = dbgComponent.intArray[0] + 1;
  111. // DEBUG ONLY END
  112. }
  113. [MenuItem("File/Save Prefab", ButtonModifier.Ctrl, ButtonCode.S)]
  114. private static void SavePrefab()
  115. {
  116. if (!string.IsNullOrEmpty(Scene.ActiveSceneUUID))
  117. {
  118. string scenePath = ProjectLibrary.GetPath(Scene.ActiveSceneUUID);
  119. Internal_SaveScene(scenePath);
  120. }
  121. else
  122. {
  123. string scenePath = "";
  124. BrowseDialog.SaveFile(ProjectLibrary.ResourceFolder, "", out scenePath);
  125. if (!PathEx.IsPartOf(scenePath, ProjectLibrary.ResourceFolder))
  126. DialogBox.Open("Error", "The location must be inside the Resources folder of the project.", DialogBox.Type.OK);
  127. else
  128. {
  129. // TODO - If path points to an existing non-scene asset or folder I should delete it otherwise
  130. // Internal_SaveScene will silently fail.
  131. Scene.ActiveSceneUUID = Internal_SaveScene(scenePath);
  132. }
  133. }
  134. }
  135. [MenuItem("File/Load Prefab", ButtonModifier.Ctrl, ButtonCode.L)]
  136. private static void LoadPrefab()
  137. {
  138. Action doLoad =
  139. () =>
  140. {
  141. string[] scenePaths;
  142. BrowseDialog.OpenFile(ProjectLibrary.ResourceFolder, "", false, out scenePaths);
  143. if(scenePaths.Length > 0)
  144. Scene.Load(scenePaths[0]);
  145. };
  146. Action<DialogBox.ResultType> dialogCallback =
  147. (result) =>
  148. {
  149. if (result == DialogBox.ResultType.Yes)
  150. {
  151. SavePrefab();
  152. doLoad();
  153. }
  154. else if (result == DialogBox.ResultType.No)
  155. doLoad();
  156. };
  157. if (Scene.IsModified())
  158. {
  159. DialogBox.Open("Warning", "You current scene has modifications. Do you wish to save them first?",
  160. DialogBox.Type.YesNoCancel, dialogCallback);
  161. }
  162. else
  163. doLoad();
  164. }
  165. [MethodImpl(MethodImplOptions.InternalCall)]
  166. private static extern string Internal_GetProjectPath();
  167. [MethodImpl(MethodImplOptions.InternalCall)]
  168. private static extern string Internal_GetProjectName();
  169. [MethodImpl(MethodImplOptions.InternalCall)]
  170. private static extern string Internal_GetCompilerPath();
  171. [MethodImpl(MethodImplOptions.InternalCall)]
  172. private static extern string Internal_GetBuiltinAssemblyPath();
  173. [MethodImpl(MethodImplOptions.InternalCall)]
  174. private static extern string Internal_GetScriptAssemblyPath();
  175. [MethodImpl(MethodImplOptions.InternalCall)]
  176. private static extern string Internal_GetFrameworkAssemblyPath();
  177. [MethodImpl(MethodImplOptions.InternalCall)]
  178. private static extern string Internal_GetEngineAssemblyName();
  179. [MethodImpl(MethodImplOptions.InternalCall)]
  180. private static extern string Internal_GetEditorAssemblyName();
  181. [MethodImpl(MethodImplOptions.InternalCall)]
  182. private static extern string Internal_GetScriptGameAssemblyName();
  183. [MethodImpl(MethodImplOptions.InternalCall)]
  184. private static extern string Internal_GetScriptEditorAssemblyName();
  185. [MethodImpl(MethodImplOptions.InternalCall)]
  186. private static extern string Internal_SaveScene(string path);
  187. }
  188. }