//********************************** Banshee Engine (www.banshee3d.com) **************************************************// //**************** Copyright (c) 2016 Marko Pintera (marko.pintera@gmail.com). All rights reserved. **********************// using System; using System.Runtime.CompilerServices; namespace BansheeEngine { /** @addtogroup Resources * @{ */ /// /// Provides a handle to a . The underlying resource might or might not be loaded. /// public class RRefBase : ScriptObject { /// /// Constructor for internal use only. /// protected RRefBase() { } /// /// Checks is the referenced resource loaded. /// public bool IsLoaded => Internal_IsLoaded(mCachedPtr); /// /// Returns the referenced resource. If the resource hasn't been loaded it will be loaded as if calling /// using default settings. /// public Resource GenericValue => Internal_GetResource(mCachedPtr); /// /// Returns the UUID of the resource this handle is referencing. /// public UUID UUID { get { Internal_GetUUID(mCachedPtr, out var uuid); return uuid; } } /// /// Casts the generic resource reference type to a specific resource reference type. /// /// Type of resource to cast the reference to. /// New reference type. public RRef As() where T : Resource { return (RRef)Internal_CastAs(mCachedPtr, typeof(T)); } /// public override bool Equals(object other) { if (ReferenceEquals(other, null)) return false; if (!(other is RRefBase)) return false; RRefBase otherRef = (RRefBase)other; Internal_GetUUID(mCachedPtr, out var lhs); Internal_GetUUID(otherRef.mCachedPtr, out var rhs); return lhs.Equals(rhs); } public bool Equals(RRefBase other) { if (ReferenceEquals(other, null)) return false; Internal_GetUUID(mCachedPtr, out var lhs); Internal_GetUUID(other.mCachedPtr, out var rhs); return lhs.Equals(rhs); } public static bool operator==(RRefBase lhs, RRefBase rhs) { if (ReferenceEquals(lhs, rhs)) return true; if (ReferenceEquals(lhs, null)) return false; if (ReferenceEquals(rhs, null)) return false; Internal_GetUUID(lhs.mCachedPtr, out var lhsUUID); Internal_GetUUID(rhs.mCachedPtr, out var rhsUUID); return lhsUUID.Equals(rhsUUID); } public static bool operator!=(RRefBase lhs, RRefBase rhs) { return !(lhs == rhs); } /// public override int GetHashCode() { return UUID.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 void Internal_GetUUID(IntPtr thisPtr, out UUID uuid); [MethodImpl(MethodImplOptions.InternalCall)] private static extern RRefBase Internal_CastAs(IntPtr thisPtr, Type type); } /// /// Provides a handle to a . The underlying resource might or might not be loaded. /// /// Resource type that the handle references public class RRef : RRefBase where T : Resource { /// /// Returns the referenced resource. If the resource hasn't been loaded it will be loaded as if calling /// using default settings. /// public T Value => (T) GenericValue; } /** @} */ }