Exemple #1
0
        /// <summary>
        /// This method handles the shortcut keys which are related to the undo/redo system.
        /// </summary>
        private void HandleEditorUndoRedoSystemKeys()
        {
            EditorUndoRedoSystem undoRedoSystem = EditorUndoRedoSystem.Instance;

            // Note: When the application is not running in editor mode, we will use the
            //       standard shortcut keys for Undo/Redo (CTRL/CMD + Z, CTRL/CMD + Y).
            //       Otherwise, we will add the SHIFT key into the mix in order to stop
            //       the Unity editor from invoking its own Undo/Redo system.
            if (!Application.isEditor)
            {
                if (Input.GetKeyDown(KeyCode.Z) && InputHelper.IsAnyCtrlOrCommandKeyPressed())
                {
                    undoRedoSystem.Undo();
                }
                else
                if (Input.GetKeyDown(KeyCode.Y) && InputHelper.IsAnyCtrlOrCommandKeyPressed())
                {
                    undoRedoSystem.Redo();
                }
            }
            else
            {
                if (Input.GetKeyDown(KeyCode.Z) && InputHelper.IsAnyCtrlOrCommandKeyPressed() && InputHelper.IsAnyShiftKeyPressed())
                {
                    undoRedoSystem.Undo();
                }
                else
                if (Input.GetKeyDown(KeyCode.Y) && InputHelper.IsAnyCtrlOrCommandKeyPressed() && InputHelper.IsAnyShiftKeyPressed())
                {
                    undoRedoSystem.Redo();
                }
            }
        }
        /// <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 undo/redo system object is selected in the scene view.
 /// </summary>
 protected virtual void OnEnable()
 {
     _editorUndoRedoSystem = target as EditorUndoRedoSystem;
 }