public void MoveCamera(CameraPositionIdentifier newPositionIdentifier, float transitionDuration) { Transform newPosition = null; switch (newPositionIdentifier) { case CameraPositionIdentifier.Room: newPosition = roomCameraPosition; break; case CameraPositionIdentifier.Computer: newPosition = computerCameraPosition; break; } if (transitioning || newPosition == null || newPosition == cameraPosition) { return; } StopCoroutine("TransitionCamera"); this.transitionDuration = transitionDuration; this.cameraPosition = newPosition; transitioning = true; OnCameraMove.Invoke(newPositionIdentifier); StartCoroutine("TransitionCamera"); }
void Update() { if (transform.position.x != oldPosition) { OnCameraMove.Invoke(oldPosition - transform.position.x); oldPosition = transform.position.x; } }
/// <summary> /// update camera movement and rotation /// </summary> private void CameraUpdate() { if (FollowingTarget) { FollowTarget(); } else { Move(); } HeightCalculation(); Rotation(); LimitPosition(); MoveDampening(); OnCameraMoved.Invoke(); }
public void OnRotateCamera(InputAction.CallbackContext context) { CameraMoveEvent.Invoke(context.ReadValue <Vector2>()); }
public void UCUpdate() { Vector3 dt = Vector3.right * panning.deltaPosition.x; Vector3 local = cam.transform.localPosition; // returns 1 when there are no touches, 0 when there are int touches = (1 + (int)Mathf.Clamp01(panning.tapCount)) % 2; float overshootL = (local.x + dt.x) - boundsWidth * -.5f; float overshootLPct = Mathf.Clamp(overshootL / 6f, -1f, 0f); int toggleOvershootL = (int)Mathf.Floor(overshootLPct) * -1; // this will multiply by 1 when no overshoot // otherwise multiply delta by the inverse distance overshot in percent dt *= 1 - (overshootLPct * -1f); // multiply overshootL by 0.98 to cause a slowdown towards the end // of the lerp // multiply by deltaTime to lerp the overshoot distance over 1 second // multiply by touches to toggle lerping when pressing or releasing the // mouse button or finger // multiply by toggleOvershootL to enable the lerp only when overshooting dt += Vector3.right * overshootL * -2.5f * Time.deltaTime * touches * toggleOvershootL; float overshootR = (local.x + dt.x) - boundsWidth * .5f; float overshootRPct = Mathf.Clamp(overshootR / 6f, 0f, 1f); int toggleOvershootR = (int)Mathf.Ceil(overshootRPct); // this will multiply by 1 when no overshoot dt *= 1 - overshootRPct; // multiply overshootR by 0.98 to cause a slowdown towards the end // of the lerp // multiply by deltaTime to lerp the overshoot distance over 1 second // multiply by touches to toggle lerping when pressing or releasing the // mouse button or finger // multiply by toggleOvershootR to enable the lerp only when overshooting dt += Vector3.right * overshootR * -2.5f * Time.deltaTime * touches * toggleOvershootR; cam.transform.localPosition += dt; float posx = cam.transform.localPosition.x; float camPos = (posx + boundsWidth * .5f) / boundsWidth; if (prevCamPos != camPos) { onCameraMove.Invoke(camPos); int len = onCameraMoveSig.callbacks.Count; for (int i = 0; i < len; i++) { onCameraMoveSig.callbacks[i].OnCameraMove(camPos); } prevCamPos = camPos; } dayNight = dayNightCycle.Evaluate(Mathf.Clamp01(camPos)); float progress = Mathf.Clamp01((camPos - dayStart) / (nightStart - dayStart)); if (dayNight != prevDayNight) { onTransition.Invoke(dayNight, camPos); int len = onDayNight.callbacks.Count; for (int i = 0; i < len; i++) { onDayNight.callbacks[i].OnDayNight(dayNight, progress); } prevDayNight = dayNight; } }