Exemplo n.º 1
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);
        }
Exemplo n.º 3
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();
        }
        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
        }
Exemplo n.º 5
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();
        }