From 5440734d820606b29a795c46172ade5d7eba8efb Mon Sep 17 00:00:00 2001
From: Tom Harley
Date: Mon, 3 Sep 2018 23:34:21 +0100
Subject: Initial commit
---
Assets/Cinemachine/Base/Runtime/Core/AxisState.cs | 200 ++++++++++
.../Base/Runtime/Core/AxisState.cs.meta | 12 +
.../Cinemachine/Base/Runtime/Core/CameraState.cs | 352 +++++++++++++++++
.../Base/Runtime/Core/CameraState.cs.meta | 12 +
.../Base/Runtime/Core/CinemachineBlend.cs | 207 ++++++++++
.../Base/Runtime/Core/CinemachineBlend.cs.meta | 12 +
.../Runtime/Core/CinemachineBlenderSettings.cs | 95 +++++
.../Core/CinemachineBlenderSettings.cs.meta | 12 +
.../Base/Runtime/Core/CinemachineComponentBase.cs | 77 ++++
.../Runtime/Core/CinemachineComponentBase.cs.meta | 12 +
.../Base/Runtime/Core/CinemachineCore.cs | 429 +++++++++++++++++++++
.../Base/Runtime/Core/CinemachineCore.cs.meta | 12 +
.../Base/Runtime/Core/CinemachineDebugLogger.cs | 47 +++
.../Runtime/Core/CinemachineDebugLogger.cs.meta | 12 +
.../Base/Runtime/Core/CinemachineExtension.cs | 89 +++++
.../Base/Runtime/Core/CinemachineExtension.cs.meta | 12 +
.../Base/Runtime/Core/CinemachinePathBase.cs | 356 +++++++++++++++++
.../Base/Runtime/Core/CinemachinePathBase.cs.meta | 12 +
.../Runtime/Core/CinemachinePropertyAttribute.cs | 70 ++++
.../Core/CinemachinePropertyAttribute.cs.meta | 12 +
.../Runtime/Core/CinemachineVirtualCameraBase.cs | 360 +++++++++++++++++
.../Core/CinemachineVirtualCameraBase.cs.meta | 12 +
.../Base/Runtime/Core/GaussianFilter.cs | 140 +++++++
.../Base/Runtime/Core/GaussianFilter.cs.meta | 12 +
.../Base/Runtime/Core/ICinemachineCamera.cs | 81 ++++
.../Base/Runtime/Core/ICinemachineCamera.cs.meta | 12 +
.../Base/Runtime/Core/ICinemachineComponent.cs | 3 +
.../Runtime/Core/ICinemachineComponent.cs.meta | 12 +
.../Cinemachine/Base/Runtime/Core/LensSettings.cs | 137 +++++++
.../Base/Runtime/Core/LensSettings.cs.meta | 12 +
.../Cinemachine/Base/Runtime/Core/NoiseSettings.cs | 82 ++++
.../Base/Runtime/Core/NoiseSettings.cs.meta | 12 +
Assets/Cinemachine/Base/Runtime/Core/Predictor.cs | 141 +++++++
.../Base/Runtime/Core/Predictor.cs.meta | 12 +
.../Base/Runtime/Core/ReflectionHelpers.cs | 186 +++++++++
.../Base/Runtime/Core/ReflectionHelpers.cs.meta | 12 +
.../Cinemachine/Base/Runtime/Core/SplineHelpers.cs | 137 +++++++
.../Base/Runtime/Core/SplineHelpers.cs.meta | 12 +
.../Base/Runtime/Core/UnityVectorExtensions.cs | 228 +++++++++++
.../Runtime/Core/UnityVectorExtensions.cs.meta | 12 +
40 files changed, 3657 insertions(+)
create mode 100644 Assets/Cinemachine/Base/Runtime/Core/AxisState.cs
create mode 100644 Assets/Cinemachine/Base/Runtime/Core/AxisState.cs.meta
create mode 100644 Assets/Cinemachine/Base/Runtime/Core/CameraState.cs
create mode 100644 Assets/Cinemachine/Base/Runtime/Core/CameraState.cs.meta
create mode 100644 Assets/Cinemachine/Base/Runtime/Core/CinemachineBlend.cs
create mode 100644 Assets/Cinemachine/Base/Runtime/Core/CinemachineBlend.cs.meta
create mode 100644 Assets/Cinemachine/Base/Runtime/Core/CinemachineBlenderSettings.cs
create mode 100644 Assets/Cinemachine/Base/Runtime/Core/CinemachineBlenderSettings.cs.meta
create mode 100644 Assets/Cinemachine/Base/Runtime/Core/CinemachineComponentBase.cs
create mode 100644 Assets/Cinemachine/Base/Runtime/Core/CinemachineComponentBase.cs.meta
create mode 100644 Assets/Cinemachine/Base/Runtime/Core/CinemachineCore.cs
create mode 100644 Assets/Cinemachine/Base/Runtime/Core/CinemachineCore.cs.meta
create mode 100644 Assets/Cinemachine/Base/Runtime/Core/CinemachineDebugLogger.cs
create mode 100644 Assets/Cinemachine/Base/Runtime/Core/CinemachineDebugLogger.cs.meta
create mode 100644 Assets/Cinemachine/Base/Runtime/Core/CinemachineExtension.cs
create mode 100644 Assets/Cinemachine/Base/Runtime/Core/CinemachineExtension.cs.meta
create mode 100644 Assets/Cinemachine/Base/Runtime/Core/CinemachinePathBase.cs
create mode 100644 Assets/Cinemachine/Base/Runtime/Core/CinemachinePathBase.cs.meta
create mode 100644 Assets/Cinemachine/Base/Runtime/Core/CinemachinePropertyAttribute.cs
create mode 100644 Assets/Cinemachine/Base/Runtime/Core/CinemachinePropertyAttribute.cs.meta
create mode 100644 Assets/Cinemachine/Base/Runtime/Core/CinemachineVirtualCameraBase.cs
create mode 100644 Assets/Cinemachine/Base/Runtime/Core/CinemachineVirtualCameraBase.cs.meta
create mode 100644 Assets/Cinemachine/Base/Runtime/Core/GaussianFilter.cs
create mode 100644 Assets/Cinemachine/Base/Runtime/Core/GaussianFilter.cs.meta
create mode 100644 Assets/Cinemachine/Base/Runtime/Core/ICinemachineCamera.cs
create mode 100644 Assets/Cinemachine/Base/Runtime/Core/ICinemachineCamera.cs.meta
create mode 100644 Assets/Cinemachine/Base/Runtime/Core/ICinemachineComponent.cs
create mode 100644 Assets/Cinemachine/Base/Runtime/Core/ICinemachineComponent.cs.meta
create mode 100644 Assets/Cinemachine/Base/Runtime/Core/LensSettings.cs
create mode 100644 Assets/Cinemachine/Base/Runtime/Core/LensSettings.cs.meta
create mode 100644 Assets/Cinemachine/Base/Runtime/Core/NoiseSettings.cs
create mode 100644 Assets/Cinemachine/Base/Runtime/Core/NoiseSettings.cs.meta
create mode 100644 Assets/Cinemachine/Base/Runtime/Core/Predictor.cs
create mode 100644 Assets/Cinemachine/Base/Runtime/Core/Predictor.cs.meta
create mode 100644 Assets/Cinemachine/Base/Runtime/Core/ReflectionHelpers.cs
create mode 100644 Assets/Cinemachine/Base/Runtime/Core/ReflectionHelpers.cs.meta
create mode 100644 Assets/Cinemachine/Base/Runtime/Core/SplineHelpers.cs
create mode 100644 Assets/Cinemachine/Base/Runtime/Core/SplineHelpers.cs.meta
create mode 100644 Assets/Cinemachine/Base/Runtime/Core/UnityVectorExtensions.cs
create mode 100644 Assets/Cinemachine/Base/Runtime/Core/UnityVectorExtensions.cs.meta
(limited to 'Assets/Cinemachine/Base/Runtime/Core')
diff --git a/Assets/Cinemachine/Base/Runtime/Core/AxisState.cs b/Assets/Cinemachine/Base/Runtime/Core/AxisState.cs
new file mode 100644
index 0000000..bad769f
--- /dev/null
+++ b/Assets/Cinemachine/Base/Runtime/Core/AxisState.cs
@@ -0,0 +1,200 @@
+using UnityEngine;
+using System;
+using Cinemachine.Utility;
+using UnityEngine.Serialization;
+
+namespace Cinemachine
+{
+ ///
+ /// Axis state for defining to react to player input.
+ /// The settings here control the responsiveness of the axis to player input.
+ ///
+ [DocumentationSorting(6.4f, DocumentationSortingAttribute.Level.UserRef)]
+ [Serializable]
+ public struct AxisState
+ {
+ /// The current value of the axis
+ [NoSaveDuringPlay]
+ [Tooltip("The current value of the axis.")]
+ public float Value;
+
+ /// How fast the axis value can travel. Increasing this number
+ /// makes the behaviour more responsive to joystick input
+ [Tooltip("The maximum speed of this axis in units/second")]
+ public float m_MaxSpeed;
+
+ /// The amount of time in seconds it takes to accelerate to
+ /// MaxSpeed with the supplied Axis at its maximum value
+ [Tooltip("The amount of time in seconds it takes to accelerate to MaxSpeed with the supplied Axis at its maximum value")]
+ public float m_AccelTime;
+
+ /// The amount of time in seconds it takes to decelerate
+ /// the axis to zero if the supplied axis is in a neutral position
+ [Tooltip("The amount of time in seconds it takes to decelerate the axis to zero if the supplied axis is in a neutral position")]
+ public float m_DecelTime;
+
+ /// The name of this axis as specified in Unity Input manager.
+ /// Setting to an empty string will disable the automatic updating of this axis
+ [FormerlySerializedAs("m_AxisName")]
+ [Tooltip("The name of this axis as specified in Unity Input manager. Setting to an empty string will disable the automatic updating of this axis")]
+ public string m_InputAxisName;
+
+ /// The value of the input axis. A value of 0 means no input
+ /// You can drive this directly from a
+ /// custom input system, or you can set the Axis Name and have the value
+ /// driven by the internal Input Manager
+ [NoSaveDuringPlay]
+ [Tooltip("The value of the input axis. A value of 0 means no input. You can drive this directly from a custom input system, or you can set the Axis Name and have the value driven by the internal Input Manager")]
+ public float m_InputAxisValue;
+
+ /// If checked, then the raw value of the input axis will be inverted
+ /// before it is used.
+ [NoSaveDuringPlay]
+ [Tooltip("If checked, then the raw value of the input axis will be inverted before it is used")]
+ public bool m_InvertAxis;
+
+ private float mCurrentSpeed;
+ private float mMinValue;
+ private float mMaxValue;
+ private bool mWrapAround;
+
+ /// Constructor with specific values
+ public AxisState(
+ float maxSpeed, float accelTime, float decelTime, float val, string name, bool invert)
+ {
+ m_MaxSpeed = maxSpeed;
+ m_AccelTime = accelTime;
+ m_DecelTime = decelTime;
+ Value = val;
+ m_InputAxisName = name;
+ m_InputAxisValue = 0;
+ m_InvertAxis = invert;
+
+ mCurrentSpeed = 0f;
+ mMinValue = 0f;
+ mMaxValue = 0f;
+ mWrapAround = false;
+ }
+
+ /// Call from OnValidate: Make sure the fields are sensible
+ public void Validate()
+ {
+ m_MaxSpeed = Mathf.Max(0, m_MaxSpeed);
+ m_AccelTime = Mathf.Max(0, m_AccelTime);
+ m_DecelTime = Mathf.Max(0, m_DecelTime);
+ }
+
+ ///
+ /// Sets the constraints by which this axis will operate on
+ ///
+ /// The lowest value this axis can achieve
+ /// The highest value this axis can achieve
+ /// If true, values commanded greater
+ /// than mMaxValue or less than mMinValue will wrap around.
+ /// If false, the value will be clamped within the range.
+ public void SetThresholds(float minValue, float maxValue, bool wrapAround)
+ {
+ mMinValue = minValue;
+ mMaxValue = maxValue;
+ mWrapAround = wrapAround;
+ }
+
+ const float Epsilon = UnityVectorExtensions.Epsilon;
+
+ ///
+ /// Updates the state of this axis based on the axis defined
+ /// by AxisState.m_AxisName
+ ///
+ /// Delta time in seconds
+ /// Returns true if this axis' input was non-zero this Update,
+ /// flase otherwise
+ public bool Update(float deltaTime)
+ {
+ if (!string.IsNullOrEmpty(m_InputAxisName))
+ {
+ try
+ {
+ m_InputAxisValue = CinemachineCore.GetInputAxis(m_InputAxisName);
+ }
+ catch (ArgumentException e)
+ {
+ Debug.LogError(e.ToString());
+ }
+ }
+
+ float input = m_InputAxisValue;
+ if (m_InvertAxis)
+ input *= -1f;
+
+ if (m_MaxSpeed > Epsilon)
+ {
+ float targetSpeed = input * m_MaxSpeed;
+ if (Mathf.Abs(targetSpeed) < Epsilon
+ || (Mathf.Sign(mCurrentSpeed) == Mathf.Sign(targetSpeed)
+ && Mathf.Abs(targetSpeed) < Mathf.Abs(mCurrentSpeed)))
+ {
+ // Need to decelerate
+ float a = Mathf.Abs(targetSpeed - mCurrentSpeed) / Mathf.Max(Epsilon, m_DecelTime);
+ float delta = Mathf.Min(a * deltaTime, Mathf.Abs(mCurrentSpeed));
+ mCurrentSpeed -= Mathf.Sign(mCurrentSpeed) * delta;
+ }
+ else
+ {
+ // Accelerate to the target speed
+ float a = Mathf.Abs(targetSpeed - mCurrentSpeed) / Mathf.Max(Epsilon, m_AccelTime);
+ mCurrentSpeed += Mathf.Sign(targetSpeed) * a * deltaTime;
+ if (Mathf.Sign(mCurrentSpeed) == Mathf.Sign(targetSpeed)
+ && Mathf.Abs(mCurrentSpeed) > Mathf.Abs(targetSpeed))
+ {
+ mCurrentSpeed = targetSpeed;
+ }
+ }
+ }
+
+ // Clamp our max speeds so we don't go crazy
+ float maxSpeed = GetMaxSpeed();
+ mCurrentSpeed = Mathf.Clamp(mCurrentSpeed, -maxSpeed, maxSpeed);
+
+ Value += mCurrentSpeed * deltaTime;
+ bool isOutOfRange = (Value > mMaxValue) || (Value < mMinValue);
+ if (isOutOfRange)
+ {
+ if (mWrapAround)
+ {
+ if (Value > mMaxValue)
+ Value = mMinValue + (Value - mMaxValue);
+ else
+ Value = mMaxValue + (Value - mMinValue);
+ }
+ else
+ {
+ Value = Mathf.Clamp(Value, mMinValue, mMaxValue);
+ mCurrentSpeed = 0f;
+ }
+ }
+ return Mathf.Abs(input) > Epsilon;
+ }
+
+ // MaxSpeed may be limited as we approach the range ends, in order
+ // to prevent a hard bump
+ private float GetMaxSpeed()
+ {
+ float range = mMaxValue - mMinValue;
+ if (!mWrapAround && range > 0)
+ {
+ float threshold = range / 10f;
+ if (mCurrentSpeed > 0 && (mMaxValue - Value) < threshold)
+ {
+ float t = (mMaxValue - Value) / threshold;
+ return Mathf.Lerp(0, m_MaxSpeed, t);
+ }
+ else if (mCurrentSpeed < 0 && (Value - mMinValue) < threshold)
+ {
+ float t = (Value - mMinValue) / threshold;
+ return Mathf.Lerp(0, m_MaxSpeed, t);
+ }
+ }
+ return m_MaxSpeed;
+ }
+ }
+}
diff --git a/Assets/Cinemachine/Base/Runtime/Core/AxisState.cs.meta b/Assets/Cinemachine/Base/Runtime/Core/AxisState.cs.meta
new file mode 100644
index 0000000..d86b4b8
--- /dev/null
+++ b/Assets/Cinemachine/Base/Runtime/Core/AxisState.cs.meta
@@ -0,0 +1,12 @@
+fileFormatVersion: 2
+guid: 557c6f70a7173744abaa3967b6da6f5d
+timeCreated: 1504195334
+licenseType: Store
+MonoImporter:
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Assets/Cinemachine/Base/Runtime/Core/CameraState.cs b/Assets/Cinemachine/Base/Runtime/Core/CameraState.cs
new file mode 100644
index 0000000..bfd9851
--- /dev/null
+++ b/Assets/Cinemachine/Base/Runtime/Core/CameraState.cs
@@ -0,0 +1,352 @@
+using UnityEngine;
+using Cinemachine.Utility;
+using System.Collections.Generic;
+
+namespace Cinemachine
+{
+ ///
+ /// The output of the Cinemachine engine for a specific virtual camera. The information
+ /// in this struct can be blended, and provides what is needed to calculate an
+ /// appropriate camera position, orientation, and lens setting.
+ ///
+ /// Raw values are what the Cinemachine behaviours generate. The correction channel
+ /// holds perturbations to the raw values - e.g. noise or smoothing, or obstacle
+ /// avoidance corrections. Coirrections are not considered when making time-based
+ /// calculations such as damping.
+ ///
+ /// The Final position and orientation is the comination of the raw values and
+ /// their corrections.
+ ///
+ public struct CameraState
+ {
+ ///
+ /// Camera Lens Settings.
+ ///
+ public LensSettings Lens { get; set; }
+
+ ///
+ /// Which way is up. World space unit vector.
+ ///
+ public Vector3 ReferenceUp { get; set; }
+
+ ///
+ /// The world space focus point of the camera. What the camera wants to look at.
+ /// There is a special constant define to represent "nothing". Be careful to
+ /// check for that (or check the HasLookAt property).
+ ///
+ public Vector3 ReferenceLookAt { get; set; }
+
+ ///
+ /// Returns true if this state has a valid ReferenceLookAt value.
+ ///
+ public bool HasLookAt { get { return ReferenceLookAt == ReferenceLookAt; } } // will be false if NaN
+
+ ///
+ /// This constant represents "no point in space" or "no direction".
+ ///
+ public static Vector3 kNoPoint = new Vector3(float.NaN, float.NaN, float.NaN);
+
+ ///
+ /// Raw (un-corrected) world space position of this camera
+ ///
+ public Vector3 RawPosition { get; set; }
+
+ ///
+ /// Raw (un-corrected) world space orientation of this camera
+ ///
+ public Quaternion RawOrientation { get; set; }
+
+ /// This is a way for the Body component to bypass aim damping,
+ /// useful for when the body need to rotate its point of view, but does not
+ /// want interference from the aim damping
+ internal Vector3 PositionDampingBypass { get; set; }
+
+ ///
+ /// Subjective estimation of how "good" the shot is.
+ /// Larger values mean better quality. Default is 1.
+ ///
+ public float ShotQuality { get; set; }
+
+ ///
+ /// Position correction. This will be added to the raw position.
+ /// This value doesn't get fed back into the system when calculating the next frame.
+ /// Can be noise, or smoothing, or both, or something else.
+ ///
+ public Vector3 PositionCorrection { get; set; }
+
+ ///
+ /// Orientation correction. This will be added to the raw orientation.
+ /// This value doesn't get fed back into the system when calculating the next frame.
+ /// Can be noise, or smoothing, or both, or something else.
+ ///
+ public Quaternion OrientationCorrection { get; set; }
+
+ ///
+ /// Position with correction applied.
+ ///
+ public Vector3 CorrectedPosition { get { return RawPosition + PositionCorrection; } }
+
+ ///
+ /// Orientation with correction applied.
+ ///
+ public Quaternion CorrectedOrientation { get { return RawOrientation * OrientationCorrection; } }
+
+ ///
+ /// Position with correction applied. This is what the final camera gets.
+ ///
+ public Vector3 FinalPosition { get { return RawPosition + PositionCorrection; } }
+
+ ///
+ /// Orientation with correction and dutch applied. This is what the final camera gets.
+ ///
+ public Quaternion FinalOrientation
+ {
+ get
+ {
+ if (Mathf.Abs(Lens.Dutch) > UnityVectorExtensions.Epsilon)
+ return CorrectedOrientation * Quaternion.AngleAxis(Lens.Dutch, Vector3.forward);
+ return CorrectedOrientation;
+ }
+ }
+
+ ///
+ /// State with default values
+ ///
+ public static CameraState Default
+ {
+ get
+ {
+ CameraState state = new CameraState();
+ state.Lens = LensSettings.Default;
+ state.ReferenceUp = Vector3.up;
+ state.ReferenceLookAt = kNoPoint;
+ state.RawPosition = Vector3.zero;
+ state.RawOrientation = Quaternion.identity;
+ state.ShotQuality = 1;
+ state.PositionCorrection = Vector3.zero;
+ state.OrientationCorrection = Quaternion.identity;
+ state.PositionDampingBypass = Vector3.zero;
+ return state;
+ }
+ }
+
+ /// Opaque structure represent extra blendable stuff and its weight.
+ /// The base system ignores this data - it is intended for extension modules
+ public struct CustomBlendable
+ {
+ /// The custom stuff that the extention module will consider
+ public Object m_Custom;
+ /// The weight of the custom stuff. Must be 0...1
+ public float m_Weight;
+
+ /// Constructor with specific values
+ /// The custom stuff that the extention module will consider
+ /// The weight of the custom stuff. Must be 0...1
+ public CustomBlendable(Object custom, float weight)
+ { m_Custom = custom; m_Weight = weight; }
+ };
+
+ // This is to avoid excessive GC allocs
+ CustomBlendable mCustom0;
+ CustomBlendable mCustom1;
+ CustomBlendable mCustom2;
+ CustomBlendable mCustom3;
+ List m_CustomOverflow;
+
+ /// The number of custom blendables that will be applied to the camera.
+ /// The base system manages but otherwise ignores this data - it is intended for
+ /// extension modules
+ public int NumCustomBlendables { get; private set; }
+
+ /// Get a custom blendable that will be applied to the camera.
+ /// The base system manages but otherwise ignores this data - it is intended for
+ /// extension modules
+ /// Which one to get. Must be in range [0...NumCustomBlendables)
+ /// The custom blendable at the specified index.
+ public CustomBlendable GetCustomBlendable(int index)
+ {
+ switch (index)
+ {
+ case 0: return mCustom0;
+ case 1: return mCustom1;
+ case 2: return mCustom2;
+ case 3: return mCustom3;
+ default:
+ {
+ index -= 4;
+ if (m_CustomOverflow != null && index < m_CustomOverflow.Count)
+ return m_CustomOverflow[index];
+ return new CustomBlendable(null, 0);
+ }
+ }
+ }
+
+ int FindCustomBlendable(Object custom)
+ {
+ if (mCustom0.m_Custom == custom)
+ return 0;
+ if (mCustom1.m_Custom == custom)
+ return 1;
+ if (mCustom2.m_Custom == custom)
+ return 2;
+ if (mCustom3.m_Custom == custom)
+ return 3;
+ if (m_CustomOverflow != null)
+ {
+ for (int i = 0; i < m_CustomOverflow.Count; ++i)
+ if (m_CustomOverflow[i].m_Custom == custom)
+ return i + 4;
+ }
+ return -1;
+ }
+
+ /// Add a custom blendable to the pot for eventual application to the camera.
+ /// The base system manages but otherwise ignores this data - it is intended for
+ /// extension modules
+ /// The custom blendable to add. If b.m_Custom is the same as an
+ /// already-added custom blendable, then they will be merged and the weights combined.
+ public void AddCustomBlendable(CustomBlendable b)
+ {
+ // Attempt to merge common blendables to avoid growth
+ int index = FindCustomBlendable(b.m_Custom);
+ if (index >= 0)
+ b.m_Weight += GetCustomBlendable(index).m_Weight;
+ else
+ {
+ index = NumCustomBlendables;
+ NumCustomBlendables = index + 1;
+ }
+ switch (index)
+ {
+ case 0: mCustom0 = b; break;
+ case 1: mCustom1 = b; break;
+ case 2: mCustom2 = b; break;
+ case 3: mCustom3 = b; break;
+ default:
+ {
+ if (m_CustomOverflow == null)
+ m_CustomOverflow = new List();
+ m_CustomOverflow.Add(b);
+ break;
+ }
+ }
+ }
+
+ /// Intelligently blend the contents of two states.
+ /// The first state, corresponding to t=0
+ /// The second state, corresponding to t=1
+ /// How much to interpolate. Internally clamped to 0..1
+ /// Linearly interpolated CameraState
+ public static CameraState Lerp(CameraState stateA, CameraState stateB, float t)
+ {
+ t = Mathf.Clamp01(t);
+ float adjustedT = t;
+
+ CameraState state = new CameraState();
+ state.Lens = LensSettings.Lerp(stateA.Lens, stateB.Lens, t);
+ state.ReferenceUp = Vector3.Slerp(stateA.ReferenceUp, stateB.ReferenceUp, t);
+ state.RawPosition = Vector3.Lerp(stateA.RawPosition, stateB.RawPosition, t);
+
+ state.ShotQuality = Mathf.Lerp(stateA.ShotQuality, stateB.ShotQuality, t);
+ state.PositionCorrection = Vector3.Lerp(
+ stateA.PositionCorrection, stateB.PositionCorrection, t);
+ // GML todo: is this right? Can it introduce a roll?
+ state.OrientationCorrection = Quaternion.Slerp(
+ stateA.OrientationCorrection, stateB.OrientationCorrection, t);
+
+ Vector3 dirTarget = Vector3.zero;
+ if (!stateA.HasLookAt || !stateB.HasLookAt)
+ state.ReferenceLookAt = kNoPoint; // can't interpolate if undefined
+ else
+ {
+ // Re-interpolate FOV to preserve target composition, if possible
+ float fovA = stateA.Lens.FieldOfView;
+ float fovB = stateB.Lens.FieldOfView;
+ if (!state.Lens.Orthographic && !Mathf.Approximately(fovA, fovB))
+ {
+ LensSettings lens = state.Lens;
+ lens.FieldOfView = state.InterpolateFOV(
+ fovA, fovB,
+ Mathf.Max((stateA.ReferenceLookAt - stateA.CorrectedPosition).magnitude, stateA.Lens.NearClipPlane),
+ Mathf.Max((stateB.ReferenceLookAt - stateB.CorrectedPosition).magnitude, stateB.Lens.NearClipPlane), t);
+ state.Lens = lens;
+
+ // Make sure we preserve the screen composition through FOV changes
+ adjustedT = Mathf.Abs((lens.FieldOfView - fovA) / (fovB - fovA));
+ }
+
+ // Linear interpolation of lookAt target point
+ state.ReferenceLookAt = Vector3.Lerp(
+ stateA.ReferenceLookAt, stateB.ReferenceLookAt, adjustedT);
+
+ // If orientations are different, use LookAt to blend them
+ float angle = Quaternion.Angle(stateA.RawOrientation, stateB.RawOrientation);
+ if (angle > UnityVectorExtensions.Epsilon)
+ dirTarget = state.ReferenceLookAt - state.CorrectedPosition;
+ }
+
+ // Clever orientation interpolation
+ if (dirTarget.AlmostZero())
+ {
+ // Don't know what we're looking at - can only slerp
+ state.RawOrientation = UnityQuaternionExtensions.SlerpWithReferenceUp(
+ stateA.RawOrientation, stateB.RawOrientation, t, state.ReferenceUp);
+ }
+ else
+ {
+ // Rotate while preserving our lookAt target
+ dirTarget = dirTarget.normalized;
+ if ((dirTarget - state.ReferenceUp).AlmostZero()
+ || (dirTarget + state.ReferenceUp).AlmostZero())
+ {
+ // Looking up or down at the pole
+ state.RawOrientation = UnityQuaternionExtensions.SlerpWithReferenceUp(
+ stateA.RawOrientation, stateB.RawOrientation, t, state.ReferenceUp);
+ }
+ else
+ {
+ // Put the target in the center
+ state.RawOrientation = Quaternion.LookRotation(dirTarget, state.ReferenceUp);
+
+ // Blend the desired offsets from center
+ Vector2 deltaA = -stateA.RawOrientation.GetCameraRotationToTarget(
+ stateA.ReferenceLookAt - stateA.CorrectedPosition, stateA.ReferenceUp);
+ Vector2 deltaB = -stateB.RawOrientation.GetCameraRotationToTarget(
+ stateB.ReferenceLookAt - stateB.CorrectedPosition, stateB.ReferenceUp);
+ state.RawOrientation = state.RawOrientation.ApplyCameraRotation(
+ Vector2.Lerp(deltaA, deltaB, adjustedT), state.ReferenceUp);
+ }
+ }
+
+ // Accumulate the custom blendables and apply the weights
+ for (int i = 0; i < stateA.NumCustomBlendables; ++i)
+ {
+ CustomBlendable b = stateA.GetCustomBlendable(i);
+ b.m_Weight *= (1-t);
+ if (b.m_Weight > UnityVectorExtensions.Epsilon)
+ state.AddCustomBlendable(b);
+ }
+ for (int i = 0; i < stateB.NumCustomBlendables; ++i)
+ {
+ CustomBlendable b = stateB.GetCustomBlendable(i);
+ b.m_Weight *= t;
+ if (b.m_Weight > UnityVectorExtensions.Epsilon)
+ state.AddCustomBlendable(b);
+ }
+ return state;
+ }
+
+ float InterpolateFOV(float fovA, float fovB, float dA, float dB, float t)
+ {
+ // We interpolate shot height
+ float hA = dA * 2f * Mathf.Tan(fovA * Mathf.Deg2Rad / 2f);
+ float hB = dB * 2f * Mathf.Tan(fovB * Mathf.Deg2Rad / 2f);
+ float h = Mathf.Lerp(hA, hB, t);
+ float fov = 179f;
+ float d = Mathf.Lerp(dA, dB, t);
+ if (d > UnityVectorExtensions.Epsilon)
+ fov = 2f * Mathf.Atan(h / (2 * d)) * Mathf.Rad2Deg;
+ return Mathf.Clamp(fov, Mathf.Min(fovA, fovB), Mathf.Max(fovA, fovB));
+ }
+ }
+}
diff --git a/Assets/Cinemachine/Base/Runtime/Core/CameraState.cs.meta b/Assets/Cinemachine/Base/Runtime/Core/CameraState.cs.meta
new file mode 100644
index 0000000..b290ca4
--- /dev/null
+++ b/Assets/Cinemachine/Base/Runtime/Core/CameraState.cs.meta
@@ -0,0 +1,12 @@
+fileFormatVersion: 2
+guid: c2a918f460a69394eb9726b31e1d404c
+timeCreated: 1488314898
+licenseType: Store
+MonoImporter:
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Assets/Cinemachine/Base/Runtime/Core/CinemachineBlend.cs b/Assets/Cinemachine/Base/Runtime/Core/CinemachineBlend.cs
new file mode 100644
index 0000000..2e8da48
--- /dev/null
+++ b/Assets/Cinemachine/Base/Runtime/Core/CinemachineBlend.cs
@@ -0,0 +1,207 @@
+using System;
+using UnityEngine;
+
+namespace Cinemachine
+{
+ ///
+ /// Describes a blend between 2 Cinemachine Virtual Cameras, and holds the
+ /// current state of the blend.
+ ///
+ public class CinemachineBlend
+ {
+ /// First camera in the blend
+ public ICinemachineCamera CamA { get; set; }
+
+ /// Second camera in the blend
+ public ICinemachineCamera CamB { get; set; }
+
+ /// The curve that describes the way the blend transitions over time
+ /// from the first camera to the second. X-axis is time in seconds over which
+ /// the blend takes place and Y axis is blend weight (0..1)
+ public AnimationCurve BlendCurve { get; set; }
+
+ /// The current time relative to the start of the blend
+ public float TimeInBlend { get; set; }
+
+ /// The current weight of the blend. This is an evaluation of the
+ /// BlendCurve at the current time relative to the start of the blend.
+ /// 0 means camA, 1 means camB.
+ public float BlendWeight
+ {
+ get { return BlendCurve != null ? BlendCurve.Evaluate(TimeInBlend) : 0; }
+ }
+
+ /// Validity test for the blend. True if both cameras are defined.
+ public bool IsValid
+ {
+ get { return (CamA != null || CamB != null); }
+ }
+
+ /// Duration in seconds of the blend.
+ /// This is given read from the BlendCurve.
+ public float Duration { get; set; }
+
+ /// True if the time relative to the start of the blend is greater
+ /// than or equal to the blend duration
+ public bool IsComplete { get { return TimeInBlend >= Duration; } }
+
+ /// Text description of the blend, for debugging
+ public string Description
+ {
+ get
+ {
+ string fromName = (CamA != null) ? "[" + CamA.Name + "]": "(none)";
+ string toName = (CamB != null) ? "[" + CamB.Name + "]" : "(none)";
+ int percent = (int)(BlendWeight * 100f);
+ return string.Format("{0} {1}% from {2}", toName, percent, fromName);
+ }
+ }
+
+ /// Does the blend use a specific Cinemachine Virtual Camera?
+ /// The camera to test
+ /// True if the camera is involved in the blend
+ public bool Uses(ICinemachineCamera cam)
+ {
+ if (cam == CamA || cam == CamB)
+ return true;
+ BlendSourceVirtualCamera b = CamA as BlendSourceVirtualCamera;
+ if (b != null && b.Blend.Uses(cam))
+ return true;
+ b = CamB as BlendSourceVirtualCamera;
+ if (b != null && b.Blend.Uses(cam))
+ return true;
+ return false;
+ }
+
+ /// Construct a blend
+ /// First camera
+ /// Second camera
+ /// Blend curve
+ /// Current time in blend, relative to the start of the blend
+ public CinemachineBlend(
+ ICinemachineCamera a, ICinemachineCamera b, AnimationCurve curve, float duration, float t)
+ {
+ if (a == null || b == null)
+ throw new ArgumentException("Blend cameras cannot be null");
+ CamA = a;
+ CamB = b;
+ BlendCurve = curve;
+ TimeInBlend = t;
+ Duration = duration;
+ }
+
+ /// Make sure the source cameras get updated.
+ /// Default world up. Individual vcams may modify this
+ /// Time increment used for calculating time-based behaviours (e.g. damping)
+ public void UpdateCameraState(Vector3 worldUp, float deltaTime)
+ {
+ // Make sure both cameras have been updated (they are not necessarily
+ // enabled, and only enabled cameras get updated automatically
+ // every frame)
+ CinemachineCore.Instance.UpdateVirtualCamera(CamA, worldUp, deltaTime);
+ CinemachineCore.Instance.UpdateVirtualCamera(CamB, worldUp, deltaTime);
+ }
+
+ /// Compute the blended CameraState for the current time in the blend.
+ public CameraState State { get { return CameraState.Lerp(CamA.State, CamB.State, BlendWeight); } }
+ }
+
+ /// Definition of a Camera blend. This struct holds the information
+ /// necessary to generate a suitable AnimationCurve for a Cinemachine Blend.
+ [Serializable]
+ [DocumentationSorting(10.2f, DocumentationSortingAttribute.Level.UserRef)]
+ public struct CinemachineBlendDefinition
+ {
+ /// Supported predefined shapes for the blend curve.
+ [DocumentationSorting(10.21f, DocumentationSortingAttribute.Level.UserRef)]
+ public enum Style
+ {
+ /// Zero-length blend
+ Cut,
+ /// S-shaped curve, giving a gentle and smooth transition
+ EaseInOut,
+ /// Linear out of the outgoing shot, and easy into the incoming
+ EaseIn,
+ /// Easy out of the outgoing shot, and linear into the incoming
+ EaseOut,
+ /// Easy out of the outgoing, and hard into the incoming
+ HardIn,
+ /// Hard out of the outgoing, and easy into the incoming
+ HardOut,
+ /// Linear blend. Mechanical-looking.
+ Linear
+ };
+
+ /// The shape of the blend curve.
+ [Tooltip("Shape of the blend curve")]
+ public Style m_Style;
+
+ /// The duration (in seconds) of the blend
+ [Tooltip("Duration of the blend, in seconds")]
+ public float m_Time;
+
+ /// Constructor
+ /// The shape of the blend curve.
+ /// The duration (in seconds) of the blend
+ public CinemachineBlendDefinition(Style style, float time)
+ {
+ m_Style = style;
+ m_Time = time;
+ }
+
+ ///
+ /// An AnimationCurve specifying the interpolation duration and value
+ /// for this camera blend. The time of the last key frame is assumed to the be the
+ /// duration of the blend. Y-axis values must be in range [0,1] (internally clamped
+ /// within Blender) and time must be in range of [0, +infinity)
+ ///
+ public AnimationCurve BlendCurve
+ {
+ get
+ {
+ float time = Mathf.Max(0, m_Time);
+ switch (m_Style)
+ {
+ default:
+ case Style.Cut: return new AnimationCurve();
+ case Style.EaseInOut: return AnimationCurve.EaseInOut(0f, 0f, time, 1f);
+ case Style.EaseIn:
+ {
+ AnimationCurve curve = AnimationCurve.Linear(0f, 0f, time, 1f);
+ Keyframe[] keys = curve.keys;
+ keys[1].inTangent = 0;
+ curve.keys = keys;
+ return curve;
+ }
+ case Style.EaseOut:
+ {
+ AnimationCurve curve = AnimationCurve.Linear(0f, 0f, time, 1f);
+ Keyframe[] keys = curve.keys;
+ keys[0].outTangent = 0;
+ curve.keys = keys;
+ return curve;
+ }
+ case Style.HardIn:
+ {
+ AnimationCurve curve = AnimationCurve.Linear(0f, 0f, time, 1f);
+ Keyframe[] keys = curve.keys;
+ keys[0].outTangent = 0;
+ keys[1].inTangent = 1.5708f; // pi/2 = up
+ curve.keys = keys;
+ return curve;
+ }
+ case Style.HardOut:
+ {
+ AnimationCurve curve = AnimationCurve.Linear(0f, 0f, time, 1f);
+ Keyframe[] keys = curve.keys;
+ keys[0].outTangent = 1.5708f; // pi/2 = up
+ keys[1].inTangent = 0;
+ curve.keys = keys;
+ return curve;
+ }
+ case Style.Linear: return AnimationCurve.Linear(0f, 0f, time, 1f);
+ }
+ }
+ }
+ }
+}
diff --git a/Assets/Cinemachine/Base/Runtime/Core/CinemachineBlend.cs.meta b/Assets/Cinemachine/Base/Runtime/Core/CinemachineBlend.cs.meta
new file mode 100644
index 0000000..61bb18d
--- /dev/null
+++ b/Assets/Cinemachine/Base/Runtime/Core/CinemachineBlend.cs.meta
@@ -0,0 +1,12 @@
+fileFormatVersion: 2
+guid: 3fed8968b96eb924891cf86f5c51f661
+timeCreated: 1484407000
+licenseType: Store
+MonoImporter:
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Assets/Cinemachine/Base/Runtime/Core/CinemachineBlenderSettings.cs b/Assets/Cinemachine/Base/Runtime/Core/CinemachineBlenderSettings.cs
new file mode 100644
index 0000000..8abb672
--- /dev/null
+++ b/Assets/Cinemachine/Base/Runtime/Core/CinemachineBlenderSettings.cs
@@ -0,0 +1,95 @@
+using UnityEngine;
+using System;
+
+namespace Cinemachine
+{
+ ///
+ /// Asset that defines the rules for blending between Virtual Cameras.
+ ///
+ [DocumentationSorting(10, DocumentationSortingAttribute.Level.UserRef)]
+ [Serializable]
+ public sealed class CinemachineBlenderSettings : ScriptableObject
+ {
+ ///
+ /// Container specifying how two specific Cinemachine Virtual Cameras
+ /// blend together.
+ ///
+ [DocumentationSorting(10.1f, DocumentationSortingAttribute.Level.UserRef)]
+ [Serializable]
+ public struct CustomBlend
+ {
+ [Tooltip("When blending from this camera")]
+ public string m_From;
+
+ [Tooltip("When blending to this camera")]
+ public string m_To;
+
+ [Tooltip("Blend curve definition")]
+ public CinemachineBlendDefinition m_Blend;
+ }
+ /// The array containing explicitly defined blends between two Virtual Cameras
+ [Tooltip("The array containing explicitly defined blends between two Virtual Cameras")]
+ public CustomBlend[] m_CustomBlends = null;
+
+ /// Internal API for the inspector editopr: a label to represent any camera
+ public const string kBlendFromAnyCameraLabel = "**ANY CAMERA**";
+
+ ///
+ /// Attempts to find a blend curve which matches the to and from cameras as specified.
+ /// If no match is found, the function returns either the
+ /// default blend for this Blender or NULL depending on the state
+ /// of returnDefaultOnNoMatch.
+ ///
+ /// The game object name of the from camera
+ /// The game object name of the to camera
+ /// Curve to return if no curve found. Can be NULL.
+ ///
+ public AnimationCurve GetBlendCurveForVirtualCameras(
+ string fromCameraName, string toCameraName, AnimationCurve defaultCurve)
+ {
+ AnimationCurve anyToMe = null;
+ AnimationCurve meToAny = null;
+ if (m_CustomBlends != null)
+ {
+ for (int i = 0; i < m_CustomBlends.Length; ++i)
+ {
+ // Attempt to find direct name first
+ CustomBlend blendParams = m_CustomBlends[i];
+ if ((blendParams.m_From == fromCameraName)
+ && (blendParams.m_To == toCameraName))
+ {
+ return blendParams.m_Blend.BlendCurve;
+ }
+ // If we come across default applicable wildcards, remember them
+ if (blendParams.m_From == kBlendFromAnyCameraLabel)
+ {
+ if (!string.IsNullOrEmpty(toCameraName)
+ && blendParams.m_To == toCameraName)
+ {
+ anyToMe = blendParams.m_Blend.BlendCurve;
+ }
+ else if (blendParams.m_To == kBlendFromAnyCameraLabel)
+ defaultCurve = blendParams.m_Blend.BlendCurve;
+ }
+ else if (blendParams.m_To == kBlendFromAnyCameraLabel
+ && !string.IsNullOrEmpty(fromCameraName)
+ && blendParams.m_From == fromCameraName)
+ {
+ meToAny = blendParams.m_Blend.BlendCurve;
+ }
+ }
+ }
+
+ // If nothing is found try to find wild card blends from any
+ // camera to our new one
+ if (anyToMe != null)
+ return anyToMe;
+
+ // Still have nothing? Try from our camera to any camera
+ if (meToAny != null)
+ return meToAny;
+
+ return defaultCurve;
+ }
+ }
+}
diff --git a/Assets/Cinemachine/Base/Runtime/Core/CinemachineBlenderSettings.cs.meta b/Assets/Cinemachine/Base/Runtime/Core/CinemachineBlenderSettings.cs.meta
new file mode 100644
index 0000000..ed99c07
--- /dev/null
+++ b/Assets/Cinemachine/Base/Runtime/Core/CinemachineBlenderSettings.cs.meta
@@ -0,0 +1,12 @@
+fileFormatVersion: 2
+guid: 36baaa8bdcb9d8b49b9199833965d2c3
+timeCreated: 1486497606
+licenseType: Store
+MonoImporter:
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Assets/Cinemachine/Base/Runtime/Core/CinemachineComponentBase.cs b/Assets/Cinemachine/Base/Runtime/Core/CinemachineComponentBase.cs
new file mode 100644
index 0000000..cfcbaf8
--- /dev/null
+++ b/Assets/Cinemachine/Base/Runtime/Core/CinemachineComponentBase.cs
@@ -0,0 +1,77 @@
+using UnityEngine;
+
+namespace Cinemachine
+{
+ ///
+ /// An abstract representation of a mutator acting on a Cinemachine Virtual Camera
+ ///
+ [DocumentationSorting(24, DocumentationSortingAttribute.Level.API)]
+ public abstract class CinemachineComponentBase : MonoBehaviour
+ {
+ /// Useful constant for very small floats
+ protected const float Epsilon = Utility.UnityVectorExtensions.Epsilon;
+
+ /// Get the associated CinemachineVirtualCameraBase
+ public CinemachineVirtualCameraBase VirtualCamera
+ {
+ get
+ {
+ if (m_vcamOwner == null)
+ m_vcamOwner = gameObject.transform.parent.gameObject.GetComponent();
+ return m_vcamOwner;
+ }
+ }
+ CinemachineVirtualCameraBase m_vcamOwner;
+
+ /// Returns the owner vcam's Follow target.
+ public Transform FollowTarget
+ {
+ get
+ {
+ CinemachineVirtualCameraBase vcam = VirtualCamera;
+ return vcam == null ? null : vcam.Follow;
+ }
+ }
+
+ /// Returns the owner vcam's LookAt target.
+ public Transform LookAtTarget
+ {
+ get
+ {
+ CinemachineVirtualCameraBase vcam = VirtualCamera;
+ return vcam == null ? null : vcam.LookAt;
+ }
+ }
+
+ /// Returns the owner vcam's CameraState.
+ public CameraState VcamState
+ {
+ get
+ {
+ CinemachineVirtualCameraBase vcam = VirtualCamera;
+ return vcam == null ? CameraState.Default : vcam.State;
+ }
+ }
+
+ /// Returns true if this object is enabled and set up to produce results.
+ public abstract bool IsValid { get; }
+
+ /// Override this to do such things as offset the RefereceLookAt.
+ /// Base class implementation does nothing.
+ /// Input state that must be mutated
+ public virtual void PrePipelineMutateCameraState(ref CameraState state) {}
+
+ /// What part of the pipeline this fits into
+ public abstract CinemachineCore.Stage Stage { get; }
+
+ /// Mutates the camera state. This state will later be applied to the camera.
+ /// Input state that must be mutated
+ /// Delta time for time-based effects (ignore if less than 0)
+ public abstract void MutateCameraState(ref CameraState curState, float deltaTime);
+
+ /// API for the editor, to process a position drag from the user.
+ /// Base class implementation does nothing.
+ /// The amount dragged this frame
+ public virtual void OnPositionDragged(Vector3 delta) {}
+ }
+}
diff --git a/Assets/Cinemachine/Base/Runtime/Core/CinemachineComponentBase.cs.meta b/Assets/Cinemachine/Base/Runtime/Core/CinemachineComponentBase.cs.meta
new file mode 100644
index 0000000..fde2723
--- /dev/null
+++ b/Assets/Cinemachine/Base/Runtime/Core/CinemachineComponentBase.cs.meta
@@ -0,0 +1,12 @@
+fileFormatVersion: 2
+guid: b2f73bdc979030e419f33c10913639cc
+timeCreated: 1510078351
+licenseType: Store
+MonoImporter:
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Assets/Cinemachine/Base/Runtime/Core/CinemachineCore.cs b/Assets/Cinemachine/Base/Runtime/Core/CinemachineCore.cs
new file mode 100644
index 0000000..8bf6877
--- /dev/null
+++ b/Assets/Cinemachine/Base/Runtime/Core/CinemachineCore.cs
@@ -0,0 +1,429 @@
+using UnityEngine;
+using System.Collections.Generic;
+
+namespace Cinemachine
+{
+ /// A singleton that manages complete lists of CinemachineBrain and,
+ /// Cinemachine Virtual Cameras, and the priority queue. Provides
+ /// services to keeping track of whether Cinemachine Virtual Cameras have
+ /// been updated each frame.
+ public sealed class CinemachineCore
+ {
+ /// Data version string. Used to upgrade from legacy projects
+ public static readonly int kStreamingVersion = 20170927;
+
+ /// Human-readable Cinemachine Version
+ public static readonly string kVersionString = "2.1";
+
+ ///
+ /// Stages in the Cinemachine Component pipeline, used for
+ /// UI organization>. This enum defines the pipeline order.
+ ///
+ public enum Stage
+ {
+ /// Second stage: position the camera in space
+ Body,
+
+ /// Third stage: orient the camera to point at the target
+ Aim,
+
+ /// Final stage: apply noise (this is done separately, in the
+ /// Correction channel of the CameraState)
+ Noise
+ };
+
+ private static CinemachineCore sInstance = null;
+
+ /// Get the singleton instance
+ public static CinemachineCore Instance
+ {
+ get
+ {
+ if (sInstance == null)
+ sInstance = new CinemachineCore();
+ return sInstance;
+ }
+ }
+
+ ///
+ /// If true, show hidden Cinemachine objects, to make manual script mapping possible.
+ ///
+ public static bool sShowHiddenObjects = false;
+
+ /// Delegate for overriding Unity's default input system. Returns the value
+ /// of the named axis.
+ public delegate float AxisInputDelegate(string axisName);
+
+ /// Delegate for overriding Unity's default input system.
+ /// If you set this, then your delegate will be called instead of
+ /// System.Input.GetAxis(axisName) whenever in-game user input is needed.
+ public static AxisInputDelegate GetInputAxis = UnityEngine.Input.GetAxis;
+
+ /// List of all active CinemachineBrains.
+ private List mActiveBrains = new List();
+
+ /// Access the array of active CinemachineBrains in the scene
+ public int BrainCount { get { return mActiveBrains.Count; } }
+
+ /// Access the array of active CinemachineBrains in the scene
+ /// without gebnerating garbage
+ /// Index of the brain to access, range 0-BrainCount
+ /// The brain at the specified index
+ public CinemachineBrain GetActiveBrain(int index)
+ {
+ return mActiveBrains[index];
+ }
+
+ /// Called when a CinemachineBrain is enabled.
+ internal void AddActiveBrain(CinemachineBrain brain)
+ {
+ // First remove it, just in case it's being added twice
+ RemoveActiveBrain(brain);
+ mActiveBrains.Insert(0, brain);
+ }
+
+ /// Called when a CinemachineBrain is disabled.
+ internal void RemoveActiveBrain(CinemachineBrain brain)
+ {
+ mActiveBrains.Remove(brain);
+ }
+
+ /// List of all active ICinemachineCameras.
+ private List mActiveCameras = new List();
+
+ ///
+ /// List of all active Cinemachine Virtual Cameras for all brains.
+ /// This list is kept sorted by priority.
+ ///
+ public int VirtualCameraCount { get { return mActiveCameras.Count; } }
+
+ /// Access the array of active ICinemachineCamera in the scene
+ /// without gebnerating garbage
+ /// Index of the camera to access, range 0-VirtualCameraCount
+ /// The virtual camera at the specified index
+ public ICinemachineCamera GetVirtualCamera(int index)
+ {
+ return mActiveCameras[index];
+ }
+
+ /// Called when a Cinemachine Virtual Camera is enabled.
+ internal void AddActiveCamera(ICinemachineCamera vcam)
+ {
+ // Bring it to the top of the list
+ RemoveActiveCamera(vcam);
+
+ // Keep list sorted by priority
+ int insertIndex;
+ for (insertIndex = 0; insertIndex < mActiveCameras.Count; ++insertIndex)
+ if (vcam.Priority >= mActiveCameras[insertIndex].Priority)
+ break;
+
+ mActiveCameras.Insert(insertIndex, vcam);
+ }
+
+ /// Called when a Cinemachine Virtual Camera is disabled.
+ internal void RemoveActiveCamera(ICinemachineCamera vcam)
+ {
+ mActiveCameras.Remove(vcam);
+ }
+
+ // Registry of all vcams that are parented (i.e. slaves of) to other vcams
+ private List> mChildCameras = new List>();
+
+ /// Called when a child vcam is enabled.
+ internal void AddChildCamera(ICinemachineCamera vcam)
+ {
+ RemoveChildCamera(vcam);
+
+ int parentLevel = 0;
+ for (ICinemachineCamera p = vcam; p != null; p = p.ParentCamera)
+ ++parentLevel;
+ while (mChildCameras.Count < parentLevel)
+ mChildCameras.Add(new List());
+ mChildCameras[parentLevel-1].Add(vcam);
+ }
+
+ /// Called when a child vcam is disabled.
+ internal void RemoveChildCamera(ICinemachineCamera vcam)
+ {
+ for (int i = 0; i < mChildCameras.Count; ++i)
+ mChildCameras[i].Remove(vcam);
+ }
+
+ /// Update all the active vcams in the scene, in the correct dependency order.
+ internal void UpdateAllActiveVirtualCameras(Vector3 worldUp, float deltaTime)
+ {
+ //UnityEngine.Profiling.Profiler.BeginSample("CinemachineCore.UpdateAllActiveVirtualCameras");
+ int numCameras;
+
+ // Update the leaf-most cameras first
+ //UnityEngine.Profiling.Profiler.BeginSample("CinemachineCore.UpdateAllActiveVirtualCameras.leaf-most");
+ for (int i = mChildCameras.Count-1; i >= 0; --i)
+ {
+ numCameras = mChildCameras[i].Count;
+ for (int j = 0; j < numCameras; ++j)
+ UpdateVirtualCamera(mChildCameras[i][j], worldUp, deltaTime);
+ }
+ //UnityEngine.Profiling.Profiler.EndSample();
+
+ // Then all the top-level cameras
+ numCameras = VirtualCameraCount;
+ for (int i = 0; i < numCameras; ++i)
+ UpdateVirtualCamera(GetVirtualCamera(i), worldUp, deltaTime);
+ //UnityEngine.Profiling.Profiler.EndSample();
+ }
+
+ ///
+ /// Update a single Cinemachine Virtual Camera if and only if it
+ /// hasn't already been updated this frame. Always update vcams via this method.
+ /// Calling this more than once per frame for the same camera will have no effect.
+ ///
+ internal bool UpdateVirtualCamera(ICinemachineCamera vcam, Vector3 worldUp, float deltaTime)
+ {
+ //UnityEngine.Profiling.Profiler.BeginSample("CinemachineCore.UpdateVirtualCamera");
+ int now = Time.frameCount;
+ UpdateFilter filter = CurrentUpdateFilter;
+ bool isSmartUpdate = filter != UpdateFilter.ForcedFixed
+ && filter != UpdateFilter.ForcedLate;
+ bool isSmartLateUpdate = filter == UpdateFilter.Late;
+ if (!isSmartUpdate)
+ {
+ if (filter == UpdateFilter.ForcedFixed)
+ filter = UpdateFilter.Fixed;
+ if (filter == UpdateFilter.ForcedLate)
+ filter = UpdateFilter.Late;
+ }
+
+ if (mUpdateStatus == null)
+ mUpdateStatus = new Dictionary();
+ if (vcam.VirtualCameraGameObject == null)
+ {
+ if (mUpdateStatus.ContainsKey(vcam))
+ mUpdateStatus.Remove(vcam);
+ //UnityEngine.Profiling.Profiler.EndSample();
+ return false; // camera was deleted
+ }
+ UpdateStatus status;
+ if (!mUpdateStatus.TryGetValue(vcam, out status))
+ {
+ status = new UpdateStatus(now);
+ mUpdateStatus.Add(vcam, status);
+ }
+
+ int subframes = isSmartLateUpdate ? 1 : CinemachineBrain.GetSubframeCount();
+ if (status.lastUpdateFrame != now)
+ status.lastUpdateSubframe = 0;
+
+ // If we're in smart update mode and the target moved, then we must examine
+ // how the target has been moving recently in order to figure out whether to
+ // update now
+ bool updateNow = !isSmartUpdate;
+ if (isSmartUpdate)
+ {
+ Matrix4x4 targetPos;
+ if (!GetTargetPosition(vcam, out targetPos))
+ updateNow = isSmartLateUpdate; // no target
+ else
+ updateNow = status.ChoosePreferredUpdate(now, targetPos, filter)
+ == filter;
+ }
+
+ if (updateNow)
+ {
+ status.preferredUpdate = filter;
+ while (status.lastUpdateSubframe < subframes)
+ {
+//Debug.Log(vcam.Name + ": frame " + Time.frameCount + "." + status.lastUpdateSubframe + ", " + CurrentUpdateFilter + ", deltaTime = " + deltaTime);
+ vcam.UpdateCameraState(worldUp, deltaTime);
+ ++status.lastUpdateSubframe;
+ }
+ status.lastUpdateFrame = now;
+ }
+
+ mUpdateStatus[vcam] = status;
+ //UnityEngine.Profiling.Profiler.EndSample();
+ return true;
+ }
+
+ struct UpdateStatus
+ {
+ const int kWindowSize = 30;
+
+ public int lastUpdateFrame;
+ public int lastUpdateSubframe;
+
+ public int windowStart;
+ public int numWindowLateUpdateMoves;
+ public int numWindowFixedUpdateMoves;
+ public int numWindows;
+ public UpdateFilter preferredUpdate;
+
+ public Matrix4x4 targetPos;
+
+ public UpdateStatus(int currentFrame)
+ {
+ lastUpdateFrame = -1;
+ lastUpdateSubframe = 0;
+ windowStart = currentFrame;
+ numWindowLateUpdateMoves = 0;
+ numWindowFixedUpdateMoves = 0;
+ numWindows = 0;
+ preferredUpdate = UpdateFilter.Late;
+ targetPos = Matrix4x4.zero;
+ }
+
+ // Important: updateFilter may ONLY be Late or Fixed
+ public UpdateFilter ChoosePreferredUpdate(
+ int currentFrame, Matrix4x4 pos, UpdateFilter updateFilter)
+ {
+ if (targetPos != pos)
+ {
+ if (updateFilter == UpdateFilter.Late)
+ ++numWindowLateUpdateMoves;
+ else if (lastUpdateSubframe == 0)
+ ++numWindowFixedUpdateMoves;
+ targetPos = pos;
+ }
+ //Debug.Log("Fixed=" + numWindowFixedUpdateMoves + ", Late=" + numWindowLateUpdateMoves);
+ UpdateFilter choice = preferredUpdate;
+ bool inconsistent = numWindowLateUpdateMoves > 0 && numWindowFixedUpdateMoves > 0;
+ if (inconsistent || numWindowLateUpdateMoves >= numWindowFixedUpdateMoves)
+ choice = UpdateFilter.Late;
+ else
+ choice = UpdateFilter.Fixed;
+ if (numWindows == 0)
+ preferredUpdate = choice;
+
+ if (windowStart + kWindowSize <= currentFrame)
+ {
+ preferredUpdate = choice;
+ ++numWindows;
+ windowStart = currentFrame;
+ numWindowLateUpdateMoves = numWindowFixedUpdateMoves = 0;
+ }
+ return preferredUpdate;
+ }
+ }
+ Dictionary mUpdateStatus;
+
+ /// Internal use only
+ public enum UpdateFilter { Fixed, ForcedFixed, Late, ForcedLate };
+ internal UpdateFilter CurrentUpdateFilter { get; set; }
+ private static bool GetTargetPosition(ICinemachineCamera vcam, out Matrix4x4 targetPos)
+ {
+ ICinemachineCamera vcamTarget = vcam.LiveChildOrSelf;
+ if (vcamTarget == null || vcamTarget.VirtualCameraGameObject == null)
+ {
+ targetPos = Matrix4x4.identity;
+ return false;
+ }
+ targetPos = vcamTarget.VirtualCameraGameObject.transform.localToWorldMatrix;
+ if (vcamTarget.LookAt != null)
+ {
+ targetPos = vcamTarget.LookAt.localToWorldMatrix;
+ return true;
+ }
+ if (vcamTarget.Follow != null)
+ {
+ targetPos = vcamTarget.Follow.localToWorldMatrix;
+ return true;
+ }
+ // If no target, use the vcam itself
+ targetPos = vcam.VirtualCameraGameObject.transform.localToWorldMatrix;
+ return true;
+ }
+
+ /// Internal use only
+ public UpdateFilter GetVcamUpdateStatus(ICinemachineCamera vcam)
+ {
+ UpdateStatus status;
+ if (mUpdateStatus == null || !mUpdateStatus.TryGetValue(vcam, out status))
+ return UpdateFilter.Late;
+ return status.preferredUpdate;
+ }
+
+ ///
+ /// Is this virtual camera currently actively controlling any Camera?
+ ///
+ public bool IsLive(ICinemachineCamera vcam)
+ {
+ if (vcam != null)
+ {
+ for (int i = 0; i < BrainCount; ++i)
+ {
+ CinemachineBrain b = GetActiveBrain(i);
+ if (b != null && b.IsLive(vcam))
+ return true;
+ }
+ }
+ return false;
+ }
+
+ ///
+ /// Signal that the virtual has been activated.
+ /// If the camera is live, then all CinemachineBrains that are showing it will
+ /// send an activation event.
+ ///
+ public void GenerateCameraActivationEvent(ICinemachineCamera vcam)
+ {
+ if (vcam != null)
+ {
+ for (int i = 0; i < BrainCount; ++i)
+ {
+ CinemachineBrain b = GetActiveBrain(i);
+ if (b != null && b.IsLive(vcam))
+ b.m_CameraActivatedEvent.Invoke(vcam);
+ }
+ }
+ }
+
+ ///
+ /// Signal that the virtual camera's content is discontinuous WRT the previous frame.
+ /// If the camera is live, then all CinemachineBrains that are showing it will send a cut event.
+ ///
+ public void GenerateCameraCutEvent(ICinemachineCamera vcam)
+ {
+ if (vcam != null)
+ {
+ for (int i = 0; i < BrainCount; ++i)
+ {
+ CinemachineBrain b = GetActiveBrain(i);
+ if (b != null && b.IsLive(vcam))
+ b.m_CameraCutEvent.Invoke(b);
+ }
+ }
+ }
+
+ ///
+ /// Try to find a CinemachineBrain to associate with a
+ /// Cinemachine Virtual Camera. The first CinemachineBrain
+ /// in which this Cinemachine Virtual Camera is live will be used.
+ /// If none, then the first active CinemachineBrain will be used.
+ /// Brains with OutputCamera == null will not be returned.
+ /// Final result may be null.
+ ///
+ /// Virtual camera whose potential brain we need.
+ /// First CinemachineBrain found that might be
+ /// appropriate for this vcam, or null
+ public CinemachineBrain FindPotentialTargetBrain(ICinemachineCamera vcam)
+ {
+ int numBrains = BrainCount;
+ if (vcam != null && numBrains > 1)
+ {
+ for (int i = 0; i < numBrains; ++i)
+ {
+ CinemachineBrain b = GetActiveBrain(i);
+ if (b != null && b.OutputCamera != null && b.IsLive(vcam))
+ return b;
+ }
+ }
+ for (int i = 0; i < numBrains; ++i)
+ {
+ CinemachineBrain b = GetActiveBrain(i);
+ if (b != null && b.OutputCamera != null)
+ return b;
+ }
+ return null;
+ }
+ }
+}
diff --git a/Assets/Cinemachine/Base/Runtime/Core/CinemachineCore.cs.meta b/Assets/Cinemachine/Base/Runtime/Core/CinemachineCore.cs.meta
new file mode 100644
index 0000000..8c8c945
--- /dev/null
+++ b/Assets/Cinemachine/Base/Runtime/Core/CinemachineCore.cs.meta
@@ -0,0 +1,12 @@
+fileFormatVersion: 2
+guid: c7d73314dfe49f8458398c6dc8edcda8
+timeCreated: 1484001119
+licenseType: Store
+MonoImporter:
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Assets/Cinemachine/Base/Runtime/Core/CinemachineDebugLogger.cs b/Assets/Cinemachine/Base/Runtime/Core/CinemachineDebugLogger.cs
new file mode 100644
index 0000000..77c4912
--- /dev/null
+++ b/Assets/Cinemachine/Base/Runtime/Core/CinemachineDebugLogger.cs
@@ -0,0 +1,47 @@
+using UnityEngine;
+using System.Collections.Generic;
+
+namespace Cinemachine.Utility
+{
+ /// Manages onscreen positions for Cinemachine debugging output
+ public class CinemachineGameWindowDebug
+ {
+ static HashSet