ca2d-unity-toolkit/Assets/Main/Scripts/UnityObjectWarp.cs
cardidi 91c24b27e8 feat: Complete Guard.IgnoreException families.
feat: Add XML documentation to some methods and classes.
remove: Cleanup BootUnit for rewriting.
2024-05-08 23:48:17 +08:00

30 lines
912 B
C#

using System;
using UnityEngine;
namespace Ca2d.Toolkit
{
/// <summary>
/// An utility which allows you to reference an <see cref="UnityEngine.Object"/> via it's interface.
/// </summary>
/// <typeparam name="T">The type of class which you are willing to reference as.</typeparam>
[Serializable]
public struct UnityObjectWarp<T> where T : class
{
[SerializeField] private UnityEngine.Object m_referencedObject;
/// <summary>
/// Is this warp reference to a valid target?
/// </summary>
public bool Valid => m_referencedObject is T;
/// <summary>
/// Trying to get the actual object of this reference.
/// </summary>
public T Object => m_referencedObject as T;
public static implicit operator T(UnityObjectWarp<T> wrapper)
{
return wrapper.Object;
}
}
}