1
This commit is contained in:
51
Unity/Scripts/Debuger/TempValue.cs
Normal file
51
Unity/Scripts/Debuger/TempValue.cs
Normal file
@@ -0,0 +1,51 @@
|
||||
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
|
||||
{
|
||||
return active.canUpdate is false;
|
||||
}
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user