using System; using UnityEngine; namespace Ca2d.Toolkit { /// /// An utility which gives a type safe boxing. /// /// The value type which will being boxing. [Serializable] public class Boxing where T : struct { [SerializeField] private T m_value; /// /// Create a copy of given boxing source. /// public Boxing(Boxing source) { m_value = source.m_value; } /// /// Create a copy of given value. /// public Boxing(T value) { m_value = value; } /// /// Create an empty boxing. /// public Boxing() {} /// /// Access to the boxing value directly in reference mode. /// public ref T Ref => ref m_value; /// /// Clean this boxing container to the default value of boxing target. /// public void Empty() { m_value = default; } public override string ToString() { return m_value.ToString(); } public static explicit operator T(Boxing wrapper) { return wrapper.m_value; } public static implicit operator Boxing(T value) { return new Boxing(value); } } }