/// <summary> /// Runs a single frame of the game and pauses it. If the game is not currently running it will be started. /// </summary> public static void FrameStep() { if (IsStopped) { if (EditorSettings.GetBool(LogWindow.CLEAR_ON_PLAY_KEY, true)) { Debug.Clear(); LogWindow log = EditorWindow.GetWindow <LogWindow>(); if (log != null) { log.Refresh(); } } } ToggleToolbarItem("Play", false); ToggleToolbarItem("Pause", true); Internal_FrameStep(); }
private void OnInitialize() { GUIToggle projectFoldout = new GUIToggle(new LocEdString("Project"), EditorStyles.Foldout); GUIToggle editorFoldout = new GUIToggle(new LocEdString("Editor"), EditorStyles.Foldout); defaultHandleSizeField = new GUIFloatField(new LocEdString("Handle size"), 200); defaultHandleSizeField.OnChanged += (x) => { EditorSettings.DefaultHandleSize = x; }; autoLoadLastProjectField = new GUIToggleField(new LocEdString("Automatically load last project"), 200); autoLoadLastProjectField.OnChanged += (x) => { EditorSettings.AutoLoadLastProject = x; }; CodeEditorType[] availableEditors = CodeEditor.AvailableEditors; Array.Resize(ref availableEditors, availableEditors.Length + 1); availableEditors[availableEditors.Length - 1] = CodeEditorType.None; string[] availableEditorNames = new string[availableEditors.Length]; for (int i = 0; i < availableEditors.Length; i++) { availableEditorNames[i] = Enum.GetName(typeof(CodeEditorType), availableEditors[i]); } codeEditorField = new GUIListBoxField(availableEditorNames, new LocEdString("Code editor"), 200); codeEditorField.OnSelectionChanged += x => { EditorSettings.SetInt(ActiveCodeEditorKey, (int)availableEditors[x]); CodeEditor.ActiveEditor = availableEditors[x]; }; fpsLimitField = new GUIIntField(new LocEdString("FPS limit"), 200); fpsLimitField.OnConfirmed += () => EditorSettings.FPSLimit = fpsLimitField.Value; fpsLimitField.OnFocusLost += () => EditorSettings.FPSLimit = fpsLimitField.Value; mouseSensitivityField = new GUISliderField(0.2f, 2.0f, new LocEdString("Mouse sensitivity")); mouseSensitivityField.OnChanged += (x) => EditorSettings.MouseSensitivity = x; GUILayout mainLayout = GUI.AddLayoutY(); mainLayout.AddElement(projectFoldout); GUILayout projectLayoutOuterY = mainLayout.AddLayoutY(); projectLayoutOuterY.AddSpace(5); GUILayout projectLayoutOuterX = projectLayoutOuterY.AddLayoutX(); projectLayoutOuterX.AddSpace(5); GUILayout projectLayout = projectLayoutOuterX.AddLayoutY(); projectLayoutOuterX.AddSpace(5); projectLayoutOuterY.AddSpace(5); mainLayout.AddElement(editorFoldout); GUILayout editorLayoutOuterY = mainLayout.AddLayoutY(); editorLayoutOuterY.AddSpace(5); GUILayout editorLayoutOuterX = editorLayoutOuterY.AddLayoutX(); editorLayoutOuterX.AddSpace(5); GUILayout editorLayout = editorLayoutOuterX.AddLayoutY(); editorLayoutOuterX.AddSpace(5); editorLayoutOuterY.AddSpace(5); mainLayout.AddFlexibleSpace(); editorLayout.AddElement(defaultHandleSizeField); editorLayout.AddElement(autoLoadLastProjectField); editorLayout.AddElement(codeEditorField); editorLayout.AddElement(fpsLimitField); editorLayout.AddElement(mouseSensitivityField); projectFoldout.Value = true; editorFoldout.Value = true; projectFoldout.OnToggled += (x) => projectLayout.Active = x; editorFoldout.OnToggled += (x) => editorLayout.Active = x; }
/// <summary> /// Triggered by the runtime when <see cref="LoadProject"/> method completes. /// </summary> private static void Internal_OnProjectLoaded() { SetStatusProject(false); if (!unitTestsExecuted) { RunUnitTests(); unitTestsExecuted = true; } if (!IsProjectLoaded) { ProjectWindow.Open(); return; } string projectPath = ProjectPath; RecentProject[] recentProjects = EditorSettings.RecentProjects; bool foundPath = false; for (int i = 0; i < recentProjects.Length; i++) { if (PathEx.Compare(recentProjects[i].path, projectPath)) { recentProjects[i].accessTimestamp = (ulong)DateTime.Now.Ticks; EditorSettings.RecentProjects = recentProjects; foundPath = true; break; } } if (!foundPath) { List <RecentProject> extendedRecentProjects = new List <RecentProject>(); extendedRecentProjects.AddRange(recentProjects); RecentProject newProject = new RecentProject(); newProject.path = projectPath; newProject.accessTimestamp = (ulong)DateTime.Now.Ticks; extendedRecentProjects.Add(newProject); EditorSettings.RecentProjects = extendedRecentProjects.ToArray(); } EditorSettings.LastOpenProject = projectPath; EditorSettings.Save(); ProjectLibrary.Refresh(); if (monitor != null) { monitor.Destroy(); monitor = null; } monitor = new FolderMonitor(ProjectLibrary.ResourceFolder); monitor.OnAdded += OnAssetModified; monitor.OnRemoved += OnAssetModified; monitor.OnModified += OnAssetModified; if (!string.IsNullOrWhiteSpace(ProjectSettings.LastOpenScene)) { lastLoadedScene = Scene.LoadAsync(ProjectSettings.LastOpenScene); SetSceneDirty(false); } }
private void OnEditorUpdate() { if (HasFocus) { if (!Input.IsPointerButtonHeld(PointerButton.Right)) { if (VirtualInput.IsButtonDown(EditorApplication.DuplicateKey)) { DuplicateSelection(); } else if (VirtualInput.IsButtonDown(EditorApplication.DeleteKey)) { DeleteSelection(); } else if (VirtualInput.IsButtonDown(toggleProfilerOverlayKey)) { EditorSettings.SetBool(ProfilerOverlayActiveKey, !EditorSettings.GetBool(ProfilerOverlayActiveKey)); } else if (VirtualInput.IsButtonDown(viewToolKey)) { EditorApplication.ActiveSceneTool = SceneViewTool.View; } else if (VirtualInput.IsButtonDown(moveToolKey)) { EditorApplication.ActiveSceneTool = SceneViewTool.Move; } else if (VirtualInput.IsButtonDown(rotateToolKey)) { EditorApplication.ActiveSceneTool = SceneViewTool.Rotate; } else if (VirtualInput.IsButtonDown(scaleToolKey)) { EditorApplication.ActiveSceneTool = SceneViewTool.Scale; } } } // Refresh GUI buttons if needed (in case someones changes the values from script) if (editorSettingsHash != EditorSettings.Hash) { UpdateButtonStates(); UpdateProfilerOverlay(); editorSettingsHash = EditorSettings.Hash; } // Update scene view handles and selection sceneGizmos.Draw(); sceneGrid.Draw(); bool handleActive = sceneHandles.IsActive() || sceneAxesGUI.IsActive(); Vector2I scenePos; bool inBounds = ScreenToScenePos(Input.PointerPosition, out scenePos); bool dragResult = false; if (Input.IsPointerButtonUp(PointerButton.Left)) { dragResult = EndDragSelection(); if (sceneHandles.IsActive()) { sceneHandles.ClearSelection(); } if (sceneAxesGUI.IsActive()) { sceneAxesGUI.ClearSelection(); } } else if (Input.IsPointerButtonDown(PointerButton.Left)) { mouseDownPosition = scenePos; } bool draggedOver = DragDrop.DragInProgress || DragDrop.DropInProgress; draggedOver &= IsPointerHovering && inBounds && DragDrop.Type == DragDropType.Resource; if (draggedOver) { if (DragDrop.DropInProgress) { dragActive = false; if (draggedSO != null) { Selection.SceneObject = draggedSO; EditorApplication.SetSceneDirty(); } draggedSO = null; } else { if (!dragActive) { dragActive = true; ResourceDragDropData dragData = (ResourceDragDropData)DragDrop.Data; string[] draggedPaths = dragData.Paths; for (int i = 0; i < draggedPaths.Length; i++) { ResourceMeta meta = ProjectLibrary.GetMeta(draggedPaths[i]); if (meta != null) { if (meta.ResType == ResourceType.Mesh) { if (!string.IsNullOrEmpty(draggedPaths[i])) { string meshName = Path.GetFileNameWithoutExtension(draggedPaths[i]); draggedSO = UndoRedo.CreateSO(meshName, "Created a new Renderable \"" + meshName + "\""); Mesh mesh = ProjectLibrary.Load <Mesh>(draggedPaths[i]); Renderable renderable = draggedSO.AddComponent <Renderable>(); renderable.Mesh = mesh; if (mesh != null) { draggedSOOffset = mesh.Bounds.Box.Center; } else { draggedSOOffset = Vector3.Zero; } } break; } else if (meta.ResType == ResourceType.Prefab) { if (!string.IsNullOrEmpty(draggedPaths[i])) { Prefab prefab = ProjectLibrary.Load <Prefab>(draggedPaths[i]); draggedSO = UndoRedo.Instantiate(prefab, "Instantiating " + prefab.Name); if (draggedSO != null) { AABox draggedObjBounds = EditorUtility.CalculateBounds(draggedSO); draggedSOOffset = draggedObjBounds.Center; } else { draggedSOOffset = Vector3.Zero; } } break; } } } } if (draggedSO != null) { if (Input.IsButtonHeld(ButtonCode.Space)) { SnapData snapData; sceneSelection.Snap(scenePos, out snapData, new SceneObject[] { draggedSO }); Quaternion q = Quaternion.FromToRotation(Vector3.YAxis, snapData.normal); draggedSO.Position = snapData.position; draggedSO.Rotation = q; } else { Ray worldRay = camera.ViewportToWorldRay(scenePos); draggedSO.Position = worldRay * DefaultPlacementDepth - draggedSOOffset; } } } return; } else { if (dragActive) { dragActive = false; if (draggedSO != null) { draggedSO.Destroy(); draggedSO = null; } } } if (HasContentFocus || IsPointerHovering) { cameraController.EnableInput(true); if (inBounds && HasContentFocus) { if (Input.IsPointerButtonDown(PointerButton.Left)) { Rect2I sceneAxesGUIBounds = new Rect2I(Width - HandleAxesGUISize - HandleAxesGUIPaddingX, HandleAxesGUIPaddingY, HandleAxesGUISize, HandleAxesGUISize); if (sceneAxesGUIBounds.Contains(scenePos)) { sceneAxesGUI.TrySelect(scenePos); } else { sceneHandles.TrySelect(scenePos); } } else if (Input.IsPointerButtonHeld(PointerButton.Left) && !handleActive && !dragActive && draggedSO == null && scenePos != mouseDownPosition) { if (isDraggingSelection) { UpdateDragSelection(scenePos); } else { StartDragSelection(scenePos); } } else if (Input.IsPointerButtonUp(PointerButton.Left)) { if (!handleActive && !dragActive && !dragResult) { bool ctrlHeld = Input.IsButtonHeld(ButtonCode.LeftControl) || Input.IsButtonHeld(ButtonCode.RightControl); sceneSelection.PickObject(scenePos, ctrlHeld, new SceneObject[] { draggedSO }); } } } } else { cameraController.EnableInput(false); } SceneHandles.BeginInput(); sceneHandles.UpdateInput(scenePos, Input.PointerDelta); sceneHandles.Draw(); sceneAxesGUI.UpdateInput(scenePos); sceneAxesGUI.Draw(); SceneHandles.EndInput(); sceneSelection.Draw(); UpdateGridMode(); if (VirtualInput.IsButtonDown(frameKey)) { cameraController.FrameSelected(); } }
private void OnInitialize() { GUILayoutY layout = GUI.AddLayoutY(); GUILayoutX titleLayout = layout.AddLayoutX(); GUIContentImages infoImages = new GUIContentImages( EditorBuiltin.GetLogIcon(LogIcon.Info, 16, false), EditorBuiltin.GetLogIcon(LogIcon.Info, 16, true)); GUIContentImages warningImages = new GUIContentImages( EditorBuiltin.GetLogIcon(LogIcon.Warning, 16, false), EditorBuiltin.GetLogIcon(LogIcon.Warning, 16, true)); GUIContentImages errorImages = new GUIContentImages( EditorBuiltin.GetLogIcon(LogIcon.Error, 16, false), EditorBuiltin.GetLogIcon(LogIcon.Error, 16, true)); GUIToggle infoBtn = new GUIToggle(new GUIContent(infoImages), EditorStyles.Button, GUIOption.FixedHeight(TITLE_HEIGHT)); GUIToggle warningBtn = new GUIToggle(new GUIContent(warningImages), EditorStyles.Button, GUIOption.FixedHeight(TITLE_HEIGHT)); GUIToggle errorBtn = new GUIToggle(new GUIContent(errorImages), EditorStyles.Button, GUIOption.FixedHeight(TITLE_HEIGHT)); GUIToggle detailsBtn = new GUIToggle(new LocEdString("Show details"), EditorStyles.Button, GUIOption.FixedHeight(TITLE_HEIGHT)); GUIButton clearBtn = new GUIButton(new LocEdString("Clear"), GUIOption.FixedHeight(TITLE_HEIGHT)); GUIToggle clearOnPlayBtn = new GUIToggle(new LocEdString("Clear on play"), EditorStyles.Button, GUIOption.FixedHeight(TITLE_HEIGHT)); titleLayout.AddElement(infoBtn); titleLayout.AddElement(warningBtn); titleLayout.AddElement(errorBtn); titleLayout.AddFlexibleSpace(); titleLayout.AddElement(detailsBtn); titleLayout.AddElement(clearBtn); titleLayout.AddElement(clearOnPlayBtn); infoBtn.Value = filter.HasFlag(EntryFilter.Info); warningBtn.Value = filter.HasFlag(EntryFilter.Warning); errorBtn.Value = filter.HasFlag(EntryFilter.Error); clearOnPlayBtn.Value = EditorSettings.GetBool(CLEAR_ON_PLAY_KEY, true); infoBtn.OnToggled += x => { if (x) { SetFilter(filter | EntryFilter.Info); } else { SetFilter(filter & ~EntryFilter.Info); } }; warningBtn.OnToggled += x => { if (x) { SetFilter(filter | EntryFilter.Warning); } else { SetFilter(filter & ~EntryFilter.Warning); } }; errorBtn.OnToggled += x => { if (x) { SetFilter(filter | EntryFilter.Error); } else { SetFilter(filter & ~EntryFilter.Error); } }; detailsBtn.OnToggled += ToggleDetailsPanel; clearBtn.OnClick += ClearLog; clearOnPlayBtn.OnToggled += ToggleClearOnPlay; GUILayoutX mainLayout = layout.AddLayoutX(); listView = new GUIListView <ConsoleGUIEntry, ConsoleEntryData>(Width, ListHeight, ENTRY_HEIGHT, mainLayout); detailsSeparator = new GUITexture(Builtin.WhiteTexture, GUIOption.FixedWidth(SEPARATOR_WIDTH)); detailsArea = new GUIScrollArea(ScrollBarType.ShowIfDoesntFit, ScrollBarType.NeverShow); mainLayout.AddElement(detailsSeparator); mainLayout.AddElement(detailsArea); detailsSeparator.Active = false; detailsArea.Active = false; detailsSeparator.SetTint(SEPARATOR_COLOR); Refresh(); Debug.OnAdded += OnEntryAdded; }
/// <summary> /// Toggles should the console be cleared when the play mode is entered. /// </summary> /// <param name="clear">True if the console should be cleared upon entering the play mode.</param> private void ToggleClearOnPlay(bool clear) { EditorSettings.SetBool(CLEAR_ON_PLAY_KEY, clear); }
private void OnEditorUpdate() { if (HasFocus) { if (!Input.IsPointerButtonHeld(PointerButton.Right)) { if (VirtualInput.IsButtonDown(toggleProfilerOverlayKey)) EditorSettings.SetBool(ProfilerOverlayActiveKey, !EditorSettings.GetBool(ProfilerOverlayActiveKey)); if (VirtualInput.IsButtonDown(viewToolKey)) EditorApplication.ActiveSceneTool = SceneViewTool.View; if (VirtualInput.IsButtonDown(moveToolKey)) EditorApplication.ActiveSceneTool = SceneViewTool.Move; if (VirtualInput.IsButtonDown(rotateToolKey)) EditorApplication.ActiveSceneTool = SceneViewTool.Rotate; if (VirtualInput.IsButtonDown(scaleToolKey)) EditorApplication.ActiveSceneTool = SceneViewTool.Scale; if (VirtualInput.IsButtonDown(duplicateKey)) { SceneObject[] selectedObjects = Selection.SceneObjects; CleanDuplicates(ref selectedObjects); if (selectedObjects.Length > 0) { String message; if (selectedObjects.Length == 1) message = "Duplicated " + selectedObjects[0].Name; else message = "Duplicated " + selectedObjects.Length + " elements"; UndoRedo.CloneSO(selectedObjects, message); EditorApplication.SetSceneDirty(); } } if (VirtualInput.IsButtonDown(deleteKey)) { SceneObject[] selectedObjects = Selection.SceneObjects; CleanDuplicates(ref selectedObjects); if (selectedObjects.Length > 0) { foreach (var so in selectedObjects) { string message = "Deleted " + so.Name; UndoRedo.DeleteSO(so, message); } EditorApplication.SetSceneDirty(); } } } } // Refresh GUI buttons if needed (in case someones changes the values from script) if (editorSettingsHash != EditorSettings.Hash) { UpdateButtonStates(); UpdateProfilerOverlay(); editorSettingsHash = EditorSettings.Hash; } // Update scene view handles and selection sceneGizmos.Draw(); sceneGrid.Draw(); bool handleActive = false; if (Input.IsPointerButtonUp(PointerButton.Left)) { if (sceneHandles.IsActive()) { sceneHandles.ClearSelection(); handleActive = true; } if (sceneAxesGUI.IsActive()) { sceneAxesGUI.ClearSelection(); handleActive = true; } } Vector2I scenePos; bool inBounds = ScreenToScenePos(Input.PointerPosition, out scenePos); bool draggedOver = DragDrop.DragInProgress || DragDrop.DropInProgress; draggedOver &= IsPointerHovering && inBounds && DragDrop.Type == DragDropType.Resource; if (draggedOver) { if (DragDrop.DropInProgress) { dragActive = false; if (draggedSO != null) { Selection.SceneObject = draggedSO; EditorApplication.SetSceneDirty(); } draggedSO = null; } else { if (!dragActive) { dragActive = true; ResourceDragDropData dragData = (ResourceDragDropData)DragDrop.Data; string[] draggedPaths = dragData.Paths; for (int i = 0; i < draggedPaths.Length; i++) { LibraryEntry entry = ProjectLibrary.GetEntry(draggedPaths[i]); if (entry != null && entry.Type == LibraryEntryType.File) { FileEntry fileEntry = (FileEntry) entry; if (fileEntry.ResType == ResourceType.Mesh) { if (!string.IsNullOrEmpty(draggedPaths[i])) { string meshName = Path.GetFileNameWithoutExtension(draggedPaths[i]); draggedSO = UndoRedo.CreateSO(meshName, "Created a new Renderable \"" + meshName + "\""); Mesh mesh = ProjectLibrary.Load<Mesh>(draggedPaths[i]); Renderable renderable = draggedSO.AddComponent<Renderable>(); renderable.Mesh = mesh; } break; } else if (fileEntry.ResType == ResourceType.Prefab) { if (!string.IsNullOrEmpty(draggedPaths[i])) { Prefab prefab = ProjectLibrary.Load<Prefab>(draggedPaths[i]); draggedSO = UndoRedo.Instantiate(prefab, "Instantiating " + prefab.Name); } break; } } } } if (draggedSO != null) { Ray worldRay = camera.ScreenToWorldRay(scenePos); draggedSO.Position = worldRay*DefaultPlacementDepth; } } return; } else { if (dragActive) { dragActive = false; if (draggedSO != null) { draggedSO.Destroy(); draggedSO = null; } } } if (HasFocus) { cameraController.EnableInput(true); if (inBounds) { if (Input.IsPointerButtonDown(PointerButton.Left)) { Rect2I sceneAxesGUIBounds = new Rect2I(Width - HandleAxesGUISize - HandleAxesGUIPaddingX, HandleAxesGUIPaddingY, HandleAxesGUISize, HandleAxesGUISize); if (sceneAxesGUIBounds.Contains(scenePos)) sceneAxesGUI.TrySelect(scenePos); else sceneHandles.TrySelect(scenePos); } else if (Input.IsPointerButtonUp(PointerButton.Left)) { if (!handleActive) { bool ctrlHeld = Input.IsButtonHeld(ButtonCode.LeftControl) || Input.IsButtonHeld(ButtonCode.RightControl); sceneSelection.PickObject(scenePos, ctrlHeld); } } } } else cameraController.EnableInput(false); SceneHandles.BeginInput(); sceneHandles.UpdateInput(scenePos, Input.PointerDelta); sceneHandles.Draw(); sceneAxesGUI.UpdateInput(scenePos); sceneAxesGUI.Draw(); SceneHandles.EndInput(); sceneSelection.Draw(); UpdateGridMode(); if (VirtualInput.IsButtonDown(frameKey)) cameraController.FrameSelected(); }