private void Init()
        {
            Camera            camera        = Window.Camera;
            IRTEGraphicsLayer graphicsLayer = Window.IOCContainer.Resolve <IRTEGraphicsLayer>();

            if (graphicsLayer != null && graphicsLayer.Camera != null)
            {
                camera = graphicsLayer.Camera.Camera;
            }

            if (camera == null)
            {
                return;
            }

            IRTEGraphics graphics = IOC.Resolve <IRTEGraphics>();

            m_rteCamera = graphics.CreateCamera(camera, CameraEvent.AfterImageEffects, false, true);
            m_rteCamera.RenderersCache.Add(m_output.GetComponent <Renderer>());
            m_rteCamera.RefreshCommandBuffer();

            DoSceneGizmo();

            if (BtnProjection != null)
            {
                BtnProjection.gameObject.SetActive(true);
            }
        }
        protected override void Render(Shader shader, string tag, Camera renderCamera)
        {
            IRTEGraphics graphics = IOC.Resolve <IRTEGraphics>();

            m_rteCamera = graphics.CreateCamera(renderCamera, UnityEngine.Rendering.CameraEvent.AfterForwardAlpha, false, true);

            for (int i = 0; i < m_renderers.Count; ++i)
            {
                Renderer[] renderers = m_renderers[i];
                for (int j = 0; j < renderers.Length; ++j)
                {
                    m_rteCamera.RenderersCache.Add(renderers[j]);
                }
            }

            //Material material = new Material(shader);
            //m_rteCamera.RenderersCache.MaterialOverride = material;

            bool invertCulling = GL.invertCulling;

            GL.invertCulling = true;
            renderCamera.projectionMatrix *= Matrix4x4.Scale(new Vector3(1, -1, 1));
            renderCamera.Render();
            GL.invertCulling = invertCulling;

            //Object.Destroy(material);
            m_rteCamera.Destroy();

            m_renderers.Clear();
        }
        private void Start()
        {
            m_graphics                = IOC.Resolve <IRTEGraphics>();
            m_meshesCache             = m_graphics.CreateMeshesCache(CameraEvent.BeforeImageEffects);
            m_meshesCache.RefreshMode = CacheRefreshMode.OnTransformChange;

            Refresh();
            StartOverride();
        }
        private void Awake()
        {
            m_window = GetComponent <RuntimeCameraWindow>();
            m_window.IOCContainer.RegisterFallback <IRTEGraphicsLayer>(this);
            m_window.CameraResized += OnCameraResized;
            m_graphics              = IOC.Resolve <IRTEGraphics>();

            PrepareGraphicsLayerCamera();
        }
Example #5
0
        private void UnregisterGraphicsCamera()
        {
            IRTEGraphics graphics = IOC.Resolve <IRTEGraphics>();

            if (graphics != null)
            {
                graphics.UnregisterCamera(m_camera);
            }
        }
Example #6
0
        private void CreateGraphicsCamera()
        {
            IRTEGraphics graphics = IOC.Resolve <IRTEGraphics>();

            if (graphics != null)
            {
                IRTECamera rteCamera = graphics.CreateCamera(m_camera);
                IOCContainer.RegisterFallback(rteCamera);
            }
        }
Example #7
0
        private void DestroyGraphicsCamera()
        {
            IRTEGraphics graphics = IOC.Resolve <IRTEGraphics>();

            if (graphics != null)
            {
                IRTECamera camera = IOCContainer.Resolve <IRTECamera>();
                IOCContainer.UnregisterFallback(camera);

                camera.Destroy();
            }
        }
Example #8
0
        private void Start()
        {
            m_graphics = IOC.Resolve <IRTEGraphics>();
            m_cache    = m_graphics.CreateSharedRenderersCache(CameraEvent.AfterEverything);
            m_cache.MaterialOverride = m_selectionMaterial;
            m_editor = IOC.Resolve <IRTE>();

            TryToAddRenderers(m_editor.Selection);
            m_editor.Selection.SelectionChanged += OnRuntimeEditorSelectionChanged;

            IOC.RegisterFallback <IOutlineManager>(this);

            StartCoroutine(EnableSelectionFullScreenPass());
        }
        private void Awake()
        {
            m_window = GetComponent <RuntimeCameraWindow>();
            m_window.IOCContainer.RegisterFallback <IRTEGraphicsLayer>(this);
            m_window.CameraResized += OnCameraResized;
            m_graphics              = IOC.Resolve <IRTEGraphics>();

            if (m_window.Index >= m_window.Editor.CameraLayerSettings.MaxGraphicsLayers)
            {
                Debug.LogError("m_editorWindow.Index >= m_editorWindow.Editor.CameraLayerSettings.MaxGraphicsLayers");
            }

            PrepareGraphicsLayerCamera();
        }
Example #10
0
        protected override void Start()
        {
            m_input = GetComponent <BaseHandleInput>();
            if (m_input == null || m_input.Handle != this)
            {
                m_input        = gameObject.AddComponent <BaseHandleInput>();
                m_input.Handle = this;
            }

            IRTEGraphicsLayer graphicsLayer = Window.IOCContainer.Resolve <IRTEGraphicsLayer>();

            if (graphicsLayer != null)
            {
                m_rteCamera = graphicsLayer.Camera;
            }

            if (m_rteCamera == null && Window.Camera != null)
            {
                IRTEGraphics graphics = IOC.Resolve <IRTEGraphics>();
                if (graphics != null)
                {
                    m_rteCamera = graphics.GetOrCreateCamera(Window.Camera, CameraEvent.AfterImageEffectsOpaque);
                }

                if (m_rteCamera == null)
                {
                    m_rteCamera       = Window.Camera.gameObject.AddComponent <RTECamera>();
                    m_rteCamera.Event = CameraEvent.AfterImageEffectsOpaque;
                }
            }

            if (Model == null && m_rteCamera != null)
            {
                m_prevScale = transform.localScale;

                m_prevCamPosition          = m_rteCamera.Camera.transform.position;
                m_prevCamRotation          = m_rteCamera.Camera.transform.rotation;
                m_prevCamOrthographic      = m_rteCamera.Camera.orthographic;
                m_prevCamOrthographicsSize = m_rteCamera.Camera.orthographicSize;
                m_prevCamRect = m_rteCamera.Camera.rect;

                m_rteCamera.CommandBufferRefresh += OnCommandBufferRefresh;
                m_rteCamera.RefreshCommandBuffer();
            }

#pragma warning disable CS0618
            OnStartOverride();
#pragma warning restore CS0618
        }
        private IRTECamera GetRTECamera()
        {
            if (Window == null || Window.Camera == null)
            {
                return(null);
            }

            IRTECamera        rteCamera;
            IRTEGraphicsLayer graphicsLayer = Window.IOCContainer.Resolve <IRTEGraphicsLayer>();

            if (graphicsLayer != null)
            {
                rteCamera = graphicsLayer.Camera;
            }
            else
            {
                IRTEGraphics graphics = IOC.Resolve <IRTEGraphics>();
                rteCamera = graphics.GetOrCreateCamera(Window.Camera, CameraEvent.AfterImageEffectsOpaque);
            }

            return(rteCamera);
        }
        protected override void Awake()
        {
            base.Awake();

            RuntimeHandlesComponent.InitializeIfRequired(ref Appearance);

            if (Pivot == null)
            {
                Pivot = transform;
            }

            m_collidersGO = new GameObject();
            m_collidersGO.transform.SetParent(transform, false);
            m_collidersGO.transform.position = GetGizmoPosition();
            m_collidersGO.transform.rotation = Quaternion.identity;
            m_collidersGO.name = "Colliders";

            m_colliderProj     = m_collidersGO.AddComponent <BoxCollider>();
            m_colliderUp       = m_collidersGO.AddComponent <BoxCollider>();
            m_colliderDown     = m_collidersGO.AddComponent <BoxCollider>();
            m_colliderLeft     = m_collidersGO.AddComponent <BoxCollider>();
            m_colliderRight    = m_collidersGO.AddComponent <BoxCollider>();
            m_colliderForward  = m_collidersGO.AddComponent <BoxCollider>();
            m_colliderBackward = m_collidersGO.AddComponent <BoxCollider>();

            m_colliders = new[] { m_colliderProj, m_colliderUp, m_colliderDown, m_colliderRight, m_colliderLeft, m_colliderForward, m_colliderBackward };
            DisableColliders();

            m_camera               = GetComponent <Camera>();
            m_rteGizmoCamera       = m_camera.gameObject.AddComponent <RTECamera>();
            m_rteGizmoCamera.Event = CameraEvent.BeforeImageEffects;
            m_rteGizmoCamera.CommandBufferRefresh += OnCommandBufferRefresh;

            m_propertyBlocks = new[] { new MaterialPropertyBlock(), new MaterialPropertyBlock(), new MaterialPropertyBlock() };

            m_cameraUtility = IOC.Resolve <IRenderPipelineCameraUtility>();
            if (m_cameraUtility != null)
            {
                m_cameraUtility.SetBackgroundColor(m_camera, new Color(0, 0, 0, 0));
                m_cameraUtility.EnablePostProcessing(m_camera, false);
                m_cameraUtility.PostProcessingEnabled += OnPostProcessingEnabled;
            }

            m_material = new Material(Shader.Find("Battlehub/RTHandles/RawImage"));

            m_output = new GameObject("SceneGizmoOutput");
            m_output.gameObject.SetActive(false);
            m_output.transform.SetParent(Window.Camera.transform, false);
            m_output.transform.localPosition = Vector3.forward * m_camera.nearClipPlane;
            m_output.AddComponent <MeshFilter>().sharedMesh       = Appearance.CreateRawImageMesh();
            m_output.AddComponent <MeshRenderer>().sharedMaterial = m_material;

            m_graphics = IOC.Resolve <IRTEGraphics>();

            m_camera.clearFlags      = CameraClearFlags.SolidColor;
            m_camera.backgroundColor = new Color(0, 0, 0, 0);
            m_camera.cullingMask     = 0;
            m_camera.orthographic    = Window.Camera.orthographic;
            m_camera.rect            = new Rect(0, 0, 1, 1);
            m_camera.stereoTargetEye = StereoTargetEyeMask.None;

            m_screenHeight = Screen.height;
            m_screenWidth  = Screen.width;

            UpdateLayout();
            InitColliders();
            UpdateAlpha(ref m_xAlpha, Vector3.right, 1);
            UpdateAlpha(ref m_yAlpha, Vector3.up, 1);
            UpdateAlpha(ref m_zAlpha, Vector3.forward, 1);
            if (Run.Instance == null)
            {
                GameObject runGO = new GameObject();
                runGO.name = "Run";
                runGO.AddComponent <Run>();
            }

            if (BtnProjection != null)
            {
                BtnProjection.onClick.AddListener(OnBtnModeClick);
                SetTextColor();
            }

            if (!GetComponent <SceneGizmoInput>())
            {
                gameObject.AddComponent <SceneGizmoInput>();
            }
        }
Example #13
0
        protected override void Awake()
        {
            base.Awake();
            if (m_rteCamera == null)
            {
                IRTEGraphics graphics = IOC.Resolve <IRTEGraphics>();
                if (graphics != null)
                {
                    m_rteCamera = graphics.GetOrCreateCamera(Window.Camera, CameraEvent.AfterForwardAlpha);
                }

                if (m_rteCamera == null)
                {
                    m_rteCamera       = Window.Camera.gameObject.AddComponent <RTECamera>();
                    m_rteCamera.Event = CameraEvent.AfterForwardAlpha;
                }
            }

            m_rteCamera.CommandBufferRefresh += OnCommandBufferRefresh;

            NavMeshTriangulation triangulation = NavMesh.CalculateTriangulation();

            m_facesMaterial       = new Material(Shader.Find("Battlehub/RTNavigation/UnlitColor"));
            m_facesMaterial.color = new Color(1, 1, 1, 0.5f);
            m_facesMaterial.SetInt("_ZTest", (int)CompareFunction.LessEqual);
            m_facesMaterial.SetFloat("_ZWrite", 0);

            m_edgesMaterial       = new Material(Shader.Find("Battlehub/RTCommon/LineBillboard"));
            m_edgesMaterial.color = new Color(0, 0, 0, 0.15f);
            m_edgesMaterial.SetFloat("_Scale", 1.0f);
            m_edgesMaterial.SetInt("_HandleZTest", (int)CompareFunction.LessEqual);

            m_verticesMaterial       = new Material(Shader.Find("Hidden/RTHandles/PointBillboard"));
            m_verticesMaterial.color = new Color(0, 0, 0, 0.3f);
            m_verticesMaterial.SetFloat("_Scale", 1.25f);
            m_verticesMaterial.SetInt("_HandleZTest", (int)CompareFunction.LessEqual);

            Vector3[] verts = triangulation.vertices;
            int[]     tris  = triangulation.indices;

            m_facesMesh = new Mesh {
                name = "Faces"
            };
            m_facesMesh.vertices  = verts;
            m_facesMesh.triangles = tris;

            int[]     areas  = triangulation.areas;
            Color32[] colors = new Color32[triangulation.vertices.Length];
            for (int i = 0; i < areas.Length; i++)
            {
                int     area  = areas[i];
                Color32 color = Colors.Kellys[(area + 3) % Colors.Kellys.Length];
                colors[tris[i * 3]]     = color;
                colors[tris[i * 3 + 1]] = color;
                colors[tris[i * 3 + 2]] = color;
            }
            m_facesMesh.colors32 = colors;

            m_edgesMesh = new Mesh {
                name = "Edges"
            };
            m_edgesMesh.vertices = verts;
            int[] indices = new int[tris.Length * 2];
            for (int i = 0; i < tris.Length; i += 3)
            {
                indices[i * 2]     = tris[i];
                indices[i * 2 + 1] = tris[i + 1];

                indices[i * 2 + 2] = tris[i + 1];
                indices[i * 2 + 3] = tris[i + 2];

                indices[i * 2 + 4] = tris[i + 2];
                indices[i * 2 + 5] = tris[i];
            }
            m_edgesMesh.SetIndices(indices, MeshTopology.Lines, 0);

            m_verticesMesh = new Mesh {
                name = "Vertices"
            };
            m_verticesMesh.vertices    = verts;
            m_verticesMesh.indexFormat = IndexFormat.UInt32;
            m_verticesMesh.SetIndices(Enumerable.Range(0, verts.Length).ToArray(), MeshTopology.Points, 0);

            m_rteCamera.RefreshCommandBuffer();
        }
        private static Texture2D Render(
            Camera camera,
            Shader shader,
            Renderer[] renderers,
            int width  = -1,
            int height = -1)
        {
            bool autoSize = width < 0 || height < 0;

            int _width  = autoSize ? (int)camera.pixelRect.width : width;
            int _height = autoSize ? (int)camera.pixelRect.height : height;

            GameObject go        = new GameObject();
            Camera     renderCam = go.AddComponent <Camera>();

            renderCam.CopyFrom(camera);

            renderCam.renderingPath   = RenderingPath.Forward;
            renderCam.enabled         = false;
            renderCam.clearFlags      = CameraClearFlags.SolidColor;
            renderCam.backgroundColor = Color.white;
            renderCam.cullingMask     = 0;

            IRenderPipelineCameraUtility cameraUtility = IOC.Resolve <IRenderPipelineCameraUtility>();

            if (cameraUtility != null)
            {
                cameraUtility.EnablePostProcessing(renderCam, false);
                cameraUtility.SetBackgroundColor(renderCam, Color.white);
            }

            renderCam.allowHDR  = false;
            renderCam.allowMSAA = false;
            renderCam.forceIntoRenderTexture = true;

            float aspect = renderCam.aspect;

            renderCam.rect   = new Rect(Vector2.zero, Vector2.one);
            renderCam.aspect = aspect;

            RenderTextureDescriptor descriptor = new RenderTextureDescriptor()
            {
                width             = _width,
                height            = _height,
                colorFormat       = RenderTextureFormat,
                autoGenerateMips  = false,
                depthBufferBits   = 16,
                dimension         = TextureDimension.Tex2D,
                enableRandomWrite = false,
                memoryless        = RenderTextureMemoryless.None,
                sRGB        = true,
                useMipMap   = false,
                volumeDepth = 1,
                msaaSamples = 1
            };
            RenderTexture rt = RenderTexture.GetTemporary(descriptor);

            RenderTexture prev = RenderTexture.active;

            renderCam.targetTexture = rt;
            RenderTexture.active    = rt;

            Material replacementMaterial = new Material(shader);

            IRTEGraphics graphics  = IOC.Resolve <IRTEGraphics>();
            IRTECamera   rteCamera = graphics.CreateCamera(renderCam, CameraEvent.AfterForwardAlpha, false, true);

            rteCamera.RenderersCache.MaterialOverride = replacementMaterial;
            rteCamera.Camera.name = "BoxSelectionCamera";
            foreach (Renderer renderer in renderers)
            {
                Material[] materials = renderer.sharedMaterials;
                for (int i = 0; i < materials.Length; ++i)
                {
                    if (materials[i] != null)
                    {
                        rteCamera.RenderersCache.Add(renderer);
                    }
                }
            }
            rteCamera.RefreshCommandBuffer();

            if (RenderPipelineInfo.Type != RPType.Standard)
            {
                bool invertCulling = GL.invertCulling;
                GL.invertCulling            = true;
                renderCam.projectionMatrix *= Matrix4x4.Scale(new Vector3(1, -1, 1));
                renderCam.Render();
                GL.invertCulling = invertCulling;
            }
            else
            {
                renderCam.Render();
            }

            Texture2D img = new Texture2D(_width, _height, TextureFormat, false, false);

            img.ReadPixels(new Rect(0, 0, _width, _height), 0, 0);
            img.Apply();

            RenderTexture.active = prev;
            RenderTexture.ReleaseTemporary(rt);

            UnityObject.DestroyImmediate(go);
            UnityObject.Destroy(replacementMaterial);

            rteCamera.Destroy();
            //System.IO.File.WriteAllBytes("Assets/box_selection.png", img.EncodeToPNG());

            return(img);
        }
        protected override void Start()
        {
            base.Start();

            BaseGizmoInput input = GetComponent <BaseGizmoInput>();

            if (input == null || input.Gizmo != this)
            {
                input       = gameObject.AddComponent <BaseGizmoInput>();
                input.Gizmo = this;
            }

            if (Target == null)
            {
                Target = transform;
            }

            if (EnableUndo)
            {
                if (!RuntimeUndoInput.IsInitialized)
                {
                    GameObject runtimeUndo = new GameObject();
                    runtimeUndo.name = "RuntimeUndo";
                    runtimeUndo.AddComponent <RuntimeUndoInput>();
                }
            }

            IRTEGraphicsLayer graphicsLayer = Window.IOCContainer.Resolve <IRTEGraphicsLayer>();

            if (graphicsLayer != null && !ForceCreateCamera)
            {
                m_rteCamera = graphicsLayer.Camera;
            }

            if (m_rteCamera == null && SceneCamera != null)
            {
                IRTEGraphics graphics = IOC.Resolve <IRTEGraphics>();
                if (graphics != null)
                {
                    m_rteCamera = graphics.GetOrCreateCamera(SceneCamera, CameraEvent);
                }

                if (m_rteCamera == null)
                {
                    m_rteCamera       = SceneCamera.gameObject.AddComponent <RTECamera>();
                    m_rteCamera.Event = CameraEvent;
                }
            }

            if (m_rteCamera != null)
            {
                m_prevPosition = transform.position;
                m_prevRotation = transform.rotation;
                m_prevScale    = transform.localScale;

                m_prevCamPosition  = m_rteCamera.Camera.transform.position;
                m_prevCamRotation  = m_rteCamera.Camera.transform.rotation;
                m_prevOrthographic = m_rteCamera.Camera.orthographic;

                m_rteCamera.CommandBufferRefresh += OnCommandBufferRefresh;
                m_rteCamera.RefreshCommandBuffer();
            }
#pragma warning disable CS0612
            StartOverride();
#pragma warning restore CS0612
        }
Example #16
0
        private void Start()
        {
            BaseGizmoInput input = GetComponent <BaseGizmoInput>();

            if (input == null || input.Gizmo != this)
            {
                input       = gameObject.AddComponent <BaseGizmoInput>();
                input.Gizmo = this;
            }

            if (SceneCamera == null)
            {
                SceneCamera = Window.Camera;
            }

            if (SceneCamera == null)
            {
                SceneCamera = Camera.main;
            }

            if (Target == null)
            {
                Target = transform;
            }

            if (EnableUndo)
            {
                if (!RuntimeUndoInput.IsInitialized)
                {
                    GameObject runtimeUndo = new GameObject();
                    runtimeUndo.name = "RuntimeUndo";
                    runtimeUndo.AddComponent <RuntimeUndoInput>();
                }
            }

            IRTEGraphicsLayer graphicsLayer = Window.IOCContainer.Resolve <IRTEGraphicsLayer>();

            if (graphicsLayer != null)
            {
                m_rteCamera = graphicsLayer.Camera;
            }

            if (m_rteCamera == null && SceneCamera != null)
            {
                IRTEGraphics graphics = IOC.Resolve <IRTEGraphics>();
                if (graphics != null)
                {
                    m_rteCamera = graphics.GetOrCreateCamera(SceneCamera, CameraEvent.AfterImageEffectsOpaque);
                }

                if (m_rteCamera == null)
                {
                    m_rteCamera       = SceneCamera.gameObject.AddComponent <RTECamera>();
                    m_rteCamera.Event = CameraEvent.AfterImageEffectsOpaque;
                }
            }

            if (m_rteCamera != null)
            {
                m_prevPosition = transform.position;
                m_prevRotation = transform.rotation;
                m_prevScale    = transform.localScale;

                m_prevCamPosition  = m_rteCamera.Camera.transform.position;
                m_prevCamRotation  = m_rteCamera.Camera.transform.rotation;
                m_prevOrthographic = m_rteCamera.Camera.orthographic;

                m_rteCamera.CommandBufferRefresh += OnCommandBufferRefresh;
                m_rteCamera.RefreshCommandBuffer();
            }

            StartOverride();
        }