diff options
Diffstat (limited to 'Assets/Cinemachine/Base/Runtime/Components')
22 files changed, 2700 insertions, 0 deletions
diff --git a/Assets/Cinemachine/Base/Runtime/Components/CinemachineBasicMultiChannelPerlin.cs b/Assets/Cinemachine/Base/Runtime/Components/CinemachineBasicMultiChannelPerlin.cs new file mode 100644 index 0000000..6b43df1 --- /dev/null +++ b/Assets/Cinemachine/Base/Runtime/Components/CinemachineBasicMultiChannelPerlin.cs @@ -0,0 +1,113 @@ +using UnityEngine; +using UnityEngine.Serialization; + +namespace Cinemachine +{ + /// <summary> + /// As a part of the Cinemachine Pipeline implementing the Noise stage, this + /// component adds Perlin Noise to the Camera state, in the Correction + /// channel of the CameraState. + /// + /// The noise is created by using a predefined noise profile asset. This defines the + /// shape of the noise over time. You can scale this in amplitude or in time, to produce + /// a large family of different noises using the same profile. + /// </summary> + /// <seealso cref="NoiseSettings"/> + [DocumentationSorting(8, DocumentationSortingAttribute.Level.UserRef)] + [AddComponentMenu("")] // Don't display in add component menu + [RequireComponent(typeof(CinemachinePipeline))] + [SaveDuringPlay] + public class CinemachineBasicMultiChannelPerlin : CinemachineComponentBase + { + /// <summary> + /// Serialized property for referencing a NoiseSettings asset + /// </summary> + [HideInInspector] + [Tooltip("The asset containing the Noise Profile. Define the frequencies and amplitudes there to make a characteristic noise profile. Make your own or just use one of the many presets.")] + [FormerlySerializedAs("m_Definition")] + public NoiseSettings m_NoiseProfile; + + /// <summary> + /// Gain to apply to the amplitudes defined in the settings asset. + /// </summary> + [Tooltip("Gain to apply to the amplitudes defined in the NoiseSettings asset. 1 is normal. Setting this to 0 completely mutes the noise.")] + public float m_AmplitudeGain = 1f; + + /// <summary> + /// Scale factor to apply to the frequencies defined in the settings asset. + /// </summary> + [Tooltip("Scale factor to apply to the frequencies defined in the NoiseSettings asset. 1 is normal. Larger magnitudes will make the noise shake more rapidly.")] + public float m_FrequencyGain = 1f; + + /// <summary>True if the component is valid, i.e. it has a noise definition and is enabled.</summary> + public override bool IsValid { get { return enabled && m_NoiseProfile != null; } } + + /// <summary>Get the Cinemachine Pipeline stage that this component implements. + /// Always returns the Noise stage</summary> + public override CinemachineCore.Stage Stage { get { return CinemachineCore.Stage.Noise; } } + + /// <summary>Applies noise to the Correction channel of the CameraState if the + /// delta time is greater than 0. Otherwise, does nothing.</summary> + /// <param name="curState">The current camera state</param> + /// <param name="deltaTime">How much to advance the perlin noise generator. + /// Noise is only applied if this value is greater than or equal to 0</param> + public override void MutateCameraState(ref CameraState curState, float deltaTime) + { + if (!IsValid || deltaTime < 0) + return; + + //UnityEngine.Profiling.Profiler.BeginSample("CinemachineBasicMultiChannelPerlin.MutateCameraState"); + if (!mInitialized) + Initialize(); + + mNoiseTime += deltaTime * m_FrequencyGain; + curState.PositionCorrection += curState.CorrectedOrientation * GetCombinedFilterResults( + m_NoiseProfile.PositionNoise, mNoiseTime, mNoiseOffsets) * m_AmplitudeGain; + Quaternion rotNoise = Quaternion.Euler(GetCombinedFilterResults( + m_NoiseProfile.OrientationNoise, mNoiseTime, mNoiseOffsets) * m_AmplitudeGain); + curState.OrientationCorrection = curState.OrientationCorrection * rotNoise; + //UnityEngine.Profiling.Profiler.EndSample(); + } + + private bool mInitialized = false; + private float mNoiseTime = 0; + private Vector3 mNoiseOffsets = Vector3.zero; + + void Initialize() + { + mInitialized = true; + mNoiseTime = 0; + mNoiseOffsets = new Vector3( + UnityEngine.Random.Range(-10000f, 10000f), + UnityEngine.Random.Range(-10000f, 10000f), + UnityEngine.Random.Range(-10000f, 10000f)); + } + + static Vector3 GetCombinedFilterResults( + NoiseSettings.TransformNoiseParams[] noiseParams, float time, Vector3 noiseOffsets) + { + float xPos = 0f; + float yPos = 0f; + float zPos = 0f; + if (noiseParams != null) + { + for (int i = 0; i < noiseParams.Length; ++i) + { + NoiseSettings.TransformNoiseParams param = noiseParams[i]; + Vector3 timeVal = new Vector3(param.X.Frequency, param.Y.Frequency, param.Z.Frequency) * time; + timeVal += noiseOffsets; + + Vector3 noise = new Vector3( + Mathf.PerlinNoise(timeVal.x, 0f) - 0.5f, + Mathf.PerlinNoise(timeVal.y, 0f) - 0.5f, + Mathf.PerlinNoise(timeVal.z, 0f) - 0.5f); + + xPos += noise.x * param.X.Amplitude; + yPos += noise.y * param.Y.Amplitude; + zPos += noise.z * param.Z.Amplitude; + } + } + return new Vector3(xPos, yPos, zPos); + } + } +} diff --git a/Assets/Cinemachine/Base/Runtime/Components/CinemachineBasicMultiChannelPerlin.cs.meta b/Assets/Cinemachine/Base/Runtime/Components/CinemachineBasicMultiChannelPerlin.cs.meta new file mode 100644 index 0000000..a4e5847 --- /dev/null +++ b/Assets/Cinemachine/Base/Runtime/Components/CinemachineBasicMultiChannelPerlin.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 68bb026fafb42b14791938953eaace77 +timeCreated: 1484001117 +licenseType: Store +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Cinemachine/Base/Runtime/Components/CinemachineComposer.cs b/Assets/Cinemachine/Base/Runtime/Components/CinemachineComposer.cs new file mode 100644 index 0000000..86c091c --- /dev/null +++ b/Assets/Cinemachine/Base/Runtime/Components/CinemachineComposer.cs @@ -0,0 +1,391 @@ +using UnityEngine; +using System; +using Cinemachine.Utility; + +namespace Cinemachine +{ + /// <summary> + /// This is a CinemachineComponent in the Aim section of the component pipeline. + /// Its job is to aim the camera at the vcam's LookAt target object, with + /// configurable offsets, damping, and composition rules. + /// + /// The composer does not change the camera's position. It will only pan and tilt the + /// camera where it is, in order to get the desired framing. To move the camera, you have + /// to use the virtual camera's Body section. + /// </summary> + [DocumentationSorting(3, DocumentationSortingAttribute.Level.UserRef)] + [ExecuteInEditMode] // for OnGUI + [AddComponentMenu("")] // Don't display in add component menu + [RequireComponent(typeof(CinemachinePipeline))] + [SaveDuringPlay] + public class CinemachineComposer : CinemachineComponentBase + { + /// <summary>Used by the Inspector Editor to display on-screen guides.</summary> + [NoSaveDuringPlay, HideInInspector] + public Action OnGUICallback = null; + + /// <summary>Target offset from the object's center in LOCAL space which + /// the Composer tracks. Use this to fine-tune the tracking target position + /// when the desired area is not in the tracked object's center</summary> + [Tooltip("Target offset from the target object's center in target-local space. Use this to fine-tune the tracking target position when the desired area is not the tracked object's center.")] + public Vector3 m_TrackedObjectOffset = Vector3.zero; + + /// <summary>This setting will instruct the composer to adjust its target offset based + /// on the motion of the target. The composer will look at a point where it estimates + /// the target will be this many seconds into the future. Note that this setting is sensitive + /// to noisy animation, and can amplify the noise, resulting in undesirable camera jitter. + /// If the camera jitters unacceptably when the target is in motion, turn down this setting, + /// or animate the target more smoothly.</summary> + [Tooltip("This setting will instruct the composer to adjust its target offset based on the motion of the target. The composer will look at a point where it estimates the target will be this many seconds into the future. Note that this setting is sensitive to noisy animation, and can amplify the noise, resulting in undesirable camera jitter. If the camera jitters unacceptably when the target is in motion, turn down this setting, or animate the target more smoothly.")] + [Range(0f, 1f)] + public float m_LookaheadTime = 0; + + /// <summary>Controls the smoothness of the lookahead algorithm. Larger values smooth out + /// jittery predictions and also increase prediction lag</summary> + [Tooltip("Controls the smoothness of the lookahead algorithm. Larger values smooth out jittery predictions and also increase prediction lag")] + [Range(3, 30)] + public float m_LookaheadSmoothing = 10; + + /// <summary>How aggressively the camera tries to follow the target in the screen-horizontal direction. + /// Small numbers are more responsive, rapidly orienting the camera to keep the target in + /// the dead zone. Larger numbers give a more heavy slowly responding camera. + /// Using different vertical and horizontal settings can yield a wide range of camera behaviors.</summary> + [Space] + [Range(0f, 20)] + [Tooltip("How aggressively the camera tries to follow the target in the screen-horizontal direction. Small numbers are more responsive, rapidly orienting the camera to keep the target in the dead zone. Larger numbers give a more heavy slowly responding camera. Using different vertical and horizontal settings can yield a wide range of camera behaviors.")] + public float m_HorizontalDamping = 0.5f; + + /// <summary>How aggressively the camera tries to follow the target in the screen-vertical direction. + /// Small numbers are more responsive, rapidly orienting the camera to keep the target in + /// the dead zone. Larger numbers give a more heavy slowly responding camera. Using different vertical + /// and horizontal settings can yield a wide range of camera behaviors.</summary> + [Range(0f, 20)] + [Tooltip("How aggressively the camera tries to follow the target in the screen-vertical direction. Small numbers are more responsive, rapidly orienting the camera to keep the target in the dead zone. Larger numbers give a more heavy slowly responding camera. Using different vertical and horizontal settings can yield a wide range of camera behaviors.")] + public float m_VerticalDamping = 0.5f; + + /// <summary>Horizontal screen position for target. The camera will rotate to the position the tracked object here</summary> + [Space] + [Range(0f, 1f)] + [Tooltip("Horizontal screen position for target. The camera will rotate to position the tracked object here.")] + public float m_ScreenX = 0.5f; + + /// <summary>Vertical screen position for target, The camera will rotate to to position the tracked object here</summary> + [Range(0f, 1f)] + [Tooltip("Vertical screen position for target, The camera will rotate to position the tracked object here.")] + public float m_ScreenY = 0.5f; + + /// <summary>Camera will not rotate horizontally if the target is within this range of the position</summary> + [Range(0f, 1f)] + [Tooltip("Camera will not rotate horizontally if the target is within this range of the position.")] + public float m_DeadZoneWidth = 0.1f; + + /// <summary>Camera will not rotate vertically if the target is within this range of the position</summary> + [Range(0f, 1f)] + [Tooltip("Camera will not rotate vertically if the target is within this range of the position.")] + public float m_DeadZoneHeight = 0.1f; + + /// <summary>When target is within this region, camera will gradually move to re-align + /// towards the desired position, depending onm the damping speed</summary> + [Range(0f, 2f)] + [Tooltip("When target is within this region, camera will gradually rotate horizontally to re-align towards the desired position, depending on the damping speed.")] + public float m_SoftZoneWidth = 0.8f; + + /// <summary>When target is within this region, camera will gradually move to re-align + /// towards the desired position, depending onm the damping speed</summary> + [Range(0f, 2f)] + [Tooltip("When target is within this region, camera will gradually rotate vertically to re-align towards the desired position, depending on the damping speed.")] + public float m_SoftZoneHeight = 0.8f; + + /// <summary>A non-zero bias will move the targt position away from the center of the soft zone</summary> + [Range(-0.5f, 0.5f)] + [Tooltip("A non-zero bias will move the target position horizontally away from the center of the soft zone.")] + public float m_BiasX = 0f; + + /// <summary>A non-zero bias will move the targt position away from the center of the soft zone</summary> + [Range(-0.5f, 0.5f)] + [Tooltip("A non-zero bias will move the target position vertically away from the center of the soft zone.")] + public float m_BiasY = 0f; + + /// <summary>True if component is enabled and has a LookAt defined</summary> + public override bool IsValid { get { return enabled && LookAtTarget != null; } } + + /// <summary>Get the Cinemachine Pipeline stage that this component implements. + /// Always returns the Aim stage</summary> + public override CinemachineCore.Stage Stage { get { return CinemachineCore.Stage.Aim; } } + + /// <summary>Internal API for inspector</summary> + public Vector3 TrackedPoint { get; private set; } + + /// <summary>Apply the target offsets to the target location. + /// Also set the TrackedPoint property, taking lookahead into account.</summary> + /// <param name="lookAt">The unoffset LookAt point</param> + /// <returns>The LookAt point with the offset applied</returns> + protected virtual Vector3 GetLookAtPointAndSetTrackedPoint(Vector3 lookAt) + { + Vector3 pos = lookAt; + if (LookAtTarget != null) + pos += LookAtTarget.transform.rotation * m_TrackedObjectOffset; + + m_Predictor.Smoothing = m_LookaheadSmoothing; + m_Predictor.AddPosition(pos); + TrackedPoint = (m_LookaheadTime > 0) + ? m_Predictor.PredictPosition(m_LookaheadTime) : pos; + + return pos; + } + +#if UNITY_EDITOR + private void OnGUI() { if (OnGUICallback != null) OnGUICallback(); } +#endif + + /// <summary>State information for damping</summary> + Vector3 m_CameraPosPrevFrame = Vector3.zero; + Vector3 m_LookAtPrevFrame = Vector3.zero; + Vector2 m_ScreenOffsetPrevFrame = Vector2.zero; + Quaternion m_CameraOrientationPrevFrame = Quaternion.identity; + PositionPredictor m_Predictor = new PositionPredictor(); + + public override void PrePipelineMutateCameraState(ref CameraState curState) + { + if (IsValid && curState.HasLookAt) + curState.ReferenceLookAt = GetLookAtPointAndSetTrackedPoint(curState.ReferenceLookAt); + } + + /// <summary>Applies the composer rules and orients the camera accordingly</summary> + /// <param name="curState">The current camera state</param> + /// <param name="deltaTime">Used for calculating damping. If less than + /// zero, then target will snap to the center of the dead zone.</param> + public override void MutateCameraState(ref CameraState curState, float deltaTime) + { + // Initialize the state for previous frame if appropriate + if (deltaTime < 0) + m_Predictor.Reset(); + + if (!IsValid || !curState.HasLookAt) + return; + + float targetDistance = (TrackedPoint - curState.CorrectedPosition).magnitude; + if (targetDistance < Epsilon) + { + if (deltaTime >= 0) + curState.RawOrientation = m_CameraOrientationPrevFrame; + return; // navel-gazing, get outa here + } + + //UnityEngine.Profiling.Profiler.BeginSample("CinemachineComposer.MutateCameraState"); + float fov, fovH; + if (curState.Lens.Orthographic) + { + // Calculate effective fov - fake it for ortho based on target distance + fov = Mathf.Rad2Deg * 2 * Mathf.Atan(curState.Lens.OrthographicSize / targetDistance); + fovH = Mathf.Rad2Deg * 2 * Mathf.Atan( + curState.Lens.Aspect * curState.Lens.OrthographicSize / targetDistance); + } + else + { + fov = curState.Lens.FieldOfView; + double radHFOV = 2 * Math.Atan(Math.Tan(fov * Mathf.Deg2Rad / 2) * curState.Lens.Aspect); + fovH = (float)(Mathf.Rad2Deg * radHFOV); + } + + Quaternion rigOrientation = curState.RawOrientation; + Rect softGuideFOV = ScreenToFOV(SoftGuideRect, fov, fovH, curState.Lens.Aspect); + if (deltaTime < 0) + { + // No damping, just snap to central bounds, skipping the soft zone + Rect rect = new Rect(softGuideFOV.center, Vector2.zero); // Force to center + RotateToScreenBounds(ref curState, rect, ref rigOrientation, fov, fovH, -1); + } + else + { + // Start with previous frame's orientation (but with current up) + Vector3 dir = m_LookAtPrevFrame - (m_CameraPosPrevFrame + curState.PositionDampingBypass); + if (dir.AlmostZero()) + rigOrientation = Quaternion.LookRotation( + m_CameraOrientationPrevFrame * Vector3.forward, curState.ReferenceUp); + else + { + rigOrientation = Quaternion.LookRotation(dir, curState.ReferenceUp); + rigOrientation = rigOrientation.ApplyCameraRotation( + -m_ScreenOffsetPrevFrame, curState.ReferenceUp); + } + + // First force the previous rotation into the hard bounds, no damping, + // then Now move it through the soft zone, with damping + Rect hardGuideFOV = ScreenToFOV(HardGuideRect, fov, fovH, curState.Lens.Aspect); + if (!RotateToScreenBounds(ref curState, hardGuideFOV, ref rigOrientation, fov, fovH, -1)) + RotateToScreenBounds(ref curState, softGuideFOV, ref rigOrientation, fov, fovH, deltaTime); + } + m_CameraPosPrevFrame = curState.CorrectedPosition; + m_LookAtPrevFrame = TrackedPoint; + m_CameraOrientationPrevFrame = UnityQuaternionExtensions.Normalized(rigOrientation); + m_ScreenOffsetPrevFrame = m_CameraOrientationPrevFrame.GetCameraRotationToTarget( + m_LookAtPrevFrame - curState.CorrectedPosition, curState.ReferenceUp); + + curState.RawOrientation = m_CameraOrientationPrevFrame; + //UnityEngine.Profiling.Profiler.EndSample(); + } + + /// <summary>Internal API for the inspector editor</summary> + public Rect SoftGuideRect + { + get + { + return new Rect( + m_ScreenX - m_DeadZoneWidth / 2, m_ScreenY - m_DeadZoneHeight / 2, + m_DeadZoneWidth, m_DeadZoneHeight); + } + set + { + m_DeadZoneWidth = Mathf.Clamp01(value.width); + m_DeadZoneHeight = Mathf.Clamp01(value.height); + m_ScreenX = Mathf.Clamp01(value.x + m_DeadZoneWidth / 2); + m_ScreenY = Mathf.Clamp01(value.y + m_DeadZoneHeight / 2); + m_SoftZoneWidth = Mathf.Max(m_SoftZoneWidth, m_DeadZoneWidth); + m_SoftZoneHeight = Mathf.Max(m_SoftZoneHeight, m_DeadZoneHeight); + } + } + + /// <summary>Internal API for the inspector editor</summary> + public Rect HardGuideRect + { + get + { + Rect r = new Rect( + m_ScreenX - m_SoftZoneWidth / 2, m_ScreenY - m_SoftZoneHeight / 2, + m_SoftZoneWidth, m_SoftZoneHeight); + r.position += new Vector2( + m_BiasX * (m_SoftZoneWidth - m_DeadZoneWidth), + m_BiasY * (m_SoftZoneHeight - m_DeadZoneHeight)); + return r; + } + set + { + m_SoftZoneWidth = Mathf.Clamp(value.width, 0, 2f); + m_SoftZoneHeight = Mathf.Clamp(value.height, 0, 2f); + m_DeadZoneWidth = Mathf.Min(m_DeadZoneWidth, m_SoftZoneWidth); + m_DeadZoneHeight = Mathf.Min(m_DeadZoneHeight, m_SoftZoneHeight); + + Vector2 center = value.center; + Vector2 bias = center - new Vector2(m_ScreenX, m_ScreenY); + float biasWidth = Mathf.Max(0, m_SoftZoneWidth - m_DeadZoneWidth); + float biasHeight = Mathf.Max(0, m_SoftZoneHeight - m_DeadZoneHeight); + m_BiasX = biasWidth < Epsilon ? 0 : Mathf.Clamp(bias.x / biasWidth, -0.5f, 0.5f); + m_BiasY = biasHeight < Epsilon ? 0 : Mathf.Clamp(bias.y / biasHeight, -0.5f, 0.5f); + } + } + + // Convert from screen coords to normalized FOV angular coords + private Rect ScreenToFOV(Rect rScreen, float fov, float fovH, float aspect) + { + Rect r = new Rect(rScreen); + Matrix4x4 persp = Matrix4x4.Perspective(fov, aspect, 0.01f, 10000f).inverse; + + Vector3 p = persp.MultiplyPoint(new Vector3(0, (r.yMin * 2f) - 1f, 0.1f)); p.z = -p.z; + float angle = UnityVectorExtensions.SignedAngle(Vector3.forward, p, Vector3.left); + r.yMin = ((fov / 2) + angle) / fov; + + p = persp.MultiplyPoint(new Vector3(0, (r.yMax * 2f) - 1f, 0.1f)); p.z = -p.z; + angle = UnityVectorExtensions.SignedAngle(Vector3.forward, p, Vector3.left); + r.yMax = ((fov / 2) + angle) / fov; + + p = persp.MultiplyPoint(new Vector3((r.xMin * 2f) - 1f, 0, 0.1f)); p.z = -p.z; + angle = UnityVectorExtensions.SignedAngle(Vector3.forward, p, Vector3.up); + r.xMin = ((fovH / 2) + angle) / fovH; + + p = persp.MultiplyPoint(new Vector3((r.xMax * 2f) - 1f, 0, 0.1f)); p.z = -p.z; + angle = UnityVectorExtensions.SignedAngle(Vector3.forward, p, Vector3.up); + r.xMax = ((fovH / 2) + angle) / fovH; + return r; + } + + /// <summary> + /// Adjust the rigOrientation to put the camera within the screen bounds. + /// If deltaTime >= 0 then damping will be applied. + /// Assumes that currentOrientation fwd is such that input rigOrientation's + /// local up is NEVER NEVER NEVER pointing downwards, relative to + /// state.ReferenceUp. If this condition is violated + /// then you will see crazy spinning. That's the symptom. + /// </summary> + private bool RotateToScreenBounds( + ref CameraState state, Rect screenRect, + ref Quaternion rigOrientation, float fov, float fovH, float deltaTime) + { + Vector3 targetDir = TrackedPoint - state.CorrectedPosition; + Vector2 rotToRect = rigOrientation.GetCameraRotationToTarget(targetDir, state.ReferenceUp); + + // Bring it to the edge of screenRect, if outside. Leave it alone if inside. + ClampVerticalBounds(ref screenRect, targetDir, state.ReferenceUp, fov); + float min = (screenRect.yMin - 0.5f) * fov; + float max = (screenRect.yMax - 0.5f) * fov; + if (rotToRect.x < min) + rotToRect.x -= min; + else if (rotToRect.x > max) + rotToRect.x -= max; + else + rotToRect.x = 0; + + min = (screenRect.xMin - 0.5f) * fovH; + max = (screenRect.xMax - 0.5f) * fovH; + if (rotToRect.y < min) + rotToRect.y -= min; + else if (rotToRect.y > max) + rotToRect.y -= max; + else + rotToRect.y = 0; + + // Apply damping + if (deltaTime >= 0) + { + rotToRect.x = Damper.Damp(rotToRect.x, m_VerticalDamping, deltaTime); + rotToRect.y = Damper.Damp(rotToRect.y, m_HorizontalDamping, deltaTime); + } + + // Rotate + rigOrientation = rigOrientation.ApplyCameraRotation(rotToRect, state.ReferenceUp); +#if false + // GML this gives false positives when the camera is moving. + // The way to address this would be to grow the hard rect by the amount + // that it would be damped + return Mathf.Abs(rotToRect.x) > Epsilon || Mathf.Abs(rotToRect.y) > Epsilon; +#else + return false; +#endif + } + + /// <summary> + /// Prevent upside-down camera situation. This can happen if we have a high + /// camera pitch combined with composer settings that cause the camera to tilt + /// beyond the vertical in order to produce the desired framing. We prevent this by + /// clamping the composer's vertical settings so that this situation can't happen. + /// </summary> + private bool ClampVerticalBounds(ref Rect r, Vector3 dir, Vector3 up, float fov) + { + float angle = Vector3.Angle(dir, up); + float halfFov = (fov / 2f) + 1; // give it a little extra to accommodate precision errors + if (angle < halfFov) + { + // looking up + float maxY = 1f - (halfFov - angle) / fov; + if (r.yMax > maxY) + { + r.yMin = Mathf.Min(r.yMin, maxY); + r.yMax = Mathf.Min(r.yMax, maxY); + return true; + } + } + if (angle > (180 - halfFov)) + { + // looking down + float minY = (angle - (180 - halfFov)) / fov; + if (minY > r.yMin) + { + r.yMin = Mathf.Max(r.yMin, minY); + r.yMax = Mathf.Max(r.yMax, minY); + return true; + } + } + return false; + } + } +} diff --git a/Assets/Cinemachine/Base/Runtime/Components/CinemachineComposer.cs.meta b/Assets/Cinemachine/Base/Runtime/Components/CinemachineComposer.cs.meta new file mode 100644 index 0000000..fa03c76 --- /dev/null +++ b/Assets/Cinemachine/Base/Runtime/Components/CinemachineComposer.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: f4044717213e31446939f7bd49c896ea +timeCreated: 1488314898 +licenseType: Store +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Cinemachine/Base/Runtime/Components/CinemachineFramingTransposer.cs b/Assets/Cinemachine/Base/Runtime/Components/CinemachineFramingTransposer.cs new file mode 100644 index 0000000..32ca9b3 --- /dev/null +++ b/Assets/Cinemachine/Base/Runtime/Components/CinemachineFramingTransposer.cs @@ -0,0 +1,497 @@ +using System; +using Cinemachine.Utility; +using UnityEngine; +using UnityEngine.Serialization; + +namespace Cinemachine +{ + /// <summary> + /// This is a Cinemachine Component in the Body section of the component pipeline. + /// Its job is to position the camera in a fixed screen-space relationship to + /// the vcam's Follow target object, with offsets and damping. + /// + /// The camera will be first moved along the camera Z axis until the Follow target + /// is at the desired distance from the camera's X-Y plane. The camera will then + /// be moved in its XY plane until the Follow target is at the desired point on + /// the camera's screen. + /// + /// The FramingTansposer will only change the camera's position in space. It will not + /// re-orient or otherwise aim the camera. + /// + /// For this component to work properly, the vcam's LookAt target must be null. + /// The Follow target will define what the camera is looking at. + /// + /// If the Follow target is a CinemachineTargetGroup, then additional controls will + /// be available to dynamically adjust the camera’s view in order to frame the entire group. + /// + /// Although this component was designed for orthographic cameras, it works equally + /// well with persective cameras and can be used in 3D environments. + /// </summary> + [DocumentationSorting(5.5f, DocumentationSortingAttribute.Level.UserRef)] + [ExecuteInEditMode] // for OnGUI + [AddComponentMenu("")] // Don't display in add component menu + [RequireComponent(typeof(CinemachinePipeline))] + [SaveDuringPlay] + public class CinemachineFramingTransposer : CinemachineComponentBase + { + /// <summary>Used by the Inspector Editor to display on-screen guides.</summary> + [NoSaveDuringPlay, HideInInspector] + public Action OnGUICallback = null; + + /// <summary>This setting will instruct the composer to adjust its target offset based + /// on the motion of the target. The composer will look at a point where it estimates + /// the target will be this many seconds into the future. Note that this setting is sensitive + /// to noisy animation, and can amplify the noise, resulting in undesirable camera jitter. + /// If the camera jitters unacceptably when the target is in motion, turn down this setting, + /// or animate the target more smoothly.</summary> + [Tooltip("This setting will instruct the composer to adjust its target offset based on the motion of the target. The composer will look at a point where it estimates the target will be this many seconds into the future. Note that this setting is sensitive to noisy animation, and can amplify the noise, resulting in undesirable camera jitter. If the camera jitters unacceptably when the target is in motion, turn down this setting, or animate the target more smoothly.")] + [Range(0f, 1f)] + public float m_LookaheadTime = 0; + + /// <summary>Controls the smoothness of the lookahead algorithm. Larger values smooth out + /// jittery predictions and also increase prediction lag</summary> + [Tooltip("Controls the smoothness of the lookahead algorithm. Larger values smooth out jittery predictions and also increase prediction lag")] + [Range(3, 30)] + public float m_LookaheadSmoothing = 10; + + /// <summary>How aggressively the camera tries to maintain the offset in the X-axis. + /// Small numbers are more responsive, rapidly translating the camera to keep the target's + /// x-axis offset. Larger numbers give a more heavy slowly responding camera. + /// Using different settings per axis can yield a wide range of camera behaviors</summary> + [Range(0f, 20f)] + [Tooltip("How aggressively the camera tries to maintain the offset in the X-axis. Small numbers are more responsive, rapidly translating the camera to keep the target's x-axis offset. Larger numbers give a more heavy slowly responding camera. Using different settings per axis can yield a wide range of camera behaviors.")] + public float m_XDamping = 1f; + + /// <summary>How aggressively the camera tries to maintain the offset in the Y-axis. + /// Small numbers are more responsive, rapidly translating the camera to keep the target's + /// y-axis offset. Larger numbers give a more heavy slowly responding camera. + /// Using different settings per axis can yield a wide range of camera behaviors</summary> + [Range(0f, 20f)] + [Tooltip("How aggressively the camera tries to maintain the offset in the Y-axis. Small numbers are more responsive, rapidly translating the camera to keep the target's y-axis offset. Larger numbers give a more heavy slowly responding camera. Using different settings per axis can yield a wide range of camera behaviors.")] + public float m_YDamping = 1f; + + /// <summary>How aggressively the camera tries to maintain the offset in the Z-axis. + /// Small numbers are more responsive, rapidly translating the camera to keep the + /// target's z-axis offset. Larger numbers give a more heavy slowly responding camera. + /// Using different settings per axis can yield a wide range of camera behaviors</summary> + [Range(0f, 20f)] + [Tooltip("How aggressively the camera tries to maintain the offset in the Z-axis. Small numbers are more responsive, rapidly translating the camera to keep the target's z-axis offset. Larger numbers give a more heavy slowly responding camera. Using different settings per axis can yield a wide range of camera behaviors.")] + public float m_ZDamping = 1f; + + /// <summary>Horizontal screen position for target. The camera will move to position the tracked object here</summary> + [Space] + [Range(0f, 1f)] + [Tooltip("Horizontal screen position for target. The camera will move to position the tracked object here.")] + public float m_ScreenX = 0.5f; + + /// <summary>Vertical screen position for target, The camera will move to to position the tracked object here</summary> + [Range(0f, 1f)] + [Tooltip("Vertical screen position for target, The camera will move to position the tracked object here.")] + public float m_ScreenY = 0.5f; + + /// <summary>The distance along the camera axis that will be maintained from the Follow target</summary> + [Tooltip("The distance along the camera axis that will be maintained from the Follow target")] + public float m_CameraDistance = 10f; + + /// <summary>Camera will not move horizontally if the target is within this range of the position</summary> + [Space] + [Range(0f, 1f)] + [Tooltip("Camera will not move horizontally if the target is within this range of the position.")] + public float m_DeadZoneWidth = 0.1f; + + /// <summary>Camera will not move vertically if the target is within this range of the position</summary> + [Range(0f, 1f)] + [Tooltip("Camera will not move vertically if the target is within this range of the position.")] + public float m_DeadZoneHeight = 0.1f; + + /// <summary>The camera will not move along its z-axis if the Follow target is within this distance of the specified camera distance</summary> + [Tooltip("The camera will not move along its z-axis if the Follow target is within this distance of the specified camera distance")] + [FormerlySerializedAs("m_DistanceDeadZoneSize")] + public float m_DeadZoneDepth = 0; + + [Space] + /// <summary>If checked, then then soft zone will be unlimited in size</summary> + [Tooltip("If checked, then then soft zone will be unlimited in size.")] + public bool m_UnlimitedSoftZone = false; + + /// <summary>When target is within this region, camera will gradually move to re-align + /// towards the desired position, depending onm the damping speed</summary> + [Range(0f, 2f)] + [Tooltip("When target is within this region, camera will gradually move horizontally to re-align towards the desired position, depending on the damping speed.")] + public float m_SoftZoneWidth = 0.8f; + + /// <summary>When target is within this region, camera will gradually move to re-align + /// towards the desired position, depending onm the damping speed</summary> + [Range(0f, 2f)] + [Tooltip("When target is within this region, camera will gradually move vertically to re-align towards the desired position, depending on the damping speed.")] + public float m_SoftZoneHeight = 0.8f; + + /// <summary>A non-zero bias will move the targt position away from the center of the soft zone</summary> + [Range(-0.5f, 0.5f)] + [Tooltip("A non-zero bias will move the target position horizontally away from the center of the soft zone.")] + public float m_BiasX = 0f; + + /// <summary>A non-zero bias will move the targt position away from the center of the soft zone</summary> + [Range(-0.5f, 0.5f)] + [Tooltip("A non-zero bias will move the target position vertically away from the center of the soft zone.")] + public float m_BiasY = 0f; + + /// <summary>What screen dimensions to consider when framing</summary> + [DocumentationSorting(4.01f, DocumentationSortingAttribute.Level.UserRef)] + public enum FramingMode + { + /// <summary>Consider only the horizontal dimension. Vertical framing is ignored.</summary> + Horizontal, + /// <summary>Consider only the vertical dimension. Horizontal framing is ignored.</summary> + Vertical, + /// <summary>The larger of the horizontal and vertical dimensions will dominate, to get the best fit.</summary> + HorizontalAndVertical, + /// <summary>Don't do any framing adjustment</summary> + None + }; + + /// <summary>What screen dimensions to consider when framing</summary> + [Space] + [Tooltip("What screen dimensions to consider when framing. Can be Horizontal, Vertical, or both")] + [FormerlySerializedAs("m_FramingMode")] + public FramingMode m_GroupFramingMode = FramingMode.HorizontalAndVertical; + + /// <summary>How to adjust the camera to get the desired framing</summary> + public enum AdjustmentMode + { + /// <summary>Do not move the camera, only adjust the FOV.</summary> + ZoomOnly, + /// <summary>Just move the camera, don't change the FOV.</summary> + DollyOnly, + /// <summary>Move the camera as much as permitted by the ranges, then + /// adjust the FOV if necessary to make the shot.</summary> + DollyThenZoom + }; + + /// <summary>How to adjust the camera to get the desired framing</summary> + [Tooltip("How to adjust the camera to get the desired framing. You can zoom, dolly in/out, or do both.")] + public AdjustmentMode m_AdjustmentMode = AdjustmentMode.DollyThenZoom; + + /// <summary>How much of the screen to fill with the bounding box of the targets.</summary> + [Tooltip("The bounding box of the targets should occupy this amount of the screen space. 1 means fill the whole screen. 0.5 means fill half the screen, etc.")] + public float m_GroupFramingSize = 0.8f; + + /// <summary>How much closer to the target can the camera go?</summary> + [Tooltip("The maximum distance toward the target that this behaviour is allowed to move the camera.")] + public float m_MaxDollyIn = 5000f; + + /// <summary>How much farther from the target can the camera go?</summary> + [Tooltip("The maximum distance away the target that this behaviour is allowed to move the camera.")] + public float m_MaxDollyOut = 5000f; + + /// <summary>Set this to limit how close to the target the camera can get</summary> + [Tooltip("Set this to limit how close to the target the camera can get.")] + public float m_MinimumDistance = 1; + + /// <summary>Set this to limit how far from the taregt the camera can get</summary> + [Tooltip("Set this to limit how far from the target the camera can get.")] + public float m_MaximumDistance = 5000f; + + /// <summary>If adjusting FOV, will not set the FOV lower than this</summary> + [Range(1, 179)] + [Tooltip("If adjusting FOV, will not set the FOV lower than this.")] + public float m_MinimumFOV = 3; + + /// <summary>If adjusting FOV, will not set the FOV higher than this</summary> + [Range(1, 179)] + [Tooltip("If adjusting FOV, will not set the FOV higher than this.")] + public float m_MaximumFOV = 60; + + /// <summary>If adjusting Orthographic Size, will not set it lower than this</summary> + [Tooltip("If adjusting Orthographic Size, will not set it lower than this.")] + public float m_MinimumOrthoSize = 1; + + /// <summary>If adjusting Orthographic Size, will not set it higher than this</summary> + [Tooltip("If adjusting Orthographic Size, will not set it higher than this.")] + public float m_MaximumOrthoSize = 100; + + /// <summary>Internal API for the inspector editor</summary> + public Rect SoftGuideRect + { + get + { + return new Rect( + m_ScreenX - m_DeadZoneWidth / 2, m_ScreenY - m_DeadZoneHeight / 2, + m_DeadZoneWidth, m_DeadZoneHeight); + } + set + { + m_DeadZoneWidth = Mathf.Clamp01(value.width); + m_DeadZoneHeight = Mathf.Clamp01(value.height); + m_ScreenX = Mathf.Clamp01(value.x + m_DeadZoneWidth / 2); + m_ScreenY = Mathf.Clamp01(value.y + m_DeadZoneHeight / 2); + m_SoftZoneWidth = Mathf.Max(m_SoftZoneWidth, m_DeadZoneWidth); + m_SoftZoneHeight = Mathf.Max(m_SoftZoneHeight, m_DeadZoneHeight); + } + } + + /// <summary>Internal API for the inspector editor</summary> + public Rect HardGuideRect + { + get + { + Rect r = new Rect( + m_ScreenX - m_SoftZoneWidth / 2, m_ScreenY - m_SoftZoneHeight / 2, + m_SoftZoneWidth, m_SoftZoneHeight); + r.position += new Vector2( + m_BiasX * (m_SoftZoneWidth - m_DeadZoneWidth), + m_BiasY * (m_SoftZoneHeight - m_DeadZoneHeight)); + return r; + } + set + { + m_SoftZoneWidth = Mathf.Clamp(value.width, 0, 2f); + m_SoftZoneHeight = Mathf.Clamp(value.height, 0, 2f); + m_DeadZoneWidth = Mathf.Min(m_DeadZoneWidth, m_SoftZoneWidth); + m_DeadZoneHeight = Mathf.Min(m_DeadZoneHeight, m_SoftZoneHeight); + + Vector2 center = value.center; + Vector2 bias = center - new Vector2(m_ScreenX, m_ScreenY); + float biasWidth = Mathf.Max(0, m_SoftZoneWidth - m_DeadZoneWidth); + float biasHeight = Mathf.Max(0, m_SoftZoneHeight - m_DeadZoneHeight); + m_BiasX = biasWidth < Epsilon ? 0 : Mathf.Clamp(bias.x / biasWidth, -0.5f, 0.5f); + m_BiasY = biasHeight < Epsilon ? 0 : Mathf.Clamp(bias.y / biasHeight, -0.5f, 0.5f); + } + } + + private void OnValidate() + { + m_CameraDistance = Mathf.Max(m_CameraDistance, kMinimumCameraDistance); + m_DeadZoneDepth = Mathf.Max(m_DeadZoneDepth, 0); + + m_GroupFramingSize = Mathf.Max(Epsilon, m_GroupFramingSize); + m_MaxDollyIn = Mathf.Max(0, m_MaxDollyIn); + m_MaxDollyOut = Mathf.Max(0, m_MaxDollyOut); + m_MinimumDistance = Mathf.Max(0, m_MinimumDistance); + m_MaximumDistance = Mathf.Max(m_MinimumDistance, m_MaximumDistance); + m_MinimumFOV = Mathf.Max(1, m_MinimumFOV); + m_MaximumFOV = Mathf.Clamp(m_MaximumFOV, m_MinimumFOV, 179); + m_MinimumOrthoSize = Mathf.Max(0.01f, m_MinimumOrthoSize); + m_MaximumOrthoSize = Mathf.Max(m_MinimumOrthoSize, m_MaximumOrthoSize); + } + +#if UNITY_EDITOR + private void OnGUI() { if (OnGUICallback != null) OnGUICallback(); } +#endif + + /// <summary>True if component is enabled and has a valid Follow target</summary> + public override bool IsValid { get { return enabled && FollowTarget != null && LookAtTarget == null; } } + + /// <summary>Get the Cinemachine Pipeline stage that this component implements. + /// Always returns the Body stage</summary> + public override CinemachineCore.Stage Stage { get { return CinemachineCore.Stage.Body; } } + + const float kMinimumCameraDistance = 0.01f; + + /// <summary>State information for damping</summary> + Vector3 m_PreviousCameraPosition = Vector3.zero; + PositionPredictor m_Predictor = new PositionPredictor(); + + /// <summary>Internal API for inspector</summary> + public Vector3 TrackedPoint { get; private set; } + + /// <summary>Positions the virtual camera according to the transposer rules.</summary> + /// <param name="curState">The current camera state</param> + /// <param name="deltaTime">Used for damping. If less than 0, no damping is done.</param> + public override void MutateCameraState(ref CameraState curState, float deltaTime) + { + if (deltaTime < 0) + { + m_Predictor.Reset(); + m_PreviousCameraPosition = curState.RawPosition + + (curState.RawOrientation * Vector3.back) * m_CameraDistance; + } + if (!IsValid) + return; + + //UnityEngine.Profiling.Profiler.BeginSample("CinemachineFramingTransposer.MutateCameraState"); + Vector3 camPosWorld = m_PreviousCameraPosition; + curState.ReferenceLookAt = FollowTarget.position; + m_Predictor.Smoothing = m_LookaheadSmoothing; + m_Predictor.AddPosition(curState.ReferenceLookAt); + TrackedPoint = (m_LookaheadTime > 0) + ? m_Predictor.PredictPosition(m_LookaheadTime) : curState.ReferenceLookAt; + + // Work in camera-local space + Quaternion localToWorld = curState.RawOrientation; + Quaternion worldToLocal = Quaternion.Inverse(localToWorld); + Vector3 cameraPos = worldToLocal * camPosWorld; + Vector3 targetPos = (worldToLocal * TrackedPoint) - cameraPos; + + // Move along camera z + Vector3 cameraOffset = Vector3.zero; + float cameraMin = Mathf.Max(kMinimumCameraDistance, m_CameraDistance - m_DeadZoneDepth/2); + float cameraMax = Mathf.Max(cameraMin, m_CameraDistance + m_DeadZoneDepth/2); + if (targetPos.z < cameraMin) + cameraOffset.z = targetPos.z - cameraMin; + if (targetPos.z > cameraMax) + cameraOffset.z = targetPos.z - cameraMax; + + // Adjust for group framing + CinemachineTargetGroup group = TargetGroup; + if (group != null && m_GroupFramingMode != FramingMode.None) + cameraOffset.z += AdjustCameraDepthAndLensForGroupFraming( + group, targetPos.z - cameraOffset.z, ref curState, deltaTime); + + // Move along the XY plane + targetPos.z -= cameraOffset.z; + float screenSize = curState.Lens.Orthographic + ? curState.Lens.OrthographicSize + : Mathf.Tan(0.5f * curState.Lens.FieldOfView * Mathf.Deg2Rad) * targetPos.z; + Rect softGuideOrtho = ScreenToOrtho(SoftGuideRect, screenSize, curState.Lens.Aspect); + if (deltaTime < 0) + { + // No damping or hard bounds, just snap to central bounds, skipping the soft zone + Rect rect = new Rect(softGuideOrtho.center, Vector2.zero); // Force to center + cameraOffset += OrthoOffsetToScreenBounds(targetPos, rect); + } + else + { + // Move it through the soft zone + cameraOffset += OrthoOffsetToScreenBounds(targetPos, softGuideOrtho); + + // Find where it intersects the hard zone + Vector3 hard = Vector3.zero; + if (!m_UnlimitedSoftZone) + { + Rect hardGuideOrtho = ScreenToOrtho(HardGuideRect, screenSize, curState.Lens.Aspect); + hard = OrthoOffsetToScreenBounds(targetPos, hardGuideOrtho); + float t = Mathf.Max(hard.x / (cameraOffset.x + Epsilon), hard.y / (cameraOffset.y + Epsilon)); + hard = cameraOffset * t; + } + // Apply damping, but only to the portion of the move that's inside the hard zone + cameraOffset = hard + Damper.Damp( + cameraOffset - hard, new Vector3(m_XDamping, m_YDamping, m_ZDamping), deltaTime); + } + curState.RawPosition = m_PreviousCameraPosition = localToWorld * (cameraPos + cameraOffset); + //UnityEngine.Profiling.Profiler.EndSample(); + } + + // Convert from screen coords to normalized orthographic distance coords + private Rect ScreenToOrtho(Rect rScreen, float orthoSize, float aspect) + { + Rect r = new Rect(); + r.yMax = 2 * orthoSize * ((1f-rScreen.yMin) - 0.5f); + r.yMin = 2 * orthoSize * ((1f-rScreen.yMax) - 0.5f); + r.xMin = 2 * orthoSize * aspect * (rScreen.xMin - 0.5f); + r.xMax = 2 * orthoSize * aspect * (rScreen.xMax - 0.5f); + return r; + } + + private Vector3 OrthoOffsetToScreenBounds(Vector3 targetPos2D, Rect screenRect) + { + // Bring it to the edge of screenRect, if outside. Leave it alone if inside. + Vector3 delta = Vector3.zero; + if (targetPos2D.x < screenRect.xMin) + delta.x += targetPos2D.x - screenRect.xMin; + if (targetPos2D.x > screenRect.xMax) + delta.x += targetPos2D.x - screenRect.xMax; + if (targetPos2D.y < screenRect.yMin) + delta.y += targetPos2D.y - screenRect.yMin; + if (targetPos2D.y > screenRect.yMax) + delta.y += targetPos2D.y - screenRect.yMax; + return delta; + } + + float m_prevTargetHeight; // State for frame damping + + /// <summary>For editor visulaization of the calculated bounding box of the group</summary> + public Bounds m_LastBounds { get; private set; } + + /// <summary>For editor visualization of the calculated bounding box of the group</summary> + public Matrix4x4 m_lastBoundsMatrix { get; private set; } + + /// <summary>Get Follow target as CinemachineTargetGroup, or null if target is not a group</summary> + public CinemachineTargetGroup TargetGroup + { + get + { + Transform follow = FollowTarget; + if (follow != null) + return follow.GetComponent<CinemachineTargetGroup>(); + return null; + } + } + + float AdjustCameraDepthAndLensForGroupFraming( + CinemachineTargetGroup group, float targetZ, + ref CameraState curState, float deltaTime) + { + float cameraOffset = 0; + + // Get the bounding box from that POV in view space, and find its height + Bounds bounds = group.BoundingBox; + Vector3 fwd = curState.RawOrientation * Vector3.forward; + m_lastBoundsMatrix = Matrix4x4.TRS( + bounds.center - (fwd * bounds.extents.magnitude), + curState.RawOrientation, Vector3.one); + m_LastBounds = group.GetViewSpaceBoundingBox(m_lastBoundsMatrix); + float targetHeight = GetTargetHeight(m_LastBounds); + + // Apply damping + if (deltaTime >= 0) + { + float delta = targetHeight - m_prevTargetHeight; + delta = Damper.Damp(delta, m_ZDamping, deltaTime); + targetHeight = m_prevTargetHeight + delta; + } + m_prevTargetHeight = targetHeight; + + // Move the camera + if (!curState.Lens.Orthographic && m_AdjustmentMode != AdjustmentMode.ZoomOnly) + { + // What distance would be needed to get the target height, at the current FOV + float desiredDistance + = targetHeight / (2f * Mathf.Tan(curState.Lens.FieldOfView * Mathf.Deg2Rad / 2f)); + + // target the near surface of the bounding box + desiredDistance += m_LastBounds.extents.z; + + // Clamp to respect min/max distance settings + desiredDistance = Mathf.Clamp( + desiredDistance, targetZ - m_MaxDollyIn, targetZ + m_MaxDollyOut); + desiredDistance = Mathf.Clamp(desiredDistance, m_MinimumDistance, m_MaximumDistance); + + // Apply + cameraOffset += desiredDistance - targetZ; + } + + // Apply zoom + if (curState.Lens.Orthographic || m_AdjustmentMode != AdjustmentMode.DollyOnly) + { + float nearBoundsDistance = (targetZ + cameraOffset) - m_LastBounds.extents.z; + float currentFOV = 179; + if (nearBoundsDistance > Epsilon) + currentFOV = 2f * Mathf.Atan(targetHeight / (2 * nearBoundsDistance)) * Mathf.Rad2Deg; + + LensSettings lens = curState.Lens; + lens.FieldOfView = Mathf.Clamp(currentFOV, m_MinimumFOV, m_MaximumFOV); + lens.OrthographicSize = Mathf.Clamp(targetHeight / 2, m_MinimumOrthoSize, m_MaximumOrthoSize); + curState.Lens = lens; + } + return -cameraOffset; + } + + float GetTargetHeight(Bounds b) + { + float framingSize = Mathf.Max(Epsilon, m_GroupFramingSize); + switch (m_GroupFramingMode) + { + case FramingMode.Horizontal: + return b.size.x / (framingSize * VcamState.Lens.Aspect); + case FramingMode.Vertical: + return b.size.y / framingSize; + default: + case FramingMode.HorizontalAndVertical: + return Mathf.Max( + b.size.x / (framingSize * VcamState.Lens.Aspect), + b.size.y / framingSize); + } + } + } +} diff --git a/Assets/Cinemachine/Base/Runtime/Components/CinemachineFramingTransposer.cs.meta b/Assets/Cinemachine/Base/Runtime/Components/CinemachineFramingTransposer.cs.meta new file mode 100644 index 0000000..c3713e2 --- /dev/null +++ b/Assets/Cinemachine/Base/Runtime/Components/CinemachineFramingTransposer.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 6ad980451443d70438faac0bc6c235a0 +timeCreated: 1502038595 +licenseType: Store +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Cinemachine/Base/Runtime/Components/CinemachineGroupComposer.cs b/Assets/Cinemachine/Base/Runtime/Components/CinemachineGroupComposer.cs new file mode 100644 index 0000000..fc59a4a --- /dev/null +++ b/Assets/Cinemachine/Base/Runtime/Components/CinemachineGroupComposer.cs @@ -0,0 +1,237 @@ +using UnityEngine; +using Cinemachine.Utility; + +namespace Cinemachine +{ + /// <summary> + /// This is a CinemachineComponent in the Aim section of the component pipeline. + /// Its job is to aim the camera at a target object, with configurable offsets, damping, + /// and composition rules. + /// + /// In addition, if the target is a CinemachineTargetGroup, the behaviour + /// will adjust the FOV and the camera distance to ensure that the entire group of targets + /// is framed properly. + /// </summary> + [DocumentationSorting(4, DocumentationSortingAttribute.Level.UserRef)] + [ExecuteInEditMode] // for OnGUI + [AddComponentMenu("")] // Don't display in add component menu + [RequireComponent(typeof(CinemachinePipeline))] + [SaveDuringPlay] + public class CinemachineGroupComposer : CinemachineComposer + { + /// <summary>How much of the screen to fill with the bounding box of the targets.</summary> + [Space] + [Tooltip("The bounding box of the targets should occupy this amount of the screen space. 1 means fill the whole screen. 0.5 means fill half the screen, etc.")] + public float m_GroupFramingSize = 0.8f; + + /// <summary>What screen dimensions to consider when framing</summary> + [DocumentationSorting(4.01f, DocumentationSortingAttribute.Level.UserRef)] + public enum FramingMode + { + /// <summary>Consider only the horizontal dimension. Vertical framing is ignored.</summary> + Horizontal, + /// <summary>Consider only the vertical dimension. Horizontal framing is ignored.</summary> + Vertical, + /// <summary>The larger of the horizontal and vertical dimensions will dominate, to get the best fit.</summary> + HorizontalAndVertical + }; + + /// <summary>What screen dimensions to consider when framing</summary> + [Tooltip("What screen dimensions to consider when framing. Can be Horizontal, Vertical, or both")] + public FramingMode m_FramingMode = FramingMode.HorizontalAndVertical; + + /// <summary>How aggressively the camera tries to frame the group. + /// Small numbers are more responsive</summary> + [Range(0, 20)] + [Tooltip("How aggressively the camera tries to frame the group. Small numbers are more responsive, rapidly adjusting the camera to keep the group in the frame. Larger numbers give a more heavy slowly responding camera.")] + public float m_FrameDamping = 2f; + + /// <summary>How to adjust the camera to get the desired framing</summary> + public enum AdjustmentMode + { + /// <summary>Do not move the camera, only adjust the FOV.</summary> + ZoomOnly, + /// <summary>Just move the camera, don't change the FOV.</summary> + DollyOnly, + /// <summary>Move the camera as much as permitted by the ranges, then + /// adjust the FOV if necessary to make the shot.</summary> + DollyThenZoom + }; + + /// <summary>How to adjust the camera to get the desired framing</summary> + [Tooltip("How to adjust the camera to get the desired framing. You can zoom, dolly in/out, or do both.")] + public AdjustmentMode m_AdjustmentMode = AdjustmentMode.DollyThenZoom; + + /// <summary>How much closer to the target can the camera go?</summary> + [Tooltip("The maximum distance toward the target that this behaviour is allowed to move the camera.")] + public float m_MaxDollyIn = 5000f; + + /// <summary>How much farther from the target can the camera go?</summary> + [Tooltip("The maximum distance away the target that this behaviour is allowed to move the camera.")] + public float m_MaxDollyOut = 5000f; + + /// <summary>Set this to limit how close to the target the camera can get</summary> + [Tooltip("Set this to limit how close to the target the camera can get.")] + public float m_MinimumDistance = 1; + + /// <summary>Set this to limit how far from the taregt the camera can get</summary> + [Tooltip("Set this to limit how far from the target the camera can get.")] + public float m_MaximumDistance = 5000f; + + /// <summary>If adjusting FOV, will not set the FOV lower than this</summary> + [Range(1, 179)] + [Tooltip("If adjusting FOV, will not set the FOV lower than this.")] + public float m_MinimumFOV = 3; + + /// <summary>If adjusting FOV, will not set the FOV higher than this</summary> + [Range(1, 179)] + [Tooltip("If adjusting FOV, will not set the FOV higher than this.")] + public float m_MaximumFOV = 60; + + /// <summary>If adjusting Orthographic Size, will not set it lower than this</summary> + [Tooltip("If adjusting Orthographic Size, will not set it lower than this.")] + public float m_MinimumOrthoSize = 1; + + /// <summary>If adjusting Orthographic Size, will not set it higher than this</summary> + [Tooltip("If adjusting Orthographic Size, will not set it higher than this.")] + public float m_MaximumOrthoSize = 100; + + private void OnValidate() + { + m_GroupFramingSize = Mathf.Max(Epsilon, m_GroupFramingSize); + m_MaxDollyIn = Mathf.Max(0, m_MaxDollyIn); + m_MaxDollyOut = Mathf.Max(0, m_MaxDollyOut); + m_MinimumDistance = Mathf.Max(0, m_MinimumDistance); + m_MaximumDistance = Mathf.Max(m_MinimumDistance, m_MaximumDistance); + m_MinimumFOV = Mathf.Max(1, m_MinimumFOV); + m_MaximumFOV = Mathf.Clamp(m_MaximumFOV, m_MinimumFOV, 179); + m_MinimumOrthoSize = Mathf.Max(0.01f, m_MinimumOrthoSize); + m_MaximumOrthoSize = Mathf.Max(m_MinimumOrthoSize, m_MaximumOrthoSize); + } + + /// <summary>Get LookAt target as CinemachineTargetGroup, or null if target is not a group</summary> + public CinemachineTargetGroup TargetGroup + { + get + { + Transform lookAt = LookAtTarget; + if (lookAt != null) + return lookAt.GetComponent<CinemachineTargetGroup>(); + return null; + } + } + + /// <summary>Applies the composer rules and orients the camera accordingly</summary> + /// <param name="state">The current camera state</param> + /// <param name="deltaTime">Used for calculating damping. If less than + /// zero, then target will snap to the center of the dead zone.</param> + public override void MutateCameraState(ref CameraState curState, float deltaTime) + { + // Can't do anything without a group to look at + CinemachineTargetGroup group = TargetGroup; + if (group == null) + { + base.MutateCameraState(ref curState, deltaTime); + return; + } + + if (!IsValid || !curState.HasLookAt) + { + m_prevTargetHeight = 0; + return; + } + + curState.ReferenceLookAt = GetLookAtPointAndSetTrackedPoint(group.transform.position); + Vector3 currentOffset = TrackedPoint - curState.RawPosition; + float currentDistance = currentOffset.magnitude; + if (currentDistance < Epsilon) + return; // navel-gazing, get outa here + + //UnityEngine.Profiling.Profiler.BeginSample("CinemachineGroupComposer.MutateCameraState"); + + // Get the camera axis + Vector3 fwd = currentOffset.AlmostZero() ? Vector3.forward : currentOffset.normalized; + + // Get the bounding box from that POV in view space, and find its width + Bounds bounds = group.BoundingBox; + m_lastBoundsMatrix = Matrix4x4.TRS( + bounds.center - (fwd * bounds.extents.magnitude), + Quaternion.LookRotation(fwd, curState.ReferenceUp), Vector3.one); + m_LastBounds = group.GetViewSpaceBoundingBox(m_lastBoundsMatrix); + float targetHeight = GetTargetHeight(m_LastBounds); + Vector3 targetPos = m_lastBoundsMatrix.MultiplyPoint3x4(m_LastBounds.center); + + // Apply damping + if (deltaTime >= 0) + { + float delta = targetHeight - m_prevTargetHeight; + delta = Damper.Damp(delta, m_FrameDamping, deltaTime); + targetHeight = m_prevTargetHeight + delta; + } + m_prevTargetHeight = targetHeight; + + // Move the camera + if (!curState.Lens.Orthographic && m_AdjustmentMode != AdjustmentMode.ZoomOnly) + { + // What distance would be needed to get the target height, at the current FOV + float currentFOV = curState.Lens.FieldOfView; + float targetDistance = targetHeight / (2f * Mathf.Tan(currentFOV * Mathf.Deg2Rad / 2f)); + + // target the near surface of the bounding box + float cameraDistance = targetDistance + m_LastBounds.extents.z; + + // Clamp to respect min/max distance settings + cameraDistance = Mathf.Clamp( + cameraDistance, currentDistance - m_MaxDollyIn, currentDistance + m_MaxDollyOut); + cameraDistance = Mathf.Clamp(cameraDistance, m_MinimumDistance, m_MaximumDistance); + + // Apply + curState.PositionCorrection += targetPos - fwd * cameraDistance - curState.RawPosition; + } + + // Apply zoom + if (curState.Lens.Orthographic || m_AdjustmentMode != AdjustmentMode.DollyOnly) + { + float nearBoundsDistance = (TrackedPoint - curState.CorrectedPosition).magnitude + - m_LastBounds.extents.z; + float currentFOV = 179; + if (nearBoundsDistance > Epsilon) + currentFOV = 2f * Mathf.Atan(targetHeight / (2 * nearBoundsDistance)) * Mathf.Rad2Deg; + + LensSettings lens = curState.Lens; + lens.FieldOfView = Mathf.Clamp(currentFOV, m_MinimumFOV, m_MaximumFOV); + lens.OrthographicSize = Mathf.Clamp(targetHeight / 2, m_MinimumOrthoSize, m_MaximumOrthoSize); + curState.Lens = lens; + } + + // Now compose normally + base.MutateCameraState(ref curState, deltaTime); + //UnityEngine.Profiling.Profiler.EndSample(); + } + + float m_prevTargetHeight; // State for damping + + /// <summary>For editor visulaization of the calculated bounding box of the group</summary> + public Bounds m_LastBounds { get; private set; } + + /// <summary>For editor visualization of the calculated bounding box of the group</summary> + public Matrix4x4 m_lastBoundsMatrix { get; private set; } + + float GetTargetHeight(Bounds b) + { + float framingSize = Mathf.Max(Epsilon, m_GroupFramingSize); + switch (m_FramingMode) + { + case FramingMode.Horizontal: + return Mathf.Max(Epsilon, b.size.x )/ (framingSize * VcamState.Lens.Aspect); + case FramingMode.Vertical: + return Mathf.Max(Epsilon, b.size.y) / framingSize; + default: + case FramingMode.HorizontalAndVertical: + return Mathf.Max( + Mathf.Max(Epsilon, b.size.x) / (framingSize * VcamState.Lens.Aspect), + Mathf.Max(Epsilon, b.size.y) / framingSize); + } + } + } +} diff --git a/Assets/Cinemachine/Base/Runtime/Components/CinemachineGroupComposer.cs.meta b/Assets/Cinemachine/Base/Runtime/Components/CinemachineGroupComposer.cs.meta new file mode 100644 index 0000000..e0738cd --- /dev/null +++ b/Assets/Cinemachine/Base/Runtime/Components/CinemachineGroupComposer.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 0f7633c93f0364a418841eeb8b058634 +timeCreated: 1496696780 +licenseType: Store +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Cinemachine/Base/Runtime/Components/CinemachineHardLockToTarget.cs b/Assets/Cinemachine/Base/Runtime/Components/CinemachineHardLockToTarget.cs new file mode 100644 index 0000000..e53ed32 --- /dev/null +++ b/Assets/Cinemachine/Base/Runtime/Components/CinemachineHardLockToTarget.cs @@ -0,0 +1,33 @@ +using UnityEngine; + +namespace Cinemachine +{ + /// <summary> + /// This is a CinemachineComponent in the Aim section of the component pipeline. + /// Its job is to place the camera on the Follow Target. + /// </summary> + [DocumentationSorting(23, DocumentationSortingAttribute.Level.UserRef)] + [AddComponentMenu("")] // Don't display in add component menu + [RequireComponent(typeof(CinemachinePipeline))] + [SaveDuringPlay] + public class CinemachineHardLockToTarget : CinemachineComponentBase + { + /// <summary>True if component is enabled and has a LookAt defined</summary> + public override bool IsValid { get { return enabled && FollowTarget != null; } } + + /// <summary>Get the Cinemachine Pipeline stage that this component implements. + /// Always returns the Aim stage</summary> + public override CinemachineCore.Stage Stage { get { return CinemachineCore.Stage.Body; } } + + /// <summary>Applies the composer rules and orients the camera accordingly</summary> + /// <param name="curState">The current camera state</param> + /// <param name="deltaTime">Used for calculating damping. If less than + /// zero, then target will snap to the center of the dead zone.</param> + public override void MutateCameraState(ref CameraState curState, float deltaTime) + { + if (IsValid) + curState.RawPosition = FollowTarget.position; + } + } +} + diff --git a/Assets/Cinemachine/Base/Runtime/Components/CinemachineHardLockToTarget.cs.meta b/Assets/Cinemachine/Base/Runtime/Components/CinemachineHardLockToTarget.cs.meta new file mode 100644 index 0000000..da28d51 --- /dev/null +++ b/Assets/Cinemachine/Base/Runtime/Components/CinemachineHardLockToTarget.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 36d1163fa822e8b418a0a603ec078d5c +timeCreated: 1506531396 +licenseType: Store +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Cinemachine/Base/Runtime/Components/CinemachineHardLookAt.cs b/Assets/Cinemachine/Base/Runtime/Components/CinemachineHardLookAt.cs new file mode 100644 index 0000000..dfb3855 --- /dev/null +++ b/Assets/Cinemachine/Base/Runtime/Components/CinemachineHardLookAt.cs @@ -0,0 +1,42 @@ +using UnityEngine; + +namespace Cinemachine +{ + /// <summary> + /// This is a CinemachineComponent in the Aim section of the component pipeline. + /// Its job is to aim the camera hard at the LookAt target. + /// </summary> + [DocumentationSorting(23, DocumentationSortingAttribute.Level.UserRef)] + [AddComponentMenu("")] // Don't display in add component menu + [RequireComponent(typeof(CinemachinePipeline))] + [SaveDuringPlay] + public class CinemachineHardLookAt : CinemachineComponentBase + { + /// <summary>True if component is enabled and has a LookAt defined</summary> + public override bool IsValid { get { return enabled && LookAtTarget != null; } } + + /// <summary>Get the Cinemachine Pipeline stage that this component implements. + /// Always returns the Aim stage</summary> + public override CinemachineCore.Stage Stage { get { return CinemachineCore.Stage.Aim; } } + + /// <summary>Applies the composer rules and orients the camera accordingly</summary> + /// <param name="curState">The current camera state</param> + /// <param name="deltaTime">Used for calculating damping. If less than + /// zero, then target will snap to the center of the dead zone.</param> + public override void MutateCameraState(ref CameraState curState, float deltaTime) + { + if (IsValid && curState.HasLookAt) + { + Vector3 dir = (curState.ReferenceLookAt - curState.CorrectedPosition); + if (dir.magnitude > Epsilon) + { + if (Vector3.Cross(dir.normalized, curState.ReferenceUp).magnitude < Epsilon) + curState.RawOrientation = Quaternion.FromToRotation(Vector3.forward, dir); + else + curState.RawOrientation = Quaternion.LookRotation(dir, curState.ReferenceUp); + } + } + } + } +} + diff --git a/Assets/Cinemachine/Base/Runtime/Components/CinemachineHardLookAt.cs.meta b/Assets/Cinemachine/Base/Runtime/Components/CinemachineHardLookAt.cs.meta new file mode 100644 index 0000000..6330854 --- /dev/null +++ b/Assets/Cinemachine/Base/Runtime/Components/CinemachineHardLookAt.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 1e8b78ac948f05a46a6d8339a503172b +timeCreated: 1506531396 +licenseType: Store +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Cinemachine/Base/Runtime/Components/CinemachineOrbitalTransposer.cs b/Assets/Cinemachine/Base/Runtime/Components/CinemachineOrbitalTransposer.cs new file mode 100644 index 0000000..b0363d4 --- /dev/null +++ b/Assets/Cinemachine/Base/Runtime/Components/CinemachineOrbitalTransposer.cs @@ -0,0 +1,530 @@ +using System; +using UnityEngine; +using Cinemachine.Utility; +using UnityEngine.Serialization; + +namespace Cinemachine +{ + /// <summary> + /// This is a CinemachineComponent in the the Body section of the component pipeline. + /// Its job is to position the camera in a variable relationship to a the vcam's + /// Follow target object, with offsets and damping. + /// + /// This component is typically used to implement a camera that follows its target. + /// It can accept player input from an input device, which allows the player to + /// dynamically control the relationship between the camera and the target, + /// for example with a joystick. + /// + /// The OrbitalTransposer introduces the concept of __Heading__, which is the direction + /// in which the target is moving, and the OrbitalTransposer will attempt to position + /// the camera in relationship to the heading, which is by default directly behind the target. + /// You can control the default relationship by adjusting the Heading Bias setting. + /// + /// If you attach an input controller to the OrbitalTransposer, then the player can also + /// control the way the camera positions itself in relation to the target heading. This allows + /// the camera to move to any spot on an orbit around the target. + /// </summary> + [DocumentationSorting(6, DocumentationSortingAttribute.Level.UserRef)] + [AddComponentMenu("")] // Don't display in add component menu + [RequireComponent(typeof(CinemachinePipeline))] + [SaveDuringPlay] + public class CinemachineOrbitalTransposer : CinemachineTransposer + { + /// <summary> + /// How the "forward" direction is defined. Orbital offset is in relation to the forward + /// direction. + /// </summary> + [DocumentationSorting(6.2f, DocumentationSortingAttribute.Level.UserRef)] + [Serializable] + public struct Heading + { + /// <summary> + /// Sets the algorithm for determining the target's heading for purposes + /// of re-centering the camera + /// </summary> + [DocumentationSorting(6.21f, DocumentationSortingAttribute.Level.UserRef)] + public enum HeadingDefinition + { + /// <summary> + /// Target heading calculated from the difference between its position on + /// the last update and current frame. + /// </summary> + PositionDelta, + /// <summary> + /// Target heading calculated from its <b>Rigidbody</b>'s velocity. + /// If no <b>Rigidbody</b> exists, it will fall back + /// to HeadingDerivationMode.PositionDelta + /// </summary> + Velocity, + /// <summary> + /// Target heading calculated from the Target <b>Transform</b>'s euler Y angle + /// </summary> + TargetForward, + /// <summary> + /// Default heading is a constant world space heading. + /// </summary> + WorldForward, + } + /// <summary>The method by which the 'default heading' is calculated if + /// recentering to target heading is enabled</summary> + [Tooltip("How 'forward' is defined. The camera will be placed by default behind the target. PositionDelta will consider 'forward' to be the direction in which the target is moving.")] + public HeadingDefinition m_HeadingDefinition; + + /// <summary>Size of the velocity sampling window for target heading filter. + /// Used only if deriving heading from target's movement</summary> + [Range(0, 10)] + [Tooltip("Size of the velocity sampling window for target heading filter. This filters out irregularities in the target's movement. Used only if deriving heading from target's movement (PositionDelta or Velocity)")] + public int m_VelocityFilterStrength; + + /// <summary>Additional Y rotation applied to the target heading. + /// When this value is 0, the camera will be placed behind the target</summary> + [Range(-180f, 180f)] + [Tooltip("Where the camera is placed when the X-axis value is zero. This is a rotation in degrees around the Y axis. When this value is 0, the camera will be placed behind the target. Nonzero offsets will rotate the zero position around the target.")] + public float m_HeadingBias; + + /// <summary>Constructor</summary> + public Heading(HeadingDefinition def, int filterStrength, float bias) + { + m_HeadingDefinition = def; + m_VelocityFilterStrength = filterStrength; + m_HeadingBias = bias; + } + }; + + /// <summary>The definition of Forward. Camera will follow behind.</summary> + [Space] + [Tooltip("The definition of Forward. Camera will follow behind.")] + public Heading m_Heading = new Heading(Heading.HeadingDefinition.TargetForward, 4, 0); + + /// <summary>Controls how automatic orbit recentering occurs</summary> + [DocumentationSorting(6.5f, DocumentationSortingAttribute.Level.UserRef)] + [Serializable] + public struct Recentering + { + /// <summary>If checked, will enable automatic recentering of the + /// camera based on the heading calculation mode. If FALSE, recenting is disabled.</summary> + [Tooltip("If checked, will enable automatic recentering of the camera based on the heading definition. If unchecked, recenting is disabled.")] + public bool m_enabled; + + /// <summary>If no input has been detected, the camera will wait + /// this long in seconds before moving its heading to the default heading.</summary> + [Tooltip("If no input has been detected, the camera will wait this long in seconds before moving its heading to the zero position.")] + public float m_RecenterWaitTime; + + /// <summary>Maximum angular speed of recentering. Will accelerate into and decelerate out of this</summary> + [Tooltip("Maximum angular speed of recentering. Will accelerate into and decelerate out of this.")] + public float m_RecenteringTime; + + /// <summary>Constructor with specific field values</summary> + public Recentering(bool enabled, float recenterWaitTime, float recenteringSpeed) + { + m_enabled = enabled; + m_RecenterWaitTime = recenterWaitTime; + m_RecenteringTime = recenteringSpeed; + m_LegacyHeadingDefinition = m_LegacyVelocityFilterStrength = -1; + } + + /// <summary>Call this from OnValidate()</summary> + public void Validate() + { + m_RecenterWaitTime = Mathf.Max(0, m_RecenterWaitTime); + m_RecenteringTime = Mathf.Max(0, m_RecenteringTime); + } + + // Legacy support + [SerializeField] [HideInInspector] [FormerlySerializedAs("m_HeadingDefinition")] private int m_LegacyHeadingDefinition; + [SerializeField] [HideInInspector] [FormerlySerializedAs("m_VelocityFilterStrength")] private int m_LegacyVelocityFilterStrength; + internal bool LegacyUpgrade(ref Heading.HeadingDefinition heading, ref int velocityFilter) + { + if (m_LegacyHeadingDefinition != -1 && m_LegacyVelocityFilterStrength != -1) + { + heading = (Heading.HeadingDefinition)m_LegacyHeadingDefinition; + velocityFilter = m_LegacyVelocityFilterStrength; + m_LegacyHeadingDefinition = m_LegacyVelocityFilterStrength = -1; + return true; + } + return false; + } + }; + + /// <summary>Parameters that control Automating Heading Recentering</summary> + [Tooltip("Automatic heading recentering. The settings here defines how the camera will reposition itself in the absence of player input.")] + public Recentering m_RecenterToTargetHeading = new Recentering(true, 1, 2); + + /// <summary>Axis representing the current heading. Value is in degrees + /// and represents a rotation about the up vector</summary> + [Tooltip("Heading Control. The settings here control the behaviour of the camera in response to the player's input.")] + public AxisState m_XAxis = new AxisState(300f, 2f, 1f, 0f, "Mouse X", true); + + // Legacy support + [SerializeField] [HideInInspector] [FormerlySerializedAs("m_Radius")] private float m_LegacyRadius = float.MaxValue; + [SerializeField] [HideInInspector] [FormerlySerializedAs("m_HeightOffset")] private float m_LegacyHeightOffset = float.MaxValue; + [SerializeField] [HideInInspector] [FormerlySerializedAs("m_HeadingBias")] private float m_LegacyHeadingBias = float.MaxValue; + protected override void OnValidate() + { + // Upgrade after a legacy deserialize + if (m_LegacyRadius != float.MaxValue + && m_LegacyHeightOffset != float.MaxValue + && m_LegacyHeadingBias != float.MaxValue) + { + m_FollowOffset = new Vector3(0, m_LegacyHeightOffset, -m_LegacyRadius); + m_LegacyHeightOffset = m_LegacyRadius = float.MaxValue; + + m_Heading.m_HeadingBias = m_LegacyHeadingBias; + m_XAxis.m_MaxSpeed /= 10; + m_XAxis.m_AccelTime /= 10; + m_XAxis.m_DecelTime /= 10; + m_LegacyHeadingBias = float.MaxValue; + m_RecenterToTargetHeading.LegacyUpgrade( + ref m_Heading.m_HeadingDefinition, ref m_Heading.m_VelocityFilterStrength); + } + m_XAxis.Validate(); + m_RecenterToTargetHeading.Validate(); + + base.OnValidate(); + } + + /// <summary> + /// Drive the x-axis setting programmatically. + /// Automatic heading updating will be disabled. + /// </summary> + [HideInInspector, NoSaveDuringPlay] + public bool m_HeadingIsSlave = false; + + /// <summary> + /// Delegate that allows the the m_XAxis object to be replaced with another one. + /// </summary> + internal delegate float UpdateHeadingDelegate( + CinemachineOrbitalTransposer orbital, float deltaTime, Vector3 up); + + /// <summary> + /// Delegate that allows the the XAxis object to be replaced with another one. + /// To use it, just call orbital.UpdateHeading() with a reference to a + /// private AxisState object, and that AxisState object will be updated and + /// used to calculate the heading. + /// </summary> + internal UpdateHeadingDelegate HeadingUpdater + = (CinemachineOrbitalTransposer orbital, float deltaTime, Vector3 up) + => { return orbital.UpdateHeading(deltaTime, up, ref orbital.m_XAxis); }; + + /// <summary> + /// Update the X axis and calculate the heading. This can be called by a delegate + /// with a custom axis. + /// <param name="deltaTime">Used for damping. If less than 0, no damping is done.</param> + /// <param name="up">World Up, set by the CinemachineBrain</param> + /// <param name="axis"></param> + /// <returns>Axis value</returns> + /// </summary> + public float UpdateHeading(float deltaTime, Vector3 up, ref AxisState axis) + { + // Only read joystick when game is playing + if (deltaTime >= 0 || CinemachineCore.Instance.IsLive(VirtualCamera)) + { + bool xAxisInput = false; + xAxisInput |= axis.Update(deltaTime); + if (xAxisInput) + { + mLastHeadingAxisInputTime = Time.time; + mHeadingRecenteringVelocity = 0; + } + } + float targetHeading = GetTargetHeading(axis.Value, GetReferenceOrientation(up), deltaTime); + if (deltaTime < 0) + { + mHeadingRecenteringVelocity = 0; + if (m_RecenterToTargetHeading.m_enabled) + axis.Value = targetHeading; + } + else + { + // Recentering + if (m_BindingMode != BindingMode.SimpleFollowWithWorldUp + && m_RecenterToTargetHeading.m_enabled + && (Time.time > (mLastHeadingAxisInputTime + m_RecenterToTargetHeading.m_RecenterWaitTime))) + { + // Scale value determined heuristically, to account for accel/decel + float recenterTime = m_RecenterToTargetHeading.m_RecenteringTime / 3f; + if (recenterTime <= deltaTime) + axis.Value = targetHeading; + else + { + float headingError = Mathf.DeltaAngle(axis.Value, targetHeading); + float absHeadingError = Mathf.Abs(headingError); + if (absHeadingError < UnityVectorExtensions.Epsilon) + { + axis.Value = targetHeading; + mHeadingRecenteringVelocity = 0; + } + else + { + float scale = deltaTime / recenterTime; + float desiredVelocity = Mathf.Sign(headingError) + * Mathf.Min(absHeadingError, absHeadingError * scale); + // Accelerate to the desired velocity + float accel = desiredVelocity - mHeadingRecenteringVelocity; + if ((desiredVelocity < 0 && accel < 0) || (desiredVelocity > 0 && accel > 0)) + desiredVelocity = mHeadingRecenteringVelocity + desiredVelocity * scale; + axis.Value += desiredVelocity; + mHeadingRecenteringVelocity = desiredVelocity; + } + } + } + } + float finalHeading = axis.Value; + if (m_BindingMode == BindingMode.SimpleFollowWithWorldUp) + axis.Value = 0; + return finalHeading; + } + + private void OnEnable() + { + m_XAxis.SetThresholds(0f, 360f, true); + PreviousTarget = null; + mLastTargetPosition = Vector3.zero; + } + + private float mLastHeadingAxisInputTime = 0f; + private float mHeadingRecenteringVelocity = 0f; + private Vector3 mLastTargetPosition = Vector3.zero; + private HeadingTracker mHeadingTracker; + private Rigidbody mTargetRigidBody = null; + private Transform PreviousTarget { get; set; } + private Quaternion mHeadingPrevFrame = Quaternion.identity; + private Vector3 mOffsetPrevFrame = Vector3.zero; + + /// <summary>Positions the virtual camera according to the transposer rules.</summary> + /// <param name="curState">The current camera state</param> + /// <param name="deltaTime">Used for damping. If less than 0, no damping is done.</param> + public override void MutateCameraState(ref CameraState curState, float deltaTime) + { + //UnityEngine.Profiling.Profiler.BeginSample("CinemachineOrbitalTransposer.MutateCameraState"); + InitPrevFrameStateInfo(ref curState, deltaTime); + + // Update the heading + if (FollowTarget != PreviousTarget) + { + PreviousTarget = FollowTarget; + mTargetRigidBody = (PreviousTarget == null) ? null : PreviousTarget.GetComponent<Rigidbody>(); + mLastTargetPosition = (PreviousTarget == null) ? Vector3.zero : PreviousTarget.position; + mHeadingTracker = null; + } + float heading = HeadingUpdater(this, deltaTime, curState.ReferenceUp); + + if (IsValid) + { + mLastTargetPosition = FollowTarget.position; + + // Calculate the heading + if (m_BindingMode != BindingMode.SimpleFollowWithWorldUp) + heading += m_Heading.m_HeadingBias; + Quaternion headingRot = Quaternion.AngleAxis(heading, curState.ReferenceUp); + + // Track the target, with damping + Vector3 offset = EffectiveOffset; + Vector3 pos; + Quaternion orient; + TrackTarget(deltaTime, curState.ReferenceUp, headingRot * offset, out pos, out orient); + + // Place the camera + curState.ReferenceUp = orient * Vector3.up; + if (deltaTime >= 0) + { + Vector3 bypass = (headingRot * offset) - mHeadingPrevFrame * mOffsetPrevFrame; + bypass = orient * bypass; + curState.PositionDampingBypass = bypass; + } + orient = orient * headingRot; + curState.RawPosition = pos + orient * offset; + + mHeadingPrevFrame = (m_BindingMode == BindingMode.SimpleFollowWithWorldUp) ? Quaternion.identity : headingRot; + mOffsetPrevFrame = offset; + } + //UnityEngine.Profiling.Profiler.EndSample(); + } + + /// <summary>API for the editor, to process a position drag from the user. + /// This implementation adds the delta to the follow offset, after zeroing out local x.</summary> + /// <param name="delta">The amount dragged this frame</param> + public override void OnPositionDragged(Vector3 delta) + { + Quaternion targetOrientation = GetReferenceOrientation(VcamState.ReferenceUp); + Vector3 localOffset = Quaternion.Inverse(targetOrientation) * delta; + localOffset.x = 0; + m_FollowOffset += localOffset; + m_FollowOffset = EffectiveOffset; + } + + static string GetFullName(GameObject current) + { + if (current == null) + return ""; + if (current.transform.parent == null) + return "/" + current.name; + return GetFullName(current.transform.parent.gameObject) + "/" + current.name; + } + + // Make sure this is calld only once per frame + private float GetTargetHeading( + float currentHeading, Quaternion targetOrientation, float deltaTime) + { + if (m_BindingMode == BindingMode.SimpleFollowWithWorldUp) + return 0; + if (FollowTarget == null) + return currentHeading; + + if (m_Heading.m_HeadingDefinition == Heading.HeadingDefinition.Velocity + && mTargetRigidBody == null) + { + Debug.Log(string.Format( + "Attempted to use HeadingDerivationMode.Velocity to calculate heading for {0}. No RigidBody was present on '{1}'. Defaulting to position delta", + GetFullName(VirtualCamera.VirtualCameraGameObject), FollowTarget)); + m_Heading.m_HeadingDefinition = Heading.HeadingDefinition.PositionDelta; + } + + Vector3 velocity = Vector3.zero; + switch (m_Heading.m_HeadingDefinition) + { + case Heading.HeadingDefinition.PositionDelta: + velocity = FollowTarget.position - mLastTargetPosition; + break; + case Heading.HeadingDefinition.Velocity: + velocity = mTargetRigidBody.velocity; + break; + case Heading.HeadingDefinition.TargetForward: + velocity = FollowTarget.forward; + break; + default: + case Heading.HeadingDefinition.WorldForward: + return 0; + } + + // Process the velocity and derive the heading from it. + int filterSize = m_Heading.m_VelocityFilterStrength * 5; + if (mHeadingTracker == null || mHeadingTracker.FilterSize != filterSize) + mHeadingTracker = new HeadingTracker(filterSize); + mHeadingTracker.DecayHistory(); + Vector3 up = targetOrientation * Vector3.up; + velocity = velocity.ProjectOntoPlane(up); + if (!velocity.AlmostZero()) + mHeadingTracker.Add(velocity); + + velocity = mHeadingTracker.GetReliableHeading(); + if (!velocity.AlmostZero()) + return UnityVectorExtensions.SignedAngle(targetOrientation * Vector3.forward, velocity, up); + + // If no reliable heading, then stay where we are. + return currentHeading; + } + + class HeadingTracker + { + struct Item + { + public Vector3 velocity; + public float weight; + public float time; + }; + Item[] mHistory; + int mTop; + int mBottom; + int mCount; + + Vector3 mHeadingSum; + float mWeightSum = 0; + float mWeightTime = 0; + + Vector3 mLastGoodHeading = Vector3.zero; + + public HeadingTracker(int filterSize) + { + mHistory = new Item[filterSize]; + float historyHalfLife = filterSize / 5f; // somewhat arbitrarily + mDecayExponent = -Mathf.Log(2f) / historyHalfLife; + ClearHistory(); + } + + public int FilterSize { get { return mHistory.Length; } } + + void ClearHistory() + { + mTop = mBottom = mCount = 0; + mWeightSum = 0; + mHeadingSum = Vector3.zero; + } + + static float mDecayExponent; + static float Decay(float time) { return Mathf.Exp(time * mDecayExponent); } + + public void Add(Vector3 velocity) + { + if (FilterSize == 0) + { + mLastGoodHeading = velocity; + return; + } + float weight = velocity.magnitude; + if (weight > UnityVectorExtensions.Epsilon) + { + Item item = new Item(); + item.velocity = velocity; + item.weight = weight; + item.time = Time.time; + if (mCount == FilterSize) + PopBottom(); + ++mCount; + mHistory[mTop] = item; + if (++mTop == FilterSize) + mTop = 0; + + mWeightSum *= Decay(item.time - mWeightTime); + mWeightTime = item.time; + mWeightSum += weight; + mHeadingSum += item.velocity; + } + } + + void PopBottom() + { + if (mCount > 0) + { + float time = Time.time; + Item item = mHistory[mBottom]; + if (++mBottom == FilterSize) + mBottom = 0; + --mCount; + + float decay = Decay(time - item.time); + mWeightSum -= item.weight * decay; + mHeadingSum -= item.velocity * decay; + if (mWeightSum <= UnityVectorExtensions.Epsilon || mCount == 0) + ClearHistory(); + } + } + + public void DecayHistory() + { + float time = Time.time; + float decay = Decay(time - mWeightTime); + mWeightSum *= decay; + mWeightTime = time; + if (mWeightSum < UnityVectorExtensions.Epsilon) + ClearHistory(); + else + mHeadingSum = mHeadingSum * decay; + } + + public Vector3 GetReliableHeading() + { + // Update Last Good Heading + if (mWeightSum > UnityVectorExtensions.Epsilon + && (mCount == mHistory.Length || mLastGoodHeading.AlmostZero())) + { + Vector3 h = mHeadingSum / mWeightSum; + if (!h.AlmostZero()) + mLastGoodHeading = h.normalized; + } + return mLastGoodHeading; + } + } + } +} diff --git a/Assets/Cinemachine/Base/Runtime/Components/CinemachineOrbitalTransposer.cs.meta b/Assets/Cinemachine/Base/Runtime/Components/CinemachineOrbitalTransposer.cs.meta new file mode 100644 index 0000000..69fc527 --- /dev/null +++ b/Assets/Cinemachine/Base/Runtime/Components/CinemachineOrbitalTransposer.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 9384ab8608cdc3d479fe89cd51eed48f +timeCreated: 1485281954 +licenseType: Store +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Cinemachine/Base/Runtime/Components/CinemachinePOV.cs b/Assets/Cinemachine/Base/Runtime/Components/CinemachinePOV.cs new file mode 100644 index 0000000..ebd357d --- /dev/null +++ b/Assets/Cinemachine/Base/Runtime/Components/CinemachinePOV.cs @@ -0,0 +1,70 @@ +using UnityEngine; + +namespace Cinemachine +{ + /// <summary> + /// This is a CinemachineComponent in the Aim section of the component pipeline. + /// Its job is to aim the camera in response to the user's mouse or joystick input. + /// + /// The composer does not change the camera's position. It will only pan and tilt the + /// camera where it is, in order to get the desired framing. To move the camera, you have + /// to use the virtual camera's Body section. + /// </summary> + [DocumentationSorting(23, DocumentationSortingAttribute.Level.UserRef)] + [AddComponentMenu("")] // Don't display in add component menu + [RequireComponent(typeof(CinemachinePipeline))] + [SaveDuringPlay] + public class CinemachinePOV : CinemachineComponentBase + { + /// <summary>The Vertical axis. Value is -90..90. Controls the vertical orientation</summary> + [Tooltip("The Vertical axis. Value is -90..90. Controls the vertical orientation")] + public AxisState m_VerticalAxis = new AxisState(300f, 0.1f, 0.1f, 0f, "Mouse Y", true); + + /// <summary>The Horizontal axis. Value is -180..180. Controls the horizontal orientation</summary> + [Tooltip("The Horizontal axis. Value is -180..180. Controls the horizontal orientation")] + public AxisState m_HorizontalAxis = new AxisState(300f, 0.1f, 0.1f, 0f, "Mouse X", false); + + /// <summary>True if component is enabled and has a LookAt defined</summary> + public override bool IsValid { get { return enabled; } } + + /// <summary>Get the Cinemachine Pipeline stage that this component implements. + /// Always returns the Aim stage</summary> + public override CinemachineCore.Stage Stage { get { return CinemachineCore.Stage.Aim; } } + + private void OnValidate() + { + m_HorizontalAxis.Validate(); + m_VerticalAxis.Validate(); + } + + private void OnEnable() + { + m_HorizontalAxis.SetThresholds(-180f, 180f, true); + m_VerticalAxis.SetThresholds(-90, 90, false); + } + + /// <summary>Applies the axis values and orients the camera accordingly</summary> + /// <param name="curState">The current camera state</param> + /// <param name="deltaTime">Used for calculating damping. Not used.</param> + public override void MutateCameraState(ref CameraState curState, float deltaTime) + { + if (!IsValid) + return; + + //UnityEngine.Profiling.Profiler.BeginSample("CinemachinePOV.MutateCameraState"); + + // Only read joystick when game is playing + if (deltaTime >= 0 || CinemachineCore.Instance.IsLive(VirtualCamera)) + { + m_HorizontalAxis.Update(deltaTime); + m_VerticalAxis.Update(deltaTime); + } + Quaternion rot = Quaternion.Euler(m_VerticalAxis.Value, m_HorizontalAxis.Value, 0); + rot = rot * Quaternion.FromToRotation(Vector3.up, curState.ReferenceUp); + curState.OrientationCorrection = curState.OrientationCorrection * rot; + + //UnityEngine.Profiling.Profiler.EndSample(); + } + } +} + diff --git a/Assets/Cinemachine/Base/Runtime/Components/CinemachinePOV.cs.meta b/Assets/Cinemachine/Base/Runtime/Components/CinemachinePOV.cs.meta new file mode 100644 index 0000000..e673e0e --- /dev/null +++ b/Assets/Cinemachine/Base/Runtime/Components/CinemachinePOV.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 3c9beda531928fc40968802117a5d256 +timeCreated: 1504204894 +licenseType: Store +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Cinemachine/Base/Runtime/Components/CinemachineSameAsFollowObject.cs b/Assets/Cinemachine/Base/Runtime/Components/CinemachineSameAsFollowObject.cs new file mode 100644 index 0000000..9d1e410 --- /dev/null +++ b/Assets/Cinemachine/Base/Runtime/Components/CinemachineSameAsFollowObject.cs @@ -0,0 +1,33 @@ +using UnityEngine; + +namespace Cinemachine +{ + /// <summary> + /// This is a CinemachineComponent in the Aim section of the component pipeline. + /// Its job is to aim the camera hard at the LookAt target. + /// </summary> + [DocumentationSorting(27, DocumentationSortingAttribute.Level.UserRef)] + [AddComponentMenu("")] // Don't display in add component menu + [RequireComponent(typeof(CinemachinePipeline))] + [SaveDuringPlay] + public class CinemachineSameAsFollowObject : CinemachineComponentBase + { + /// <summary>True if component is enabled and has a Follow target defined</summary> + public override bool IsValid { get { return enabled && FollowTarget != null; } } + + /// <summary>Get the Cinemachine Pipeline stage that this component implements. + /// Always returns the Aim stage</summary> + public override CinemachineCore.Stage Stage { get { return CinemachineCore.Stage.Aim; } } + + /// <summary>Applies the composer rules and orients the camera accordingly</summary> + /// <param name="curState">The current camera state</param> + /// <param name="deltaTime">Used for calculating damping. If less than + /// zero, then target will snap to the center of the dead zone.</param> + public override void MutateCameraState(ref CameraState curState, float deltaTime) + { + if (IsValid) + curState.RawOrientation = FollowTarget.transform.rotation; + } + } +} + diff --git a/Assets/Cinemachine/Base/Runtime/Components/CinemachineSameAsFollowObject.cs.meta b/Assets/Cinemachine/Base/Runtime/Components/CinemachineSameAsFollowObject.cs.meta new file mode 100644 index 0000000..2309dcd --- /dev/null +++ b/Assets/Cinemachine/Base/Runtime/Components/CinemachineSameAsFollowObject.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: a4c41ac9245b87c4192012080077d830 +timeCreated: 1511551300 +licenseType: Store +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Cinemachine/Base/Runtime/Components/CinemachineTrackedDolly.cs b/Assets/Cinemachine/Base/Runtime/Components/CinemachineTrackedDolly.cs new file mode 100644 index 0000000..3ce9b14 --- /dev/null +++ b/Assets/Cinemachine/Base/Runtime/Components/CinemachineTrackedDolly.cs @@ -0,0 +1,312 @@ +using UnityEngine; +using System; +using Cinemachine.Utility; +using UnityEngine.Serialization; + +namespace Cinemachine +{ + /// <summary> + /// A Cinemachine Virtual Camera Body component that constrains camera motion + /// to a CinemachinePath. The camera can move along the path. + /// + /// This behaviour can operate in two modes: manual positioning, and Auto-Dolly positioning. + /// In Manual mode, the camera's position is specified by animating the Path Position field. + /// In Auto-Dolly mode, the Path Position field is animated automatically every frame by finding + /// the position on the path that's closest to the virtual camera's Follow target. + /// </summary> + [DocumentationSorting(7, DocumentationSortingAttribute.Level.UserRef)] + [AddComponentMenu("")] // Don't display in add component menu + [RequireComponent(typeof(CinemachinePipeline))] + [SaveDuringPlay] + public class CinemachineTrackedDolly : CinemachineComponentBase + { + /// <summary>The path to which the camera will be constrained. This must be non-null.</summary> + [Tooltip("The path to which the camera will be constrained. This must be non-null.")] + public CinemachinePathBase m_Path; + + /// <summary>The position along the path at which the camera will be placed. + /// This can be animated directly, or set automatically by the Auto-Dolly feature + /// to get as close as possible to the Follow target.</summary> + [Tooltip("The position along the path at which the camera will be placed. This can be animated directly, or set automatically by the Auto-Dolly feature to get as close as possible to the Follow target. The value is interpreted according to the Position Units setting.")] + public float m_PathPosition; + + /// <summary>How to interpret the Path Position</summary> + [Tooltip("How to interpret Path Position. If set to Path Units, values are as follows: 0 represents the first waypoint on the path, 1 is the second, and so on. Values in-between are points on the path in between the waypoints. If set to Distance, then Path Position represents distance along the path.")] + public CinemachinePathBase.PositionUnits m_PositionUnits = CinemachinePathBase.PositionUnits.PathUnits; + + /// <summary>Where to put the camera realtive to the path postion. X is perpendicular to the path, Y is up, and Z is parallel to the path.</summary> + [Tooltip("Where to put the camera relative to the path position. X is perpendicular to the path, Y is up, and Z is parallel to the path. This allows the camera to be offset from the path itself (as if on a tripod, for example).")] + public Vector3 m_PathOffset = Vector3.zero; + + /// <summary>How aggressively the camera tries to maintain the offset perpendicular to the path. + /// Small numbers are more responsive, rapidly translating the camera to keep the target's + /// x-axis offset. Larger numbers give a more heavy slowly responding camera. + /// Using different settings per axis can yield a wide range of camera behaviors</summary> + [Range(0f, 20f)] + [Tooltip("How aggressively the camera tries to maintain its position in a direction perpendicular to the path. Small numbers are more responsive, rapidly translating the camera to keep the target's x-axis offset. Larger numbers give a more heavy slowly responding camera. Using different settings per axis can yield a wide range of camera behaviors.")] + public float m_XDamping = 0f; + + /// <summary>How aggressively the camera tries to maintain the offset in the path-local up direction. + /// Small numbers are more responsive, rapidly translating the camera to keep the target's + /// y-axis offset. Larger numbers give a more heavy slowly responding camera. + /// Using different settings per axis can yield a wide range of camera behaviors</summary> + [Range(0f, 20f)] + [Tooltip("How aggressively the camera tries to maintain its position in the path-local up direction. Small numbers are more responsive, rapidly translating the camera to keep the target's y-axis offset. Larger numbers give a more heavy slowly responding camera. Using different settings per axis can yield a wide range of camera behaviors.")] + public float m_YDamping = 0f; + + /// <summary>How aggressively the camera tries to maintain the offset parallel to the path. + /// Small numbers are more responsive, rapidly translating the camera to keep the + /// target's z-axis offset. Larger numbers give a more heavy slowly responding camera. + /// Using different settings per axis can yield a wide range of camera behaviors</summary> + [Range(0f, 20f)] + [Tooltip("How aggressively the camera tries to maintain its position in a direction parallel to the path. Small numbers are more responsive, rapidly translating the camera to keep the target's z-axis offset. Larger numbers give a more heavy slowly responding camera. Using different settings per axis can yield a wide range of camera behaviors.")] + public float m_ZDamping = 1f; + + /// <summary>Different ways to set the camera's up vector</summary> + [DocumentationSorting(7.1f, DocumentationSortingAttribute.Level.UserRef)] + public enum CameraUpMode + { + /// <summary>Leave the camera's up vector alone. It will be set according to the Brain's WorldUp.</summary> + Default, + /// <summary>Take the up vector from the path's up vector at the current point</summary> + Path, + /// <summary>Take the up vector from the path's up vector at the current point, but with the roll zeroed out</summary> + PathNoRoll, + /// <summary>Take the up vector from the Follow target's up vector</summary> + FollowTarget, + /// <summary>Take the up vector from the Follow target's up vector, but with the roll zeroed out</summary> + FollowTargetNoRoll, + }; + + /// <summary>How to set the virtual camera's Up vector. This will affect the screen composition.</summary> + [Tooltip("How to set the virtual camera's Up vector. This will affect the screen composition, because the camera Aim behaviours will always try to respect the Up direction.")] + public CameraUpMode m_CameraUp = CameraUpMode.Default; + + /// <summary>"How aggressively the camera tries to track the target rotation's X angle. + /// Small numbers are more responsive. Larger numbers give a more heavy slowly responding camera.</summary> + [Range(0f, 20f)] + [Tooltip("How aggressively the camera tries to track the target rotation's X angle. Small numbers are more responsive. Larger numbers give a more heavy slowly responding camera.")] + public float m_PitchDamping = 0; + + /// <summary>How aggressively the camera tries to track the target rotation's Y angle. + /// Small numbers are more responsive. Larger numbers give a more heavy slowly responding camera.</summary> + [Range(0f, 20f)] + [Tooltip("How aggressively the camera tries to track the target rotation's Y angle. Small numbers are more responsive. Larger numbers give a more heavy slowly responding camera.")] + public float m_YawDamping = 0; + + /// <summary>How aggressively the camera tries to track the target rotation's Z angle. + /// Small numbers are more responsive. Larger numbers give a more heavy slowly responding camera.</summary> + [Range(0f, 20f)] + [Tooltip("How aggressively the camera tries to track the target rotation's Z angle. Small numbers are more responsive. Larger numbers give a more heavy slowly responding camera.")] + public float m_RollDamping = 0f; + + /// <summary>Controls how automatic dollying occurs</summary> + [DocumentationSorting(7.2f, DocumentationSortingAttribute.Level.UserRef)] + [Serializable] + public struct AutoDolly + { + /// <summary>If checked, will enable automatic dolly, which chooses a path position + /// that is as close as possible to the Follow target.</summary> + [Tooltip("If checked, will enable automatic dolly, which chooses a path position that is as close as possible to the Follow target. Note: this can have significant performance impact")] + public bool m_Enabled; + + /// <summary>Offset, in current position units, from the closest point on the path to the follow target.</summary> + [Tooltip("Offset, in current position units, from the closest point on the path to the follow target")] + public float m_PositionOffset; + + /// <summary>Search up to how many waypoints on either side of the current position. Use 0 for Entire path</summary> + [Tooltip("Search up to how many waypoints on either side of the current position. Use 0 for Entire path.")] + public int m_SearchRadius; + + /// <summary>We search between waypoints by dividing the segment into this many straight pieces. + /// The higher the number, the more accurate the result, but performance is + /// proportionally slower for higher numbers</summary> + [FormerlySerializedAs("m_StepsPerSegment")] + [Tooltip("We search between waypoints by dividing the segment into this many straight pieces. The higher the number, the more accurate the result, but performance is proportionally slower for higher numbers")] + public int m_SearchResolution; + + /// <summary>Constructor with specific field values</summary> + public AutoDolly(bool enabled, float positionOffset, int searchRadius, int stepsPerSegment) + { + m_Enabled = enabled; + m_PositionOffset = positionOffset; + m_SearchRadius = searchRadius; + m_SearchResolution = stepsPerSegment; + } + }; + + /// <summary>Controls how automatic dollying occurs</summary> + [Tooltip("Controls how automatic dollying occurs. A Follow target is necessary to use this feature.")] + public AutoDolly m_AutoDolly = new AutoDolly(false, 0, 2, 5); + + /// <summary>True if component is enabled and has a path</summary> + public override bool IsValid { get { return enabled && m_Path != null; } } + + /// <summary>Get the Cinemachine Pipeline stage that this component implements. + /// Always returns the Body stage</summary> + public override CinemachineCore.Stage Stage { get { return CinemachineCore.Stage.Body; } } + + /// <summary>Positions the virtual camera according to the transposer rules.</summary> + /// <param name="curState">The current camera state</param> + /// <param name="deltaTime">Used for damping. If less that 0, no damping is done.</param> + public override void MutateCameraState(ref CameraState curState, float deltaTime) + { + // Init previous frame state info + if (deltaTime < 0) + { + m_PreviousPathPosition = m_PathPosition; + m_PreviousCameraPosition = curState.RawPosition; + } + + if (!IsValid) + return; + + //UnityEngine.Profiling.Profiler.BeginSample("CinemachineTrackedDolly.MutateCameraState"); + // Get the new ideal path base position + if (m_AutoDolly.m_Enabled && FollowTarget != null) + { + float prevPos = m_PreviousPathPosition; + if (m_PositionUnits == CinemachinePathBase.PositionUnits.Distance) + prevPos = m_Path.GetPathPositionFromDistance(prevPos); + // This works in path units + m_PathPosition = m_Path.FindClosestPoint( + FollowTarget.transform.position, + Mathf.FloorToInt(prevPos), + (deltaTime < 0 || m_AutoDolly.m_SearchRadius <= 0) + ? -1 : m_AutoDolly.m_SearchRadius, + m_AutoDolly.m_SearchResolution); + if (m_PositionUnits == CinemachinePathBase.PositionUnits.Distance) + m_PathPosition = m_Path.GetPathDistanceFromPosition(m_PathPosition); + + // Apply the path position offset + m_PathPosition += m_AutoDolly.m_PositionOffset; + } + float newPathPosition = m_PathPosition; + + if (deltaTime >= 0) + { + // Normalize previous position to find the shortest path + float maxUnit = m_Path.MaxUnit(m_PositionUnits); + if (maxUnit > 0) + { + float prev = m_Path.NormalizeUnit(m_PreviousPathPosition, m_PositionUnits); + float next = m_Path.NormalizeUnit(newPathPosition, m_PositionUnits); + if (m_Path.Looped && Mathf.Abs(next - prev) > maxUnit / 2) + { + if (next > prev) + prev += maxUnit; + else + prev -= maxUnit; + } + m_PreviousPathPosition = prev; + newPathPosition = next; + } + + // Apply damping along the path direction + float offset = m_PreviousPathPosition - newPathPosition; + offset = Damper.Damp(offset, m_ZDamping, deltaTime); + newPathPosition = m_PreviousPathPosition - offset; + } + m_PreviousPathPosition = newPathPosition; + Quaternion newPathOrientation = m_Path.EvaluateOrientationAtUnit(newPathPosition, m_PositionUnits); + + // Apply the offset to get the new camera position + Vector3 newCameraPos = m_Path.EvaluatePositionAtUnit(newPathPosition, m_PositionUnits); + Vector3 offsetX = newPathOrientation * Vector3.right; + Vector3 offsetY = newPathOrientation * Vector3.up; + Vector3 offsetZ = newPathOrientation * Vector3.forward; + newCameraPos += m_PathOffset.x * offsetX; + newCameraPos += m_PathOffset.y * offsetY; + newCameraPos += m_PathOffset.z * offsetZ; + + // Apply damping to the remaining directions + if (deltaTime >= 0) + { + Vector3 currentCameraPos = m_PreviousCameraPosition; + Vector3 delta = (currentCameraPos - newCameraPos); + Vector3 delta1 = Vector3.Dot(delta, offsetY) * offsetY; + Vector3 delta0 = delta - delta1; + delta0 = Damper.Damp(delta0, m_XDamping, deltaTime); + delta1 = Damper.Damp(delta1, m_YDamping, deltaTime); + newCameraPos = currentCameraPos - (delta0 + delta1); + } + curState.RawPosition = m_PreviousCameraPosition = newCameraPos; + + // Set the orientation and up + Quaternion newOrientation + = GetTargetOrientationAtPathPoint(newPathOrientation, curState.ReferenceUp); + if (deltaTime < 0) + m_PreviousOrientation = newOrientation; + else + { + if (deltaTime >= 0) + { + Vector3 relative = (Quaternion.Inverse(m_PreviousOrientation) + * newOrientation).eulerAngles; + for (int i = 0; i < 3; ++i) + if (relative[i] > 180) + relative[i] -= 360; + relative = Damper.Damp(relative, AngularDamping, deltaTime); + newOrientation = m_PreviousOrientation * Quaternion.Euler(relative); + } + m_PreviousOrientation = newOrientation; + } + + curState.RawOrientation = newOrientation; + curState.ReferenceUp = curState.RawOrientation * Vector3.up; + //UnityEngine.Profiling.Profiler.EndSample(); + } + + /// <summary>API for the editor, to process a position drag from the user. + /// This implementation adds the delta to the follow offset.</summary> + /// <param name="delta">The amount dragged this frame</param> + public override void OnPositionDragged(Vector3 delta) + { + Quaternion targetOrientation = m_Path.EvaluateOrientationAtUnit(m_PathPosition, m_PositionUnits); + Vector3 localOffset = Quaternion.Inverse(targetOrientation) * delta; + m_PathOffset += localOffset; + } + + private Quaternion GetTargetOrientationAtPathPoint(Quaternion pathOrientation, Vector3 up) + { + switch (m_CameraUp) + { + default: + case CameraUpMode.Default: break; + case CameraUpMode.Path: return pathOrientation; + case CameraUpMode.PathNoRoll: + return Quaternion.LookRotation(pathOrientation * Vector3.forward, up); + case CameraUpMode.FollowTarget: + if (FollowTarget != null) + return FollowTarget.rotation; + break; + case CameraUpMode.FollowTargetNoRoll: + if (FollowTarget != null) + return Quaternion.LookRotation(FollowTarget.rotation * Vector3.forward, up); + break; + } + return Quaternion.LookRotation(transform.rotation * Vector3.forward, up); + } + + private Vector3 AngularDamping + { + get + { + switch (m_CameraUp) + { + case CameraUpMode.PathNoRoll: + case CameraUpMode.FollowTargetNoRoll: + return new Vector3(m_PitchDamping, m_YawDamping, 0); + case CameraUpMode.Default: + return Vector3.zero; + default: + return new Vector3(m_PitchDamping, m_YawDamping, m_RollDamping); + } + } + } + + private float m_PreviousPathPosition = 0; + Quaternion m_PreviousOrientation = Quaternion.identity; + private Vector3 m_PreviousCameraPosition = Vector3.zero; + } +} diff --git a/Assets/Cinemachine/Base/Runtime/Components/CinemachineTrackedDolly.cs.meta b/Assets/Cinemachine/Base/Runtime/Components/CinemachineTrackedDolly.cs.meta new file mode 100644 index 0000000..da09029 --- /dev/null +++ b/Assets/Cinemachine/Base/Runtime/Components/CinemachineTrackedDolly.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 418e42c7d0405cc48a7b83f63ea53bb3 +timeCreated: 1493213884 +licenseType: Store +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Cinemachine/Base/Runtime/Components/CinemachineTransposer.cs b/Assets/Cinemachine/Base/Runtime/Components/CinemachineTransposer.cs new file mode 100644 index 0000000..9537d58 --- /dev/null +++ b/Assets/Cinemachine/Base/Runtime/Components/CinemachineTransposer.cs @@ -0,0 +1,310 @@ +using Cinemachine.Utility; +using UnityEngine; + +namespace Cinemachine +{ + /// <summary> + /// This is a CinemachineComponent in the Body section of the component pipeline. + /// Its job is to position the camera in a fixed relationship to the vcam's Follow + /// target object, with offsets and damping. + /// + /// The Tansposer will only change the camera's position in space. It will not + /// re-orient or otherwise aim the camera. To to that, you need to instruct + /// the vcam in the Aim section of its pipeline. + /// </summary> + [DocumentationSorting(5, DocumentationSortingAttribute.Level.UserRef)] + [AddComponentMenu("")] // Don't display in add component menu + [RequireComponent(typeof(CinemachinePipeline))] + [SaveDuringPlay] + public class CinemachineTransposer : CinemachineComponentBase + { + /// <summary> + /// The coordinate space to use when interpreting the offset from the target + /// </summary> + [DocumentationSorting(5.01f, DocumentationSortingAttribute.Level.UserRef)] + public enum BindingMode + { + /// <summary> + /// Camera will be bound to the Follow target using a frame of reference consisting + /// of the target's local frame at the moment when the virtual camera was enabled, + /// or when the target was assigned. + /// </summary> + LockToTargetOnAssign = 0, + /// <summary> + /// Camera will be bound to the Follow target using a frame of reference consisting + /// of the target's local frame, with the tilt and roll zeroed out. + /// </summary> + LockToTargetWithWorldUp = 1, + /// <summary> + /// Camera will be bound to the Follow target using a frame of reference consisting + /// of the target's local frame, with the roll zeroed out. + /// </summary> + LockToTargetNoRoll = 2, + /// <summary> + /// Camera will be bound to the Follow target using the target's local frame. + /// </summary> + LockToTarget = 3, + /// <summary>Camera will be bound to the Follow target using a world space offset.</summary> + WorldSpace = 4, + /// <summary>Offsets will be calculated relative to the target, using Camera-local axes</summary> + SimpleFollowWithWorldUp = 5 + } + /// <summary>The coordinate space to use when interpreting the offset from the target</summary> + [Tooltip("The coordinate space to use when interpreting the offset from the target. This is also used to set the camera's Up vector, which will be maintained when aiming the camera.")] + public BindingMode m_BindingMode = BindingMode.LockToTargetWithWorldUp; + + /// <summary>The distance which the transposer will attempt to maintain from the transposer subject</summary> + [Tooltip("The distance vector that the transposer will attempt to maintain from the Follow target")] + public Vector3 m_FollowOffset = Vector3.back * 10f; + + /// <summary>How aggressively the camera tries to maintain the offset in the X-axis. + /// Small numbers are more responsive, rapidly translating the camera to keep the target's + /// x-axis offset. Larger numbers give a more heavy slowly responding camera. + /// Using different settings per axis can yield a wide range of camera behaviors</summary> + [Range(0f, 20f)] + [Tooltip("How aggressively the camera tries to maintain the offset in the X-axis. Small numbers are more responsive, rapidly translating the camera to keep the target's x-axis offset. Larger numbers give a more heavy slowly responding camera. Using different settings per axis can yield a wide range of camera behaviors.")] + public float m_XDamping = 1f; + + /// <summary>How aggressively the camera tries to maintain the offset in the Y-axis. + /// Small numbers are more responsive, rapidly translating the camera to keep the target's + /// y-axis offset. Larger numbers give a more heavy slowly responding camera. + /// Using different settings per axis can yield a wide range of camera behaviors</summary> + [Range(0f, 20f)] + [Tooltip("How aggressively the camera tries to maintain the offset in the Y-axis. Small numbers are more responsive, rapidly translating the camera to keep the target's y-axis offset. Larger numbers give a more heavy slowly responding camera. Using different settings per axis can yield a wide range of camera behaviors.")] + public float m_YDamping = 1f; + + /// <summary>How aggressively the camera tries to maintain the offset in the Z-axis. + /// Small numbers are more responsive, rapidly translating the camera to keep the + /// target's z-axis offset. Larger numbers give a more heavy slowly responding camera. + /// Using different settings per axis can yield a wide range of camera behaviors</summary> + [Range(0f, 20f)] + [Tooltip("How aggressively the camera tries to maintain the offset in the Z-axis. Small numbers are more responsive, rapidly translating the camera to keep the target's z-axis offset. Larger numbers give a more heavy slowly responding camera. Using different settings per axis can yield a wide range of camera behaviors.")] + public float m_ZDamping = 1f; + + /// <summary>How aggressively the camera tries to track the target rotation's X angle. + /// Small numbers are more responsive. Larger numbers give a more heavy slowly responding camera.</summary> + [Range(0f, 20f)] + [Tooltip("How aggressively the camera tries to track the target rotation's X angle. Small numbers are more responsive. Larger numbers give a more heavy slowly responding camera.")] + public float m_PitchDamping = 0; + + /// <summary>How aggressively the camera tries to track the target rotation's Y angle. + /// Small numbers are more responsive. Larger numbers give a more heavy slowly responding camera.</summary> + [Range(0f, 20f)] + [Tooltip("How aggressively the camera tries to track the target rotation's Y angle. Small numbers are more responsive. Larger numbers give a more heavy slowly responding camera.")] + public float m_YawDamping = 0; + + /// <summary>How aggressively the camera tries to track the target rotation's Z angle. + /// Small numbers are more responsive. Larger numbers give a more heavy slowly responding camera.</summary> + [Range(0f, 20f)] + [Tooltip("How aggressively the camera tries to track the target rotation's Z angle. Small numbers are more responsive. Larger numbers give a more heavy slowly responding camera.")] + public float m_RollDamping = 0f; + + protected virtual void OnValidate() + { + m_FollowOffset = EffectiveOffset; + } + + /// <summary>Get the target offset, with sanitization</summary> + protected Vector3 EffectiveOffset + { + get + { + Vector3 offset = m_FollowOffset; + if (m_BindingMode == BindingMode.SimpleFollowWithWorldUp) + { + offset.x = 0; + offset.z = -Mathf.Abs(offset.z); + } + return offset; + } + } + + /// <summary>True if component is enabled and has a valid Follow target</summary> + public override bool IsValid { get { return enabled && FollowTarget != null; } } + + /// <summary>Get the Cinemachine Pipeline stage that this component implements. + /// Always returns the Body stage</summary> + public override CinemachineCore.Stage Stage { get { return CinemachineCore.Stage.Body; } } + + /// <summary>Positions the virtual camera according to the transposer rules.</summary> + /// <param name="curState">The current camera state</param> + /// <param name="deltaTime">Used for damping. If less than 0, no damping is done.</param> + public override void MutateCameraState(ref CameraState curState, float deltaTime) + { + //UnityEngine.Profiling.Profiler.BeginSample("CinemachineTransposer.MutateCameraState"); + InitPrevFrameStateInfo(ref curState, deltaTime); + if (IsValid) + { + Vector3 pos; + Quaternion orient; + Vector3 offset = EffectiveOffset; + TrackTarget(deltaTime, curState.ReferenceUp, offset, out pos, out orient); + curState.RawPosition = pos + orient * offset; + curState.ReferenceUp = orient * Vector3.up; + } + //UnityEngine.Profiling.Profiler.EndSample(); + } + + /// <summary>API for the editor, to process a position drag from the user. + /// This implementation adds the delta to the follow offset.</summary> + /// <param name="delta">The amount dragged this frame</param> + public override void OnPositionDragged(Vector3 delta) + { + Quaternion targetOrientation = GetReferenceOrientation(VcamState.ReferenceUp); + Vector3 localOffset = Quaternion.Inverse(targetOrientation) * delta; + m_FollowOffset += localOffset; + m_FollowOffset = EffectiveOffset; + } + + /// <summary>Initializes the state for previous frame if appropriate.</summary> + protected void InitPrevFrameStateInfo( + ref CameraState curState, float deltaTime) + { + if (m_previousTarget != FollowTarget || deltaTime < 0) + { + m_previousTarget = FollowTarget; + m_targetOrientationOnAssign + = (m_previousTarget == null) ? Quaternion.identity : FollowTarget.rotation; + } + if (deltaTime < 0) + { + m_PreviousTargetPosition = curState.RawPosition; + m_PreviousReferenceOrientation = GetReferenceOrientation(curState.ReferenceUp); + } + } + + /// <summary>Positions the virtual camera according to the transposer rules.</summary> + /// <param name="deltaTime">Used for damping. If less than 0, no damping is done.</param> + /// <param name="up">Current camera up</param> + /// <param name="desiredCameraOffset">Where we want to put the camera relative to the follow target</param> + /// <param name="outTargetPosition">Resulting camera position</param> + /// <param name="outTargetOrient">Damped target orientation</param> + protected void TrackTarget( + float deltaTime, Vector3 up, Vector3 desiredCameraOffset, + out Vector3 outTargetPosition, out Quaternion outTargetOrient) + { + Quaternion targetOrientation = GetReferenceOrientation(up); + Quaternion dampedOrientation = targetOrientation; + if (deltaTime >= 0) + { + Vector3 relative = (Quaternion.Inverse(m_PreviousReferenceOrientation) + * targetOrientation).eulerAngles; + for (int i = 0; i < 3; ++i) + if (relative[i] > 180) + relative[i] -= 360; + relative = Damper.Damp(relative, AngularDamping, deltaTime); + dampedOrientation = m_PreviousReferenceOrientation * Quaternion.Euler(relative); + } + m_PreviousReferenceOrientation = dampedOrientation; + + Vector3 targetPosition = FollowTarget.position; + Vector3 currentPosition = m_PreviousTargetPosition; + Vector3 worldOffset = targetPosition - currentPosition; + + // Adjust for damping, which is done in camera-offset-local coords + if (deltaTime >= 0) + { + Quaternion dampingSpace; + if (desiredCameraOffset.AlmostZero()) + dampingSpace = VcamState.RawOrientation; + else + dampingSpace = Quaternion.LookRotation(dampedOrientation * desiredCameraOffset.normalized, up); + Vector3 localOffset = Quaternion.Inverse(dampingSpace) * worldOffset; + localOffset = Damper.Damp(localOffset, Damping, deltaTime); + worldOffset = dampingSpace * localOffset; + } + outTargetPosition = m_PreviousTargetPosition = currentPosition + worldOffset; + outTargetOrient = dampedOrientation; + } + + /// <summary> + /// Damping speeds for each of the 3 axes of the offset from target + /// </summary> + protected Vector3 Damping + { + get + { + switch (m_BindingMode) + { + case BindingMode.SimpleFollowWithWorldUp: + return new Vector3(0, m_YDamping, m_ZDamping); + default: + return new Vector3(m_XDamping, m_YDamping, m_ZDamping); + } + } + } + + /// <summary> + /// Damping speeds for each of the 3 axes of the target's rotation + /// </summary> + protected Vector3 AngularDamping + { + get + { + switch (m_BindingMode) + { + case BindingMode.LockToTargetNoRoll: + return new Vector3(m_PitchDamping, m_YawDamping, 0); + case BindingMode.LockToTargetWithWorldUp: + return new Vector3(0, m_YawDamping, 0); + case BindingMode.LockToTargetOnAssign: + case BindingMode.WorldSpace: + case BindingMode.SimpleFollowWithWorldUp: + return Vector3.zero; + default: + return new Vector3(m_PitchDamping, m_YawDamping, m_RollDamping); + } + } + } + + /// <summary>Internal API for the Inspector Editor, so it can draw a marker at the target</summary> + public Vector3 GeTargetCameraPosition(Vector3 worldUp) + { + if (!IsValid) + return Vector3.zero; + return FollowTarget.position + GetReferenceOrientation(worldUp) * EffectiveOffset; + } + + /// <summary>State information for damping</summary> + Vector3 m_PreviousTargetPosition = Vector3.zero; + Quaternion m_PreviousReferenceOrientation = Quaternion.identity; + Quaternion m_targetOrientationOnAssign = Quaternion.identity; + Transform m_previousTarget = null; + + /// <summary>Internal API for the Inspector Editor, so it can draw a marker at the target</summary> + public Quaternion GetReferenceOrientation(Vector3 worldUp) + { + if (FollowTarget != null) + { + Quaternion targetOrientation = FollowTarget.rotation; + switch (m_BindingMode) + { + case BindingMode.LockToTargetOnAssign: + return m_targetOrientationOnAssign; + case BindingMode.LockToTargetWithWorldUp: + return Uppify(targetOrientation, worldUp); + case BindingMode.LockToTargetNoRoll: + return Quaternion.LookRotation(targetOrientation * Vector3.forward, worldUp); + case BindingMode.LockToTarget: + return targetOrientation; + case BindingMode.SimpleFollowWithWorldUp: + { + Vector3 dir = FollowTarget.position - VcamState.RawPosition; + if (dir.AlmostZero()) + break; + return Uppify(Quaternion.LookRotation(dir, worldUp), worldUp); + } + default: + break; + } + } + return Quaternion.identity; + } + + static Quaternion Uppify(Quaternion q, Vector3 up) + { + Quaternion r = Quaternion.FromToRotation(q * Vector3.up, up); + return r * q; + } + } +} diff --git a/Assets/Cinemachine/Base/Runtime/Components/CinemachineTransposer.cs.meta b/Assets/Cinemachine/Base/Runtime/Components/CinemachineTransposer.cs.meta new file mode 100644 index 0000000..e2e0701 --- /dev/null +++ b/Assets/Cinemachine/Base/Runtime/Components/CinemachineTransposer.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: fa7155796051b734daa718462081dc5f +timeCreated: 1484001119 +licenseType: Store +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: |
