public CameraModifierData GetCameraData(CameraModifierData prev) { var next = prev; switch (currentType) { case ECurrentType.LeaderSquad: { if (viewLeaderSquad.IsViewingUnitDetails) { next.FieldOfView = math.lerp(prev.FieldOfView, 2.5f, Time.deltaTime * 10); next.Position = math.lerp(prev.Position, viewLeaderSquad.Position - new Vector3(1f, 0), Time.deltaTime * 10); } else { next.FieldOfView = math.lerp(prev.FieldOfView, 3.9f, Time.deltaTime * 7); next.Position = math.lerp(prev.Position, transform.position + new Vector3(-2, 0, 0), Time.deltaTime * 7); } break; } case ECurrentType.Player: { next.FieldOfView = math.lerp(prev.FieldOfView, 2.5f, Time.deltaTime * 10); next.Position = math.lerp(prev.Position, transform.position - new Vector3(1f, 0), Time.deltaTime * 10); break; } default: throw new ArgumentOutOfRangeException(); } return(next); }
protected override void OnUpdate() { if (!m_CameraWithoutUpdateComp.IsEmptyIgnoreFilter) { EntityManager.AddComponent(m_CameraWithoutUpdateComp, typeof(SystemData)); } Entity defaultCamera = default; if (HasSingleton <DefaultCamera>()) { defaultCamera = GetSingletonEntity <DefaultCamera>(); if (!EntityManager.HasComponent <ComputedCameraState>(defaultCamera)) { EntityManager.AddComponentData(defaultCamera, new ComputedCameraState()); } } Entities .WithAll <GameCamera>() .ForEach((Entity entity, ref SystemData update) => { update.Mode = CameraMode.Default; update.Priority = int.MinValue; }) .Run(); var cameraTargetFromEntity = GetComponentDataFromEntity <CameraStateCameraTarget>(true); var updateFromEntity = GetComponentDataFromEntity <SystemData>(); Entities .ForEach((Entity entity, in LocalCameraState cameraState) => { var camera = defaultCamera; if (cameraTargetFromEntity.HasComponent(entity)) { camera = cameraTargetFromEntity[entity].Value; } var updater = updateFromEntity.GetUpdater(camera); if (!updater.Out(out var cameraStateUpdate).possess) { return; } if (cameraStateUpdate.Mode > cameraState.Mode) { return; } cameraStateUpdate.Mode = cameraState.Mode; cameraStateUpdate.Priority = 0; cameraStateUpdate.StateEntity = entity; cameraStateUpdate.StateData = cameraState.Data; updater.Update(cameraStateUpdate); }) .WithName("Check_LocalCameraState_AndReplaceSystemData") .WithReadOnly(cameraTargetFromEntity) .Run(); // use ScheduleSingle() when it will be out. Entities .WithAll <PlayerIsLocal>() .ForEach((Entity entity, in ServerCameraState cameraState) => { var camera = defaultCamera; if (cameraTargetFromEntity.HasComponent(entity)) { camera = cameraTargetFromEntity[entity].Value; } var updater = updateFromEntity.GetUpdater(camera); if (!updater.Out(out var cameraStateUpdate).possess) { return; } if (cameraStateUpdate.Mode > cameraState.Mode) { return; } cameraStateUpdate.Mode = cameraState.Mode; cameraStateUpdate.Priority = 0; cameraStateUpdate.StateEntity = entity; cameraStateUpdate.StateData = cameraState.Data; updater.Update(cameraStateUpdate); }) .WithName("Check_ServerCameraState_AndReplaceSystemData") .WithReadOnly(cameraTargetFromEntity) .Run(); // use ScheduleSingle() when it will be out. Entities.ForEach((ref ComputedCameraState computed, in SystemData systemData) => { computed.UseModifier = true; computed.Focus = systemData.Focus; computed.StateData = systemData.StateData; computed.StateEntity = systemData.StateEntity; if (!math.all(computed.StateData.Offset.rot.value)) { computed.StateData.Offset.rot = quaternion.identity; } }).Run(); World.GetExistingSystem <CameraModifyTargetSystemGroup>().Update(); var modifierFromEntity = GetComponentDataFromEntity <CameraModifierData>(true); Entities .ForEach((ref Translation translation, ref Rotation rotation, ref LocalToWorld ltw, ref ComputedCameraState computed) => { var offset = computed.StateData.Offset; if (!math.all(offset.rot.value)) { offset.rot = quaternion.identity; } CameraModifierData modifier = default; if (computed.UseModifier && modifierFromEntity.TryGet(computed.StateData.Target, out modifier)) { computed.Focus = modifier.FieldOfView; } else { modifier.Rotation = quaternion.identity; modifier.FieldOfView = 8; computed.Focus = modifier.FieldOfView; } translation.Value = modifier.Position + offset.pos; rotation.Value = math.mul(modifier.Rotation, offset.rot); translation.Value.z = -100; // temporary for now ltw.Value = new float4x4(rotation.Value, translation.Value); }).WithReadOnly(modifierFromEntity).Run(); }