大修
This commit is contained in:
92
Assets/Scripts/SLSUtilities/General/MathExtensions.cs
Normal file
92
Assets/Scripts/SLSUtilities/General/MathExtensions.cs
Normal file
@@ -0,0 +1,92 @@
|
||||
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 class LerpFloat
|
||||
{
|
||||
public float currentValue;
|
||||
public float targetValue;
|
||||
public float lerpSpeed;
|
||||
|
||||
public LerpFloat(float initialValue, float lerpSpeed)
|
||||
{
|
||||
this.currentValue = initialValue;
|
||||
this.targetValue = initialValue;
|
||||
this.lerpSpeed = lerpSpeed;
|
||||
}
|
||||
|
||||
public void Update(float deltaTime)
|
||||
{
|
||||
currentValue = Mathf.Lerp(currentValue, targetValue, lerpSpeed * deltaTime);
|
||||
}
|
||||
|
||||
public 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user