/// <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;
        }
 protected override void OnEnable()
 {
     base.OnEnable();
     _volumeScaleGizmo = target as VolumeScaleGizmo;
 }
        /// <summary>
        /// Called when the inspector needs to be rendered.
        /// </summary>
        public override void OnInspectorGUI()
        {
            // Let the user specify the translation gizmo
            EditorGUILayout.BeginVertical("Box");
            TranslationGizmo translationGizmo = EditorGUILayout.ObjectField("Translation Gizmo", _gizmoSystem.TranslationGizmo, typeof(TranslationGizmo), true) as TranslationGizmo;

            if (translationGizmo != _gizmoSystem.TranslationGizmo)
            {
                UnityEditorUndoHelper.RecordObjectForInspectorPropertyChange(_gizmoSystem);
                _gizmoSystem.TranslationGizmo = translationGizmo;
            }

            // Let the user specify the rotation gizmo
            RotationGizmo rotationGizmo = EditorGUILayout.ObjectField("Rotation Gizmo", _gizmoSystem.RotationGizmo, typeof(RotationGizmo), true) as RotationGizmo;

            if (rotationGizmo != _gizmoSystem.RotationGizmo)
            {
                UnityEditorUndoHelper.RecordObjectForInspectorPropertyChange(_gizmoSystem);
                _gizmoSystem.RotationGizmo = rotationGizmo;
            }

            // Let the user specify the scale gizmo
            ScaleGizmo scaleGizmo = EditorGUILayout.ObjectField("Scale Gizmo", _gizmoSystem.ScaleGizmo, typeof(ScaleGizmo), true) as ScaleGizmo;

            if (scaleGizmo != _gizmoSystem.ScaleGizmo)
            {
                UnityEditorUndoHelper.RecordObjectForInspectorPropertyChange(_gizmoSystem);
                _gizmoSystem.ScaleGizmo = scaleGizmo;
            }

            VolumeScaleGizmo volumeScaleGizmo = EditorGUILayout.ObjectField("Volume Scale Gizmo", _gizmoSystem.VolumeScaleGizmo, typeof(VolumeScaleGizmo), true) as VolumeScaleGizmo;

            if (scaleGizmo != _gizmoSystem.VolumeScaleGizmo)
            {
                UnityEditorUndoHelper.RecordObjectForInspectorPropertyChange(_gizmoSystem);
                _gizmoSystem.VolumeScaleGizmo = volumeScaleGizmo;
            }

            // Let the user specify the active gimo type
            if (_gizmoSystem.IsAnyGizmoTypeAvailable())
            {
                EditorGUILayout.Separator();
                GizmoType newActiveGizmoType = (GizmoType)EditorGUILayout.EnumPopup("Active Gizmo Type", _gizmoSystem.ActiveGizmoType);
                if (newActiveGizmoType != _gizmoSystem.ActiveGizmoType)
                {
                    UnityEditorUndoHelper.RecordObjectForInspectorPropertyChange(_gizmoSystem);
                    _gizmoSystem.ActiveGizmoType = newActiveGizmoType;
                }
            }

            EditorGUILayout.Separator();
            List <GizmoType> allGizmoTypes = Enum.GetValues(typeof(GizmoType)).Cast <GizmoType>().ToList();

            foreach (var gizmoType in allGizmoTypes)
            {
                bool isGizmoTypeAvailable = _gizmoSystem.IsGizmoTypeAvailable(gizmoType);
                bool newBool = EditorGUILayout.ToggleLeft(gizmoType.ToString(), isGizmoTypeAvailable);
                if (isGizmoTypeAvailable != newBool)
                {
                    UnityEditorUndoHelper.RecordObjectForInspectorPropertyChange(_gizmoSystem);
                    if (newBool)
                    {
                        _gizmoSystem.SetGizmoTypeAvailable(gizmoType, true);
                    }
                    else
                    {
                        _gizmoSystem.SetGizmoTypeAvailable(gizmoType, false);
                    }
                }
            }
            EditorGUILayout.EndVertical();

            _keyMappingsAreVisible = EditorGUILayout.Foldout(_keyMappingsAreVisible, "Key mappings");
            if (_keyMappingsAreVisible)
            {
                _gizmoSystem.ActivateTranslationGizmoShortcut.RenderView(_gizmoSystem);
                _gizmoSystem.ActivateRotationGizmoShortcut.RenderView(_gizmoSystem);
                _gizmoSystem.ActivateScaleGizmoShortcut.RenderView(_gizmoSystem);
                _gizmoSystem.ActivateVolumeScaleGizmoShortcut.RenderView(_gizmoSystem);
                _gizmoSystem.ActivateGlobalTransformShortcut.RenderView(_gizmoSystem);
                _gizmoSystem.ActivateLocalTransformShortcut.RenderView(_gizmoSystem);
                _gizmoSystem.TurnOffGizmosShortcut.RenderView(_gizmoSystem);
                _gizmoSystem.TogglePivotShortcut.RenderView(_gizmoSystem);
            }
        }