using System;
using UnityEngine;
namespace Ca2d.Toolkit
{
///
/// An utility which allows you to reference an via it's interface.
///
/// The type of class which you are willing to reference as.
[Serializable]
public struct UnityObjectWarp where T : class
{
[SerializeField] private UnityEngine.Object m_referencedObject;
///
/// Is this warp reference to a valid target?
///
public bool Is => m_referencedObject is T;
///
/// Trying to get the actual object of this reference.
///
public T As => m_referencedObject as T;
///
/// Is this warp reference to a valid target? If this is valid, give the casting result.
///
public bool IsAs(out T val)
{
if (m_referencedObject is T referenced)
{
val = referenced;
return true;
}
val = null;
return false;
}
}
}