using System;
using System.Runtime.CompilerServices;
namespace BansheeEngine
{
///
/// Common class for all resource references.
///
public class ResourceRefBase : ScriptObject
{
///
/// Constructor for internal use only.
///
protected ResourceRefBase()
{ }
///
/// Checks is the referenced resource loaded
///
public bool IsLoaded
{
get { return Internal_IsLoaded(mCachedPtr); }
}
///
public override bool Equals(object other)
{
if (!(other is ResourceRefBase))
return false;
ResourceRefBase otherRef = (ResourceRefBase)other;
return Internal_GetUUID(mCachedPtr).Equals(Internal_GetUUID(otherRef.mCachedPtr));
}
///
public override int GetHashCode()
{
return Internal_GetUUID(mCachedPtr).GetHashCode();
}
[MethodImpl(MethodImplOptions.InternalCall)]
private static extern bool Internal_IsLoaded(IntPtr thisPtr);
[MethodImpl(MethodImplOptions.InternalCall)]
protected static extern Resource Internal_GetResource(IntPtr thisPtr);
[MethodImpl(MethodImplOptions.InternalCall)]
private static extern string Internal_GetUUID(IntPtr thisPtr);
}
///
/// Allows you to store a reference to a resource without needing to have that resource loaded.
///
public class ResourceRef : ResourceRefBase where T : Resource
{
///
/// Retrieves the referenced resource. This will load the resources if it is not already loaded.
///
/// Type of the resource to load.
/// Loaded resource object.
public T Get()
{
return (T)Internal_GetResource(mCachedPtr);
}
}
}