| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412 |
- 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(); } }
- public static bool IsProjectLoaded { get { return Internal_GetProjectLoaded(); } }
- 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 static FolderMonitor monitor;
- 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);
- inputConfig.RegisterButton(SceneWindow.ToggleProfilerOverlayBinding, ButtonCode.P, ButtonModifier.CtrlAlt);
- inputConfig.RegisterButton(SceneWindow.ViewToolBinding, ButtonCode.Q);
- inputConfig.RegisterButton(SceneWindow.MoveToolBinding, ButtonCode.W);
- inputConfig.RegisterButton(SceneWindow.RotateToolBinding, ButtonCode.E);
- inputConfig.RegisterButton(SceneWindow.ScaleToolBinding, ButtonCode.R);
- inputConfig.RegisterButton(SceneWindow.DuplicateBinding, ButtonCode.D, ButtonModifier.Ctrl);
- if (EditorSettings.AutoLoadLastProject)
- {
- string projectPath = EditorSettings.LastOpenProject;
- if (Internal_IsValidProject(projectPath))
- LoadProject(projectPath);
- }
- if (!IsProjectLoaded)
- ProjectWindow.Show();
- }
- private static void OnAssetModified(string path)
- {
- ProjectLibrary.Refresh(path);
- }
- internal void OnEditorUpdate()
- {
- ProjectLibrary.Update();
- }
- [MenuItem("File/Save Scene", ButtonModifier.Ctrl, ButtonCode.S, 50, true)]
- private static void SaveScene()
- {
- if (!string.IsNullOrEmpty(Scene.ActiveSceneUUID))
- {
- string scenePath = ProjectLibrary.GetPath(Scene.ActiveSceneUUID);
- Internal_SaveScene(scenePath);
- }
- else
- SaveSceneAs();
- }
- [MenuItem("File/Save Scene As", 50)]
- private static void SaveSceneAs()
- {
- string scenePath = "";
- if (BrowseDialog.SaveFile(ProjectLibrary.ResourceFolder, "*.prefab", 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 + ".prefab");
- }
- }
- }
- [MenuItem("File/Load Scene", ButtonModifier.Ctrl, ButtonCode.L, 50)]
- private static void LoadScene()
- {
- string[] scenePaths;
- if (BrowseDialog.OpenFile(ProjectLibrary.ResourceFolder, "", false, out scenePaths))
- {
- if (scenePaths.Length > 0)
- LoadScene(scenePaths[0]);
- }
- }
- public static void LoadScene(string path)
- {
- Action<string> continueLoad =
- (scenePath) =>
- {
- Scene.Load(path);
- ProjectSettings.LastOpenScene = scenePath;
- ProjectSettings.Save();
- };
- Action<DialogBox.ResultType> dialogCallback =
- (result) =>
- {
- if (result == DialogBox.ResultType.Yes)
- {
- SaveScene();
- continueLoad(path);
- }
- else if (result == DialogBox.ResultType.No)
- continueLoad(path);
- };
- if (Scene.IsModified())
- {
- DialogBox.Open("Warning", "You current scene has modifications. Do you wish to save them first?",
- DialogBox.Type.YesNoCancel, dialogCallback);
- }
- else
- continueLoad(path);
- }
- public static void LoadProject(string path)
- {
- if (Internal_IsValidProject(path))
- {
- Debug.LogWarning("Provided path: \"" + path + "\" is not a valid project.");
- return;
- }
- Internal_LoadProject(path);
- ProjectLibrary.Refresh();
- monitor = new FolderMonitor(ProjectLibrary.ResourceFolder);
- monitor.OnAdded += OnAssetModified;
- monitor.OnRemoved += OnAssetModified;
- monitor.OnModified += OnAssetModified;
- if(!string.IsNullOrWhiteSpace(ProjectSettings.LastOpenScene))
- Scene.Load(ProjectSettings.LastOpenScene);
- }
- public static void UnloadProject()
- {
- // TODO - Save dirty assets
- Action continueUnload =
- () =>
- {
- Scene.Clear();
- if (monitor != null)
- {
- monitor.Destroy();
- monitor = null;
- }
- LibraryWindow window = EditorWindow.GetWindow<LibraryWindow>();
- if(window != null)
- window.Reset();
- Internal_UnloadProject();
- };
- Action<DialogBox.ResultType> dialogCallback =
- (result) =>
- {
- if (result == DialogBox.ResultType.Yes)
- SaveScene();
- continueUnload();
- };
- if (Scene.IsModified())
- {
- DialogBox.Open("Warning", "You current scene has modifications. Do you wish to save them first?",
- DialogBox.Type.YesNoCancel, dialogCallback);
- }
- else
- continueUnload();
- }
- [MenuItem("Components/Camera")]
- private static void AddCamera()
- {
- SceneObject so = Selection.sceneObject;
- if (so == null)
- return;
- UndoRedo.RecordSO(so, "Added a Camera component");
- so.AddComponent<Camera>();
- }
- [MenuItem("Components/Renderable")]
- private static void AddRenderable()
- {
- SceneObject so = Selection.sceneObject;
- if (so == null)
- return;
- UndoRedo.RecordSO(so, "Added a Renderable component");
- so.AddComponent<Renderable>();
- }
- [MenuItem("Components/Point light")]
- private static void AddPointLight()
- {
- SceneObject so = Selection.sceneObject;
- if (so == null)
- return;
- UndoRedo.RecordSO(so, "Added a Light component");
- Light light = so.AddComponent<Light>();
- light.Type = LightType.Point;
- }
- [MenuItem("Components/Spot light")]
- private static void AddSpotLight()
- {
- SceneObject so = Selection.sceneObject;
- if (so == null)
- return;
- UndoRedo.RecordSO(so, "Added a Light component");
- Light light = so.AddComponent<Light>();
- light.Type = LightType.Spot;
- }
- [MenuItem("Components/Directional light")]
- private static void AddDirectionalLight()
- {
- SceneObject so = Selection.sceneObject;
- if (so == null)
- return;
- UndoRedo.RecordSO(so, "Added a Light component");
- Light light = so.AddComponent<Light>();
- light.Type = LightType.Directional;
- }
- [MenuItem("Scene Objects/Camera")]
- private static void AddCameraSO()
- {
- SceneObject so = UndoRedo.CreateSO("Camera", "Created a Camera");
- so.AddComponent<Camera>();
- Selection.sceneObject = so;
- }
- [MenuItem("Scene Objects/Renderable")]
- private static void AddRenderableSO()
- {
- SceneObject so = UndoRedo.CreateSO("Renderable", "Created a Renderable");
- so.AddComponent<Renderable>();
- Selection.sceneObject = so;
- }
- [MenuItem("Scene Objects/Point light")]
- private static void AddPointLightSO()
- {
- SceneObject so = UndoRedo.CreateSO("Point light", "Created a Light");
- Light light = so.AddComponent<Light>();
- light.Type = LightType.Point;
- Selection.sceneObject = so;
- }
- [MenuItem("Scene Objects/Spot light")]
- private static void AddSpotLightSO()
- {
- SceneObject so = UndoRedo.CreateSO("Spot light", "Created a Light");
- Light light = so.AddComponent<Light>();
- light.Type = LightType.Spot;
- Selection.sceneObject = so;
- }
- [MenuItem("Scene Objects/Directional light")]
- private static void AddDirectionalLightSO()
- {
- SceneObject so = UndoRedo.CreateSO("Directional light", "Created a Light");
- Light light = so.AddComponent<Light>();
- light.Type = LightType.Directional;
- Selection.sceneObject = so;
- }
- [MethodImpl(MethodImplOptions.InternalCall)]
- private static extern string Internal_GetProjectPath();
- [MethodImpl(MethodImplOptions.InternalCall)]
- private static extern string Internal_GetProjectName();
- [MethodImpl(MethodImplOptions.InternalCall)]
- private static extern bool Internal_GetProjectLoaded();
- [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);
- [MethodImpl(MethodImplOptions.InternalCall)]
- private static extern bool Internal_IsValidProject(string path);
- [MethodImpl(MethodImplOptions.InternalCall)]
- private static extern void Internal_LoadProject(string path);
- [MethodImpl(MethodImplOptions.InternalCall)]
- private static extern void Internal_UnloadProject();
- }
- }
|