فهرست منبع

Removed templated version of ResourceRef as it was more confusing than useful

BearishSun 10 سال پیش
والد
کامیت
b63918d2cc

+ 4 - 4
MBansheeEditor/BuildManager.cs

@@ -37,7 +37,7 @@ namespace BansheeEditor
         /// <summary>
         /// Initial scene that is loaded when application is first started.
         /// </summary>
-        public ResourceRef<Prefab> MainScene
+        public ResourceRef MainScene
         {
             get { return Internal_GetMainScene(mCachedPtr); }
             set
@@ -121,7 +121,7 @@ namespace BansheeEditor
         private static extern void Internal_SetDefines(IntPtr thisPtr, string value);
 
         [MethodImpl(MethodImplOptions.InternalCall)]
-        private static extern ResourceRef<Prefab> Internal_GetMainScene(IntPtr thisPtr);
+        private static extern ResourceRef Internal_GetMainScene(IntPtr thisPtr);
 
         [MethodImpl(MethodImplOptions.InternalCall)]
         static extern void Internal_SetMainScene(IntPtr thisPtr, IntPtr prefabPtr);
@@ -168,7 +168,7 @@ namespace BansheeEditor
         /// <summary>
         /// Texture that will be displayed on the application's executable.
         /// </summary>
-        public ResourceRef<Texture2D> Icon
+        public ResourceRef Icon
         {
             get { return Internal_GetIcon(mCachedPtr); }
             set
@@ -191,7 +191,7 @@ namespace BansheeEditor
         }
         
         [MethodImpl(MethodImplOptions.InternalCall)]
-        private static extern ResourceRef<Texture2D> Internal_GetIcon(IntPtr thisPtr);
+        private static extern ResourceRef Internal_GetIcon(IntPtr thisPtr);
 
         [MethodImpl(MethodImplOptions.InternalCall)]
         private static extern void Internal_SetIcon(IntPtr thisPtr, IntPtr texturePtr);

+ 2 - 2
MBansheeEditor/BuildWindow.cs

@@ -191,7 +191,7 @@ namespace BansheeEditor
                 heightField.Active = false;
             }
 
-            sceneField.OnChanged += x => platformInfo.MainScene = x as ResourceRef<Prefab>;
+            sceneField.OnChanged += x => platformInfo.MainScene = x;
             debugToggle.OnChanged += x => platformInfo.Debug = x;
             definesField.OnChanged += x => platformInfo.Defines = x;
             fullscreenField.OnChanged += x =>
@@ -222,7 +222,7 @@ namespace BansheeEditor
                     iconField.ValueRef = winPlatformInfo.Icon;
 
                     titleField.OnChanged += x => winPlatformInfo.TitleText = x;
-                    iconField.OnChanged += x => winPlatformInfo.Icon = x as ResourceRef<Texture2D>;
+                    iconField.OnChanged += x => winPlatformInfo.Icon = x;
                 }
                     break;
             }

+ 6 - 6
MBansheeEditor/GUI/GUIResourceField.cs

@@ -10,7 +10,7 @@ namespace BansheeEditor
     /// </summary>
     public sealed class GUIResourceField : GUIElement
     {
-        public delegate void OnChangedDelegate(ResourceRefBase newValue);
+        public delegate void OnChangedDelegate(ResourceRef newValue);
 
         /// <summary>
         /// Triggered when the value in the field changes.
@@ -36,11 +36,11 @@ namespace BansheeEditor
         /// <summary>
         /// Reference to the <see cref="Resource"/> referenced by the field.
         /// </summary>
-        public ResourceRefBase ValueRef
+        public ResourceRef ValueRef
         {
             get
             {
-                ResourceRefBase value;
+                ResourceRef value;
                 Internal_GetValueRef(mCachedPtr, out value);
                 return value;
             }
@@ -91,7 +91,7 @@ namespace BansheeEditor
         /// Triggered by the runtime when the value of the field changes.
         /// </summary>
         /// <param name="newValue">New resource referenced by the field.</param>
-        private void DoOnChanged(ResourceRefBase newValue)
+        private void DoOnChanged(ResourceRef newValue)
         {
             if (OnChanged != null)
                 OnChanged(newValue);
@@ -108,10 +108,10 @@ namespace BansheeEditor
         private static extern void Internal_SetValue(IntPtr nativeInstance, Resource value);
 
         [MethodImpl(MethodImplOptions.InternalCall)]
-        private static extern void Internal_GetValueRef(IntPtr nativeInstance, out ResourceRefBase value);
+        private static extern void Internal_GetValueRef(IntPtr nativeInstance, out ResourceRef value);
 
         [MethodImpl(MethodImplOptions.InternalCall)]
-        private static extern void Internal_SetValueRef(IntPtr nativeInstance, ResourceRefBase value);
+        private static extern void Internal_SetValueRef(IntPtr nativeInstance, ResourceRef value);
 
         [MethodImpl(MethodImplOptions.InternalCall)]
         private static extern void Internal_SetTint(IntPtr nativeInstance, Color color);

+ 6 - 6
MBansheeEditor/GUI/GUITextureField.cs

@@ -11,7 +11,7 @@ namespace BansheeEditor
     /// </summary>
     public sealed class GUITextureField : GUIElement
     {
-        public delegate void OnChangedDelegate(ResourceRefBase newValue);
+        public delegate void OnChangedDelegate(ResourceRef newValue);
 
         /// <summary>
         /// Triggered when the value in the field changes.
@@ -37,11 +37,11 @@ namespace BansheeEditor
         /// <summary>
         /// Reference to the <see cref="Texture"/> referenced by the field.
         /// </summary>
-        public ResourceRefBase ValueRef
+        public ResourceRef ValueRef
         {
             get
             {
-                ResourceRefBase value;
+                ResourceRef value;
                 Internal_GetValueRef(mCachedPtr, out value);
                 return value;
             }
@@ -90,7 +90,7 @@ namespace BansheeEditor
         /// Triggered by the runtime when the value of the field changes.
         /// </summary>
         /// <param name="newValue">New resource referenced by the field.</param>
-        private void Internal_DoOnChanged(ResourceRefBase newValue)
+        private void Internal_DoOnChanged(ResourceRef newValue)
         {
             if (OnChanged != null)
                 OnChanged(newValue);
@@ -107,10 +107,10 @@ namespace BansheeEditor
         private static extern void Internal_SetValue(IntPtr nativeInstance, Texture value);
 
         [MethodImpl(MethodImplOptions.InternalCall)]
-        private static extern void Internal_GetValueRef(IntPtr nativeInstance, out ResourceRefBase value);
+        private static extern void Internal_GetValueRef(IntPtr nativeInstance, out ResourceRef value);
 
         [MethodImpl(MethodImplOptions.InternalCall)]
-        private static extern void Internal_SetValueRef(IntPtr nativeInstance, ResourceRefBase value);
+        private static extern void Internal_SetValueRef(IntPtr nativeInstance, ResourceRef value);
 
         [MethodImpl(MethodImplOptions.InternalCall)]
         private static extern void Internal_SetTint(IntPtr nativeInstance, Color color);

+ 1 - 1
MBansheeEditor/Inspector/InspectableResourceRef.cs

@@ -53,7 +53,7 @@ namespace BansheeEditor
         /// Triggered when the user drops a new resource onto the field, or clears the current value.
         /// </summary>
         /// <param name="newValue">New resource to reference.</param>
-        private void OnFieldValueChanged(ResourceRefBase newValue)
+        private void OnFieldValueChanged(ResourceRef newValue)
         {
             Resource res = Resources.Load<Resource>(newValue);
 

+ 5 - 21
MBansheeEngine/ResourceRef.cs

@@ -4,14 +4,14 @@ using System.Runtime.CompilerServices;
 namespace BansheeEngine
 {
     /// <summary>
-    /// Common class for all resource references. <see cref="ResourceRef{T}"/>
+    /// Allows you to store a reference to a resource without needing to have that resource loaded.
     /// </summary>
-    public class ResourceRefBase : ScriptObject
+    public class ResourceRef : ScriptObject
     {
         /// <summary>
         /// Constructor for internal use only.
         /// </summary>
-        protected ResourceRefBase()
+        protected ResourceRef()
         { }
 
         /// <summary>
@@ -25,10 +25,10 @@ namespace BansheeEngine
         /// <inheritdoc/>
         public override bool Equals(object other)
         {
-            if (!(other is ResourceRefBase))
+            if (!(other is ResourceRef))
                 return false;
 
-            ResourceRefBase otherRef = (ResourceRefBase)other;
+            ResourceRef otherRef = (ResourceRef)other;
             return Internal_GetUUID(mCachedPtr).Equals(Internal_GetUUID(otherRef.mCachedPtr));
         }
 
@@ -47,20 +47,4 @@ namespace BansheeEngine
         [MethodImpl(MethodImplOptions.InternalCall)]
         private static extern string Internal_GetUUID(IntPtr thisPtr);
     }
-
-    /// <summary>
-    /// Allows you to store a reference to a resource without needing to have that resource loaded.
-    /// </summary>
-    public class ResourceRef<T> : ResourceRefBase where T : Resource
-    {
-        /// <summary>
-        /// Retrieves the referenced resource. This will load the resources if it is not already loaded.
-        /// </summary>
-        /// <typeparam name="T">Type of the resource to load.</typeparam>
-        /// <returns>Loaded resource object.</returns>
-        public T Get()
-        {
-            return (T)Internal_GetResource(mCachedPtr);
-        }
-    }
 }

+ 2 - 2
MBansheeEngine/Resources.cs

@@ -30,7 +30,7 @@ namespace BansheeEngine
         /// <typeparam name="T">Type of the resource.</typeparam>
         /// <param name="reference">Reference to the resource to load.</param>
         /// <returns>Loaded resource, or null if resource cannot be found.</returns>
-        public static T Load<T>(ResourceRefBase reference) where T : Resource
+        public static T Load<T>(ResourceRef reference) where T : Resource
         {
             return (T)Internal_LoadRef(reference);
         }
@@ -48,7 +48,7 @@ namespace BansheeEngine
         private static extern Resource Internal_Load(string path);
 
         [MethodImpl(MethodImplOptions.InternalCall)]
-        private static extern Resource Internal_LoadRef(ResourceRefBase reference);
+        private static extern Resource Internal_LoadRef(ResourceRef reference);
 
         [MethodImpl(MethodImplOptions.InternalCall)]
         private static extern void Internal_UnloadUnused();

+ 2 - 2
SBansheeEditor/Include/BsScriptPlatformInfo.h

@@ -48,7 +48,7 @@ namespace BansheeEngine
 		static MonoString* internal_GetDefines(ScriptPlatformInfoBase* thisPtr);
 		static void internal_SetDefines(ScriptPlatformInfoBase* thisPtr, MonoString* value);
 		static MonoObject* internal_GetMainScene(ScriptPlatformInfoBase* thisPtr);
-		static void internal_SetMainScene(ScriptPlatformInfoBase* thisPtr, ScriptResourceRefBase* prefabRef);
+		static void internal_SetMainScene(ScriptPlatformInfoBase* thisPtr, ScriptResourceRef* prefabRef);
 		static bool internal_GetFullscreen(ScriptPlatformInfoBase* thisPtr);
 		static void internal_SetFullscreen(ScriptPlatformInfoBase* thisPtr, bool fullscreen);
 		static void internal_GetResolution(ScriptPlatformInfoBase* thisPtr, UINT32* width, UINT32* height);
@@ -83,7 +83,7 @@ namespace BansheeEngine
 		/* 								CLR HOOKS						   		*/
 		/************************************************************************/
 		static MonoObject* internal_GetIcon(ScriptWinPlatformInfo* thisPtr);
-		static void internal_SetIcon(ScriptWinPlatformInfo* thisPtr, ScriptResourceRefBase* textureRef);
+		static void internal_SetIcon(ScriptWinPlatformInfo* thisPtr, ScriptResourceRef* textureRef);
 		static MonoString* internal_GetTitleText(ScriptWinPlatformInfo* thisPtr);
 		static void internal_SetTitleText(ScriptWinPlatformInfo* thisPtr, MonoString* text);
 	};

+ 1 - 1
SBansheeEditor/Source/BsScriptGUIResourceField.cpp

@@ -114,7 +114,7 @@ namespace BansheeEngine
 			resourceField->setValue(HTexture());
 		else
 		{
-			ScriptResourceRefBase* scriptTexture = ScriptResourceRefBase::toNative(value);
+			ScriptResourceRef* scriptTexture = ScriptResourceRef::toNative(value);
 			resourceField->setValueWeak(static_resource_cast<Texture>(scriptTexture->getHandle()));
 		}
 	}

+ 1 - 1
SBansheeEditor/Source/BsScriptGUITextureField.cpp

@@ -107,7 +107,7 @@ namespace BansheeEngine
 			textureField->setValue(HTexture());
 		else
 		{
-			ScriptResourceRefBase* scriptTexture = ScriptResourceRefBase::toNative(value);
+			ScriptResourceRef* scriptTexture = ScriptResourceRef::toNative(value);
 			textureField->setValueWeak(static_resource_cast<Texture>(scriptTexture->getHandle()));
 		}
 	}

+ 2 - 2
SBansheeEditor/Source/BsScriptPlatformInfo.cpp

@@ -74,7 +74,7 @@ namespace BansheeEngine
 		return nullptr;
 	}
 
-	void ScriptPlatformInfo::internal_SetMainScene(ScriptPlatformInfoBase* thisPtr, ScriptResourceRefBase* prefabRef)
+	void ScriptPlatformInfo::internal_SetMainScene(ScriptPlatformInfoBase* thisPtr, ScriptResourceRef* prefabRef)
 	{
 		WeakResourceHandle<Prefab> prefab;
 
@@ -154,7 +154,7 @@ namespace BansheeEngine
 		return nullptr;
 	}
 
-	void ScriptWinPlatformInfo::internal_SetIcon(ScriptWinPlatformInfo* thisPtr, ScriptResourceRefBase* textureRef)
+	void ScriptWinPlatformInfo::internal_SetIcon(ScriptWinPlatformInfo* thisPtr, ScriptResourceRef* textureRef)
 	{
 		WeakResourceHandle<Texture> icon;
 

+ 0 - 1
SBansheeEngine/Include/BsScriptEnginePrerequisites.h

@@ -77,7 +77,6 @@ namespace BansheeEngine
 	class ScriptContextMenu;
 	class ScriptGUISkin;
 	class ScriptResourceRef;
-	class ScriptResourceRefBase;
 
 	typedef GameObjectHandle<ManagedComponent> HManagedComponent;
 	typedef ResourceHandle<ManagedResource> HManagedResource;

+ 16 - 28
SBansheeEngine/Include/BsScriptResourceRef.h

@@ -9,39 +9,13 @@
 
 namespace BansheeEngine
 {
-	/**
-	 * @brief	Interop class between C++ & CLR for ResourceRefBase.
-	 */
-	class BS_SCR_BE_EXPORT ScriptResourceRefBase : public ScriptObject<ScriptResourceRefBase>
-	{
-	public:
-		SCRIPT_OBJ(ENGINE_ASSEMBLY, "BansheeEngine", "ResourceRefBase")
-
-		ScriptResourceRefBase(MonoObject* instance, const WeakResourceHandle<Resource>& resource);
-
-		/**
-		 * @brief	Returns a weak handle to the resource referenced by this object.
-		 */
-		WeakResourceHandle<Resource> getHandle() const { return mResource; }
-
-	private:
-		WeakResourceHandle<Resource> mResource;
-
-		/************************************************************************/
-		/* 								CLR HOOKS						   		*/
-		/************************************************************************/
-		static bool internal_IsLoaded(ScriptResourceRefBase* nativeInstance);
-		static MonoObject* internal_GetResource(ScriptResourceRefBase* nativeInstance);
-		static MonoString* internal_GetUUID(ScriptResourceRefBase* thisPtr);
-	};
-
 	/**
 	 * @brief	Interop class between C++ & CLR for ResourceRef.
 	 */
 	class BS_SCR_BE_EXPORT ScriptResourceRef : public ScriptObject<ScriptResourceRef>
 	{
 	public:
-		SCRIPT_OBJ(ENGINE_ASSEMBLY, "BansheeEngine", "ResourceRef`1")
+		SCRIPT_OBJ(ENGINE_ASSEMBLY, "BansheeEngine", "ResourceRef")
 
 		/**
 		 * @brief	Creates a new managed ResourceRef for the provided resource.
@@ -65,10 +39,15 @@ namespace BansheeEngine
 		 */
 		static MonoObject* create(const WeakResourceHandle<Texture>& handle, TextureType type = TEX_TYPE_2D);
 
+		/**
+		 * @brief	Returns a weak handle to the resource referenced by this object.
+		 */
+		WeakResourceHandle<Resource> getHandle() const { return mResource; }
+
 	private:
 		friend class ScriptResourceRefBase;
 
-		ScriptResourceRef(MonoObject* instance);
+		ScriptResourceRef(MonoObject* instance, const WeakResourceHandle<Resource>& handle);
 
 		/**
 		 * @brief	Creates a new managed ResourceRef for the provided resource type.
@@ -77,5 +56,14 @@ namespace BansheeEngine
 		 * @param	handle			Handle to the resource to wrap.
 		 */
 		static MonoObject* create(::MonoClass* resourceClass, const WeakResourceHandle<Resource>& handle);
+
+		WeakResourceHandle<Resource> mResource;
+
+		/************************************************************************/
+		/* 								CLR HOOKS						   		*/
+		/************************************************************************/
+		static bool internal_IsLoaded(ScriptResourceRef* nativeInstance);
+		static MonoObject* internal_GetResource(ScriptResourceRef* nativeInstance);
+		static MonoString* internal_GetUUID(ScriptResourceRef* thisPtr);
 	};
 }

+ 29 - 41
SBansheeEngine/Source/BsScriptResourceRef.cpp

@@ -13,55 +13,21 @@
 
 namespace BansheeEngine
 {
-	ScriptResourceRefBase::ScriptResourceRefBase(MonoObject* instance, const WeakResourceHandle<Resource>& resource)
+	ScriptResourceRef::ScriptResourceRef(MonoObject* instance, const WeakResourceHandle<Resource>& resource)
 		:ScriptObject(instance), mResource(resource)
 	{ }
 
-	void ScriptResourceRefBase::initRuntimeData()
-	{
-		metaData.scriptClass->addInternalCall("Internal_IsLoaded", &ScriptResourceRefBase::internal_IsLoaded);
-		metaData.scriptClass->addInternalCall("Internal_GetResource", &ScriptResourceRefBase::internal_GetResource);
-		metaData.scriptClass->addInternalCall("Internal_GetUUID", &ScriptResourceRefBase::internal_GetUUID);
-	}
-
-	bool ScriptResourceRefBase::internal_IsLoaded(ScriptResourceRefBase* nativeInstance)
-	{
-		return nativeInstance->mResource.isLoaded(false);
-	}
-
-	MonoObject* ScriptResourceRefBase::internal_GetResource(ScriptResourceRefBase* nativeInstance)
-	{
-		HResource resource = gResources().load(nativeInstance->mResource);
-		ScriptResourceBase* scriptResource;
-
-		ScriptResourceManager::instance().getScriptResource(resource, &scriptResource, true);
-
-		return scriptResource->getManagedInstance();
-	}
-
-	MonoString* ScriptResourceRefBase::internal_GetUUID(ScriptResourceRefBase* thisPtr)
+	void ScriptResourceRef::initRuntimeData()
 	{
-		const String& uuid = thisPtr->getHandle().getUUID();
-
-		return MonoUtil::stringToMono(uuid);
+		metaData.scriptClass->addInternalCall("Internal_IsLoaded", &ScriptResourceRef::internal_IsLoaded);
+		metaData.scriptClass->addInternalCall("Internal_GetResource", &ScriptResourceRef::internal_GetResource);
+		metaData.scriptClass->addInternalCall("Internal_GetUUID", &ScriptResourceRef::internal_GetUUID);
 	}
 
-	ScriptResourceRef::ScriptResourceRef(MonoObject* instance)
-		:ScriptObject(instance)
-	{ }
-
-	void ScriptResourceRef::initRuntimeData()
-	{ }
-
 	MonoObject* ScriptResourceRef::create(::MonoClass* resourceClass, const WeakResourceHandle<Resource>& handle)
 	{
-		MonoType* genParams[1] = { mono_class_get_type(resourceClass) };
-
-		::MonoClass* resourceRefClass = mono_class_bind_generic_parameters(metaData.scriptClass->_getInternalClass(), 1, genParams, false);
-		MonoObject* obj = mono_object_new(MonoManager::instance().getDomain(), resourceRefClass);
-		mono_runtime_object_init(obj);
-
-		ScriptResourceRefBase* scriptResourceRef = new (bs_alloc<ScriptResourceRefBase>()) ScriptResourceRefBase(obj, handle);
+		MonoObject* obj = metaData.scriptClass->createInstance();
+		ScriptResourceRef* scriptResourceRef = new (bs_alloc<ScriptResourceRef>()) ScriptResourceRef(obj, handle);
 
 		return obj;
 	}
@@ -79,7 +45,29 @@ namespace BansheeEngine
 		}
 
 		return nullptr;
+	}
 
+	bool ScriptResourceRef::internal_IsLoaded(ScriptResourceRef* nativeInstance)
+	{
+		return nativeInstance->mResource.isLoaded(false);
 	}
+
+	MonoObject* ScriptResourceRef::internal_GetResource(ScriptResourceRef* nativeInstance)
+	{
+		HResource resource = gResources().load(nativeInstance->mResource);
+		ScriptResourceBase* scriptResource;
+
+		ScriptResourceManager::instance().getScriptResource(resource, &scriptResource, true);
+
+		return scriptResource->getManagedInstance();
+	}
+
+	MonoString* ScriptResourceRef::internal_GetUUID(ScriptResourceRef* thisPtr)
+	{
+		const String& uuid = thisPtr->getHandle().getUUID();
+
+		return MonoUtil::stringToMono(uuid);
+	}
+
 }
 

+ 1 - 0
TODO.txt

@@ -59,6 +59,7 @@ Optional:
 
 Seriously optional:
  - Drag to select in scene view
+ - Coroutines
  - Automatically generate readable inspector names and add [Name] attribute that allows custom naming
  - Add Range[] attribute to C# that forces a float/int to be displayed as a slider
  - GUI tabbing to switch between elements