Exemplo n.º 1
0
        Entity ConstructScreenSpaceCamera(Entity e, UnityEngine.RectTransform urc)
        {
            SceneSection sceneSection = DstEntityManager.GetSharedComponentData <SceneSection>(e);
            Entity       eCam         = DstEntityManager.CreateEntity();

            DstEntityManager.AddSharedComponentData(eCam, sceneSection);

            var sizeDelta = urc.sizeDelta;

            var camera = new Unity.Tiny.Rendering.Camera
            {
                clearFlags      = Tiny.Rendering.CameraClearFlags.DepthOnly,
                backgroundColor = new Unity.Tiny.Color(0, 0, 0, 0),
                viewportRect    = new Tiny.Rect(0, 0, 1, 1),
                depth           = 0.0f,
                fov             = sizeDelta.y * 0.5f,
                mode            = ProjectionMode.Orthographic,
                clipZNear       = 0,
                clipZFar        = 102,
                aspect          = sizeDelta.x / sizeDelta.y
            };

            DstEntityManager.AddComponentData(eCam, camera);
            DstEntityManager.AddComponentData(eCam,
                                              new Unity.Tiny.Rendering.CameraMask {
                mask = (ulong)(1 << urc.gameObject.layer)
            });

            // For CameraSettings2D
            float3 customSortAxisSetting = new float3(0, 0, 1.0f);

            if (UnityEngine.Rendering.GraphicsSettings.transparencySortMode ==
                UnityEngine.TransparencySortMode.CustomAxis)
            {
                customSortAxisSetting = UnityEngine.Rendering.GraphicsSettings.transparencySortAxis;
            }
            DstEntityManager.AddComponentData(eCam, new Unity.Tiny.Rendering.CameraSettings2D
            {
                customSortAxis = customSortAxisSetting
            });

            // tag the camera as auto aspect
            DstEntityManager.AddComponentData(eCam, new CameraAutoAspectFromNode {
                Node = Entity.Null
            });

            DstEntityManager.AddComponentData(eCam, new LocalToWorld {
                Value = float4x4.identity
            });
            DstEntityManager.AddComponentData(eCam,
                                              new Translation {
                Value = new float3(sizeDelta.x / 2, sizeDelta.y / 2, -10)
            });
            DstEntityManager.AddComponentData(eCam, new Rotation {
                Value = quaternion.identity
            });
            DstEntityManager.AddComponent <UICamera>(eCam);
            return(eCam);
        }
Exemplo n.º 2
0
        protected override void OnUpdate()
        {
            Entities.ForEach((UnityEngine.Camera uCamera) =>
            {
                var entity = GetPrimaryEntity(uCamera);

                var camera             = new Unity.Tiny.Rendering.Camera();
                camera.clearFlags      = uCamera.clearFlags.ToTiny();
                camera.backgroundColor = uCamera.backgroundColor.linear.ToTiny();
                camera.viewportRect    = uCamera.rect.ToTiny();
                camera.depth           = uCamera.depth;
                camera.fov             = uCamera.orthographic ? uCamera.orthographicSize : uCamera.fieldOfView;
                camera.mode            = uCamera.orthographic ? ProjectionMode.Orthographic : ProjectionMode.Perspective;
                camera.clipZNear       = uCamera.nearClipPlane;
                camera.clipZFar        = uCamera.farClipPlane;
                camera.aspect          = uCamera.aspect;

                DstEntityManager.AddComponentData(entity, camera);
                DstEntityManager.AddComponentData(entity, new Unity.Tiny.Rendering.CameraMask {
                    mask = (ulong)uCamera.cullingMask
                });

                // For CameraSettings2D
                float3 customSortAxisSetting = new float3(0, 0, 1.0f);
                if (UnityEngine.Rendering.GraphicsSettings.transparencySortMode == UnityEngine.TransparencySortMode.CustomAxis)
                {
                    customSortAxisSetting = UnityEngine.Rendering.GraphicsSettings.transparencySortAxis;
                }
                DstEntityManager.AddComponentData(entity, new Unity.Tiny.Rendering.CameraSettings2D
                {
                    customSortAxis = customSortAxisSetting
                });

                if (DstEntityManager.HasComponent <NonUniformScale>(entity))
                {
                    DstEntityManager.SetComponentData(entity, new NonUniformScale()
                    {
                        Value = new float3(1f)
                    });
                }

                // tag the camera as auto aspect
                DstEntityManager.AddComponentData(entity, new CameraAutoAspectFromNode {
                    Node = Entity.Null
                });
            });
        }
Exemplo n.º 3
0
        protected override void OnUpdate()
        {
            Entities.ForEach((UnityEngine.Camera uCamera) =>
            {
                var entity = GetPrimaryEntity(uCamera);

                var camera             = new Unity.Tiny.Rendering.Camera();
                camera.clearFlags      = uCamera.clearFlags.ToTiny();
                camera.backgroundColor = uCamera.backgroundColor.ToTiny();
                camera.viewportRect    = uCamera.rect.ToTiny();
                camera.fov             = uCamera.orthographic ? uCamera.orthographicSize : uCamera.fieldOfView;
                camera.mode            = uCamera.orthographic ? ProjectionMode.Orthographic : ProjectionMode.Perspective;
                camera.clipZNear       = uCamera.nearClipPlane;
                camera.clipZFar        = uCamera.farClipPlane;
                camera.aspect          = (float)1920 / (float)1080; //fixed for now

                DstEntityManager.AddComponentData(entity, camera);
                DstEntityManager.AddComponent <Frustum>(entity);
            });
        }