mirror of
https://github.com/Cardidi/ca2d-unity-toolkit.git
synced 2025-12-20 09:16:03 +08:00
feat: Add XML documentation to some methods and classes. remove: Cleanup BootUnit for rewriting.
30 lines
912 B
C#
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;
|
|
}
|
|
}
|
|
} |