Explorar el Código

Show resource name in GUIResourceField if the resource is not part of the project library
Assign resource name on import

BearishSun hace 10 años
padre
commit
2962eb1e81

+ 3 - 3
BansheeCore/Include/BsResourceMetaDataRTTI.h

@@ -18,18 +18,18 @@ namespace BansheeEngine
 			addPlainField("displayName", 0, &ResourceMetaDataRTTI::getDisplayName, &ResourceMetaDataRTTI::setDisplayName);
 		}
 
-		virtual const String& getRTTIName()
+		virtual const String& getRTTIName() override
 		{
 			static String name = "ResourceMetaData";
 			return name;
 		}
 
-		virtual UINT32 getRTTIId()
+		virtual UINT32 getRTTIId() override
 		{
 			return TID_ResourceMetaData;
 		}
 
-		virtual std::shared_ptr<IReflectable> newRTTIObject()
+		virtual std::shared_ptr<IReflectable> newRTTIObject() override
 		{
 			return bs_shared_ptr_new<ResourceMetaData>();
 		}

+ 3 - 0
BansheeCore/Source/BsPrefabImporter.cpp

@@ -42,6 +42,9 @@ namespace BansheeEngine
 
 		ResourcePtr resource = std::static_pointer_cast<Resource>(loadedData);
 
+		WString fileName = filePath.getWFilename(false);
+		resource->setName(fileName);
+
 		return resource;
 	}
 }

+ 2 - 0
BansheeEditor/Source/BsProjectLibrary.cpp

@@ -613,6 +613,8 @@ namespace BansheeEngine
 			return;
 		}
 
+		resource->setName(path.getWFilename(false));
+
 		Resources::instance().save(resource, assetPath.getAbsolute(getResourcesFolder()), false);
 		checkForModifications(assetPath);
 	}

+ 3 - 0
BansheeEditor/Source/BsResourceImporter.cpp

@@ -44,6 +44,9 @@ namespace BansheeEngine
 
 		ResourcePtr resource = std::static_pointer_cast<Resource>(loadedData);
 
+		WString fileName = filePath.getWFilename(false);
+		resource->setName(fileName);
+
 		return resource;
 	}
 }

+ 4 - 1
BansheeSL/Source/BsSLImporter.cpp

@@ -34,6 +34,9 @@ namespace BansheeEngine
 		DataStreamPtr stream = FileSystem::openFile(filePath);
 		String source = stream->getAsString();
 
-		return BSLFXCompiler::compile(source);
+		ShaderPtr shader = BSLFXCompiler::compile(source);
+		shader->setName(filePath.getWFilename(false));
+
+		return shader;
 	}
 }

+ 9 - 0
MBansheeEngine/Resource.cs

@@ -8,6 +8,15 @@ namespace BansheeEngine
     /// </summary>
     public class Resource : ScriptObject
     {
+        /// <summary>
+        /// Name of the resource. Use primarily for easier identification and not important to the engine itself.
+        /// </summary>
+        public string Name
+        {
+            get { return Internal_GetName(mCachedPtr); }
+        }
 
+        [MethodImpl(MethodImplOptions.InternalCall)]
+        private static extern string Internal_GetName(IntPtr nativeInstance);
     }
 }

+ 6 - 6
SBansheeEditor/Include/BsGUIResourceField.h

@@ -178,12 +178,6 @@ namespace BansheeEngine
 		 */
 		String getUUID() const { return mUUID; }
 
-		/**
-		 * @brief	Sets the resource referenced by the field by finding
-		 *			the resource with the provided UUID.
-		 */
-		void setUUID(const String& uuid);
-
 		/**
 		 * @copydoc	GUIElement::setTint
 		 */
@@ -207,6 +201,12 @@ namespace BansheeEngine
 	private:
 		virtual ~GUIResourceField();
 
+		/**
+		 * @brief	Sets the resource referenced by the field by finding
+		 *			the resource with the provided UUID.
+		 */
+		void setUUID(const String& uuid);
+
 		/**
 		 * @copydoc	GUIElement::styleUpdated
 		 */

+ 16 - 3
SBansheeEditor/Source/BsGUIResourceField.cpp

@@ -187,7 +187,20 @@ namespace BansheeEngine
 	void GUIResourceField::setValue(const HResource& value)
 	{
 		if (value)
-			setUUID(value.getUUID());
+		{
+			Path resPath = gProjectLibrary().uuidToPath(value.getUUID());
+			if (!resPath.isEmpty())
+				setUUID(value.getUUID());
+			else // A non-project library resource
+			{
+				mUUID = value.getUUID();
+
+				WString title = value->getName() + L" (" + toWString(mType) + L")";
+				mDropButton->setContent(GUIContent(HEString(title)));
+
+				onValueChanged(mUUID);
+			}
+		}
 		else
 			setUUID("");
 	}
@@ -200,10 +213,10 @@ namespace BansheeEngine
 		if (!resPath.isEmpty())
 		{
 			WString title = resPath.getWFilename(false) + L" (" + toWString(mType) + L")";
-			mDropButton->setContent(GUIContent(HString(title)));
+			mDropButton->setContent(GUIContent(HEString(title)));
 		}
 		else
-			mDropButton->setContent(GUIContent(HString(L"None (" + toWString(mType) + L")")));
+			mDropButton->setContent(GUIContent(HEString(L"None (" + toWString(mType) + L")")));
 
 		onValueChanged(mUUID);
 	}

+ 5 - 0
SBansheeEngine/Include/BsScriptResource.h

@@ -152,5 +152,10 @@ namespace BansheeEngine
 		ScriptResource(MonoObject* instance)
 			:ScriptObject(instance)
 		{ }
+
+		/************************************************************************/
+		/* 								CLR HOOKS						   		*/
+		/************************************************************************/
+		static MonoString* internal_getName(ScriptResourceBase* nativeInstance);
 	};
 }

+ 8 - 1
SBansheeEngine/Source/BsScriptResource.cpp

@@ -1,5 +1,7 @@
 #include "BsScriptResource.h"
 #include "BsScriptResourceManager.h"
+#include "BsResource.h"
+#include "BsMonoUtil.h"
 
 namespace BansheeEngine
 {
@@ -31,7 +33,7 @@ namespace BansheeEngine
 
 	void ScriptResource::initRuntimeData()
 	{
-		
+		metaData.scriptClass->addInternalCall("Internal_GetName", &ScriptResource::internal_getName);
 	}
 
 	ScriptResourceType ScriptResource::getTypeFromTypeId(UINT32 typeId)
@@ -95,4 +97,9 @@ namespace BansheeEngine
 
 		return 0;
 	}
+
+	MonoString* ScriptResource::internal_getName(ScriptResourceBase* nativeInstance)
+	{
+		return MonoUtil::wstringToMono(MonoManager::instance().getDomain(), nativeInstance->getGenericHandle()->getName());
+	}
 }