public Entity AddCameraShake(CameraShakeProperties newProperties) { var component = _cameraShakeComponentPool.Count > 0 ? _cameraShakeComponentPool.Pop() : new CameraShakeComponent(); component.properties = newProperties; return(AddComponent(ComponentIds.CameraShake, component)); }
public void StartShake(CameraShakeProperties properties) { if (currentShakeCoroutine != null) { StopCoroutine(currentShakeCoroutine); } currentShakeCoroutine = Shake(properties); StartCoroutine(currentShakeCoroutine); }
public Entity ReplaceCameraShake(CameraShakeProperties newProperties) { var previousComponent = hasCameraShake ? cameraShake : null; var component = _cameraShakeComponentPool.Count > 0 ? _cameraShakeComponentPool.Pop() : new CameraShakeComponent(); component.properties = newProperties; ReplaceComponent(ComponentIds.CameraShake, component); if (previousComponent != null) { _cameraShakeComponentPool.Push(previousComponent); } return this; }
public Entity ReplaceCameraShake(CameraShakeProperties newProperties) { var previousComponent = hasCameraShake ? cameraShake : null; var component = _cameraShakeComponentPool.Count > 0 ? _cameraShakeComponentPool.Pop() : new CameraShakeComponent(); component.properties = newProperties; ReplaceComponent(ComponentIds.CameraShake, component); if (previousComponent != null) { _cameraShakeComponentPool.Push(previousComponent); } return(this); }
public void Execute() { float deltaTime = _time.GetSingleEntity().time.deltaTime; CameraComponent camera = _camera.GetSingleEntity().camera; bool wasFirstOne = false; foreach (Entity e in _group.GetEntities()) { if (wasFirstOne) { e.isDestroyEntity = true; return; } CameraShakeProperties componentProperties = e.cameraShake.properties; componentProperties.time -= deltaTime; if (componentProperties.time < 0.0f) { e.isDestroyEntity = true; } else { if (!componentProperties.velocityCalculated) { componentProperties.velocity = componentProperties.totalOffsetX * 4.0f / componentProperties.totalTime; } Vector3 originalPosition = camera.camera.transform.position; componentProperties.offsetX += componentProperties.direction * componentProperties.velocity * deltaTime; if (componentProperties.offsetX >= componentProperties.totalOffsetX) { componentProperties.direction = -1; } else if (componentProperties.offsetX <= -componentProperties.totalOffsetX) { componentProperties.direction = 1; } camera.camera.transform.position = new Vector3(originalPosition.x + componentProperties.offsetX, originalPosition.y, originalPosition.z); wasFirstOne = true; } } }
IEnumerator Shake(CameraShakeProperties properties) { float completionPercent = 0; float movePercent = 0; float angle_radians = properties.angle * Mathf.Deg2Rad - Mathf.PI; Vector3 previousWaypoint = Vector3.zero; Vector3 currentWaypoint = Vector3.zero; float moveDistance = 0; float speed = 0; Quaternion targetRotation = Quaternion.identity; Quaternion previousRotation = Quaternion.identity; do { if (movePercent >= 1 || completionPercent == 0) { float dampingFactor = DampingCurve(completionPercent, properties.dampingPercent); float noiseAngle = (Random.value - .5f) * Mathf.PI; angle_radians += Mathf.PI + noiseAngle * properties.noisePercent; currentWaypoint = new Vector3(Mathf.Cos(angle_radians), Mathf.Sin(angle_radians)) * properties.strength * dampingFactor; previousWaypoint = transform.localPosition; moveDistance = Vector3.Distance(currentWaypoint, previousWaypoint); targetRotation = Quaternion.Euler(new Vector3(currentWaypoint.y, currentWaypoint.x).normalized *properties.rotationPercent *dampingFactor *maxAngle); previousRotation = transform.localRotation; speed = Mathf.Lerp(properties.minSpeed, properties.maxSpeed, dampingFactor); movePercent = 0; } completionPercent += Time.deltaTime / properties.duration; movePercent += Time.deltaTime / moveDistance * speed; transform.localPosition = Vector3.Lerp(previousWaypoint, currentWaypoint, movePercent); transform.localRotation = Quaternion.Slerp(previousRotation, targetRotation, movePercent); yield return(null); } while (moveDistance > 0); }
public Entity AddCameraShake(CameraShakeProperties newProperties) { var component = _cameraShakeComponentPool.Count > 0 ? _cameraShakeComponentPool.Pop() : new CameraShakeComponent(); component.properties = newProperties; return AddComponent(ComponentIds.CameraShake, component); }