change: more alterations to the new movement and settingvalue system

This commit is contained in:
Chris
2025-09-22 14:24:50 -04:00
parent d4231d4f38
commit b21adf93e2
18 changed files with 399 additions and 333 deletions

View File

@@ -1,24 +1,80 @@
using System;
using UnityEngine;
using UnityEngine.Serialization;
public interface IResettableSettingValue{
public abstract void SmoothAndEase();
}
[Serializable]
public struct SettingValue<T>{
public T value;
public float smoothing; // Smoothing changes how fast value is changed.
public float easing; // Easing changes how fast smoothing is changed, when given a new value.
public struct SettingValue<T> : IResettableSettingValue{
public T targetValue;
public T currentValue;
public T refVel;
public float currentSmoothing; // Actively eased and accessed value
public float currentValue; // Actively smoothed and accessed value
public float targetSmoothing; // Smoothing changes how fast the value is changed.
public float targetEasing; // Easing changes how fast smoothing is changed, when given a new value.
public T refVel; // For use with SmoothDamp
public T Value{
get => currentValue;
set => targetValue = value;
}
private float currentSmoothing;
public T defaultValue;
public float defaultSmoothing;
public float defaultEasing;
private float refVelFloat; // For use with SmoothDamp
private Vector3 refVelV3; // For use with SmoothDamp
private Vector2 refVelV2; // For use with SmoothDamp
public SettingValue(T initValue, float defaultEasing = 2f, float defaultSmoothing = 1f){
value = initValue;
easing = defaultEasing;
value = default;
smoothing = defaultSmoothing;
currentSmoothing = 0;
currentValue = 0;
targetValue = initValue;
this.defaultSmoothing = defaultSmoothing;
this.defaultEasing = defaultEasing;
targetEasing = defaultEasing;
targetSmoothing = defaultSmoothing;
currentSmoothing = targetSmoothing;
currentValue = targetValue;
refVelFloat = 0;
refVelV3 = default;
refVelV2 = default;
refVel = default;
defaultValue = initValue;
}
public void SmoothAndEase(){
Debug.Log("Worked!");
return;
currentSmoothing = Mathf.MoveTowards(currentSmoothing, targetSmoothing, targetEasing * 1f * Time.deltaTime);
if (typeof(T) == typeof(float)) {
currentValue = (T)(object)Mathf.SmoothDamp((float)(object)currentValue, (float)(object)targetValue, ref refVelFloat, currentSmoothing * Time.deltaTime);
}
if (typeof(T) == typeof(Vector2)) {
currentValue = (T)(object)Vector2.SmoothDamp((Vector2)(object)currentValue, (Vector2)(object)targetValue, ref refVelV2, currentSmoothing * Time.deltaTime);
}
if (typeof(T) == typeof(Vector3)) {
currentValue = (T)(object)Vector3.SmoothDamp((Vector3)(object)currentValue, (Vector3)(object)targetValue, ref refVelV3, currentSmoothing * Time.deltaTime);
}
if (typeof(T) == typeof(Vector4) || typeof(T) == typeof(Quaternion)) {
// I have... zero clue if this will work. There is no Vector4 or Quaternion SmoothDamp
Vector3 v3value = Vector3.SmoothDamp((Vector4)(object)currentValue, (Vector4)(object)targetValue, ref refVelV3, currentSmoothing * Time.deltaTime);
float v4value = Mathf.SmoothDamp(((Vector4)(object)currentValue).z, ((Vector4)(object)targetValue).z, ref refVelFloat, currentSmoothing * Time.deltaTime);
currentValue = (T)(object)new Vector4(v3value.x, v3value.y, v3value.z, v4value);
}
}
}