2023-06-05 19:57:17 +08:00
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using UnityEngine;
|
|
|
|
using System;
|
|
|
|
namespace BITKit
|
|
|
|
{
|
|
|
|
[System.Serializable]
|
|
|
|
public class TempValue<T>
|
|
|
|
{
|
|
|
|
public static implicit operator T(TempValue<T> self) => self.Get();
|
|
|
|
public static implicit operator bool(TempValue<T> self) => self.IsActive();
|
|
|
|
public IEnumerable<T> optionals = new List<T>();
|
|
|
|
public T value = default;
|
|
|
|
public float lowValue = -90;
|
|
|
|
public float highValue = 90;
|
|
|
|
public bool locked;
|
|
|
|
Action<T> onValueChanged;
|
|
|
|
IntervalUpdate active = new(1);
|
|
|
|
|
|
|
|
public T Get() => value;
|
|
|
|
public bool IsActive()
|
|
|
|
{
|
|
|
|
if (locked)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-06-29 14:57:11 +08:00
|
|
|
return active.AllowUpdateWithoutReset is false;
|
2023-06-05 19:57:17 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
public void Set(T t)
|
|
|
|
{
|
|
|
|
value = t;
|
|
|
|
onValueChanged?.Invoke(value);
|
|
|
|
active.Reset();
|
|
|
|
}
|
|
|
|
public void SetOptionals(IEnumerable<T> optionals)
|
|
|
|
{
|
|
|
|
this.optionals = optionals;
|
|
|
|
}
|
|
|
|
public void AddListener(Action<T> action)
|
|
|
|
{
|
|
|
|
onValueChanged += action;
|
|
|
|
}
|
|
|
|
public void RemoveListener(Action<T> action)
|
|
|
|
{
|
|
|
|
onValueChanged -= action;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|