| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231 |
- using System;
- using System.Collections.Generic;
- using System.Runtime.CompilerServices;
- using BansheeEngine;
- namespace BansheeEditor
- {
- public enum SceneViewTool
- {
- View,
- Move,
- Rotate,
- Scale
- }
- public enum HandlePivotMode
- {
- Center,
- Pivot
- }
- public enum HandleCoordinateMode
- {
- Local,
- World
- }
- public enum EditorPlatformType
- {
- Windows
- }
- public class EditorApplication
- {
- public static SceneViewTool ActiveSceneTool
- {
- get { return EditorSettings.ActiveSceneTool; }
- set { EditorSettings.ActiveSceneTool = value; }
- }
- public static HandleCoordinateMode ActiveCoordinateMode
- {
- get { return EditorSettings.ActiveCoordinateMode; }
- set { EditorSettings.ActiveCoordinateMode = value; }
- }
- public static HandlePivotMode ActivePivotMode
- {
- get { return EditorSettings.ActivePivotMode; }
- set { EditorSettings.ActivePivotMode = value; }
- }
- public static Camera SceneViewCamera
- {
- get { return EditorWindow.GetWindow<SceneWindow>().GetCamera(); }
- }
- public static EditorPlatformType EditorPlatform
- {
- get { return EditorPlatformType.Windows; } // TODO - Set this properly once we have support for more platforms
- }
- public static string ProjectPath { get { return Internal_GetProjectPath(); } }
- public static string ProjectName { get { return Internal_GetProjectName(); } }
- internal static string CompilerPath { get { return Internal_GetCompilerPath(); } }
- internal static string BuiltinAssemblyPath { get { return Internal_GetBuiltinAssemblyPath(); } }
- internal static string ScriptAssemblyPath { get { return Internal_GetScriptAssemblyPath(); } }
- internal static string FrameworkAssemblyPath { get { return Internal_GetFrameworkAssemblyPath(); } }
- internal static string EngineAssembly { get { return Internal_GetEngineAssemblyName(); } }
- internal static string EditorAssembly { get { return Internal_GetEditorAssemblyName(); } }
- internal static string ScriptGameAssembly { get { return Internal_GetScriptGameAssemblyName(); } }
- internal static string ScriptEditorAssembly { get { return Internal_GetScriptEditorAssemblyName(); } }
- private static EditorApplication instance;
- private FolderMonitor monitor;
- // DEBUG ONLY
- Debug_Component1 dbgComponent;
- // END DEBUG ONLY
- internal EditorApplication()
- {
- instance = this;
- // Register controls
- InputConfiguration inputConfig = VirtualInput.KeyConfig;
- inputConfig.RegisterButton(SceneCamera.MoveForwardBinding, ButtonCode.W);
- inputConfig.RegisterButton(SceneCamera.MoveBackBinding, ButtonCode.S);
- inputConfig.RegisterButton(SceneCamera.MoveLeftBinding, ButtonCode.A);
- inputConfig.RegisterButton(SceneCamera.MoveRightBinding, ButtonCode.D);
- inputConfig.RegisterButton(SceneCamera.MoveForwardBinding, ButtonCode.Up);
- inputConfig.RegisterButton(SceneCamera.MoveBackBinding, ButtonCode.Down);
- inputConfig.RegisterButton(SceneCamera.MoveLeftBinding, ButtonCode.Left);
- inputConfig.RegisterButton(SceneCamera.MoveRightBinding, ButtonCode.Right);
- inputConfig.RegisterButton(SceneCamera.FastMoveBinding, ButtonCode.LeftShift);
- inputConfig.RegisterButton(SceneCamera.RotateBinding, ButtonCode.MouseRight);
- inputConfig.RegisterAxis(SceneCamera.HorizontalAxisBinding, InputAxis.MouseX);
- inputConfig.RegisterAxis(SceneCamera.VerticalAxisBinding, InputAxis.MouseY);
- ProjectLibrary.Refresh();
- monitor = new FolderMonitor(ProjectLibrary.ResourceFolder);
- monitor.OnAdded += OnAssetModified;
- monitor.OnRemoved += OnAssetModified;
- monitor.OnModified += OnAssetModified;
- // DEBUG ONLY
- SceneObject newDbgObject = new SceneObject("NewDbgObject");
- dbgComponent = newDbgObject.AddComponent<Debug_Component1>();
- newDbgObject.AddComponent<Debug_Component2>();
- SceneObject gizmoDbgObject = new SceneObject("GizmoDebug");
- gizmoDbgObject.AddComponent<DbgGizmoComponent>();
- //ProgressBar.Show("Test", 0.5f);
- //ColorPicker.Show();
- // DEBUG ONLY END
- }
- private void OnAssetModified(string path)
- {
- ProjectLibrary.Refresh(path);
- }
- internal void OnEditorUpdate()
- {
- ProjectLibrary.Update();
- // DEBUG ONLY
- if (dbgComponent != null)
- dbgComponent.intArray[0] = dbgComponent.intArray[0] + 1;
- // DEBUG ONLY END
- }
- [MenuItem("File/Save Prefab", ButtonModifier.Ctrl, ButtonCode.S)]
- private static void SavePrefab()
- {
- if (!string.IsNullOrEmpty(Scene.ActiveSceneUUID))
- {
- string scenePath = ProjectLibrary.GetPath(Scene.ActiveSceneUUID);
- Internal_SaveScene(scenePath);
- }
- else
- {
- string scenePath = "";
- BrowseDialog.SaveFile(ProjectLibrary.ResourceFolder, "", out scenePath);
- if (!PathEx.IsPartOf(scenePath, ProjectLibrary.ResourceFolder))
- DialogBox.Open("Error", "The location must be inside the Resources folder of the project.", DialogBox.Type.OK);
- else
- {
- // TODO - If path points to an existing non-scene asset or folder I should delete it otherwise
- // Internal_SaveScene will silently fail.
- Scene.ActiveSceneUUID = Internal_SaveScene(scenePath);
- }
- }
- }
- [MenuItem("File/Load Prefab", ButtonModifier.Ctrl, ButtonCode.L)]
- private static void LoadPrefab()
- {
- Action doLoad =
- () =>
- {
- string[] scenePaths;
- BrowseDialog.OpenFile(ProjectLibrary.ResourceFolder, "", false, out scenePaths);
- if(scenePaths.Length > 0)
- Scene.Load(scenePaths[0]);
- };
- Action<DialogBox.ResultType> dialogCallback =
- (result) =>
- {
- if (result == DialogBox.ResultType.Yes)
- {
- SavePrefab();
- doLoad();
- }
- else if (result == DialogBox.ResultType.No)
- doLoad();
- };
- if (Scene.IsModified())
- {
- DialogBox.Open("Warning", "You current scene has modifications. Do you wish to save them first?",
- DialogBox.Type.YesNoCancel, dialogCallback);
- }
- else
- doLoad();
- }
- [MethodImpl(MethodImplOptions.InternalCall)]
- private static extern string Internal_GetProjectPath();
- [MethodImpl(MethodImplOptions.InternalCall)]
- private static extern string Internal_GetProjectName();
- [MethodImpl(MethodImplOptions.InternalCall)]
- private static extern string Internal_GetCompilerPath();
- [MethodImpl(MethodImplOptions.InternalCall)]
- private static extern string Internal_GetBuiltinAssemblyPath();
- [MethodImpl(MethodImplOptions.InternalCall)]
- private static extern string Internal_GetScriptAssemblyPath();
- [MethodImpl(MethodImplOptions.InternalCall)]
- private static extern string Internal_GetFrameworkAssemblyPath();
- [MethodImpl(MethodImplOptions.InternalCall)]
- private static extern string Internal_GetEngineAssemblyName();
- [MethodImpl(MethodImplOptions.InternalCall)]
- private static extern string Internal_GetEditorAssemblyName();
- [MethodImpl(MethodImplOptions.InternalCall)]
- private static extern string Internal_GetScriptGameAssemblyName();
- [MethodImpl(MethodImplOptions.InternalCall)]
- private static extern string Internal_GetScriptEditorAssemblyName();
- [MethodImpl(MethodImplOptions.InternalCall)]
- private static extern string Internal_SaveScene(string path);
- }
- }
|