using System;
using UnityEngine.Assertions;
namespace Ca2d.Toolkit
{
///
/// An utility structure which helps you to create an optional field in Unity Editor or a
/// alternative.
///
/// The type which will be optional.
[Serializable]
public struct Option
{
///
/// Is option set to fill.
///
public bool Enabled;
///
/// Value inside of option
///
public T Value;
public T ValueOrDefault()
{
return Enabled ? Value : default;
}
public T ValueOrDefault(T def)
{
return Enabled ? Value : def;
}
public T ValueOrDefault(Func def)
{
Assert.IsNotNull(def);
return Enabled ? Value : def();
}
public T ValueOrDefault(TSelector src, Func def)
{
Assert.IsNotNull(def);
return Enabled ? Value : def(src);
}
public Option(T value)
{
Enabled = true;
Value = value;
}
public static implicit operator T(Option wrapper)
{
return wrapper.Value;
}
public static implicit operator Option(T value)
{
return new Option(value);
}
}
}