change: fixing of many issues in handler, deprecation/deletion of variables, cleanup of UnitMovementHandler, cleaning up of inspector

This commit is contained in:
Chris
2025-09-23 14:14:47 -04:00
parent b21adf93e2
commit bd2903a0b2
10 changed files with 445 additions and 838 deletions

View File

@@ -1,39 +1,53 @@
using System;
using Sirenix.OdinInspector;
using UnityEngine;
using UnityEngine.Serialization;
public interface IResettableSettingValue{
public abstract void SmoothAndEase();
public void Verify();
public void SmoothAndEase();
public void Initialize();
}
[Serializable]
public struct SettingValue<T> : IResettableSettingValue{
public T targetValue;
public T currentValue;
public T refVel;
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 class SettingValue<T> : IResettableSettingValue{
[HorizontalGroup("Settings", width: .3f), VerticalGroup("Settings/Value"), BoxGroup("Settings/Value/Value"), LabelText("Target")]
public T targetValue;
[HorizontalGroup("Settings"), VerticalGroup("Settings/Value"), BoxGroup("Settings/Value/Value"), LabelText("Current")]
public T currentValue;
[HorizontalGroup("Settings"), VerticalGroup("Settings/Smoothing"), BoxGroup("Settings/Smoothing/Smoothing"), LabelText("Target"), ShowIf("@IsSmoothable()")]
public float targetSmoothing; // Smoothing changes how fast the value is changed.
[HorizontalGroup("Settings"), VerticalGroup("Settings/Easing"), BoxGroup("Settings/Easing/Easing"), LabelText("Target"), ShowIf("@IsSmoothable()")]
public float targetEasing; // Easing changes how fast smoothing is changed, when given a new value.
public T Value{
get => currentValue;
set => targetValue = value;
}
[HorizontalGroup("Settings"), VerticalGroup("Settings/Smoothing"), BoxGroup("Settings/Smoothing/Smoothing"), LabelText("Current"), ShowIf("@IsSmoothable()")]
private float currentSmoothing;
[HorizontalGroup("Settings"), VerticalGroup("Settings/Value"), BoxGroup("Settings/Value/Value"), LabelText("Default")]
public T defaultValue;
[HorizontalGroup("Settings"), VerticalGroup("Settings/Smoothing"), BoxGroup("Settings/Smoothing/Smoothing"), LabelText("Default"), ShowIf("@IsSmoothable()")]
public float defaultSmoothing;
[HorizontalGroup("Settings"), VerticalGroup("Settings/Easing"), BoxGroup("Settings/Easing/Easing"), LabelText("Default"), ShowIf("@IsSmoothable()")]
public float defaultEasing;
private float refVelFloat; // For use with SmoothDamp
private Vector3 refVelV3; // For use with SmoothDamp
private Vector2 refVelV2; // For use with SmoothDamp
private bool verified;
bool IsSmoothable(){
return (typeof(T) == typeof(float) || typeof(T) == typeof(Vector2) || typeof(T) == typeof(Vector3) || typeof(T) == typeof(Vector4) || typeof(T) == typeof(Quaternion) );
}
public SettingValue(T initValue, float defaultEasing = 2f, float defaultSmoothing = 1f){
targetValue = initValue;
defaultValue = initValue;
this.defaultSmoothing = defaultSmoothing;
this.defaultEasing = defaultEasing;
@@ -46,14 +60,20 @@ public struct SettingValue<T> : IResettableSettingValue{
refVelFloat = 0;
refVelV3 = default;
refVelV2 = default;
refVel = default;
defaultValue = initValue;
}
public void Verify(){
if (targetValue.Equals(currentValue) == false) {
Debug.LogWarning($"A SettingValue ({this}) doesn't have its current and target value matching. This should have been set!");
}
verified = true;
}
public void SmoothAndEase(){
Debug.Log("Worked!");
return;
if (!verified) {
Debug.LogWarning($"A SettingValue ({this}) wasn't verified before being smoothed and eased. What's up with that?");
}
currentSmoothing = Mathf.MoveTowards(currentSmoothing, targetSmoothing, targetEasing * 1f * Time.deltaTime);
@@ -77,4 +97,9 @@ public struct SettingValue<T> : IResettableSettingValue{
currentValue = (T)(object)new Vector4(v3value.x, v3value.y, v3value.z, v4value);
}
}
public void Initialize(){
currentValue = targetValue;
Debug.Log(Value);
}
}