예제 #1
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();
        }
예제 #2
0
        /// <summary>
        /// Creates the scene camera and updates the render texture. Should be called at least once before using the
        /// scene view. Should be called whenever the window is resized.
        /// </summary>
        /// <param name="width">Width of the scene render target, in pixels.</param>
        /// <param name="height">Height of the scene render target, in pixels.</param>
        private void UpdateRenderTexture(int width, int height)
        {
            width  = MathEx.Max(20, width);
            height = MathEx.Max(20, height);

            // Note: Depth buffer and readable flags are required because ScenePicking uses it
            Texture colorTex = Texture.Create2D(width, height, PixelFormat.RGBA8, TextureUsage.Render | TextureUsage.CPUReadable);
            Texture depthTex = Texture.Create2D(width, height, PixelFormat.D32_S8X24, TextureUsage.DepthStencil | TextureUsage.CPUReadable);

            renderTexture          = new RenderTexture(colorTex, depthTex);
            renderTexture.Priority = 1;

            if (camera == null)
            {
                SceneObject sceneCameraSO = new SceneObject("SceneCamera", true);
                camera = sceneCameraSO.AddComponent <Camera>();
                camera.Viewport.Target = renderTexture;
                camera.Viewport.Area   = new Rect2(0.0f, 0.0f, 1.0f, 1.0f);

                Vector3 camPosition = new Vector3(0.0f, 1.7f, 5.0f);
                object  camPosObj   = ProjectSettings.GetObject <object>(CameraPositionKey);
                if (camPosObj is Vector3)
                {
                    camPosition = (Vector3)camPosObj;
                }

                Quaternion camRotation = Quaternion.Identity;
                object     camRotObj   = ProjectSettings.GetObject <object>(CameraRotationKey);
                if (camRotObj is Quaternion)
                {
                    camRotation = (Quaternion)camRotObj;
                }

                sceneCameraSO.Position = camPosition;
                sceneCameraSO.Rotation = camRotation;

                camera.Priority            = 2;
                camera.Viewport.ClearColor = ClearColor;
                camera.Layers = UInt64.MaxValue & ~SceneAxesHandle.LAYER; // Don't draw scene axes in this camera

                sceneCamera = sceneCameraSO.AddComponent <SceneCamera>();

                renderTextureGUI = new GUIRenderTexture(renderTexture);
                rtPanel.AddElement(renderTextureGUI);

                sceneGrid      = new SceneGrid(camera);
                sceneSelection = new SceneSelection(camera);
                sceneGizmos    = new SceneGizmos(camera);
                sceneHandles   = new SceneHandles(this, camera);
            }
            else
            {
                camera.Viewport.Target         = renderTexture;
                renderTextureGUI.RenderTexture = renderTexture;
            }

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

            renderTextureGUI.Bounds = rtBounds;
            focusCatcher.Bounds     = GUIUtility.CalculateBounds(rtPanel, GUI);

            sceneAxesGUI.SetPosition(width - HandleAxesGUISize - HandleAxesGUIPaddingX, HandleAxesGUIPaddingY);

            // TODO - Consider only doing the resize once user stops resizing the widget in order to reduce constant
            // render target destroy/create cycle for every single pixel.

            camera.AspectRatio = width / (float)height;
        }
예제 #3
0
 private void SaveSettings()
 {
     ProjectSettings.SetObject(ExpandStatesKey, expandStates);
 }
예제 #4
0
 /// <summary>
 /// Sets the field of view of the scene camera
 /// </summary>
 /// <param name="fieldOfView">The field of view value.</param>
 public void SetFieldOfView(float fieldOfView)
 {
     FieldOfView = (Degree)fieldOfView;
     ProjectSettings.SetFloat("SceneCameraOptions_FieldOfView", fieldOfView);
 }
예제 #5
0
 /// <summary>
 /// Sets the acceleration of the scene camera
 /// </summary>
 /// <param name="acceleration">The acceleration value.</param>
 public void SetAcceleration(float acceleration)
 {
     Acceleration = acceleration;
     ProjectSettings.SetFloat("SceneCameraOptions_Acceleration", acceleration);
 }
예제 #6
0
 /// <summary>
 /// Sets the orthographic size of the scene camera.
 /// </summary>
 /// <param name="orthographicSize">The orthographic size value.</param>
 public void SetOrthographicSize(float orthographicSize)
 {
     OrthographicSize = orthographicSize;
     ProjectSettings.SetFloat("SceneCameraOptions_OrthographicSize", orthographicSize);
 }
예제 #7
0
 /// <summary>
 /// Sets the rotation speed of the scene camera
 /// </summary>
 /// <param name="rotationalSpeed">The rotation speed  value.</param>
 public void SetRotationalSpeed(float rotationalSpeed)
 {
     RotationalSpeed = rotationalSpeed;
     ProjectSettings.SetFloat("SceneCameraOptions_RotationalSpeed", rotationalSpeed);
 }
예제 #8
0
 /// <summary>
 /// Sets the scroll speed of the scene camera
 /// </summary>
 /// <param name="scrollSpeed">The scroll speed value.</param>
 public void SetScrollSpeed(float scrollSpeed)
 {
     ScrollSpeed = scrollSpeed;
     ProjectSettings.SetFloat("SceneCameraOptions_ScrollSpeed", scrollSpeed);
 }
예제 #9
0
 /// <summary>
 /// Sets the pan speed of the scene camera
 /// </summary>
 /// <param name="panSpeed">The pan speed value.</param>
 public void SetPanSpeed(float panSpeed)
 {
     PanSpeed = panSpeed;
     ProjectSettings.SetFloat("SceneCameraOptions_PanSpeed", panSpeed);
 }
예제 #10
0
 /// <summary>
 /// Sets the fast mode multiplier of the scene camera
 /// </summary>
 /// <param name="fastModeMultiplier">The fast mode multiplier value.</param>
 public void SetFastModeMultiplier(float fastModeMultiplier)
 {
     FastModeMultiplier = fastModeMultiplier;
     ProjectSettings.SetFloat("SceneCameraOptions_FastModeMultiplier", fastModeMultiplier);
 }