using Core.Camera; using UnityEngine; namespace Core.Input { /// /// Abstract base input scheme for schemes that control the CameraRig /// public abstract class CameraInputScheme : InputScheme { /// /// Camera rig to control /// public CameraRig cameraRig; /// /// Pan speed factor when fully zoomed-in /// public float nearZoomPanSpeedModifier = 0.2f; /// /// Gets our pan speed multiplier for the given zoom level /// /// protected float GetPanSpeedForZoomLevel() { return cameraRig != null ? Mathf.Lerp(nearZoomPanSpeedModifier, 1, cameraRig.CalculateZoomRatio()) : 1.0f; } /// /// Do screen edge panning with the given screen coordinates /// /// The screen position of the cursor panning the camera /// The screen edge threshold in pixels /// Speed of panning protected void PanWithScreenCoordinates(Vector2 screenPosition, float screenEdgeThreshold, float panSpeed) { // Calculate zoom ratio float zoomRatio = GetPanSpeedForZoomLevel(); // Left if ((screenPosition.x < screenEdgeThreshold)) { float panAmount = (screenEdgeThreshold - screenPosition.x) / screenEdgeThreshold; panAmount = Mathf.Clamp01(Mathf.Log(panAmount) + 1); if (cameraRig.trackingObject == null) { cameraRig.PanCamera(Vector3.left * Time.deltaTime * panSpeed * panAmount * zoomRatio); cameraRig.StopTracking(); } } // Right if ((screenPosition.x > Screen.width - screenEdgeThreshold)) { float panAmount = ((screenEdgeThreshold - Screen.width) + screenPosition.x) / screenEdgeThreshold; panAmount = Mathf.Clamp01(Mathf.Log(panAmount) + 1); if (cameraRig.trackingObject == null) { cameraRig.PanCamera(Vector3.right * Time.deltaTime * panSpeed * panAmount * zoomRatio); } cameraRig.StopTracking(); } // Down if ((screenPosition.y < screenEdgeThreshold)) { float panAmount = (screenEdgeThreshold - screenPosition.y) / screenEdgeThreshold; panAmount = Mathf.Clamp01(Mathf.Log(panAmount) + 1); if (cameraRig.trackingObject == null) { cameraRig.PanCamera(Vector3.back * Time.deltaTime * panSpeed * panAmount * zoomRatio); cameraRig.StopTracking(); } } // Up if ((screenPosition.y > Screen.height - screenEdgeThreshold)) { float panAmount = ((screenEdgeThreshold - Screen.height) + screenPosition.y) / screenEdgeThreshold; panAmount = Mathf.Clamp01(Mathf.Log(panAmount) + 1); if (cameraRig.trackingObject == null) { cameraRig.PanCamera(Vector3.forward * Time.deltaTime * panSpeed * panAmount * zoomRatio); cameraRig.StopTracking(); } } } } }