39 lines
No EOL
1.1 KiB
C#
39 lines
No EOL
1.1 KiB
C#
using R3;
|
|
using UnityEngine;
|
|
|
|
namespace KitsuneCafe.SOAP
|
|
{
|
|
/// <summary>
|
|
/// Base class for ScriptableObject assets that represent a constant, immutable value.
|
|
/// Implements IReactiveSource<T> by emitting its value once and completing.
|
|
/// </summary>
|
|
/// <typeparam name="T">The type of the constant value.</typeparam>
|
|
public abstract class ConstantValue<T> : ScriptableObject, IReactiveSource<T>
|
|
{
|
|
#if UNITY_EDITOR
|
|
[Multiline]
|
|
public string Description = "";
|
|
#endif
|
|
|
|
[SerializeField]
|
|
protected T value;
|
|
|
|
/// <summary>
|
|
/// Gets the immutable constant value.
|
|
/// </summary>
|
|
public T Value => value;
|
|
|
|
/// <summary>
|
|
/// Provides an Observable that emits the constant value once and then completes.
|
|
/// </summary>
|
|
public Observable<T> AsObservable()
|
|
{
|
|
return Observable.Return(value);
|
|
}
|
|
|
|
public override string ToString()
|
|
{
|
|
return $"Constant<{typeof(T).Name}>({value?.ToString() ?? "null"})";
|
|
}
|
|
}
|
|
} |