chore: initial commit
This commit is contained in:
@@ -0,0 +1,99 @@
|
||||
using UnityEngine;
|
||||
using System;
|
||||
using System.Reflection;
|
||||
#if UNITY_EDITOR
|
||||
using UnityEditor;
|
||||
#endif
|
||||
|
||||
namespace MoreMountains.Tools
|
||||
{
|
||||
/// <summary>
|
||||
/// This class will let you create and save a .curves asset in the specified path
|
||||
/// This asset will include curves (anti or not) from the MMTween library, to use anywhere animation curves are required
|
||||
/// </summary>
|
||||
public class MMAnimationCurveGenerator : MonoBehaviour
|
||||
{
|
||||
[Header("Save settings")]
|
||||
/// the path to save the asset at
|
||||
public string AnimationCurveFilePath = "Assets/MMTools/MMTween/Editor/";
|
||||
/// the name of the asset
|
||||
public string AnimationCurveFileName = "MMCurves.curves";
|
||||
|
||||
[Header("Animation Curves")]
|
||||
/// the dots resolution (higher is better)
|
||||
public int Resolution = 50;
|
||||
/// whether to generate anti curves (y goes from 1 to 0) or regular ones (y goes from 0 to 1)
|
||||
public bool GenerateAntiCurves = false;
|
||||
|
||||
[MMInspectorButton("GenerateAnimationCurvesAsset")]
|
||||
public bool GenerateAnimationCurvesButton;
|
||||
|
||||
protected Type _scriptableObjectType;
|
||||
protected Keyframe _keyframe = new Keyframe();
|
||||
protected MethodInfo _addMethodInfo;
|
||||
protected object[] _parameters;
|
||||
|
||||
/// <summary>
|
||||
/// Generates the asset and saves it at the requested path
|
||||
/// </summary>
|
||||
public virtual void GenerateAnimationCurvesAsset()
|
||||
{
|
||||
// we get the method to add to our object
|
||||
_scriptableObjectType = Type.GetType("UnityEditor.CurvePresetLibrary, UnityEditor");
|
||||
_addMethodInfo = _scriptableObjectType.GetMethod("Add");
|
||||
|
||||
// we create a new instance of our curve asset
|
||||
ScriptableObject curveAsset = ScriptableObject.CreateInstance(_scriptableObjectType);
|
||||
|
||||
// for each type of curve, we create an animation curve
|
||||
foreach (MMTween.MMTweenCurve curve in Enum.GetValues(typeof(MMTween.MMTweenCurve)))
|
||||
{
|
||||
CreateAnimationCurve(curveAsset, curve, Resolution, GenerateAntiCurves);
|
||||
}
|
||||
|
||||
// we save it to file
|
||||
#if UNITY_EDITOR
|
||||
AssetDatabase.CreateAsset(curveAsset, AnimationCurveFilePath + AnimationCurveFileName);
|
||||
AssetDatabase.SaveAssets();
|
||||
AssetDatabase.Refresh();
|
||||
#endif
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates an animation curve of the specified type and resolution, and adds it to the specified asset
|
||||
/// </summary>
|
||||
/// <param name="asset"></param>
|
||||
/// <param name="curveType"></param>
|
||||
/// <param name="curveResolution"></param>
|
||||
/// <param name="anti"></param>
|
||||
protected virtual void CreateAnimationCurve(ScriptableObject asset, MMTween.MMTweenCurve curveType, int curveResolution, bool anti)
|
||||
{
|
||||
// generates an animation curve
|
||||
AnimationCurve animationCurve = new AnimationCurve();
|
||||
|
||||
for (int i = 0; i < curveResolution; i++)
|
||||
{
|
||||
_keyframe.time = i / (curveResolution - 1f);
|
||||
if (anti)
|
||||
{
|
||||
_keyframe.value = MMTween.Tween(_keyframe.time, 0f, 1f, 1f, 0f, curveType);
|
||||
}
|
||||
else
|
||||
{
|
||||
_keyframe.value = MMTween.Tween(_keyframe.time, 0f, 1f, 0f, 1f, curveType);
|
||||
}
|
||||
animationCurve.AddKey(_keyframe);
|
||||
}
|
||||
// smoothes the curve's tangents
|
||||
for (int j = 0; j < curveResolution; j++)
|
||||
{
|
||||
animationCurve.SmoothTangents(j, 0f);
|
||||
}
|
||||
|
||||
// we add the curve to the scriptable object
|
||||
_parameters = new object[] { animationCurve, curveType.ToString() };
|
||||
_addMethodInfo.Invoke(asset, _parameters);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ce2656e6b00dc8d4788dc4d382e1588a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
476
Assets/Feel/MMTools/Core/MMTween/MMFollowTarget.cs
Normal file
476
Assets/Feel/MMTools/Core/MMTween/MMFollowTarget.cs
Normal file
@@ -0,0 +1,476 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace MoreMountains.Tools
|
||||
{
|
||||
/// <summary>
|
||||
/// Add this component to an object and it'll get moved towards the target at update, with or without interpolation based on your settings
|
||||
/// </summary>
|
||||
[AddComponentMenu("More Mountains/Tools/Movement/MMFollowTarget")]
|
||||
public class MMFollowTarget : MonoBehaviour
|
||||
{
|
||||
/// the possible update modes
|
||||
public enum UpdateModes { Update, FixedUpdate, LateUpdate }
|
||||
/// the possible follow modes
|
||||
public enum FollowModes { RegularLerp, MMLerp, MMSpring }
|
||||
/// whether to operate in world or local space
|
||||
public enum PositionSpaces { World, Local }
|
||||
|
||||
[Header("Follow Position")]
|
||||
/// whether or not the object is currently following its target's position
|
||||
public bool FollowPosition = true;
|
||||
/// whether this object should follow its target on the X axis
|
||||
[MMCondition("FollowPosition", true)]
|
||||
public bool FollowPositionX = true;
|
||||
/// whether this object should follow its target on the Y axis
|
||||
[MMCondition("FollowPosition", true)]
|
||||
public bool FollowPositionY = true;
|
||||
/// whether this object should follow its target on the Z axis
|
||||
[MMCondition("FollowPosition", true)]
|
||||
public bool FollowPositionZ = true;
|
||||
/// whether to operate in world or local space
|
||||
[MMCondition("FollowPosition", true)]
|
||||
public PositionSpaces PositionSpace = PositionSpaces.World;
|
||||
|
||||
[Header("Follow Rotation")]
|
||||
/// whether or not the object is currently following its target's rotation
|
||||
public bool FollowRotation = true;
|
||||
|
||||
[Header("Follow Scale")]
|
||||
/// whether or not the object is currently following its target's rotation
|
||||
public bool FollowScale = true;
|
||||
/// the factor to apply to the scale when following
|
||||
[MMCondition("FollowScale", true)]
|
||||
public float FollowScaleFactor = 1f;
|
||||
|
||||
[Header("Target")]
|
||||
/// the target to follow
|
||||
public Transform Target;
|
||||
/// the offset to apply to the followed target
|
||||
[MMCondition("FollowPosition", true)]
|
||||
public Vector3 Offset;
|
||||
///whether or not to add the initial x distance to the offset
|
||||
[MMCondition("FollowPosition", true)]
|
||||
public bool AddInitialDistanceXToXOffset = false;
|
||||
///whether or not to add the initial y distance to the offset
|
||||
[MMCondition("FollowPosition", true)]
|
||||
public bool AddInitialDistanceYToYOffset = false;
|
||||
///whether or not to add the initial z distance to the offset
|
||||
[MMCondition("FollowPosition", true)]
|
||||
public bool AddInitialDistanceZToZOffset = false;
|
||||
|
||||
[Header("Position Interpolation")]
|
||||
/// whether or not we need to interpolate the movement
|
||||
public bool InterpolatePosition = true;
|
||||
/// the follow mode to use when following position
|
||||
[MMCondition("InterpolatePosition", true)]
|
||||
public FollowModes FollowPositionMode = FollowModes.MMLerp;
|
||||
/// the speed at which to interpolate the follower's movement
|
||||
[MMCondition("InterpolatePosition", true)]
|
||||
public float FollowPositionSpeed = 10f;
|
||||
/// higher values mean more damping, less spring, low values mean less damping, more spring
|
||||
[MMEnumCondition("FollowPositionMode", (int)FollowModes.MMSpring)]
|
||||
[Range(0.01f, 1.0f)]
|
||||
public float PositionSpringDamping = 0.3f;
|
||||
/// the frequency at which the spring should "vibrate", in Hz (1 : the spring will do one full period in one second)
|
||||
[MMEnumCondition("FollowPositionMode", (int)FollowModes.MMSpring)]
|
||||
public float PositionSpringFrequency = 3f;
|
||||
|
||||
[Header("Rotation Interpolation")]
|
||||
/// whether or not we need to interpolate the movement
|
||||
public bool InterpolateRotation = true;
|
||||
/// the follow mode to use when interpolating the rotation
|
||||
[MMCondition("InterpolateRotation", true)]
|
||||
public FollowModes FollowRotationMode = FollowModes.MMLerp;
|
||||
/// the speed at which to interpolate the follower's rotation
|
||||
[MMCondition("InterpolateRotation", true)]
|
||||
public float FollowRotationSpeed = 10f;
|
||||
/// higher values mean more damping, less spring, low values mean less damping, more spring
|
||||
[MMEnumCondition("FollowRotationMode", (int)FollowModes.MMSpring)]
|
||||
[Range(0.01f, 1.0f)]
|
||||
public float RotationSpringDamping = 0.3f;
|
||||
/// the frequency at which the spring should "vibrate", in Hz (1 : the spring will do one full period in one second)
|
||||
[MMEnumCondition("FollowRotationMode", (int)FollowModes.MMSpring)]
|
||||
public float RotationSpringFrequency = 3f;
|
||||
|
||||
[Header("Scale Interpolation")]
|
||||
/// whether or not we need to interpolate the scale
|
||||
public bool InterpolateScale = true;
|
||||
/// the follow mode to use when interpolating the scale
|
||||
[MMCondition("InterpolateScale", true)]
|
||||
public FollowModes FollowScaleMode = FollowModes.MMLerp;
|
||||
/// the speed at which to interpolate the follower's scale
|
||||
[MMCondition("InterpolateScale", true)]
|
||||
public float FollowScaleSpeed = 10f;
|
||||
/// higher values mean more damping, less spring, low values mean less damping, more spring
|
||||
[MMEnumCondition("FollowScaleMode", (int)FollowModes.MMSpring)]
|
||||
[Range(0.01f, 1.0f)]
|
||||
public float ScaleSpringDamping = 0.3f;
|
||||
/// the frequency at which the spring should "vibrate", in Hz (1 : the spring will do one full period in one second)
|
||||
[MMEnumCondition("FollowScaleMode", (int)FollowModes.MMSpring)]
|
||||
public float ScaleSpringFrequency = 3f;
|
||||
|
||||
[Header("Mode")]
|
||||
/// the update at which the movement happens
|
||||
public UpdateModes UpdateMode = UpdateModes.Update;
|
||||
/// if this is true, this component will self disable when its host game object gets disabled
|
||||
public bool DisableSelfOnSetActiveFalse = false;
|
||||
|
||||
[Header("Distances")]
|
||||
/// whether or not to force a minimum distance between the object and its target before it starts following
|
||||
public bool UseMinimumDistanceBeforeFollow = false;
|
||||
/// the minimum distance to keep between the object and its target
|
||||
public float MinimumDistanceBeforeFollow = 1f;
|
||||
/// whether or not we want to make sure the object is never too far away from its target
|
||||
public bool UseMaximumDistance = false;
|
||||
/// the maximum distance at which the object can be away from its target
|
||||
public float MaximumDistance = 1f;
|
||||
|
||||
[Header("Anchor")]
|
||||
/// if this is true, the movement will be constrained around the initial position
|
||||
public bool AnchorToInitialPosition;
|
||||
/// the maximum distance around the initial position at which the transform can move
|
||||
[MMCondition("AnchorToInitialPosition", true)]
|
||||
public float MaxDistanceToAnchor = 1f;
|
||||
|
||||
protected bool _localSpace { get { return PositionSpace == PositionSpaces.Local; } }
|
||||
|
||||
protected Vector3 _positionVelocity = Vector3.zero;
|
||||
protected Vector3 _scaleVelocity = Vector3.zero;
|
||||
protected Vector3 _rotationVelocity = Vector3.zero;
|
||||
|
||||
protected Vector3 _initialPosition;
|
||||
protected Vector3 _direction;
|
||||
|
||||
protected Vector3 _newPosition;
|
||||
protected Vector3 _newRotation;
|
||||
protected Vector3 _newScale;
|
||||
|
||||
protected Vector3 _newTargetPosition;
|
||||
protected Quaternion _newTargetRotation;
|
||||
protected Vector3 _newTargetRotationEulerAngles;
|
||||
protected Vector3 _newTargetRotationEulerAnglesLastFrame;
|
||||
protected Vector3 _newTargetScale;
|
||||
|
||||
protected float _rotationFloatVelocity;
|
||||
protected float _rotationFloatCurrent;
|
||||
protected float _rotationFloatTarget;
|
||||
|
||||
protected Vector3 _currentRotationEulerAngles;
|
||||
protected Quaternion _rotationBeforeSpring;
|
||||
|
||||
protected Quaternion _initialRotation;
|
||||
protected Vector3 _lastTargetPosition;
|
||||
|
||||
/// <summary>
|
||||
/// On start we store our initial position
|
||||
/// </summary>
|
||||
protected virtual void Start()
|
||||
{
|
||||
Initialization();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes the follow
|
||||
/// </summary>
|
||||
public virtual void Initialization()
|
||||
{
|
||||
SetInitialPosition();
|
||||
SetOffset();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Prevents the object from following the target anymore
|
||||
/// </summary>
|
||||
public virtual void StopFollowing()
|
||||
{
|
||||
FollowPosition = false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Makes the object follow the target
|
||||
/// </summary>
|
||||
public virtual void StartFollowing()
|
||||
{
|
||||
FollowPosition = true;
|
||||
SetInitialPosition();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Stores the initial position
|
||||
/// </summary>
|
||||
protected virtual void SetInitialPosition()
|
||||
{
|
||||
_initialPosition = _localSpace ? this.transform.localPosition : this.transform.position;
|
||||
_initialRotation = this.transform.rotation;
|
||||
_lastTargetPosition = _localSpace ? this.transform.localPosition : this.transform.position;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds initial offset to the offset if needed
|
||||
/// </summary>
|
||||
protected virtual void SetOffset()
|
||||
{
|
||||
if (Target == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Vector3 difference = this.transform.position - Target.transform.position;
|
||||
Offset.x = AddInitialDistanceXToXOffset ? difference.x : Offset.x;
|
||||
Offset.y = AddInitialDistanceYToYOffset ? difference.y : Offset.y;
|
||||
Offset.z = AddInitialDistanceZToZOffset ? difference.z : Offset.z;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// At update we follow our target
|
||||
/// </summary>
|
||||
protected virtual void Update()
|
||||
{
|
||||
if (Target == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (UpdateMode == UpdateModes.Update)
|
||||
{
|
||||
FollowTargetRotation();
|
||||
FollowTargetScale();
|
||||
FollowTargetPosition();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// At fixed update we follow our target
|
||||
/// </summary>
|
||||
protected virtual void FixedUpdate()
|
||||
{
|
||||
if (UpdateMode == UpdateModes.FixedUpdate)
|
||||
{
|
||||
FollowTargetRotation();
|
||||
FollowTargetScale();
|
||||
FollowTargetPosition();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// At late update we follow our target
|
||||
/// </summary>
|
||||
protected virtual void LateUpdate()
|
||||
{
|
||||
if (UpdateMode == UpdateModes.LateUpdate)
|
||||
{
|
||||
FollowTargetRotation();
|
||||
FollowTargetScale();
|
||||
FollowTargetPosition();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Follows the target, lerping the position or not based on what's been defined in the inspector
|
||||
/// </summary>
|
||||
protected virtual void FollowTargetPosition()
|
||||
{
|
||||
if (Target == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!FollowPosition)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_newTargetPosition = Target.position + Offset;
|
||||
if (!FollowPositionX) { _newTargetPosition.x = _initialPosition.x; }
|
||||
if (!FollowPositionY) { _newTargetPosition.y = _initialPosition.y; }
|
||||
if (!FollowPositionZ) { _newTargetPosition.z = _initialPosition.z; }
|
||||
|
||||
float trueDistance = 0f;
|
||||
_direction = (_newTargetPosition - this.transform.position).normalized;
|
||||
trueDistance = Vector3.Distance(this.transform.position, _newTargetPosition);
|
||||
|
||||
float interpolatedDistance = trueDistance;
|
||||
if (InterpolatePosition)
|
||||
{
|
||||
switch (FollowPositionMode)
|
||||
{
|
||||
case FollowModes.MMLerp:
|
||||
interpolatedDistance = MMMaths.Lerp(0f, trueDistance, FollowPositionSpeed, Time.deltaTime);
|
||||
interpolatedDistance = ApplyMinMaxDistancing(trueDistance, interpolatedDistance);
|
||||
this.transform.Translate(_direction * interpolatedDistance, Space.World);
|
||||
break;
|
||||
case FollowModes.RegularLerp:
|
||||
interpolatedDistance = Mathf.Lerp(0f, trueDistance, Time.deltaTime * FollowPositionSpeed);
|
||||
interpolatedDistance = ApplyMinMaxDistancing(trueDistance, interpolatedDistance);
|
||||
this.transform.Translate(_direction * interpolatedDistance, Space.World);
|
||||
break;
|
||||
case FollowModes.MMSpring:
|
||||
_newPosition = this.transform.position;
|
||||
MMMaths.Spring(ref _newPosition, _newTargetPosition, ref _positionVelocity, PositionSpringDamping, PositionSpringFrequency, Time.deltaTime);
|
||||
if (_localSpace)
|
||||
{
|
||||
this.transform.localPosition = _newPosition;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.transform.position = _newPosition;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
interpolatedDistance = ApplyMinMaxDistancing(trueDistance, interpolatedDistance);
|
||||
this.transform.Translate(_direction * interpolatedDistance, Space.World);
|
||||
}
|
||||
|
||||
if (AnchorToInitialPosition)
|
||||
{
|
||||
if (Vector3.Distance(this.transform.position, _initialPosition) > MaxDistanceToAnchor)
|
||||
{
|
||||
if (_localSpace)
|
||||
{
|
||||
this.transform.localPosition = _initialPosition + Vector3.ClampMagnitude(this.transform.localPosition - _initialPosition, MaxDistanceToAnchor);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.transform.position = _initialPosition + Vector3.ClampMagnitude(this.transform.position - _initialPosition, MaxDistanceToAnchor);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Applies minimal and maximal distance rules to the interpolated distance
|
||||
/// </summary>
|
||||
/// <param name="trueDistance"></param>
|
||||
/// <param name="interpolatedDistance"></param>
|
||||
/// <returns></returns>
|
||||
protected virtual float ApplyMinMaxDistancing(float trueDistance, float interpolatedDistance)
|
||||
{
|
||||
if (UseMinimumDistanceBeforeFollow && (trueDistance - interpolatedDistance < MinimumDistanceBeforeFollow))
|
||||
{
|
||||
interpolatedDistance = 0f;
|
||||
}
|
||||
|
||||
if (UseMaximumDistance && (trueDistance - interpolatedDistance >= MaximumDistance))
|
||||
{
|
||||
interpolatedDistance = trueDistance - MaximumDistance;
|
||||
}
|
||||
|
||||
return interpolatedDistance;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Makes the object follow its target's rotation
|
||||
/// </summary>
|
||||
protected virtual void FollowTargetRotation()
|
||||
{
|
||||
if (Target == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!FollowRotation)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_newTargetRotation = Target.rotation;
|
||||
|
||||
_newTargetRotationEulerAngles = Target.rotation.eulerAngles;
|
||||
_currentRotationEulerAngles = this.transform.rotation.eulerAngles;
|
||||
|
||||
if (FollowRotationMode == FollowModes.MMSpring && (_newTargetRotationEulerAnglesLastFrame != _newTargetRotationEulerAngles))
|
||||
{
|
||||
_rotationBeforeSpring = this.transform.rotation;
|
||||
_rotationFloatCurrent = 0f;
|
||||
_rotationFloatTarget = (Mathf.Abs(_newTargetRotation.eulerAngles.x)
|
||||
+ Mathf.Abs(_newTargetRotation.eulerAngles.y)
|
||||
+ Mathf.Abs(_newTargetRotation.z))
|
||||
-
|
||||
(Mathf.Abs(_currentRotationEulerAngles.x)
|
||||
+ Mathf.Abs(_currentRotationEulerAngles.y)
|
||||
+ Mathf.Abs(_currentRotationEulerAngles.z));
|
||||
|
||||
_rotationFloatTarget = Mathf.Abs(_rotationFloatTarget);
|
||||
}
|
||||
|
||||
if (InterpolateRotation)
|
||||
{
|
||||
switch (FollowRotationMode)
|
||||
{
|
||||
case FollowModes.MMLerp:
|
||||
this.transform.rotation = MMMaths.Lerp(this.transform.rotation, _newTargetRotation, FollowRotationSpeed, Time.deltaTime);
|
||||
break;
|
||||
case FollowModes.RegularLerp:
|
||||
this.transform.rotation = Quaternion.Lerp(this.transform.rotation, _newTargetRotation, Time.deltaTime * FollowRotationSpeed);
|
||||
break;
|
||||
case FollowModes.MMSpring:
|
||||
if (_rotationFloatCurrent == _rotationFloatTarget)
|
||||
{
|
||||
break;
|
||||
}
|
||||
MMMaths.Spring(ref _rotationFloatCurrent, _rotationFloatTarget, ref _rotationFloatVelocity, RotationSpringDamping, RotationSpringFrequency, Time.deltaTime);
|
||||
float lerpValue = MMMaths.Remap(_rotationFloatCurrent, 0f, _rotationFloatTarget, 0f, 1f);
|
||||
this.transform.rotation = Quaternion.LerpUnclamped(_rotationBeforeSpring, _newTargetRotation, lerpValue );
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this.transform.rotation = _newTargetRotation;
|
||||
}
|
||||
|
||||
_newTargetRotationEulerAnglesLastFrame = _newTargetRotationEulerAngles;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Makes the object follow its target's scale
|
||||
/// </summary>
|
||||
protected virtual void FollowTargetScale()
|
||||
{
|
||||
if (Target == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!FollowScale)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_newTargetScale = Target.localScale * FollowScaleFactor;
|
||||
|
||||
if (InterpolateScale)
|
||||
{
|
||||
switch (FollowScaleMode)
|
||||
{
|
||||
case FollowModes.MMLerp:
|
||||
this.transform.localScale = MMMaths.Lerp(this.transform.localScale, _newTargetScale, FollowScaleSpeed, Time.deltaTime);
|
||||
break;
|
||||
case FollowModes.RegularLerp:
|
||||
this.transform.localScale = Vector3.Lerp(this.transform.localScale, _newTargetScale, Time.deltaTime * FollowScaleSpeed);
|
||||
break;
|
||||
case FollowModes.MMSpring:
|
||||
_newScale = this.transform.localScale;
|
||||
MMMaths.Spring(ref _newScale, _newTargetScale, ref _scaleVelocity, ScaleSpringDamping, ScaleSpringFrequency, Time.deltaTime);
|
||||
this.transform.localScale = _newScale;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this.transform.localScale = _newTargetScale;
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void ChangeFollowTarget(Transform newTarget) => Target = newTarget;
|
||||
|
||||
protected virtual void OnDisable()
|
||||
{
|
||||
if (DisableSelfOnSetActiveFalse)
|
||||
{
|
||||
this.enabled = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/Feel/MMTools/Core/MMTween/MMFollowTarget.cs.meta
Normal file
11
Assets/Feel/MMTools/Core/MMTween/MMFollowTarget.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bd8ab284de1a65c49870e4b81e46134a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
203
Assets/Feel/MMTools/Core/MMTween/MMSignal.cs
Normal file
203
Assets/Feel/MMTools/Core/MMTween/MMSignal.cs
Normal file
@@ -0,0 +1,203 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace MoreMountains.Tools
|
||||
{
|
||||
/// <summary>
|
||||
/// This class lets you output the value corresponding to one of the basic signal types it contains. Useful to draw basic signal curves.
|
||||
/// </summary>
|
||||
public class MMSignal
|
||||
{
|
||||
public enum SignalType
|
||||
{
|
||||
Sine,
|
||||
Pulse,
|
||||
Sawtooth,
|
||||
Square,
|
||||
Triangle,
|
||||
DigitalNoise,
|
||||
WhiteNoise,
|
||||
PerlinNoise,
|
||||
ValueNoise,
|
||||
AnimationCurve,
|
||||
MMTween
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the corresponding value based on the selected SignalType for a given time value
|
||||
/// </summary>
|
||||
/// <param name="time"></param>
|
||||
/// <param name="signalType"></param>
|
||||
/// <param name="phase"></param>
|
||||
/// <param name="amplitude"></param>
|
||||
/// <param name="frequency"></param>
|
||||
/// <param name="offset"></param>
|
||||
/// <param name="Invert"></param>
|
||||
/// <returns></returns>
|
||||
public static float GetValue(float time, SignalType signalType, float phase, float amplitude, float frequency, float offset, bool Invert = false, AnimationCurve curve = null, MMTween.MMTweenCurve tweenCurve = MMTween.MMTweenCurve.LinearTween)
|
||||
{
|
||||
float value = 0f;
|
||||
float invert = Invert ? -1 : 1;
|
||||
float t = frequency * time + phase;
|
||||
|
||||
switch (signalType)
|
||||
{
|
||||
case SignalType.Sine:
|
||||
value = (float)Mathf.Sin(2f * Mathf.PI * t);
|
||||
break;
|
||||
case SignalType.Square:
|
||||
value = Mathf.Sign(Mathf.Sin(2f * Mathf.PI * t));
|
||||
break;
|
||||
case SignalType.Triangle:
|
||||
value = 1f - 4f * (float)Mathf.Abs(Mathf.Round(t - 0.25f) - (t - 0.25f));
|
||||
break;
|
||||
case SignalType.Sawtooth:
|
||||
value = 2f * (t - (float)Mathf.Floor(t + 0.5f));
|
||||
break;
|
||||
case SignalType.Pulse:
|
||||
value = (Mathf.Abs(Mathf.Sin(2 * Mathf.PI * t)) < 1.0 - 10E-3) ? (0) : (1);
|
||||
break;
|
||||
case SignalType.WhiteNoise:
|
||||
value = 2f * Random.Range(0,int.MaxValue) / int.MaxValue - 1f;
|
||||
break;
|
||||
case SignalType.DigitalNoise:
|
||||
value = Random.Range(0,2);
|
||||
break;
|
||||
case SignalType.PerlinNoise:
|
||||
value = Mathf.PerlinNoise(time * frequency, time * amplitude);
|
||||
break;
|
||||
case SignalType.ValueNoise:
|
||||
value = ValueNoise(time, frequency) * amplitude;
|
||||
break;
|
||||
case SignalType.AnimationCurve:
|
||||
if (curve == null) { return 0f; }
|
||||
t = (t != 1f) ? t - Mathf.Floor(t) : 1f;
|
||||
value = curve.Evaluate(t);
|
||||
break;
|
||||
case SignalType.MMTween:
|
||||
t = (t != 1f) ? t - Mathf.Floor(t) : 1f;
|
||||
value = MMTween.Tween(t, 0f, 1f, 0f, 1f, tweenCurve);
|
||||
break;
|
||||
}
|
||||
|
||||
return (invert * amplitude * value + offset);
|
||||
}
|
||||
|
||||
public static float GetValueNormalized(float time, SignalType signalType,
|
||||
float phase, float amplitude, float frequency, float offset, bool Invert = false,
|
||||
AnimationCurve curve = null, MMTween.MMTweenCurve tweenCurve = MMTween.MMTweenCurve.LinearTween,
|
||||
bool clamp = true, float clampMin = 0f, float clampMax = 1f, bool backAndForth = false, float backAndForthTippingPoint = 0.5f)
|
||||
{
|
||||
float value = 0f;
|
||||
float invert = Invert ? -1 : 1;
|
||||
|
||||
if (backAndForth)
|
||||
{
|
||||
if (time < backAndForthTippingPoint)
|
||||
{
|
||||
time = MMMaths.Remap(time, 0f, backAndForthTippingPoint, 0f, 1f);
|
||||
}
|
||||
else if (time == backAndForthTippingPoint)
|
||||
{
|
||||
time = 1f;
|
||||
}
|
||||
else if (time > backAndForthTippingPoint)
|
||||
{
|
||||
time = MMMaths.Remap(time, backAndForthTippingPoint, 1f, 1f, 0f);
|
||||
}
|
||||
}
|
||||
|
||||
float t = frequency * time + phase;
|
||||
|
||||
switch (signalType)
|
||||
{
|
||||
case SignalType.Sine:
|
||||
value = (float)Mathf.Sin(2f * Mathf.PI * t);
|
||||
value = MMMaths.Remap(value, -1f, 1f, 0f, 1f);
|
||||
break;
|
||||
case SignalType.Square:
|
||||
value = Mathf.Sign(Mathf.Sin(2f * Mathf.PI * t));
|
||||
value = MMMaths.Remap(value, -1f, 1f, 0f, 1f);
|
||||
break;
|
||||
case SignalType.Triangle:
|
||||
value = 1f - 4f * (float)Mathf.Abs(Mathf.Round(t - 0.25f) - (t - 0.25f));
|
||||
value = MMMaths.Remap(value, -1f, 1f, 0f, 1f);
|
||||
break;
|
||||
case SignalType.Sawtooth:
|
||||
value = 2f * (t - (float)Mathf.Floor(t + 0.5f));
|
||||
value = MMMaths.Remap(value, -1f, 1f, 0f, 1f);
|
||||
break;
|
||||
case SignalType.Pulse:
|
||||
value = (Mathf.Abs(Mathf.Sin(2 * Mathf.PI * t)) < 1.0 - 10E-3) ? (0) : (1);
|
||||
break;
|
||||
case SignalType.WhiteNoise:
|
||||
value = 2f * Random.Range(0, int.MaxValue) / int.MaxValue - 1f;
|
||||
value = MMMaths.Remap(value, -1f, 1f, 0f, 1f);
|
||||
break;
|
||||
case SignalType.DigitalNoise:
|
||||
value = Random.Range(0, 2);
|
||||
break;
|
||||
case SignalType.PerlinNoise:
|
||||
value = Mathf.PerlinNoise(t, t * amplitude);
|
||||
break;
|
||||
case SignalType.ValueNoise:
|
||||
value = ValueNoise(time, frequency) * amplitude;
|
||||
break;
|
||||
case SignalType.AnimationCurve:
|
||||
if (curve == null) { return 0f; }
|
||||
t = (t != 1f) ? t - Mathf.Floor(t) : 1f;
|
||||
value = curve.Evaluate(t);
|
||||
break;
|
||||
case SignalType.MMTween:
|
||||
t = (t != 1f) ? t - Mathf.Floor(t) : 1f;
|
||||
value = MMTween.Tween(t, 0f, 1f, 0f, 1f, tweenCurve);
|
||||
break;
|
||||
}
|
||||
|
||||
if (Invert)
|
||||
{
|
||||
value = MMMaths.Remap(value, 0f, 1f, 1f, 0f);
|
||||
}
|
||||
|
||||
float returnValue = amplitude * value + offset;
|
||||
|
||||
// we clamp the value
|
||||
if (clamp)
|
||||
{
|
||||
returnValue = Mathf.Clamp(returnValue, clampMin, clampMax);
|
||||
}
|
||||
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
private static int[] hash = {
|
||||
151,160,137, 91, 90, 15,131, 13,201, 95, 96, 53,194,233, 7,225,
|
||||
140, 36,103, 30, 69,142, 8, 99, 37,240, 21, 10, 23,190, 6,148,
|
||||
247,120,234, 75, 0, 26,197, 62, 94,252,219,203,117, 35, 11, 32,
|
||||
57,177, 33, 88,237,149, 56, 87,174, 20,125,136,171,168, 68,175,
|
||||
74,165, 71,134,139, 48, 27,166, 77,146,158,231, 83,111,229,122,
|
||||
60,211,133,230,220,105, 92, 41, 55, 46,245, 40,244,102,143, 54,
|
||||
65, 25, 63,161, 1,216, 80, 73,209, 76,132,187,208, 89, 18,169,
|
||||
200,196,135,130,116,188,159, 86,164,100,109,198,173,186, 3, 64,
|
||||
52,217,226,250,124,123, 5,202, 38,147,118,126,255, 82, 85,212,
|
||||
207,206, 59,227, 47, 16, 58, 17,182,189, 28, 42,223,183,170,213,
|
||||
119,248,152, 2, 44,154,163, 70,221,153,101,155,167, 43,172, 9,
|
||||
129, 22, 39,253, 19, 98,108,110, 79,113,224,232,178,185,112,104,
|
||||
218,246, 97,228,251, 34,242,193,238,210,144, 12,191,179,162,241,
|
||||
81, 51,145,235,249, 14,239,107, 49,192,214, 31,181,199,106,157,
|
||||
184, 84,204,176,115,121, 50, 45,127, 4,150,254,138,236,205, 93,
|
||||
222,114, 67, 29, 24, 72,243,141,128,195, 78, 66,215, 61,156,180
|
||||
};
|
||||
private const int hashMask = 255;
|
||||
|
||||
protected static float ValueNoise(float time, float frequency)
|
||||
{
|
||||
|
||||
time *= frequency;
|
||||
int i = Mathf.FloorToInt(time);
|
||||
i &= hashMask;
|
||||
return hash[i] * (1f / hashMask);
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/Feel/MMTools/Core/MMTween/MMSignal.cs.meta
Normal file
11
Assets/Feel/MMTools/Core/MMTween/MMSignal.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2b0d2c9595529ed47a73e3b75de4eae6
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
445
Assets/Feel/MMTools/Core/MMTween/MMTween.cs
Normal file
445
Assets/Feel/MMTools/Core/MMTween/MMTween.cs
Normal file
@@ -0,0 +1,445 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
|
||||
namespace MoreMountains.Tools
|
||||
{
|
||||
/// <summary>
|
||||
/// The formulas described here are (loosely) based on Robert Penner's easing equations http://robertpenner.com/easing/
|
||||
/// </summary>
|
||||
|
||||
public class MMTween : MonoBehaviour
|
||||
{
|
||||
/// <summary>
|
||||
/// A list of all the possible curves you can tween a value along
|
||||
/// </summary>
|
||||
public enum MMTweenCurve
|
||||
{
|
||||
LinearTween,
|
||||
EaseInQuadratic, EaseOutQuadratic, EaseInOutQuadratic,
|
||||
EaseInCubic, EaseOutCubic, EaseInOutCubic,
|
||||
EaseInQuartic, EaseOutQuartic, EaseInOutQuartic,
|
||||
EaseInQuintic, EaseOutQuintic, EaseInOutQuintic,
|
||||
EaseInSinusoidal, EaseOutSinusoidal, EaseInOutSinusoidal,
|
||||
EaseInBounce, EaseOutBounce, EaseInOutBounce,
|
||||
EaseInOverhead, EaseOutOverhead, EaseInOutOverhead,
|
||||
EaseInExponential, EaseOutExponential, EaseInOutExponential,
|
||||
EaseInElastic, EaseOutElastic, EaseInOutElastic,
|
||||
EaseInCircular, EaseOutCircular, EaseInOutCircular,
|
||||
AntiLinearTween, AlmostIdentity
|
||||
}
|
||||
|
||||
public static TweenDelegate[] TweenDelegateArray = new TweenDelegate[]
|
||||
{
|
||||
LinearTween,
|
||||
EaseInQuadratic, EaseOutQuadratic, EaseInOutQuadratic,
|
||||
EaseInCubic, EaseOutCubic, EaseInOutCubic,
|
||||
EaseInQuartic, EaseOutQuartic, EaseInOutQuartic,
|
||||
EaseInQuintic, EaseOutQuintic, EaseInOutQuintic,
|
||||
EaseInSinusoidal, EaseOutSinusoidal, EaseInOutSinusoidal,
|
||||
EaseInBounce, EaseOutBounce, EaseInOutBounce,
|
||||
EaseInOverhead, EaseOutOverhead, EaseInOutOverhead,
|
||||
EaseInExponential, EaseOutExponential, EaseInOutExponential,
|
||||
EaseInElastic, EaseOutElastic, EaseInOutElastic,
|
||||
EaseInCircular, EaseOutCircular, EaseInOutCircular,
|
||||
AntiLinearTween, AlmostIdentity
|
||||
};
|
||||
|
||||
// Core methods ---------------------------------------------------------------------------------------------------------------
|
||||
|
||||
/// <summary>
|
||||
/// Moves a value between a startValue and an endValue based on a currentTime, along the specified tween curve
|
||||
/// </summary>
|
||||
/// <param name="currentTime"></param>
|
||||
/// <param name="initialTime"></param>
|
||||
/// <param name="endTime"></param>
|
||||
/// <param name="startValue"></param>
|
||||
/// <param name="endValue"></param>
|
||||
/// <param name="curve"></param>
|
||||
/// <returns></returns>
|
||||
public static float Tween(float currentTime, float initialTime, float endTime, float startValue, float endValue, MMTweenCurve curve)
|
||||
{
|
||||
currentTime = MMMaths.Remap(currentTime, initialTime, endTime, 0f, 1f);
|
||||
currentTime = TweenDelegateArray[(int)curve](currentTime);
|
||||
return startValue + currentTime * (endValue - startValue);
|
||||
}
|
||||
|
||||
public static long Tween(float currentTime, float initialTime, float endTime, long startValue, long endValue, MMTweenCurve curve)
|
||||
{
|
||||
currentTime = MMMaths.Remap(currentTime, initialTime, endTime, 0f, 1f);
|
||||
currentTime = TweenDelegateArray[(int)curve](currentTime);
|
||||
return startValue + (long)(currentTime * (endValue - startValue));
|
||||
}
|
||||
|
||||
public static float Evaluate(float t, MMTweenCurve curve)
|
||||
{
|
||||
return TweenDelegateArray[(int)curve](t);
|
||||
}
|
||||
|
||||
public static float Evaluate(float t, MMTweenType tweenType)
|
||||
{
|
||||
if (tweenType.MMTweenDefinitionType == MMTweenDefinitionTypes.MMTween)
|
||||
{
|
||||
return Evaluate(t, tweenType.MMTweenCurve);
|
||||
}
|
||||
if (tweenType.MMTweenDefinitionType == MMTweenDefinitionTypes.AnimationCurve)
|
||||
{
|
||||
return tweenType.Curve.Evaluate(t);
|
||||
}
|
||||
return 0f;
|
||||
}
|
||||
|
||||
public delegate float TweenDelegate(float currentTime);
|
||||
|
||||
public static float LinearTween(float currentTime) { return MMTweenDefinitions.Linear_Tween(currentTime); }
|
||||
public static float AntiLinearTween(float currentTime) { return MMTweenDefinitions.LinearAnti_Tween(currentTime); }
|
||||
public static float EaseInQuadratic(float currentTime) { return MMTweenDefinitions.EaseIn_Quadratic(currentTime); }
|
||||
public static float EaseOutQuadratic(float currentTime) { return MMTweenDefinitions.EaseOut_Quadratic(currentTime); }
|
||||
public static float EaseInOutQuadratic(float currentTime) { return MMTweenDefinitions.EaseInOut_Quadratic(currentTime); }
|
||||
public static float EaseInCubic(float currentTime) { return MMTweenDefinitions.EaseIn_Cubic(currentTime); }
|
||||
public static float EaseOutCubic(float currentTime) { return MMTweenDefinitions.EaseOut_Cubic(currentTime); }
|
||||
public static float EaseInOutCubic(float currentTime) { return MMTweenDefinitions.EaseInOut_Cubic(currentTime); }
|
||||
public static float EaseInQuartic(float currentTime) { return MMTweenDefinitions.EaseIn_Quartic(currentTime); }
|
||||
public static float EaseOutQuartic(float currentTime) { return MMTweenDefinitions.EaseOut_Quartic(currentTime); }
|
||||
public static float EaseInOutQuartic(float currentTime) { return MMTweenDefinitions.EaseInOut_Quartic(currentTime); }
|
||||
public static float EaseInQuintic(float currentTime) { return MMTweenDefinitions.EaseIn_Quintic(currentTime); }
|
||||
public static float EaseOutQuintic(float currentTime) { return MMTweenDefinitions.EaseOut_Quintic(currentTime); }
|
||||
public static float EaseInOutQuintic(float currentTime) { return MMTweenDefinitions.EaseInOut_Quintic(currentTime); }
|
||||
public static float EaseInSinusoidal(float currentTime) { return MMTweenDefinitions.EaseIn_Sinusoidal(currentTime); }
|
||||
public static float EaseOutSinusoidal(float currentTime) { return MMTweenDefinitions.EaseOut_Sinusoidal(currentTime); }
|
||||
public static float EaseInOutSinusoidal(float currentTime) { return MMTweenDefinitions.EaseInOut_Sinusoidal(currentTime); }
|
||||
public static float EaseInBounce(float currentTime) { return MMTweenDefinitions.EaseIn_Bounce(currentTime); }
|
||||
public static float EaseOutBounce(float currentTime) { return MMTweenDefinitions.EaseOut_Bounce(currentTime); }
|
||||
public static float EaseInOutBounce(float currentTime) { return MMTweenDefinitions.EaseInOut_Bounce(currentTime); }
|
||||
public static float EaseInOverhead(float currentTime) { return MMTweenDefinitions.EaseIn_Overhead(currentTime); }
|
||||
public static float EaseOutOverhead(float currentTime) { return MMTweenDefinitions.EaseOut_Overhead(currentTime); }
|
||||
public static float EaseInOutOverhead(float currentTime) { return MMTweenDefinitions.EaseInOut_Overhead(currentTime); }
|
||||
public static float EaseInExponential(float currentTime) { return MMTweenDefinitions.EaseIn_Exponential(currentTime); }
|
||||
public static float EaseOutExponential(float currentTime) { return MMTweenDefinitions.EaseOut_Exponential(currentTime); }
|
||||
public static float EaseInOutExponential(float currentTime) { return MMTweenDefinitions.EaseInOut_Exponential(currentTime); }
|
||||
public static float EaseInElastic(float currentTime) { return MMTweenDefinitions.EaseIn_Elastic(currentTime); }
|
||||
public static float EaseOutElastic(float currentTime) { return MMTweenDefinitions.EaseOut_Elastic(currentTime); }
|
||||
public static float EaseInOutElastic(float currentTime) { return MMTweenDefinitions.EaseInOut_Elastic(currentTime); }
|
||||
public static float EaseInCircular(float currentTime) { return MMTweenDefinitions.EaseIn_Circular(currentTime); }
|
||||
public static float EaseOutCircular(float currentTime) { return MMTweenDefinitions.EaseOut_Circular(currentTime); }
|
||||
public static float EaseInOutCircular(float currentTime) { return MMTweenDefinitions.EaseInOut_Circular(currentTime); }
|
||||
public static float AlmostIdentity(float currentTime) { return MMTweenDefinitions.AlmostIdentity(currentTime); }
|
||||
|
||||
/// <summary>
|
||||
/// To use :
|
||||
/// public MMTween.MMTweenCurve Tween = MMTween.MMTweenCurve.EaseInOutCubic;
|
||||
/// private MMTween.TweenDelegate _tween;
|
||||
///
|
||||
/// _tween = MMTween.GetTweenMethod(Tween);
|
||||
/// float t = _tween(someFloat);
|
||||
/// </summary>
|
||||
/// <param name="tween"></param>
|
||||
/// <returns></returns>
|
||||
public static TweenDelegate GetTweenMethod(MMTweenCurve tween)
|
||||
{
|
||||
switch (tween)
|
||||
{
|
||||
case MMTweenCurve.LinearTween: return LinearTween;
|
||||
case MMTweenCurve.AntiLinearTween: return AntiLinearTween;
|
||||
case MMTweenCurve.EaseInQuadratic: return EaseInQuadratic;
|
||||
case MMTweenCurve.EaseOutQuadratic: return EaseOutQuadratic;
|
||||
case MMTweenCurve.EaseInOutQuadratic: return EaseInOutQuadratic;
|
||||
case MMTweenCurve.EaseInCubic: return EaseInCubic;
|
||||
case MMTweenCurve.EaseOutCubic: return EaseOutCubic;
|
||||
case MMTweenCurve.EaseInOutCubic: return EaseInOutCubic;
|
||||
case MMTweenCurve.EaseInQuartic: return EaseInQuartic;
|
||||
case MMTweenCurve.EaseOutQuartic: return EaseOutQuartic;
|
||||
case MMTweenCurve.EaseInOutQuartic: return EaseInOutQuartic;
|
||||
case MMTweenCurve.EaseInQuintic: return EaseInQuintic;
|
||||
case MMTweenCurve.EaseOutQuintic: return EaseOutQuintic;
|
||||
case MMTweenCurve.EaseInOutQuintic: return EaseInOutQuintic;
|
||||
case MMTweenCurve.EaseInSinusoidal: return EaseInSinusoidal;
|
||||
case MMTweenCurve.EaseOutSinusoidal: return EaseOutSinusoidal;
|
||||
case MMTweenCurve.EaseInOutSinusoidal: return EaseInOutSinusoidal;
|
||||
case MMTweenCurve.EaseInBounce: return EaseInBounce;
|
||||
case MMTweenCurve.EaseOutBounce: return EaseOutBounce;
|
||||
case MMTweenCurve.EaseInOutBounce: return EaseInOutBounce;
|
||||
case MMTweenCurve.EaseInOverhead: return EaseInOverhead;
|
||||
case MMTweenCurve.EaseOutOverhead: return EaseOutOverhead;
|
||||
case MMTweenCurve.EaseInOutOverhead: return EaseInOutOverhead;
|
||||
case MMTweenCurve.EaseInExponential: return EaseInExponential;
|
||||
case MMTweenCurve.EaseOutExponential: return EaseOutExponential;
|
||||
case MMTweenCurve.EaseInOutExponential: return EaseInOutExponential;
|
||||
case MMTweenCurve.EaseInElastic: return EaseInElastic;
|
||||
case MMTweenCurve.EaseOutElastic: return EaseOutElastic;
|
||||
case MMTweenCurve.EaseInOutElastic: return EaseInOutElastic;
|
||||
case MMTweenCurve.EaseInCircular: return EaseInCircular;
|
||||
case MMTweenCurve.EaseOutCircular: return EaseOutCircular;
|
||||
case MMTweenCurve.EaseInOutCircular: return EaseInOutCircular;
|
||||
case MMTweenCurve.AlmostIdentity: return AlmostIdentity;
|
||||
}
|
||||
return LinearTween;
|
||||
}
|
||||
|
||||
public static Vector2 Tween(float currentTime, float initialTime, float endTime, Vector2 startValue, Vector2 endValue, MMTweenCurve curve)
|
||||
{
|
||||
startValue.x = Tween(currentTime, initialTime, endTime, startValue.x, endValue.x, curve);
|
||||
startValue.y = Tween(currentTime, initialTime, endTime, startValue.y, endValue.y, curve);
|
||||
return startValue;
|
||||
}
|
||||
|
||||
public static Vector3 Tween(float currentTime, float initialTime, float endTime, Vector3 startValue, Vector3 endValue, MMTweenCurve curve)
|
||||
{
|
||||
startValue.x = Tween(currentTime, initialTime, endTime, startValue.x, endValue.x, curve);
|
||||
startValue.y = Tween(currentTime, initialTime, endTime, startValue.y, endValue.y, curve);
|
||||
startValue.z = Tween(currentTime, initialTime, endTime, startValue.z, endValue.z, curve);
|
||||
return startValue;
|
||||
}
|
||||
|
||||
public static Vector4 Tween(float currentTime, float initialTime, float endTime, Vector4 startValue, Vector4 endValue, MMTweenCurve curve)
|
||||
{
|
||||
startValue.x = Tween(currentTime, initialTime, endTime, startValue.x, endValue.x, curve);
|
||||
startValue.y = Tween(currentTime, initialTime, endTime, startValue.y, endValue.y, curve);
|
||||
startValue.z = Tween(currentTime, initialTime, endTime, startValue.z, endValue.z, curve);
|
||||
startValue.w = Tween(currentTime, initialTime, endTime, startValue.w, endValue.w, curve);
|
||||
return startValue;
|
||||
}
|
||||
|
||||
public static Quaternion Tween(float currentTime, float initialTime, float endTime, Quaternion startValue, Quaternion endValue, MMTweenCurve curve)
|
||||
{
|
||||
float turningRate = Tween(currentTime, initialTime, endTime, 0f, 1f, curve);
|
||||
startValue = Quaternion.Slerp(startValue, endValue, turningRate);
|
||||
return startValue;
|
||||
}
|
||||
|
||||
// Animation curve methods --------------------------------------------------------------------------------------------------------------
|
||||
|
||||
public static float Tween(float currentTime, float initialTime, float endTime, float startValue, float endValue, AnimationCurve curve)
|
||||
{
|
||||
currentTime = MMMaths.Remap(currentTime, initialTime, endTime, 0f, 1f);
|
||||
currentTime = curve.Evaluate(currentTime);
|
||||
return startValue + currentTime * (endValue - startValue);
|
||||
}
|
||||
|
||||
public static long Tween(float currentTime, float initialTime, float endTime, long startValue, long endValue, AnimationCurve curve)
|
||||
{
|
||||
currentTime = MMMaths.Remap(currentTime, initialTime, endTime, 0f, 1f);
|
||||
currentTime = curve.Evaluate(currentTime);
|
||||
return startValue + (long)currentTime * (endValue - startValue);
|
||||
}
|
||||
|
||||
public static Vector2 Tween(float currentTime, float initialTime, float endTime, Vector2 startValue, Vector2 endValue, AnimationCurve curve)
|
||||
{
|
||||
startValue.x = Tween(currentTime, initialTime, endTime, startValue.x, endValue.x, curve);
|
||||
startValue.y = Tween(currentTime, initialTime, endTime, startValue.y, endValue.y, curve);
|
||||
return startValue;
|
||||
}
|
||||
|
||||
public static Vector3 Tween(float currentTime, float initialTime, float endTime, Vector3 startValue, Vector3 endValue, AnimationCurve curve)
|
||||
{
|
||||
startValue.x = Tween(currentTime, initialTime, endTime, startValue.x, endValue.x, curve);
|
||||
startValue.y = Tween(currentTime, initialTime, endTime, startValue.y, endValue.y, curve);
|
||||
startValue.z = Tween(currentTime, initialTime, endTime, startValue.z, endValue.z, curve);
|
||||
return startValue;
|
||||
}
|
||||
|
||||
public static Vector4 Tween(float currentTime, float initialTime, float endTime, Vector4 startValue, Vector4 endValue, AnimationCurve curve)
|
||||
{
|
||||
startValue.x = Tween(currentTime, initialTime, endTime, startValue.x, endValue.x, curve);
|
||||
startValue.y = Tween(currentTime, initialTime, endTime, startValue.y, endValue.y, curve);
|
||||
startValue.z = Tween(currentTime, initialTime, endTime, startValue.z, endValue.z, curve);
|
||||
startValue.w = Tween(currentTime, initialTime, endTime, startValue.w, endValue.w, curve);
|
||||
return startValue;
|
||||
}
|
||||
|
||||
public static Quaternion Tween(float currentTime, float initialTime, float endTime, Quaternion startValue, Quaternion endValue, AnimationCurve curve)
|
||||
{
|
||||
float turningRate = Tween(currentTime, initialTime, endTime, 0f, 1f, curve);
|
||||
startValue = Quaternion.Slerp(startValue, endValue, turningRate);
|
||||
return startValue;
|
||||
}
|
||||
|
||||
// Tween type methods ------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
public static float Tween(float currentTime, float initialTime, float endTime, float startValue, float endValue, MMTweenType tweenType)
|
||||
{
|
||||
if (tweenType.MMTweenDefinitionType == MMTweenDefinitionTypes.MMTween)
|
||||
{
|
||||
return Tween(currentTime, initialTime, endTime, startValue, endValue, tweenType.MMTweenCurve);
|
||||
}
|
||||
if (tweenType.MMTweenDefinitionType == MMTweenDefinitionTypes.AnimationCurve)
|
||||
{
|
||||
return Tween(currentTime, initialTime, endTime, startValue, endValue, tweenType.Curve);
|
||||
}
|
||||
return 0f;
|
||||
}
|
||||
public static long Tween(float currentTime, float initialTime, float endTime, long startValue, long endValue, MMTweenType tweenType)
|
||||
{
|
||||
if (tweenType.MMTweenDefinitionType == MMTweenDefinitionTypes.MMTween)
|
||||
{
|
||||
return Tween(currentTime, initialTime, endTime, startValue, endValue, tweenType.MMTweenCurve);
|
||||
}
|
||||
if (tweenType.MMTweenDefinitionType == MMTweenDefinitionTypes.AnimationCurve)
|
||||
{
|
||||
return Tween(currentTime, initialTime, endTime, startValue, endValue, tweenType.Curve);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
public static Vector2 Tween(float currentTime, float initialTime, float endTime, Vector2 startValue, Vector2 endValue, MMTweenType tweenType)
|
||||
{
|
||||
if (tweenType.MMTweenDefinitionType == MMTweenDefinitionTypes.MMTween)
|
||||
{
|
||||
return Tween(currentTime, initialTime, endTime, startValue, endValue, tweenType.MMTweenCurve);
|
||||
}
|
||||
if (tweenType.MMTweenDefinitionType == MMTweenDefinitionTypes.AnimationCurve)
|
||||
{
|
||||
return Tween(currentTime, initialTime, endTime, startValue, endValue, tweenType.Curve);
|
||||
}
|
||||
return Vector2.zero;
|
||||
}
|
||||
public static Vector3 Tween(float currentTime, float initialTime, float endTime, Vector3 startValue, Vector3 endValue, MMTweenType tweenType)
|
||||
{
|
||||
if (tweenType.MMTweenDefinitionType == MMTweenDefinitionTypes.MMTween)
|
||||
{
|
||||
return Tween(currentTime, initialTime, endTime, startValue, endValue, tweenType.MMTweenCurve);
|
||||
}
|
||||
if (tweenType.MMTweenDefinitionType == MMTweenDefinitionTypes.AnimationCurve)
|
||||
{
|
||||
return Tween(currentTime, initialTime, endTime, startValue, endValue, tweenType.Curve);
|
||||
}
|
||||
return Vector3.zero;
|
||||
}
|
||||
public static Vector4 Tween(float currentTime, float initialTime, float endTime, Vector4 startValue, Vector4 endValue, MMTweenType tweenType)
|
||||
{
|
||||
if (tweenType.MMTweenDefinitionType == MMTweenDefinitionTypes.MMTween)
|
||||
{
|
||||
return Tween(currentTime, initialTime, endTime, startValue, endValue, tweenType.MMTweenCurve);
|
||||
}
|
||||
if (tweenType.MMTweenDefinitionType == MMTweenDefinitionTypes.AnimationCurve)
|
||||
{
|
||||
return Tween(currentTime, initialTime, endTime, startValue, endValue, tweenType.Curve);
|
||||
}
|
||||
return Vector3.zero;
|
||||
}
|
||||
public static Quaternion Tween(float currentTime, float initialTime, float endTime, Quaternion startValue, Quaternion endValue, MMTweenType tweenType)
|
||||
{
|
||||
if (tweenType.MMTweenDefinitionType == MMTweenDefinitionTypes.MMTween)
|
||||
{
|
||||
return Tween(currentTime, initialTime, endTime, startValue, endValue, tweenType.MMTweenCurve);
|
||||
}
|
||||
if (tweenType.MMTweenDefinitionType == MMTweenDefinitionTypes.AnimationCurve)
|
||||
{
|
||||
return Tween(currentTime, initialTime, endTime, startValue, endValue, tweenType.Curve);
|
||||
}
|
||||
return Quaternion.identity;
|
||||
}
|
||||
|
||||
// MOVE METHODS ---------------------------------------------------------------------------------------------------------
|
||||
public static Coroutine MoveTransform(MonoBehaviour mono, Transform targetTransform, Vector3 origin, Vector3 destination,
|
||||
WaitForSeconds delay, float delayDuration, float duration, MMTween.MMTweenCurve curve, bool ignoreTimescale = false)
|
||||
{
|
||||
return mono.StartCoroutine(MoveTransformCo(targetTransform, origin, destination, delay, delayDuration, duration, curve, ignoreTimescale));
|
||||
}
|
||||
|
||||
public static Coroutine MoveRectTransform(MonoBehaviour mono, RectTransform targetTransform, Vector3 origin, Vector3 destination,
|
||||
WaitForSeconds delay, float delayDuration, float duration, MMTween.MMTweenCurve curve, bool ignoreTimescale = false)
|
||||
{
|
||||
return mono.StartCoroutine(MoveRectTransformCo(targetTransform, origin, destination, delay, delayDuration, duration, curve, ignoreTimescale));
|
||||
}
|
||||
|
||||
public static Coroutine MoveTransform(MonoBehaviour mono, Transform targetTransform, Transform origin, Transform destination, WaitForSeconds delay, float delayDuration, float duration,
|
||||
MMTween.MMTweenCurve curve, bool updatePosition = true, bool updateRotation = true, bool ignoreTimescale = false)
|
||||
{
|
||||
return mono.StartCoroutine(MoveTransformCo(targetTransform, origin, destination, delay, delayDuration, duration, curve, updatePosition, updateRotation, ignoreTimescale));
|
||||
}
|
||||
|
||||
public static Coroutine RotateTransformAround(MonoBehaviour mono, Transform targetTransform, Transform center, Transform destination, float angle, WaitForSeconds delay, float delayDuration,
|
||||
float duration, MMTween.MMTweenCurve curve, bool ignoreTimescale = false)
|
||||
{
|
||||
return mono.StartCoroutine(RotateTransformAroundCo(targetTransform, center, destination, angle, delay, delayDuration, duration, curve, ignoreTimescale));
|
||||
}
|
||||
|
||||
protected static IEnumerator MoveRectTransformCo(RectTransform targetTransform, Vector3 origin, Vector3 destination, WaitForSeconds delay,
|
||||
float delayDuration, float duration, MMTween.MMTweenCurve curve, bool ignoreTimescale = false)
|
||||
{
|
||||
if (delayDuration > 0f)
|
||||
{
|
||||
yield return delay;
|
||||
}
|
||||
float timeLeft = duration;
|
||||
while (timeLeft > 0f)
|
||||
{
|
||||
targetTransform.localPosition = MMTween.Tween(duration - timeLeft, 0f, duration, origin, destination, curve);
|
||||
timeLeft -= ignoreTimescale ? Time.unscaledDeltaTime : Time.deltaTime;
|
||||
yield return null;
|
||||
}
|
||||
targetTransform.localPosition = destination;
|
||||
}
|
||||
|
||||
protected static IEnumerator MoveTransformCo(Transform targetTransform, Vector3 origin, Vector3 destination, WaitForSeconds delay,
|
||||
float delayDuration, float duration, MMTween.MMTweenCurve curve, bool ignoreTimescale = false)
|
||||
{
|
||||
if (delayDuration > 0f)
|
||||
{
|
||||
yield return delay;
|
||||
}
|
||||
float timeLeft = duration;
|
||||
while (timeLeft > 0f)
|
||||
{
|
||||
targetTransform.transform.position = MMTween.Tween(duration - timeLeft, 0f, duration, origin, destination, curve);
|
||||
timeLeft -= ignoreTimescale ? Time.unscaledDeltaTime : Time.deltaTime;
|
||||
yield return null;
|
||||
}
|
||||
targetTransform.transform.position = destination;
|
||||
}
|
||||
|
||||
protected static IEnumerator MoveTransformCo(Transform targetTransform, Transform origin, Transform destination, WaitForSeconds delay, float delayDuration, float duration,
|
||||
MMTween.MMTweenCurve curve, bool updatePosition = true, bool updateRotation = true, bool ignoreTimescale = false)
|
||||
{
|
||||
if (delayDuration > 0f)
|
||||
{
|
||||
yield return delay;
|
||||
}
|
||||
float timeLeft = duration;
|
||||
while (timeLeft > 0f)
|
||||
{
|
||||
if (updatePosition)
|
||||
{
|
||||
targetTransform.transform.position = MMTween.Tween(duration - timeLeft, 0f, duration, origin.position, destination.position, curve);
|
||||
}
|
||||
if (updateRotation)
|
||||
{
|
||||
targetTransform.transform.rotation = MMTween.Tween(duration - timeLeft, 0f, duration, origin.rotation, destination.rotation, curve);
|
||||
}
|
||||
timeLeft -= ignoreTimescale ? Time.unscaledDeltaTime : Time.deltaTime;
|
||||
yield return null;
|
||||
}
|
||||
if (updatePosition) { targetTransform.transform.position = destination.position; }
|
||||
if (updateRotation) { targetTransform.transform.localEulerAngles = destination.localEulerAngles; }
|
||||
}
|
||||
|
||||
protected static IEnumerator RotateTransformAroundCo(Transform targetTransform, Transform center, Transform destination, float angle, WaitForSeconds delay, float delayDuration, float duration,
|
||||
MMTween.MMTweenCurve curve, bool ignoreTimescale = false)
|
||||
{
|
||||
if (delayDuration > 0f)
|
||||
{
|
||||
yield return delay;
|
||||
}
|
||||
|
||||
Vector3 initialRotationPosition = targetTransform.transform.position;
|
||||
Quaternion initialRotationRotation = targetTransform.transform.rotation;
|
||||
|
||||
float rate = 1f / duration;
|
||||
|
||||
float timeSpent = 0f;
|
||||
while (timeSpent < duration)
|
||||
{
|
||||
|
||||
float newAngle = MMTween.Tween(timeSpent, 0f, duration, 0f, angle, curve);
|
||||
|
||||
targetTransform.transform.position = initialRotationPosition;
|
||||
initialRotationRotation = targetTransform.transform.rotation;
|
||||
targetTransform.RotateAround(center.transform.position, center.transform.up, newAngle);
|
||||
targetTransform.transform.rotation = initialRotationRotation;
|
||||
|
||||
timeSpent += ignoreTimescale ? Time.unscaledDeltaTime : Time.deltaTime;
|
||||
yield return null;
|
||||
}
|
||||
targetTransform.transform.position = destination.position;
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/Feel/MMTools/Core/MMTween/MMTween.cs.meta
Normal file
11
Assets/Feel/MMTools/Core/MMTween/MMTween.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: cd6b5fb73f238654ba224ef88b91ac2a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
273
Assets/Feel/MMTools/Core/MMTween/MMTweenDefinitions.cs
Normal file
273
Assets/Feel/MMTools/Core/MMTween/MMTweenDefinitions.cs
Normal file
@@ -0,0 +1,273 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace MoreMountains.Tools
|
||||
{
|
||||
public class MMTweenDefinitions
|
||||
{
|
||||
// Linear ---------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
public static float Linear_Tween(float t)
|
||||
{
|
||||
return t;
|
||||
}
|
||||
|
||||
public static float LinearAnti_Tween(float t)
|
||||
{
|
||||
return 1 - t;
|
||||
}
|
||||
|
||||
// Almost Identity
|
||||
|
||||
public static float AlmostIdentity(float t)
|
||||
{
|
||||
return t * t * (2.0f - t);
|
||||
}
|
||||
|
||||
// Quadratic ---------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
public static float EaseIn_Quadratic(float t)
|
||||
{
|
||||
return t * t;
|
||||
}
|
||||
|
||||
public static float EaseOut_Quadratic(float t)
|
||||
{
|
||||
return 1 - EaseIn_Quadratic(1 - t);
|
||||
}
|
||||
|
||||
public static float EaseInOut_Quadratic(float t)
|
||||
{
|
||||
if (t < 0.5f)
|
||||
{
|
||||
return EaseIn_Quadratic(t * 2f) / 2f;
|
||||
}
|
||||
else
|
||||
{
|
||||
return 1 - EaseIn_Quadratic((1f - t) * 2f) / 2;
|
||||
}
|
||||
}
|
||||
|
||||
// Cubic ---------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
public static float EaseIn_Cubic(float t)
|
||||
{
|
||||
return t * t * t;
|
||||
}
|
||||
|
||||
public static float EaseOut_Cubic(float t)
|
||||
{
|
||||
return 1 - EaseIn_Cubic(1 - t);
|
||||
}
|
||||
|
||||
public static float EaseInOut_Cubic(float t)
|
||||
{
|
||||
if (t < 0.5f)
|
||||
{
|
||||
return EaseIn_Cubic(t * 2f) / 2f;
|
||||
}
|
||||
else
|
||||
{
|
||||
return 1 - EaseIn_Cubic((1f - t) * 2f) / 2;
|
||||
}
|
||||
}
|
||||
|
||||
// Quartic ---------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
public static float EaseIn_Quartic(float t)
|
||||
{
|
||||
return Mathf.Pow(t, 4f);
|
||||
}
|
||||
|
||||
public static float EaseOut_Quartic(float t)
|
||||
{
|
||||
return 1 - EaseIn_Quartic(1 - t);
|
||||
}
|
||||
|
||||
public static float EaseInOut_Quartic(float t)
|
||||
{
|
||||
if (t < 0.5f)
|
||||
{
|
||||
return EaseIn_Quartic(t * 2f) / 2f;
|
||||
}
|
||||
else
|
||||
{
|
||||
return 1 - EaseIn_Quartic((1f - t) * 2f) / 2;
|
||||
}
|
||||
}
|
||||
|
||||
// Quintic ---------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
public static float EaseIn_Quintic(float t)
|
||||
{
|
||||
return Mathf.Pow(t, 5f);
|
||||
}
|
||||
|
||||
public static float EaseOut_Quintic(float t)
|
||||
{
|
||||
return 1 - EaseIn_Quintic(1 - t);
|
||||
}
|
||||
|
||||
public static float EaseInOut_Quintic(float t)
|
||||
{
|
||||
if (t < 0.5f)
|
||||
{
|
||||
return EaseIn_Quintic(t * 2f) / 2f;
|
||||
}
|
||||
else
|
||||
{
|
||||
return 1 - EaseIn_Quintic((1f - t) * 2f) / 2;
|
||||
}
|
||||
}
|
||||
|
||||
// Bounce ---------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
public static float EaseIn_Bounce(float t)
|
||||
{
|
||||
float p = 0.3f;
|
||||
return Mathf.Pow(2, -10 * t) * Mathf.Sin((t - p / 4) * (2 * Mathf.PI) / p) + 1;
|
||||
}
|
||||
|
||||
public static float EaseOut_Bounce(float t)
|
||||
{
|
||||
return 1 - EaseIn_Bounce(1 - t);
|
||||
}
|
||||
|
||||
public static float EaseInOut_Bounce(float t)
|
||||
{
|
||||
if (t < 0.5f)
|
||||
{
|
||||
return EaseIn_Bounce(t * 2f) / 2f;
|
||||
}
|
||||
else
|
||||
{
|
||||
return 1 - EaseIn_Bounce((1f - t) * 2f) / 2;
|
||||
}
|
||||
}
|
||||
|
||||
// Sinusoidal ---------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
public static float EaseIn_Sinusoidal(float t)
|
||||
{
|
||||
return 1 + Mathf.Sin(Mathf.PI / 2f * t - Mathf.PI / 2f);
|
||||
}
|
||||
|
||||
public static float EaseOut_Sinusoidal(float t)
|
||||
{
|
||||
return 1 - EaseIn_Sinusoidal(1 - t);
|
||||
}
|
||||
|
||||
public static float EaseInOut_Sinusoidal(float t)
|
||||
{
|
||||
if (t < 0.5f)
|
||||
{
|
||||
return EaseIn_Sinusoidal(t * 2f) / 2f;
|
||||
}
|
||||
else
|
||||
{
|
||||
return 1 - EaseIn_Sinusoidal((1f - t) * 2f) / 2;
|
||||
}
|
||||
}
|
||||
|
||||
// Overhead ---------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
public static float EaseIn_Overhead(float t)
|
||||
{
|
||||
float back = 1.6f;
|
||||
return t * t * ((back + 1f) * t - back);
|
||||
}
|
||||
|
||||
public static float EaseOut_Overhead(float t)
|
||||
{
|
||||
return 1 - EaseIn_Overhead(1 - t);
|
||||
}
|
||||
|
||||
public static float EaseInOut_Overhead(float t)
|
||||
{
|
||||
if (t < 0.5f)
|
||||
{
|
||||
return EaseIn_Overhead(t * 2f) / 2f;
|
||||
}
|
||||
else
|
||||
{
|
||||
return 1 - EaseIn_Overhead((1f - t) * 2f) / 2;
|
||||
}
|
||||
}
|
||||
|
||||
// Exponential ---------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
public static float EaseIn_Exponential(float t)
|
||||
{
|
||||
return t == 0f ? 0f : Mathf.Pow(1024f, t - 1f);
|
||||
}
|
||||
|
||||
public static float EaseOut_Exponential(float t)
|
||||
{
|
||||
return 1 - EaseIn_Exponential(1 - t);
|
||||
}
|
||||
|
||||
public static float EaseInOut_Exponential(float t)
|
||||
{
|
||||
if (t < 0.5f)
|
||||
{
|
||||
return EaseIn_Exponential(t * 2f) / 2f;
|
||||
}
|
||||
else
|
||||
{
|
||||
return 1 - EaseIn_Exponential((1f - t) * 2f) / 2;
|
||||
}
|
||||
}
|
||||
|
||||
// Elastic ---------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
public static float EaseIn_Elastic(float t)
|
||||
{
|
||||
if (t == 0f) { return 0f; }
|
||||
if (t == 1f) { return 1f; }
|
||||
return -Mathf.Pow(2f, 10f * (t -= 1f)) * Mathf.Sin((t - 0.1f) * (2f * Mathf.PI) / 0.4f);
|
||||
}
|
||||
|
||||
public static float EaseOut_Elastic(float t)
|
||||
{
|
||||
return 1 - EaseIn_Elastic(1 - t);
|
||||
}
|
||||
|
||||
public static float EaseInOut_Elastic(float t)
|
||||
{
|
||||
if (t < 0.5f)
|
||||
{
|
||||
return EaseIn_Elastic(t * 2f) / 2f;
|
||||
}
|
||||
else
|
||||
{
|
||||
return 1 - EaseIn_Elastic((1f - t) * 2f) / 2;
|
||||
}
|
||||
}
|
||||
|
||||
// Circular ---------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
public static float EaseIn_Circular(float t)
|
||||
{
|
||||
return 1f - Mathf.Sqrt(1f - t * t);
|
||||
}
|
||||
|
||||
public static float EaseOut_Circular(float t)
|
||||
{
|
||||
return 1 - EaseIn_Circular(1 - t);
|
||||
}
|
||||
|
||||
public static float EaseInOut_Circular(float t)
|
||||
{
|
||||
if (t < 0.5f)
|
||||
{
|
||||
return EaseIn_Circular(t * 2f) / 2f;
|
||||
}
|
||||
else
|
||||
{
|
||||
return 1 - EaseIn_Circular((1f - t) * 2f) / 2;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
11
Assets/Feel/MMTools/Core/MMTween/MMTweenDefinitions.cs.meta
Normal file
11
Assets/Feel/MMTools/Core/MMTween/MMTweenDefinitions.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 540be5b94edd9f347bf404fe0d020285
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
35
Assets/Feel/MMTools/Core/MMTween/MMTweenType.cs
Normal file
35
Assets/Feel/MMTools/Core/MMTween/MMTweenType.cs
Normal file
@@ -0,0 +1,35 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace MoreMountains.Tools
|
||||
{
|
||||
public enum MMTweenDefinitionTypes { MMTween, AnimationCurve }
|
||||
|
||||
[Serializable]
|
||||
public class MMTweenType
|
||||
{
|
||||
public static MMTweenType DefaultEaseInCubic { get; } = new MMTweenType(MMTween.MMTweenCurve.EaseInCubic);
|
||||
public MMTweenDefinitionTypes MMTweenDefinitionType = MMTweenDefinitionTypes.MMTween;
|
||||
public MMTween.MMTweenCurve MMTweenCurve = MMTween.MMTweenCurve.EaseInCubic;
|
||||
public AnimationCurve Curve = new AnimationCurve(new Keyframe(0, 0), new Keyframe(1, 1f));
|
||||
public bool Initialized = false;
|
||||
|
||||
public MMTweenType(MMTween.MMTweenCurve newCurve)
|
||||
{
|
||||
MMTweenCurve = newCurve;
|
||||
MMTweenDefinitionType = MMTweenDefinitionTypes.MMTween;
|
||||
}
|
||||
public MMTweenType(AnimationCurve newCurve)
|
||||
{
|
||||
Curve = newCurve;
|
||||
MMTweenDefinitionType = MMTweenDefinitionTypes.AnimationCurve;
|
||||
}
|
||||
|
||||
public float Evaluate(float t)
|
||||
{
|
||||
return MMTween.Evaluate(t, this);
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/Feel/MMTools/Core/MMTween/MMTweenType.cs.meta
Normal file
11
Assets/Feel/MMTools/Core/MMTween/MMTweenType.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 503fff45948a0ea4cb047c033294e914
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user