Beispiel #1
0
        private static void Play()
        {
            GameWindow  gameWindow  = GetWindow <GameWindow>();
            SceneWindow sceneWindow = GetWindow <SceneWindow>();

            PlayInEditorState state = PlayInEditor.State;

            if (state != PlayInEditorState.Playing)
            {
                gameWindow.Active   = true;
                gameWindow.HasFocus = true;
            }
            else
            {
                sceneWindow.Active   = true;
                sceneWindow.HasFocus = true;
            }

            if (state == PlayInEditorState.Paused)
            {
                PlayInEditor.State = PlayInEditorState.Playing;
            }
            else
            {
                if (state == PlayInEditorState.Playing)
                {
                    PlayInEditor.State = PlayInEditorState.Stopped;
                }
                else
                {
                    PlayInEditor.State = PlayInEditorState.Playing;
                }
            }
        }
Beispiel #2
0
        private static void Play()
        {
            GameWindow  gameWindow  = GetWindow <GameWindow>();
            SceneWindow sceneWindow = GetWindow <SceneWindow>();

            if (!EditorApplication.IsPlaying)
            {
                gameWindow.Active   = true;
                gameWindow.HasFocus = true;
            }
            else
            {
                sceneWindow.Active   = true;
                sceneWindow.HasFocus = true;
            }

            if (EditorApplication.IsPaused)
            {
                EditorApplication.IsPaused = false;
            }
            else
            {
                EditorApplication.IsPlaying = !EditorApplication.IsPlaying;
            }
        }
Beispiel #3
0
        private static void OpenSettingsWindow()
        {
            SceneWindow window = GetWindow <SceneWindow>();

            if (window != null)
            {
                window.sceneCamera.FrameSelected();
            }
        }
Beispiel #4
0
        private static void SetScaleTool()
        {
            SceneWindow window = GetWindow <SceneWindow>();

            if (window != null)
            {
                window.OnSceneToolButtonClicked(SceneViewTool.Scale);
            }
        }
Beispiel #5
0
        private void RotateCameraTo(Vector3 axis)
        {
            SceneWindow sceneWindow = EditorWindow.GetWindow <SceneWindow>();

            if (sceneWindow != null)
            {
                sceneWindow.LookAlong(axis);
            }
        }
Beispiel #6
0
        private void OnEditorUpdate()
        {
            InspectableState viewOptionsState = guiViewSettings.Refresh();

            if (viewOptionsState != InspectableState.NotModified)
            {
                SceneWindow sceneWindow = SceneWindow.GetWindow <SceneWindow>();
                if (sceneWindow != null)
                {
                    sceneWindow.Camera.ViewSettings = viewSettings;
                }

                ProjectSettings.SetObject(SceneCamera.ViewSettingsKey, viewSettings);
            }

            InspectableState moveOptionsState = guiMovementSettings.Refresh();

            if (moveOptionsState != InspectableState.NotModified)
            {
                SceneWindow sceneWindow = SceneWindow.GetWindow <SceneWindow>();
                if (sceneWindow != null)
                {
                    sceneWindow.Camera.MoveSettings = moveSettings;
                }

                ProjectSettings.SetObject(SceneCamera.MoveSettingsKey, moveSettings);
            }

            InspectableState renderOptionsState = guiRenderSettings.Refresh();

            if (renderOptionsState != InspectableState.NotModified)
            {
                SceneWindow sceneWindow = SceneWindow.GetWindow <SceneWindow>();
                if (sceneWindow != null)
                {
                    sceneWindow.Camera.RenderSettings = renderSettings;
                }

                ProjectSettings.SetObject(SceneCamera.RenderSettingsKey, renderSettings);
            }

            InspectableState gizmoOptionsState = guiGizmoSettings.Refresh();

            if (gizmoOptionsState != InspectableState.NotModified)
            {
                gizmoSettings = (GizmoDrawSettings)objGizmoSettings;

                SceneWindow sceneWindow = SceneWindow.GetWindow <SceneWindow>();
                if (sceneWindow != null)
                {
                    sceneWindow.GizmoDrawSettings = gizmoSettings;
                }

                ProjectSettings.SetObject(SceneWindow.GizmoDrawSettingsKey, gizmoSettings);
            }
        }
        /// <summary>
        /// Initializes the drop down window by creating the necessary GUI. Must be called after construction and before
        /// use.
        /// </summary>
        /// <param name="parent">Scene window that this drop down window is a part of.</param>
        /// <param name="cameraOptions">Reference to the current scene camera options.</param>
        internal void Initialize(SceneWindow parent)
        {
            this.Parent = parent;

            GUIEnumField cameraProjectionTypeField = new GUIEnumField(typeof(ProjectionType), new LocEdString("Projection type"));

            cameraProjectionTypeField.Value = (ulong)Parent.ProjectionType;
            cameraProjectionTypeField.OnSelectionChanged += SetCameraProjectionType;

            nearClipPlaneInput            = new GUIFloatField(new LocEdString("Near plane"));
            nearClipPlaneInput.Value      = Parent.NearClipPlane;
            nearClipPlaneInput.OnChanged += OnNearClipPlaneChanged;
            nearClipPlaneInput.SetRange(SceneCameraOptions.MinNearClipPlane, SceneCameraOptions.MaxNearClipPlane);

            farClipPlaneInput            = new GUIFloatField(new LocEdString("Far plane"));
            farClipPlaneInput.Value      = Parent.FarClipPlane;
            farClipPlaneInput.OnChanged += OnFarClipPlaneChanged;
            farClipPlaneInput.SetRange(SceneCameraOptions.MinFarClipPlane, SceneCameraOptions.MaxFarClipPlane);

            cameraFieldOfView            = new GUISliderField(1, 360, new LocEdString("Field of view"));
            cameraFieldOfView.Value      = Parent.FieldOfView.Degrees;
            cameraFieldOfView.OnChanged += SetFieldOfView;

            cameraOrthographicSize            = new GUIFloatField(new LocEdString("Orthographic size"));
            cameraOrthographicSize.Value      = Parent.OrthographicSize;
            cameraOrthographicSize.OnChanged += SetOrthographicSize;

            GUISliderField cameraScrollSpeed = new GUISliderField(SceneCameraOptions.MinScrollSpeed, SceneCameraOptions.MaxScrollSpeed,
                                                                  new LocEdString("Scroll speed"));

            cameraScrollSpeed.Value      = Parent.ScrollSpeed;
            cameraScrollSpeed.OnChanged += SetScrollSpeed;

            GUILayoutY vertLayout = GUI.AddLayoutY();

            vertLayout.AddSpace(10);

            GUILayoutX cameraOptionsLayoutX = vertLayout.AddLayoutX();

            cameraOptionsLayoutX.AddSpace(10);

            GUILayoutY cameraOptionsLayoutY = cameraOptionsLayoutX.AddLayoutY();

            cameraOptionsLayoutY.AddElement(cameraProjectionTypeField);
            cameraOptionsLayoutY.AddElement(nearClipPlaneInput);
            cameraOptionsLayoutY.AddElement(farClipPlaneInput);
            cameraOptionsLayoutY.AddElement(cameraFieldOfView);
            cameraOptionsLayoutY.AddElement(cameraOrthographicSize);
            cameraOptionsLayoutY.AddElement(cameraScrollSpeed);
            cameraOptionsLayoutX.AddSpace(10);

            vertLayout.AddSpace(10);

            ToggleTypeSpecificFields((ProjectionType)cameraProjectionTypeField.Value);
        }
Beispiel #8
0
        /// <summary>
        /// Creates a new scene axes GUI.
        /// </summary>
        /// <param name="window">Window in which the GUI is located in.</param>
        /// <param name="panel">Panel onto which to place the GUI element.</param>
        /// <param name="width">Width of the GUI element.</param>
        /// <param name="height">Height of the GUI element.</param>
        /// <param name="projType">Projection type to display on the GUI.</param>
        public SceneAxesGUI(SceneWindow window, GUIPanel panel, int width, int height, ProjectionType projType)
        {
            renderTexture          = new RenderTexture(PixelFormat.RGBA8, width, height);
            renderTexture.Priority = 1;

            SceneObject cameraSO = new SceneObject("SceneAxesCamera", true);

            camera = cameraSO.AddComponent <Camera>();
            camera.Viewport.Target = renderTexture;
            camera.Viewport.Area   = new Rect2(0.0f, 0.0f, 1.0f, 1.0f);

            cameraSO.Position = new Vector3(0, 0, 5);
            cameraSO.LookAt(new Vector3(0, 0, 0));

            camera.Priority            = 2;
            camera.NearClipPlane       = 0.05f;
            camera.FarClipPlane        = 1000.0f;
            camera.Viewport.ClearColor = new Color(0.0f, 0.0f, 0.0f, 0.0f);
            camera.ProjectionType      = ProjectionType.Orthographic;
            camera.Layers      = SceneAxesHandle.LAYER;
            camera.AspectRatio = 1.0f;
            camera.OrthoHeight = 2.0f;
            camera.RenderSettings.EnableHDR    = false;
            camera.RenderSettings.EnableSkybox = false;
            camera.Flags |= CameraFlag.OnDemand;

            renderTextureGUI = new GUIRenderTexture(renderTexture, true);

            GUILayoutY layout        = panel.AddLayoutY();
            GUILayoutX textureLayout = layout.AddLayoutX();

            textureLayout.AddElement(renderTextureGUI);
            textureLayout.AddFlexibleSpace();

            Rect2I bounds = new Rect2I(0, 0, width, height);

            sceneHandles            = new SceneHandles(window, camera);
            renderTextureGUI.Bounds = bounds;

            labelGUI = new GUILabel(projType.ToString(), EditorStyles.LabelCentered);
            layout.AddElement(labelGUI);
            layout.AddFlexibleSpace();

            this.panel  = panel;
            this.bounds = bounds;

            NotifyNeedsRedraw();
        }
Beispiel #9
0
        private void ToggleProjectionType()
        {
            SceneWindow sceneWindow = EditorWindow.GetWindow <SceneWindow>();

            if (sceneWindow != null)
            {
                if (sceneWindow.Camera.Camera.ProjectionType == ProjectionType.Orthographic)
                {
                    sceneWindow.Camera.ChangeProjectionType(ProjectionType.Perspective);
                }
                else
                {
                    sceneWindow.Camera.ChangeProjectionType(ProjectionType.Orthographic);
                }
            }
        }
Beispiel #10
0
        /// <summary>
        /// Sets keyboard focus to the Hierarchy or Scene windows if open.
        /// </summary>
        private static void FocusOnHierarchyOrScene()
        {
            SceneWindow sceneWindow = EditorWindow.GetWindow <SceneWindow>();

            if (sceneWindow != null)
            {
                sceneWindow.HasFocus = true;
                return;
            }

            HierarchyWindow hierarchyWindow = EditorWindow.GetWindow <HierarchyWindow>();

            if (hierarchyWindow != null)
            {
                hierarchyWindow.HasFocus = true;
            }
        }
Beispiel #11
0
        /// <summary>
        /// Resets all scene camera settings to default values.
        /// </summary>
        private void ResetToDefault()
        {
            viewSettings   = new SceneCameraViewSettings();
            moveSettings   = new SceneCameraMoveSettings();
            renderSettings = new RenderSettings();

            SceneWindow sceneWindow = SceneWindow.GetWindow <SceneWindow>();

            if (sceneWindow != null)
            {
                sceneWindow.Camera.ViewSettings   = viewSettings;
                sceneWindow.Camera.MoveSettings   = moveSettings;
                sceneWindow.Camera.RenderSettings = renderSettings;
            }

            ProjectSettings.SetObject(SceneCamera.ViewSettingsKey, viewSettings);
            ProjectSettings.SetObject(SceneCamera.MoveSettingsKey, moveSettings);
            ProjectSettings.SetObject(SceneCamera.RenderSettingsKey, renderSettings);
        }
Beispiel #12
0
        private void OnInitialize()
        {
            EditorApplication.OnProjectSave += SaveSettings;

            SceneWindow sceneWindow = SceneWindow.GetWindow <SceneWindow>();

            if (sceneWindow != null)
            {
                viewSettings   = sceneWindow.Camera.ViewSettings;
                moveSettings   = sceneWindow.Camera.MoveSettings;
                renderSettings = sceneWindow.Camera.RenderSettings;
                gizmoSettings  = sceneWindow.GizmoDrawSettings;
            }
            else
            {
                viewSettings   = ProjectSettings.GetObject <SceneCameraViewSettings>(SceneCamera.ViewSettingsKey);
                moveSettings   = ProjectSettings.GetObject <SceneCameraMoveSettings>(SceneCamera.MoveSettingsKey);
                renderSettings = ProjectSettings.GetObject <RenderSettings>(SceneCamera.RenderSettingsKey);

                if (ProjectSettings.HasKey(SceneWindow.GizmoDrawSettingsKey))
                {
                    gizmoSettings = ProjectSettings.GetObject <GizmoDrawSettings>(SceneWindow.GizmoDrawSettingsKey);
                }
                else
                {
                    gizmoSettings = GizmoDrawSettings.Default();
                }
            }

            expandStates = ProjectSettings.GetObject <SerializableProperties>(ExpandStatesKey);
            InspectableContext inspectableContext = new InspectableContext(expandStates);

            GUILayout mainLayout = GUI.AddLayoutY();

            GUIScrollArea scrollArea = new GUIScrollArea(ScrollBarType.ShowIfDoesntFit, ScrollBarType.NeverShow);

            mainLayout.AddElement(scrollArea);

            GUILayoutX horzPadLayout = scrollArea.Layout.AddLayoutX(GUIOption.FlexibleWidth(100, 400));

            horzPadLayout.AddSpace(5);

            GUILayout vertLayout = horzPadLayout.AddLayoutY();

            horzPadLayout.AddSpace(5);

            vertLayout.AddSpace(5);

            vertLayout.AddElement(new GUILabel(new LocEdString("View Settings"), EditorStyles.LabelBold));
            GUILayoutY viewSettingsLayout = vertLayout.AddLayoutY();

            vertLayout.AddSpace(10);

            vertLayout.AddElement(new GUILabel(new LocEdString("Gizmo Settings"), EditorStyles.LabelBold));
            GUILayoutY gizmoSettingsLayout = vertLayout.AddLayoutY();

            vertLayout.AddSpace(10);

            vertLayout.AddElement(new GUILabel(new LocEdString("Move Settings"), EditorStyles.LabelBold));
            GUILayoutY moveSettingsLayout = vertLayout.AddLayoutY();

            vertLayout.AddSpace(10);

            vertLayout.AddElement(new GUILabel(new LocEdString("Render Settings"), EditorStyles.LabelBold));
            GUILayoutY renderSettingsLayout = vertLayout.AddLayoutY();

            guiViewSettings     = new InspectorFieldDrawer(inspectableContext, viewSettingsLayout);
            guiGizmoSettings    = new InspectorFieldDrawer(inspectableContext, gizmoSettingsLayout);
            guiMovementSettings = new InspectorFieldDrawer(inspectableContext, moveSettingsLayout);
            guiRenderSettings   = new InspectorFieldDrawer(inspectableContext, renderSettingsLayout);

            objGizmoSettings = gizmoSettings;

            guiViewSettings.AddDefault(viewSettings);
            guiGizmoSettings.AddDefault(objGizmoSettings);
            guiMovementSettings.AddDefault(moveSettings);
            guiRenderSettings.AddDefault(renderSettings);

            mainLayout.AddSpace(5);
            GUILayout buttonCenterLayout = mainLayout.AddLayoutX();

            mainLayout.AddSpace(5);

            GUIButton resetToDefaultBtn = new GUIButton(new LocEdString("Reset to defaults"));

            resetToDefaultBtn.OnClick += () => ConfirmResetToDefault(ResetToDefault, null);

            buttonCenterLayout.AddFlexibleSpace();
            buttonCenterLayout.AddElement(resetToDefaultBtn);
            buttonCenterLayout.AddFlexibleSpace();
        }
Beispiel #13
0
        private void OnUpdate()
        {
            bool  isOrthographic = camera.ProjectionType == ProjectionType.Orthographic;
            float frameDelta     = Time.FrameDelta;

            if (inputEnabled)
            {
                bool goingForward = VirtualInput.IsButtonHeld(moveForwardBtn);
                bool goingBack    = VirtualInput.IsButtonHeld(moveBackwardBtn);
                bool goingLeft    = VirtualInput.IsButtonHeld(moveLeftBtn);
                bool goingRight   = VirtualInput.IsButtonHeld(moveRightBtn);
                bool goingUp      = VirtualInput.IsButtonHeld(moveUpBtn);
                bool goingDown    = VirtualInput.IsButtonHeld(moveDownBtn);
                bool fastMove     = VirtualInput.IsButtonHeld(fastMoveBtn);
                bool camActive    = VirtualInput.IsButtonHeld(activeBtn);
                bool isPanning    = VirtualInput.IsButtonHeld(panBtn);

                bool hideCursor = camActive || isPanning;
                if (hideCursor != lastHideCursorState)
                {
                    if (hideCursor)
                    {
                        Cursor.Hide();

                        Rect2I clipRect;
                        clipRect.x      = Input.PointerPosition.x - 2;
                        clipRect.y      = Input.PointerPosition.y - 2;
                        clipRect.width  = 4;
                        clipRect.height = 4;

                        Cursor.ClipToRect(clipRect);
                    }
                    else
                    {
                        Cursor.Show();
                        Cursor.ClipDisable();
                    }

                    lastHideCursorState = hideCursor;
                }

                if (camActive)
                {
                    float horzValue = VirtualInput.GetAxisValue(horizontalAxis);
                    float vertValue = VirtualInput.GetAxisValue(verticalAxis);

                    float rotationAmount = SceneCameraOptions.RotationalSpeed * EditorSettings.MouseSensitivity;

                    yaw   += new Degree(horzValue * rotationAmount);
                    pitch += new Degree(vertValue * rotationAmount);

                    yaw   = MathEx.WrapAngle(yaw);
                    pitch = MathEx.WrapAngle(pitch);

                    Quaternion yRot = Quaternion.FromAxisAngle(Vector3.YAxis, yaw);
                    Quaternion xRot = Quaternion.FromAxisAngle(Vector3.XAxis, pitch);

                    Quaternion camRot = yRot * xRot;
                    camRot.Normalize();

                    SceneObject.Rotation = camRot;

                    // Handle movement using movement keys
                    Vector3 direction = Vector3.Zero;

                    if (goingForward)
                    {
                        direction += SceneObject.Forward;
                    }
                    if (goingBack)
                    {
                        direction -= SceneObject.Forward;
                    }
                    if (goingRight)
                    {
                        direction += SceneObject.Right;
                    }
                    if (goingLeft)
                    {
                        direction -= SceneObject.Right;
                    }
                    if (goingUp)
                    {
                        direction += SceneObject.Up;
                    }
                    if (goingDown)
                    {
                        direction -= SceneObject.Up;
                    }

                    if (direction.SqrdLength != 0)
                    {
                        direction.Normalize();

                        float multiplier = 1.0f;
                        if (fastMove)
                        {
                            multiplier = SceneCameraOptions.FastModeMultiplier;
                        }

                        currentSpeed  = MathEx.Clamp(currentSpeed + SceneCameraOptions.Acceleration * frameDelta, SceneCameraOptions.StartSpeed, SceneCameraOptions.TopSpeed);
                        currentSpeed *= multiplier;
                    }
                    else
                    {
                        currentSpeed = 0.0f;
                    }

                    const float tooSmall = 0.0001f;
                    if (currentSpeed > tooSmall)
                    {
                        Vector3 velocity = direction * currentSpeed;
                        SceneObject.Move(velocity * frameDelta);
                    }
                }

                // Pan
                if (isPanning)
                {
                    float horzValue = VirtualInput.GetAxisValue(horizontalAxis);
                    float vertValue = VirtualInput.GetAxisValue(verticalAxis);

                    Vector3 direction = new Vector3(horzValue, -vertValue, 0.0f);
                    direction = camera.SceneObject.Rotation.Rotate(direction);

                    SceneObject.Move(direction * SceneCameraOptions.PanSpeed * frameDelta);
                }
            }
            else
            {
                if (lastHideCursorState)
                {
                    Cursor.Show();
                    Cursor.ClipDisable();

                    lastHideCursorState = false;
                }
            }

            SceneWindow sceneWindow = EditorWindow.GetWindow <SceneWindow>();

            if ((sceneWindow.Active && sceneWindow.HasFocus) || sceneWindow.IsPointerHovering)
            {
                Rect2I bounds = sceneWindow.Bounds;

                // Move using scroll wheel
                if (bounds.Contains(Input.PointerPosition))
                {
                    float scrollAmount = VirtualInput.GetAxisValue(scrollAxis);

                    if (scrollAmount != 0)
                    {
                        if (!isOrthographic)
                        {
                            SceneObject.Move(SceneObject.Forward * scrollAmount * SceneCameraOptions.ScrollSpeed * frameDelta);
                        }
                        else
                        {
                            float orthoHeight = MathEx.Max(1.0f, OrthographicSize - scrollAmount * frameDelta);

                            if (OrthographicSize != orthoHeight)
                            {
                                OrthographicSize = orthoHeight;
                            }
                        }
                    }
                }
            }

            UpdateAnim();
        }