Exemple #1
0
        private void CreateRenderTextureTexture(int id, CameraData cameraData, Camera camera, UnityEngine.UI.RawImage image)//, int textureWidth, int textureHeight)
        {
            // Debug.LogError("NewRender Size: " + image.rectTransform.rect.size.ToString());
            int textureWidth  = (int)(image.rectTransform.rect.size.x) / cameraData.textureDivision;
            int textureHeight = (int)(image.rectTransform.rect.size.y) / cameraData.textureDivision;

            if (cameraRenders.ContainsKey(id))
            {
                GameObject.Destroy(cameraRenders[id]);
                cameraRenders.Remove(id);
            }
            RenderTexture newTexture = new RenderTexture(textureWidth, textureHeight, 16, UnityEngine.RenderTextureFormat.ARGB32);

            newTexture.filterMode = FilterMode.Point;
            newTexture.name       = camera.gameObject.name;
            image.texture         = newTexture;
            camera.targetTexture  = newTexture;
            cameraRenders.Add(id, newTexture);
            if (cameras.ContainsKey(id) == false)
            {
                Debug.LogError("Camera does not exist: " + id);
                return;
            }

            if (World.EntityManager.HasComponent <CameraLink>(cameras[id]))
            {
                CameraLink cameraLink = World.EntityManager.GetComponentData <CameraLink>(cameras[id]);
                cameraLink.aspectRatio = ((float)textureWidth) / ((float)textureHeight);
                World.EntityManager.SetComponentData(cameras[id], cameraLink);
            }
            else
            {
                int characterID = World.EntityManager.GetComponentData <ZoxID>(cameras[id]).creatorID;
                if (characterSpawnSystem.characters.ContainsKey(characterID))
                {
                    if (World.EntityManager.HasComponent <CameraLink>(characterSpawnSystem.characters[characterID]))
                    {
                        CameraLink cameraLink = World.EntityManager.GetComponentData <CameraLink>(characterSpawnSystem.characters[characterID]);
                        cameraLink.aspectRatio = ((float)textureWidth) / ((float)textureHeight);
                        World.EntityManager.SetComponentData(characterSpawnSystem.characters[characterID], cameraLink);
                    }
                }
            }
            // connected UIs
            CharacterUIList uiList = World.EntityManager.GetComponentData <CharacterUIList>(cameras[id]);

            Entity[] uis = uiList.uis.ToArray();
            for (int i = 0; i < uis.Length; i++)
            {
                if (World.EntityManager.Exists(uis[i]))
                {
                    CameraLink cameraLink = World.EntityManager.GetComponentData <CameraLink>(uis[i]);
                    cameraLink.aspectRatio = ((float)textureWidth) / ((float)textureHeight);
                    World.EntityManager.SetComponentData(uis[i], cameraLink);
                    //World.EntityManager.SetComponentData(uis[i], orbitor);
                    OrbitCamera orbitor = World.EntityManager.GetComponentData <OrbitCamera>(uis[i]);
                    UIUtilities.UpdateOrbiter(World.EntityManager, uis[i], orbitor.orbitPosition, orbitor.lerpSpeed);
                }
            }
        }
Exemple #2
0
        public static void UpdateOrbiter(EntityManager EntityManager, Entity panelUI, float3 orbitPosition, float orbitLerpSpeed)
        {
            CameraLink  cameraLink = EntityManager.GetComponentData <CameraLink>(panelUI);
            OrbitCamera orbitor    = new OrbitCamera
            {
                orbitPosition = orbitPosition,
                lerpSpeed     = orbitLerpSpeed
            };
            var   frustumHeight = 2.0f * orbitor.orbitPosition.z * math.tan(math.radians(cameraLink.fov) * 0.5f);
            var   frustumWidth  = frustumHeight * cameraLink.aspectRatio;
            float positionX     = orbitor.orbitPosition.x * frustumWidth;
            float positionY     = -orbitor.orbitPosition.y * frustumHeight;

            orbitor.position = new float3(positionX, positionY, orbitor.orbitPosition.z);
            EntityManager.SetComponentData(panelUI, orbitor);
            if (EntityManager.Exists(cameraLink.camera))
            {
                float3     cameraPosition = EntityManager.GetComponentData <Translation>(cameraLink.camera).Value;
                quaternion cameraRotation = EntityManager.GetComponentData <Rotation>(cameraLink.camera).Value;
                EntityManager.SetComponentData(panelUI, new Translation {
                    Value = orbitor.GetTranslatedPosition(cameraPosition, cameraRotation)
                });
            }
        }