Insanely huge initial commit

This commit is contained in:
2026-02-21 16:40:15 -08:00
parent 208d626100
commit f74c547a13
33825 changed files with 5213498 additions and 0 deletions

View File

@@ -0,0 +1,101 @@
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
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);
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: ce2656e6b00dc8d4788dc4d382e1588a
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View 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);
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 2b0d2c9595529ed47a73e3b75de4eae6
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,391 @@
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
using System;
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 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 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 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 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 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 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;
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: cd6b5fb73f238654ba224ef88b91ac2a
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View 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;
}
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 540be5b94edd9f347bf404fe0d020285
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View 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);
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 503fff45948a0ea4cb047c033294e914
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: