internal ProfilerOverlayInternal(Camera camera)
        {
            IntPtr ptr = IntPtr.Zero;
            if (camera != null)
                ptr = camera.Native.GetCachedPtr();

            Internal_CreateInstance(this, ptr);
        }
Example #2
0
        /// <summary>
        /// Returns a scale that can be applied to a handle in order to keep it at constant size regardless of distance
        /// from the provided camera.
        /// </summary>
        /// <param name="camera">Camera through which the handle is being viewed.</param>
        /// <param name="position">Center of the handle.</param>
        /// <returns>Uniform scale to apply to the handle.</returns>
        public static float GetHandleSize(Camera camera, Vector3 position)
        {
            if (camera.ProjectionType == ProjectionType.Perspective)
            {
                Vector3 cameraPos = camera.SceneObject.Position;

                Vector3 diff = position - cameraPos;
                float distAlongViewDir = Math.Abs(Vector3.Dot(diff, camera.SceneObject.Rotation.Forward));

                return distAlongViewDir*EditorSettings.DefaultHandleSize;
            }
            else
            {
                return camera.OrthoHeight*EditorSettings.DefaultHandleSize;
            }
        }
Example #3
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 RenderTexture2D(PixelFormat.R8G8B8A8, width, height);
            renderTexture.Priority = 1;

            SceneObject cameraSO = new SceneObject("SceneAxesCamera", true);
            camera = cameraSO.AddComponent<Camera>();
            camera.Target = renderTexture;
            camera.ViewportRect = 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.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.HDR = false;

            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;
        }
Example #4
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
            Texture2D colorTex = new Texture2D(width, height, PixelFormat.R8G8B8A8, TextureUsage.Render | TextureUsage.CPUReadable);
            Texture2D depthTex = new Texture2D(width, height, PixelFormat.D32_S8X24, TextureUsage.DepthStencil | TextureUsage.CPUReadable);

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

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

                sceneCameraSO.Position = new Vector3(0, 0.5f, 1);
                sceneCameraSO.LookAt(new Vector3(0, 0.5f, 0));

                camera.Priority = 2;
                camera.NearClipPlane = 0.05f;
                camera.FarClipPlane = 2500.0f;
                camera.ClearColor = ClearColor;
                camera.Layers = UInt64.MaxValue & ~SceneAxesHandle.LAYER; // Don't draw scene axes in this camera

                cameraController = 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.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;

            if (profilerCamera != null)
                profilerCamera.Target = renderTexture;
        }
Example #5
0
        /// <summary>
        /// Activates or deactivates the profiler overlay according to current editor settings.
        /// </summary>
        private void UpdateProfilerOverlay()
        {
            if (EditorSettings.GetBool(ProfilerOverlayActiveKey))
            {
                if (activeProfilerOverlay == null)
                {
                    SceneObject profilerSO = new SceneObject("EditorProfilerOverlay");
                    profilerCamera = profilerSO.AddComponent<Camera>();
                    profilerCamera.Target = renderTexture;
                    profilerCamera.ClearFlags = ClearFlags.None;
                    profilerCamera.Priority = 1;
                    profilerCamera.Layers = 0;
                    profilerCamera.HDR = false;

                    activeProfilerOverlay = profilerSO.AddComponent<ProfilerOverlay>();
                }
            }
            else
            {
                if (activeProfilerOverlay != null)
                {
                    activeProfilerOverlay.SceneObject.Destroy();
                    activeProfilerOverlay = null;
                    profilerCamera = null;
                }
            }
        }
Example #6
0
        private void OnDestroy()
        {
            if (camera != null)
            {
                camera.SceneObject.Destroy();
                camera = null;
            }

            sceneAxesGUI.Destroy();
            sceneAxesGUI = null;
        }
 /// <summary>
 /// Creates a new scene selection manager.
 /// </summary>
 /// <param name="sceneCamera">Camera into which to render the selection overlay, and perform picking from.</param>
 internal SceneSelection(Camera sceneCamera)
 {
     Internal_Create(this, sceneCamera.Native.GetCachedPtr());
 }
Example #8
0
        private void OnReset()
        {
            camera = SceneObject.GetComponent<Camera>();

            moveForwardBtn = new VirtualButton(MoveForwardBinding);
            moveLeftBtn = new VirtualButton(MoveLeftBinding);
            moveRightBtn = new VirtualButton(MoveRightBinding);
            moveBackwardBtn = new VirtualButton(MoveBackBinding);
            moveUpBtn = new VirtualButton(MoveUpBinding);
            moveDownBtn = new VirtualButton(MoveDownBinding);
            fastMoveBtn = new VirtualButton(FastMoveBinding);
            activeBtn = new VirtualButton(RotateBinding);
            panBtn = new VirtualButton(PanBinding);
            horizontalAxis = new VirtualAxis(HorizontalAxisBinding);
            verticalAxis = new VirtualAxis(VerticalAxisBinding);
            scrollAxis = new VirtualAxis(ScrollAxisBinding);
        }
Example #9
0
 /// <summary>
 /// Creates a new scene gizmo renderer.
 /// </summary>
 /// <param name="sceneCamera">Camera into which the gizmos will be rendered.</param>
 internal SceneGizmos(Camera sceneCamera)
 {
     Internal_Create(this, sceneCamera.Native.GetCachedPtr());
 }
Example #10
0
 /// <summary>
 /// Creates a new scene handle manager.
 /// </summary>
 /// <param name="parent">Editor window in which the scene handles are displayed.</param>
 /// <param name="sceneCamera">Camera through which the scene handles are displayed.</param>
 internal SceneHandles(EditorWindow parent, Camera sceneCamera)
 {
     Internal_Create(this, parent.GetCachedPtr(), sceneCamera.Native.GetCachedPtr());
 }