131 lines
3.8 KiB
C#
131 lines
3.8 KiB
C#
using System;
|
|
using UnityEngine;
|
|
|
|
namespace SLSUtilities.General
|
|
{
|
|
public static class MathExtensions
|
|
{
|
|
public static float ClampAngle(float lfAngle, float lfMin, float lfMax)
|
|
{
|
|
if (lfAngle < -360f) lfAngle += 360f;
|
|
if (lfAngle > 360f) lfAngle -= 360f;
|
|
return Mathf.Clamp(lfAngle, lfMin, lfMax);
|
|
}
|
|
|
|
public static Vector3 Flatten(this Vector3 vector)
|
|
{
|
|
return new Vector3(vector.x, 0, vector.z);
|
|
}
|
|
}
|
|
|
|
public abstract class LerpValue<T>
|
|
{
|
|
public T currentValue;
|
|
public T targetValue;
|
|
public bool IsPausing { get; set; }
|
|
|
|
public bool advancedSettings = false;
|
|
|
|
public abstract void Update(float deltaTime);
|
|
|
|
public abstract void Update(float customSpeed, float deltaTime);
|
|
}
|
|
|
|
public class LerpFloat : LerpValue<float>
|
|
{
|
|
public float lerpSpeed;
|
|
public float increaseSpeed;
|
|
public float decreaseSpeed;
|
|
|
|
public LerpFloat(float initialValue, float lerpSpeed)
|
|
{
|
|
this.currentValue = initialValue;
|
|
this.targetValue = initialValue;
|
|
this.advancedSettings = false;
|
|
this.lerpSpeed = lerpSpeed;
|
|
}
|
|
|
|
public LerpFloat(float initialValue, float increaseSpeed, float decreaseSpeed)
|
|
{
|
|
this.currentValue = initialValue;
|
|
this.targetValue = initialValue;
|
|
this.advancedSettings = true;
|
|
this.increaseSpeed = increaseSpeed;
|
|
this.decreaseSpeed = decreaseSpeed;
|
|
}
|
|
|
|
public override void Update(float deltaTime)
|
|
{
|
|
if (IsPausing) return;
|
|
|
|
if (advancedSettings)
|
|
{
|
|
if(targetValue > currentValue)
|
|
{
|
|
currentValue = Mathf.Lerp(currentValue, targetValue, increaseSpeed * deltaTime);
|
|
}
|
|
else
|
|
{
|
|
currentValue = Mathf.Lerp(currentValue, targetValue, decreaseSpeed * deltaTime);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
currentValue = Mathf.Lerp(currentValue, targetValue, lerpSpeed * deltaTime);
|
|
}
|
|
}
|
|
|
|
public override void Update(float customSpeed, float deltaTime)
|
|
{
|
|
currentValue = Mathf.Lerp(currentValue, targetValue, customSpeed * deltaTime);
|
|
}
|
|
}
|
|
|
|
public class LerpVector3
|
|
{
|
|
public Vector3 currentValue;
|
|
public Vector3 targetValue;
|
|
public float lerpSpeed;
|
|
|
|
public LerpVector3(Vector3 initialValue, float lerpSpeed)
|
|
{
|
|
this.currentValue = initialValue;
|
|
this.targetValue = initialValue;
|
|
this.lerpSpeed = lerpSpeed;
|
|
}
|
|
|
|
public void Update(float deltaTime)
|
|
{
|
|
currentValue = Vector3.Lerp(currentValue, targetValue, lerpSpeed * deltaTime);
|
|
}
|
|
|
|
public void Update(float customSpeed, float deltaTime)
|
|
{
|
|
currentValue = Vector3.Lerp(currentValue, targetValue, customSpeed * deltaTime);
|
|
}
|
|
}
|
|
|
|
public class LerpColor
|
|
{
|
|
public Color currentValue;
|
|
public Color targetValue;
|
|
public float lerpSpeed;
|
|
|
|
public LerpColor(Color initialValue, float lerpSpeed)
|
|
{
|
|
this.currentValue = initialValue;
|
|
this.targetValue = initialValue;
|
|
this.lerpSpeed = lerpSpeed;
|
|
}
|
|
|
|
public void Update(float deltaTime)
|
|
{
|
|
currentValue = Color.Lerp(currentValue, targetValue, lerpSpeed * deltaTime);
|
|
}
|
|
|
|
public void Update(float customSpeed, float deltaTime)
|
|
{
|
|
currentValue = Color.Lerp(currentValue, targetValue, customSpeed * deltaTime);
|
|
}
|
|
}
|
|
} |