Exemplo n.º 1
0
        private void Init()
        {
            if (m_window == null)
            {
                m_window = GetComponent <RuntimeWindow>();
            }

            if (m_window.Camera != null)
            {
                m_renderTextureCamera = m_window.Camera.GetComponent <RenderTextureCamera>();
                if (m_renderTextureCamera != null)
                {
                    m_canvasScaler = GetComponentInParent <CanvasScaler>();
                }
            }
        }
        protected virtual void Init()
        {
            if (m_window == null)
            {
                m_window = GetComponent <RuntimeWindow>();
            }

            m_canvas = GetComponentInParent <Canvas>();

            if (m_window.Camera != null)
            {
                m_renderTextureCamera = m_window.Camera.GetComponent <RenderTextureCamera>();
                if (m_renderTextureCamera != null)
                {
                    m_canvasScaler = GetComponentInParent <CanvasScaler>();
                }
            }
        }
Exemplo n.º 3
0
        protected override void AwakeOverride()
        {
            base.AwakeOverride();

            m_rectTransform = GetComponent <RectTransform>();

            if (Camera != null)
            {
                Image windowBackground = GetComponent <Image>();
                if (windowBackground != null)
                {
                    Color color = windowBackground.color;
                    color.a = 0;
                    windowBackground.color = color;
                }

                if (RenderTextureUsage == RenderTextureUsage.Off || RenderTextureUsage == RenderTextureUsage.UsePipelineSettings && !RenderPipelineInfo.UseRenderTextures)
                {
                    RenderTextureCamera renderTextureCamera = Camera.GetComponent <RenderTextureCamera>();
                    if (renderTextureCamera != null)
                    {
                        DestroyImmediate(renderTextureCamera);
                    }
                }

                RenderPipelineInfo.XRFix(Camera);
            }

            if (m_pointer == null)
            {
                m_pointer = gameObject.AddComponent <Pointer>();
            }

            if (m_camera != null)
            {
                SetCullingMask();
                if (WindowType == RuntimeWindowType.Scene)
                {
                    RegisterGraphicsCamera();
                }
            }
        }
        private void CreateRenderTextureCamera()
        {
            bool wasActive = m_camera.gameObject.activeSelf;

            m_camera.gameObject.SetActive(false);
            m_renderTextureCamera = m_camera.gameObject.AddComponent <RenderTextureCamera>();

            if (m_output != null)
            {
                m_renderTextureCamera.OutputRoot = m_output;
            }
            else
            {
                IRTE          rte         = IOC.Resolve <IRTE>();
                RuntimeWindow sceneWindow = rte.GetWindow(RuntimeWindowType.Scene);
                m_renderTextureCamera.OutputRoot = (RectTransform)sceneWindow.transform;
            }
            m_renderTextureCamera.OverlayMaterial = new Material(Shader.Find("Battlehub/RTCommon/RenderTextureOverlay"));
            m_camera.clearFlags      = CameraClearFlags.SolidColor;
            m_camera.backgroundColor = new Color(0, 0, 0, 0);
            m_camera.gameObject.SetActive(wasActive);
        }
Exemplo n.º 5
0
        private void OnEndFrameRendering(UnityEngine.Rendering.ScriptableRenderContext arg1, Camera[] arg2)
        {
            UnityEngine.Rendering.RenderPipelineManager.endFrameRendering -= OnEndFrameRendering;

            //LWRP OR HDRP;

            bool wasActive = m_graphicsLayerCamera.gameObject.activeSelf;

            m_graphicsLayerCamera.gameObject.SetActive(false);

            m_renderTextureCamera = m_graphicsLayerCamera.gameObject.AddComponent <RenderTextureCamera>();
            //m_renderTextureCamera.Fullscreen = false;

            IRTE          rte         = IOC.Resolve <IRTE>();
            RuntimeWindow sceneWindow = rte.GetWindow(RuntimeWindowType.Scene);

            m_renderTextureCamera.OutputRoot      = (RectTransform)sceneWindow.transform;
            m_renderTextureCamera.OverlayMaterial = new Material(Shader.Find("Battlehub/RTCommon/RenderTextureOverlay"));
            m_graphicsLayerCamera.clearFlags      = CameraClearFlags.SolidColor;
            m_graphicsLayerCamera.backgroundColor = new Color(0, 0, 0, 0);

            m_graphicsLayerCamera.gameObject.SetActive(wasActive);
        }
        private void PrepareGraphicsLayerCamera()
        {
            bool wasActive = m_window.Camera.gameObject.activeSelf;

            m_window.Camera.gameObject.SetActive(false);

            if (m_window.Editor.IsVR && m_window.Camera.stereoEnabled && m_window.Camera.stereoTargetEye == StereoTargetEyeMask.Both)
            {
                m_camera = Instantiate(m_window.Camera, m_window.Camera.transform.parent);
                m_camera.transform.SetSiblingIndex(m_window.Camera.transform.GetSiblingIndex() + 1);
            }
            else
            {
                m_camera = Instantiate(m_window.Camera, m_window.Camera.transform);
            }

            for (int i = m_camera.transform.childCount - 1; i >= 0; i--)
            {
                Destroy(m_camera.transform.GetChild(i).gameObject);
            }

            Component[] components = m_camera.GetComponents <Component>();
            for (int i = 0; i < components.Length; ++i)
            {
                Component component = components[i];
                if (component is Transform)
                {
                    continue;
                }
                if (component is Camera)
                {
                    continue;
                }
                if (component is RenderTextureCamera)
                {
                    continue;
                }

                Destroy(component);
            }

            m_camera.transform.localPosition = Vector3.zero;
            m_camera.transform.localRotation = Quaternion.identity;
            m_camera.transform.localScale    = Vector3.one;
            m_camera.name        = "GraphicsLayerCamera";
            m_camera.depth       = m_window.Camera.depth + 1;
            m_camera.cullingMask = 0;

            if (RenderPipelineInfo.Type == RPType.Standard)
            {
                m_graphicsCamera = m_graphics.CreateCamera(m_camera, CameraEvent.BeforeImageEffects, true, true);
            }
            else
            {
                m_graphicsCamera = m_graphics.CreateCamera(m_camera, CameraEvent.AfterImageEffectsOpaque, true, true);
            }

            m_renderTextureCamera = m_camera.GetComponent <RenderTextureCamera>();
            if (m_renderTextureCamera == null)
            {
                if (RenderPipelineInfo.Type == RPType.Standard)
                {
                    if (m_window.RenderTextureUsage == RenderTextureUsage.On || m_window.RenderTextureUsage == RenderTextureUsage.UsePipelineSettings && RenderPipelineInfo.UseRenderTextures)
                    {
                        CreateRenderTextureCamera();
                    }
                    else
                    {
                        m_camera.clearFlags = CameraClearFlags.Depth;
                    }
                }
                else
                {
                    RenderPipelineManager.beginFrameRendering += OnBeginFrameRendering;
                    RenderPipelineManager.endFrameRendering   += OnEndFrameRendering;
                }
            }
            else
            {
                if (m_window.RenderTextureUsage == RenderTextureUsage.Off || m_window.RenderTextureUsage == RenderTextureUsage.UsePipelineSettings && !RenderPipelineInfo.UseRenderTextures)
                {
                    DestroyImmediate(m_renderTextureCamera);
                }
                else
                {
                    m_renderTextureCamera.OverlayMaterial = new Material(Shader.Find("Battlehub/RTCommon/RenderTextureOverlay"));
                    m_camera.clearFlags      = CameraClearFlags.SolidColor;
                    m_camera.backgroundColor = new Color(0, 0, 0, 0);
                }
            }

            m_camera.allowHDR         = false;                            //fix strange screen blinking bug...
            m_camera.projectionMatrix = m_window.Camera.projectionMatrix; //for ARCore

            m_window.Camera.gameObject.SetActive(wasActive);
            m_camera.gameObject.SetActive(true);
        }
Exemplo n.º 7
0
        private void PrepareGraphicsLayerCamera()
        {
            bool wasActive = m_editorWindow.Camera.gameObject.activeSelf;

            m_editorWindow.Camera.gameObject.SetActive(false);

            //m_trackedPoseDriver = m_editorWindow.Camera.GetComponent<TrackedPoseDriver>();
            if (m_editorWindow.Editor.IsVR && m_editorWindow.Camera.stereoEnabled && m_editorWindow.Camera.stereoTargetEye == StereoTargetEyeMask.Both)
            {
                m_graphicsLayerCamera = Instantiate(m_editorWindow.Camera, m_editorWindow.Camera.transform.parent);
                m_graphicsLayerCamera.transform.SetSiblingIndex(m_editorWindow.Camera.transform.GetSiblingIndex() + 1);
            }
            else
            {
                m_graphicsLayerCamera = Instantiate(m_editorWindow.Camera, m_editorWindow.Camera.transform);
            }

            for (int i = m_graphicsLayerCamera.transform.childCount - 1; i >= 0; i--)
            {
                Destroy(m_graphicsLayerCamera.transform.GetChild(i).gameObject);
            }

            Component[] components = m_graphicsLayerCamera.GetComponents <Component>();
            for (int i = 0; i < components.Length; ++i)
            {
                Component component = components[i];
                if (component is Transform)
                {
                    continue;
                }
                if (component is Camera)
                {
                    continue;
                }
                if (component is RenderTextureCamera)
                {
                    continue;
                }

                Destroy(component);
            }

            m_graphicsLayerCamera.transform.localPosition = Vector3.zero;
            m_graphicsLayerCamera.transform.localRotation = Quaternion.identity;
            m_graphicsLayerCamera.transform.localScale    = Vector3.one;
            m_graphicsLayerCamera.name        = "GraphicsLayerCamera";
            m_graphicsLayerCamera.depth       = m_editorWindow.Camera.depth + 1;
            m_graphicsLayerCamera.cullingMask = 1 << (m_editorWindow.Editor.CameraLayerSettings.RuntimeGraphicsLayer + m_editorWindow.Index);

            m_renderTextureCamera = m_graphicsLayerCamera.GetComponent <RenderTextureCamera>();
            if (m_renderTextureCamera == null)
            {
                #if UNITY_2019_1_OR_NEWER
                UnityEngine.Rendering.RenderPipelineManager.endFrameRendering += OnEndFrameRendering;
                #endif
                m_graphicsLayerCamera.clearFlags = CameraClearFlags.Depth;
            }
            else
            {
                m_renderTextureCamera.OverlayMaterial = new Material(Shader.Find("Battlehub/RTCommon/RenderTextureOverlay"));
                m_graphicsLayerCamera.clearFlags      = CameraClearFlags.SolidColor;
                m_graphicsLayerCamera.backgroundColor = new Color(0, 0, 0, 0);
            }

            m_graphicsLayerCamera.allowHDR         = false;                                  //fix strange screen blinking bug...
            m_graphicsLayerCamera.projectionMatrix = m_editorWindow.Camera.projectionMatrix; //for ARCore


            m_editorWindow.Camera.gameObject.SetActive(wasActive);
            m_graphicsLayerCamera.gameObject.SetActive(wasActive);
        }
        protected override void AwakeOverride()
        {
            base.AwakeOverride();
            if (!RenderPipelineInfo.UseRenderTextures && !ForceUseRenderTextures)
            {
                if (Camera != null)
                {
                    Image windowBackground = GetComponent <Image>();
                    if (windowBackground != null)
                    {
                        Color color = windowBackground.color;
                        color.a = 0;
                        windowBackground.color = color;
                    }

                    RenderTextureCamera renderTextureCamera = Camera.GetComponent <RenderTextureCamera>();
                    if (renderTextureCamera != null)
                    {
                        DestroyImmediate(renderTextureCamera);
                    }

                    Camera.allowMSAA = true;
                }
            }

            if (m_background == null)
            {
                if (!Editor.IsVR)
                {
                    m_background = GetComponent <Image>();
                    if (m_background == null)
                    {
                        m_background               = gameObject.AddComponent <Image>();
                        m_background.color         = new Color(0, 0, 0, 0);
                        m_background.raycastTarget = true;
                    }
                    else
                    {
                        m_background.raycastTarget = true;
                    }
                }
            }

            if (m_pointer == null)
            {
                if (Editor.IsVR)
                {
                    m_pointer = gameObject.AddComponent <VRPointer>();
                }
                else
                {
                    m_pointer = gameObject.AddComponent <Pointer>();
                }
            }

            m_rectTransform = GetComponent <RectTransform>();
            m_canvas        = GetComponentInParent <Canvas>();
            m_canvasGroup   = GetComponent <CanvasGroup>();
            if (m_canvasGroup == null)
            {
                m_canvasGroup = gameObject.AddComponent <CanvasGroup>();
            }

            if (m_canvasGroup != null)
            {
                m_canvasGroup.blocksRaycasts     = true;
                m_canvasGroup.ignoreParentGroups = true;
            }

            Editor.ActiveWindowChanged += OnActiveWindowChanged;

            m_index = Editor.GetIndex(WindowType);

            if (m_camera != null)
            {
                SetCullingMask();
                if (WindowType == RuntimeWindowType.Scene)
                {
                    GLCamera glCamera = m_camera.GetComponent <GLCamera>();
                    if (!glCamera)
                    {
                        glCamera = m_camera.gameObject.AddComponent <GLCamera>();
                    }
                    glCamera.CullingMask = 1 << (Editor.CameraLayerSettings.RuntimeGraphicsLayer + m_index);
                }
            }

            Editor.RegisterWindow(this);
        }