Exemplo n.º 1
0
        private Entity SpawnCamera(int id, float3 spawnPosition, quaternion spawnRotation, Entity attachEntity, CameraData cameraData)
        {
            if (cameraData.isRenderTexture == 0)
            {
                if (Camera.main)
                {
                    //Camera.main.gameObject.tag = "Untagged";
                    Camera.main.gameObject.SetActive(false);
                    if (canvas)
                    {
                        canvas.SetActive(false);
                    }
                }
            }
            else
            {
                if (canvas)
                {
                    canvas.SetActive(true);
                }
            }
            //AudioManager.instance.SpawnMonsterSpawnSound(spawnPosition);
            cameraDatas.Add(id, cameraData);
            GameObject cameraObject = SpawnCameraGameObject(id, cameraData, spawnPosition, spawnRotation);

            cameraObjects.Add(id, cameraObject);
            var    cameraEntity = AddECSComponents(cameraObject, id, attachEntity, cameraData);
            Camera camera       = cameraObject.GetComponent <Camera>();

            if (World.EntityManager.Exists(attachEntity))
            {
                //Entity charaterEntity = characterSpawnSystem.characters[followID];
                if (cameraData.cameraType == ((byte)CameraDataType.ThirdPerson))
                {
                    Translation characterTranslation = World.EntityManager.GetComponentData <Translation>(attachEntity);
                    Rotation    characterRotation    = World.EntityManager.GetComponentData <Rotation>(attachEntity);
                    spawnPosition  = characterTranslation.Value + new float3(0, cameraData.followCameraData.cameraAddition.y, 0);
                    spawnPosition += math.rotate(characterRotation.Value, new float3(0, 0, cameraData.followCameraData.cameraAddition.z));
                    Quaternion newRotation = new Quaternion(characterRotation.Value.value.x,
                                                            characterRotation.Value.value.y, characterRotation.Value.value.z, characterRotation.Value.value.w);
                    float3 newRotation2 = newRotation.eulerAngles;
                    newRotation2.x = cameraData.followCameraData.cameraRotation.x;
                    spawnRotation  = Quaternion.Euler(newRotation2);
                }
                if (World.EntityManager.HasComponent <CameraLink>(attachEntity))
                {
                    CameraLink cameraLink = World.EntityManager.GetComponentData <CameraLink>(attachEntity);
                    cameraLink.camera = cameraEntity;
                    cameraLink.fov    = camera.fieldOfView;
                    World.EntityManager.SetComponentData(attachEntity, cameraLink);
                }
            }
            else
            {
                World.EntityManager.AddComponentData(cameras[id], new CameraLink
                {
                    camera = cameraEntity,
                    fov    = camera.fieldOfView
                });
            }
            // Setup camera object
            if (cameraData.isRenderTexture == 1)
            {
                CreateRenderTexture(camera, cameraData, id);
            }
            else
            {
                Camera.SetupCurrent(camera);
                camera.tag = "MainCamera";
            }
            Debug.Log("Spawned camera: " + id);
            ResizeRenderTextures();
            return(cameraEntity);
        }
Exemplo n.º 2
0
        private Entity AddECSComponents(GameObject cameraObject, int id, Entity attachEntity, CameraData cameraData)
        {
            Entity camera = World.EntityManager.CreateEntity(firstPersonCameraArchtype);

            cameras.Add(id, camera);
            World.EntityManager.SetComponentData(camera, new Translation {
                Value = cameraObject.transform.position
            });
            World.EntityManager.SetComponentData(camera, new Rotation {
                Value = cameraObject.transform.rotation
            });
            World.EntityManager.SetComponentData(camera, new CameraSynch
            {
                Value         = attachEntity,
                localPosition = cameraData.firstPersonCamera.cameraAddition
            });
            int creatorID = 0;

            if (World.EntityManager.Exists(attachEntity))
            {
                creatorID = World.EntityManager.GetComponentData <ZoxID>(attachEntity).id;
                World.EntityManager.SetComponentData(camera, new CharacterLink {
                    character = attachEntity
                });
            }
            World.EntityManager.SetComponentData(camera, new ZoxID
            {
                id        = id,
                creatorID = creatorID
            });
            return(camera);
        }
Exemplo n.º 3
0
        public void ConnectCameraToCharacter(Entity camera, Entity attachEntity)
        {
            if (World.EntityManager.Exists(camera) == false)
            {
                Debug.LogError("Cannot connect camera to character as camera id is false.");
                return;
            }
            if (World.EntityManager.Exists(attachEntity) == false)
            {
                Debug.LogError("Cannot connect camera to character as character id is false.");
                return;
            }
            int zoxID = World.EntityManager.GetComponentData <ZoxID>(camera).id;
            //Debug.LogError("attaching camera " + cameraID + " to character " + characterID);
            CameraData cameraData = cameraDatas[zoxID];
            //Entity characterEntity = characterSpawnSystem.characters[characterID];
            //Entity cameraEntity = cameras[zoxID];
            Translation characterTranslation = World.EntityManager.GetComponentData <Translation>(attachEntity);

            //AudioManager.instance.SpawnMonsterSpawnSound(characterTranslation.Value);
            if (World.EntityManager.HasComponent <CameraLink>(attachEntity))
            {
                //Debug.LogError("Connecting Camera to character: " + characterEntity.Index + "::" + cameraID);
                CameraLink cameraLink = World.EntityManager.GetComponentData <CameraLink>(attachEntity);
                cameraLink.camera = camera;
                cameraLink.fov    = cameraObjects[zoxID].GetComponent <Camera>().fieldOfView; //camera.fieldOfView;
                World.EntityManager.SetComponentData(attachEntity, cameraLink);
            }
            if (World.EntityManager.HasComponent <CameraLink>(camera))
            {
                World.EntityManager.RemoveComponent <CameraLink>(camera);
            }
            int           characterID       = World.EntityManager.GetComponentData <ZoxID>(attachEntity).id;
            CharacterLink characterToCamera = new CharacterLink {
                character = attachEntity
            };

            if (World.EntityManager.HasComponent <CharacterLink>(camera))
            {
                World.EntityManager.SetComponentData(camera, characterToCamera);
            }
            else
            {
                World.EntityManager.AddComponentData(camera, characterToCamera);
            }
            if (cameraData.cameraType == 0)
            {
                //Debug.LogError("Setting camera position offset: " + cameraData.firstPersonCamera.cameraAddition);
                //Debug.LogError("Setting camera position offset2: " + World.EntityManager.GetComponentData<FirstPersonCamera>(cameras[cameraID]).Value.cameraAddition);
                World.EntityManager.SetComponentData(camera, new ZoxID {
                    id        = zoxID,
                    creatorID = characterID
                });
                World.EntityManager.SetComponentData(camera, new CameraSynch
                {
                    Value         = attachEntity,
                    localPosition = cameraData.firstPersonCamera.cameraAddition
                });
                // Debug.LogError("Setting camera FirstPersonCamera: " + cameraEntity.Index);
                // Debug.LogError("    Pre camera FirstPersonCamera enabled: " + World.EntityManager.GetComponentData<FirstPersonCamera>(cameraEntity).enabled);
                World.EntityManager.SetComponentData(camera, new FirstPersonCamera
                {
                    enabled = 1,
                    Value   = cameraData.firstPersonCamera
                });
                //Debug.LogError("    Post camera FirstPersonCamera enabled: " + World.EntityManager.GetComponentData<FirstPersonCamera>(cameraEntity).enabled);
            }
        }