/// <summary> /// This method can be called to redo the action. /// </summary> public void Redo() { EditorGizmoSystem gizmoSystem = EditorGizmoSystem.Instance; gizmoSystem.TransformSpace = _newTransformSpace; TransformSpaceChangedMessage.SendToInterestedListeners(_oldTransformSpace, _newTransformSpace); }
/// <summary> /// This method can be called to redo the action. /// </summary> public void Redo() { EditorGizmoSystem gizmoSystem = EditorGizmoSystem.Instance; gizmoSystem.ActiveGizmoType = _newActiveGizmoType; ActiveGizmoTypeChangedMessage.SendToInterestedListeners(_oldActiveGizmoType, _newActiveGizmoType); }
/// <summary> /// This method can be called to redo the action. /// </summary> public void Redo() { EditorGizmoSystem gizmoSystem = EditorGizmoSystem.Instance; gizmoSystem.TransformPivotPoint = _newPivotPoint; TransformPivotPointChangedMessage.SendToInterestedListeners(_oldPivotPoint, _newPivotPoint); }
/// <summary> /// This method can be called to redo the action. /// </summary> public void Redo() { EditorGizmoSystem gizmoSystem = EditorGizmoSystem.Instance; gizmoSystem.TurnOffGizmos(); GizmosTurnedOffMessage.SendToInterestedListeners(_activeGizmoType); }
/// <summary> /// This method can be called to undo the action. /// </summary> public void Undo() { EditorGizmoSystem gizmoSystem = EditorGizmoSystem.Instance; GizmoType oldActiveGizmoType = gizmoSystem.ActiveGizmoType; gizmoSystem.ActiveGizmoType = _activeGizmoType; ActiveGizmoTypeChangedMessage.SendToInterestedListeners(oldActiveGizmoType, _activeGizmoType); }
/// <summary> /// Executes the action. /// </summary> public void Execute() { // If the pivot points differ, execute the action if (_oldPivotPoint != _newPivotPoint) { EditorGizmoSystem gizmoSystem = EditorGizmoSystem.Instance; gizmoSystem.TransformPivotPoint = _newPivotPoint; TransformPivotPointChangedMessage.SendToInterestedListeners(_oldPivotPoint, _newPivotPoint); EditorUndoRedoSystem.Instance.RegisterAction(this); } }
/// <summary> /// Executes the action. /// </summary> public void Execute() { // If the gizmo types differ, execute the action EditorGizmoSystem gizmoSystem = EditorGizmoSystem.Instance; if (_oldActiveGizmoType != _newActiveGizmoType || gizmoSystem.AreGizmosTurnedOff) { gizmoSystem.ActiveGizmoType = _newActiveGizmoType; ActiveGizmoTypeChangedMessage.SendToInterestedListeners(_oldActiveGizmoType, _newActiveGizmoType); EditorUndoRedoSystem.Instance.RegisterAction(this); } }
/// <summary> /// Executes the action. /// </summary> public void Execute() { // Execute the action if the gizmos are not already turned off EditorGizmoSystem gizmoSystem = EditorGizmoSystem.Instance; if (!gizmoSystem.AreGizmosTurnedOff) { gizmoSystem.TurnOffGizmos(); GizmosTurnedOffMessage.SendToInterestedListeners(_activeGizmoType); EditorUndoRedoSystem.Instance.RegisterAction(this); } }
/// <summary> /// Creates all the necessary runtime editor subsystems. /// </summary> private static void CreateRuntimeEditorApplicationSubsystems() { // First, make sure all existing subsystems are destroyed DestroyExistingSubsystems(); // Now, create each subsystem RuntimeEditorApplication runtimeEditorApplication = CreateSubsystemObject <RuntimeEditorApplication>(null); Transform runtimeEditorApplicationTransform = runtimeEditorApplication.transform; EditorGizmoSystem editorGizmoSystem = CreateSubsystemObject <EditorGizmoSystem>(runtimeEditorApplicationTransform); CreateSubsystemObject <EditorObjectSelection>(runtimeEditorApplicationTransform); EditorCamera editorCamera = CreateSubsystemObject <EditorCamera>(runtimeEditorApplicationTransform); editorCamera.gameObject.AddComponent <Camera>(); CreateSubsystemObject <EditorUndoRedoSystem>(runtimeEditorApplicationTransform); CreateSubsystemObject <EditorMeshDatabase>(runtimeEditorApplicationTransform); CreateSubsystemObject <MessageListenerDatabase>(runtimeEditorApplicationTransform); CreateSubsystemObject <InputDevice>(runtimeEditorApplicationTransform); CreateSubsystemObject <SceneGizmo>(runtimeEditorApplicationTransform); // Create all transform gizmos and attach them to the gizmo system GameObject gizmoObject = new GameObject(); gizmoObject.name = "Translation Gizmo"; gizmoObject.transform.parent = runtimeEditorApplicationTransform; TranslationGizmo translationGizmo = gizmoObject.AddComponent <TranslationGizmo>(); editorGizmoSystem.TranslationGizmo = translationGizmo; gizmoObject = new GameObject(); gizmoObject.name = "Rotation Gizmo"; gizmoObject.transform.parent = runtimeEditorApplicationTransform; RotationGizmo rotationGizmo = gizmoObject.AddComponent <RotationGizmo>(); rotationGizmo.GizmoBaseScale = 1.3f; editorGizmoSystem.RotationGizmo = rotationGizmo; gizmoObject = new GameObject(); gizmoObject.name = "Scale Gizmo"; gizmoObject.transform.parent = runtimeEditorApplicationTransform; ScaleGizmo scaleGizmo = gizmoObject.AddComponent <ScaleGizmo>(); editorGizmoSystem.ScaleGizmo = scaleGizmo; gizmoObject = new GameObject(); gizmoObject.name = "Volume Scale Gizmo"; gizmoObject.transform.parent = runtimeEditorApplicationTransform; VolumeScaleGizmo volumeScaleGizmo = gizmoObject.AddComponent <VolumeScaleGizmo>(); editorGizmoSystem.VolumeScaleGizmo = volumeScaleGizmo; }
/// <summary> /// Creates all the necessary runtime editor subsystems. /// </summary> private static void CreateRuntimeEditorApplicationSubsystems() { // First, make sure all existing subsystems are destroyed DestroyExistingSubsystems(); // Now, create each subsystem RuntimeEditorApplication runtimeEditorApplication = RuntimeEditorApplication.Instance; Transform runtimeEditorApplicationTransform = runtimeEditorApplication.transform; EditorGizmoSystem editorGizmoSystem = EditorGizmoSystem.Instance; editorGizmoSystem.transform.parent = runtimeEditorApplicationTransform; EditorObjectSelection editorObjectSelection = EditorObjectSelection.Instance; editorObjectSelection.transform.parent = runtimeEditorApplicationTransform; EditorCamera editorCamera = EditorCamera.Instance; editorCamera.transform.parent = runtimeEditorApplicationTransform; editorCamera.gameObject.AddComponent <Camera>(); EditorUndoRedoSystem editorUndoRedoSystem = EditorUndoRedoSystem.Instance; editorUndoRedoSystem.transform.parent = runtimeEditorApplicationTransform; EditorShortuctKeys editorShortcutKeys = EditorShortuctKeys.Instance; editorShortcutKeys.transform.parent = runtimeEditorApplicationTransform; EditorMeshDatabase editorMeshDatabase = EditorMeshDatabase.Instance; editorMeshDatabase.transform.parent = runtimeEditorApplicationTransform; // Create all gizmos and attach them to the gizmo system GameObject gizmoObject = new GameObject(); gizmoObject.name = "Translation Gizmo"; // TranslationGizmo translationGizmo = gizmoObject.AddComponent<TranslationGizmo>(); // editorGizmoSystem.TranslationGizmo = translationGizmo; gizmoObject = new GameObject(); gizmoObject.name = "Rotation Gizmo"; RotationGizmo rotationGizmo = gizmoObject.AddComponent <RotationGizmo>(); rotationGizmo.GizmoBaseScale = 1.3f; editorGizmoSystem.RotationGizmo = rotationGizmo; gizmoObject = new GameObject(); gizmoObject.name = "Scale Gizmo"; // ScaleGizmo scaleGizmo = gizmoObject.AddComponent<ScaleGizmo>(); // editorGizmoSystem.ScaleGizmo = scaleGizmo; }
/// <summary> /// Called when the gizmo system object is selected in the scene view. /// </summary> private void OnEnable() { _gizmoSystem = target as EditorGizmoSystem; }
/// <summary> /// This method handles the shortcut keys which are related to the gizmo system. /// </summary> private void HandleEditorGizmoSystemKeys() { EditorGizmoSystem gizmoSystem = EditorGizmoSystem.Instance; // Check which shortcut key was pressed and execute the corresponding action if (Input.GetKeyDown(KeyCode.W) && !Input.GetMouseButton((int)MouseButton.Right)) { var action = new ActiveGizmoTypeChangeAction(gizmoSystem.ActiveGizmoType, GizmoType.Translation); action.Execute(); } else if (Input.GetKeyDown(KeyCode.E) && !Input.GetMouseButton((int)MouseButton.Right)) { var action = new ActiveGizmoTypeChangeAction(gizmoSystem.ActiveGizmoType, GizmoType.Rotation); action.Execute(); } else if (Input.GetKeyDown(KeyCode.R)) { var action = new ActiveGizmoTypeChangeAction(gizmoSystem.ActiveGizmoType, GizmoType.Scale); action.Execute(); } else if (Input.GetKeyDown(KeyCode.G)) { EditorGizmoSystem.Instance.TransformSpace = TransformSpace.Global; } else if (Input.GetKeyDown(KeyCode.L)) { EditorGizmoSystem.Instance.TransformSpace = TransformSpace.Local; } else if (Input.GetKeyDown(KeyCode.Q) && !Input.GetMouseButton((int)MouseButton.Right)) { var action = new GizmosTurnOffAction(gizmoSystem.ActiveGizmoType); action.Execute(); } else if (Input.GetKeyDown(KeyCode.P)) { // Toggle the pivot point and execute the action TransformPivotPoint newTransformPivotPoint = gizmoSystem.TransformPivotPoint == TransformPivotPoint.Center ? TransformPivotPoint.MeshPivot : TransformPivotPoint.Center; EditorGizmoSystem.Instance.TransformPivotPoint = newTransformPivotPoint; } // Check if any gizmo shorcut keys were pressed. We will do this based on which type of // gizmo is currently active. GizmoType activeGizmoType = gizmoSystem.ActiveGizmoType; if (activeGizmoType == GizmoType.Translation) { // // If the SHIFT key is pressed, we will activate translation along the camera right and up axes // TranslationGizmo translationGizmo = gizmoSystem.TranslationGizmo; // bool isShiftPressed = InputHelper.IsAnyShiftKeyPressed(); // if (isShiftPressed) translationGizmo.TranslateAlongCameraRightAndUpAxes = true; // else translationGizmo.TranslateAlongCameraRightAndUpAxes = false; // // // If the CTRL/COMMAND key is pressed, we will activate step snapping // bool isCtrlOrCommandPressed = InputHelper.IsAnyCtrlOrCommandKeyPressed(); // if (isCtrlOrCommandPressed) translationGizmo.SnapSettings.IsStepSnappingEnabled = true; // else translationGizmo.SnapSettings.IsStepSnappingEnabled = false; // // // If the 'V' key was pressed in the current frame, we will activate vertex snapping. When // // the 'V' key is released in the current frame, we will deactivate vertex snapping. // if (Input.GetKeyDown(KeyCode.V)) // { // translationGizmo.SnapSettings.IsVertexSnappingEnabled = true; // VertexSnappingEnabledMessage.SendToInterestedListeners(); // } // if (Input.GetKeyUp(KeyCode.V)) // { // translationGizmo.SnapSettings.IsVertexSnappingEnabled = false; // VertexSnappingDisabledMessage.SendToInterestedListeners(); // } // // if (Input.GetKeyDown(KeyCode.Space)) translationGizmo.PlaceObjectsOnSurface = true; // // Axis alignmentAxis = Axis.Y; // if (Input.GetKey(KeyCode.X)) alignmentAxis = Axis.X; // else if (Input.GetKey(KeyCode.Z)) alignmentAxis = Axis.Z; // translationGizmo.SurfaceAlignmentAxis = alignmentAxis; // // if (Input.GetKey(KeyCode.LeftControl) || Input.GetKey(KeyCode.LeftCommand)) translationGizmo.AlignObjectAxisToSurface = false; // else translationGizmo.AlignObjectAxisToSurface = true; // // if (Input.GetKeyUp(KeyCode.Space)) translationGizmo.PlaceObjectsOnSurface = false; } else if (activeGizmoType == GizmoType.Rotation) { // If the CTRL/COMMAND key is pressed, we will activate snapping RotationGizmo rotationGizmo = gizmoSystem.RotationGizmo; bool isCtrlOrCommandPressed = InputHelper.IsAnyCtrlOrCommandKeyPressed(); if (isCtrlOrCommandPressed) { rotationGizmo.SnapSettings.IsSnappingEnabled = true; } else { rotationGizmo.SnapSettings.IsSnappingEnabled = false; } } else if (activeGizmoType == GizmoType.Scale) { // If the shift key is pressed, we will activate scaling along all axes at once // ScaleGizmo scaleGizmo = gizmoSystem.ScaleGizmo; // bool isShiftPressed = InputHelper.IsAnyShiftKeyPressed(); // if (isShiftPressed) scaleGizmo.ScaleAlongAllAxes = true; // else scaleGizmo.ScaleAlongAllAxes = false; // // // If the CTRL/COMMAND key is pressed, we will activate snapping // bool isCtrlOrCommandPressed = InputHelper.IsAnyCtrlOrCommandKeyPressed(); // if (isCtrlOrCommandPressed) scaleGizmo.SnapSettings.IsSnappingEnabled = true; // else scaleGizmo.SnapSettings.IsSnappingEnabled = false; } }