Browse Source

Bugfix: Various fixes regarding material inspector and sprite textures
- Sprite texture drag and drop to GUITextureField now works
- GUITextureField will resolve the preview image properly if a preview icon doesn't exist
- Material inspector will avoid fully loading a texture resource, just to check its type
- Assigned sprite texture will no longer be immediately overriden by a null normal texture

BearishSun 6 years ago
parent
commit
0428040e0d

+ 18 - 7
Source/EditorManaged/Inspectors/MaterialInspector.cs

@@ -677,12 +677,23 @@ namespace bs.Editor
                 case ShaderParameterType.TextureCube:
                 case ShaderParameterType.TextureCube:
                     guiElem.OnChanged += (x) =>
                     guiElem.OnChanged += (x) =>
                     {
                     {
-                        Resource resource = x.Value;
-
-                        if(resource is Texture tex)
-                            material.SetTexture(shaderParam.name, tex);
-                        else if(resource is SpriteTexture spriteTex)
-                            material.SetSpriteTexture(shaderParam.name, spriteTex);
+                        string path = ProjectLibrary.GetPath(x.UUID);
+                        if (!string.IsNullOrEmpty(path))
+                        {
+                            if (ProjectLibrary.GetEntry(path) is FileEntry fileEntry)
+                            {
+                                if (fileEntry.ResourceMetas.Length > 0)
+                                {
+                                    ResourceMeta meta = fileEntry.ResourceMetas[0];
+                                    if (meta.ResType == ResourceType.SpriteTexture)
+                                        material.SetSpriteTexture(shaderParam.name, x.As<SpriteTexture>());
+                                    else if(meta.ResType == ResourceType.Texture)
+                                        material.SetTexture(shaderParam.name, x.As<Texture>());
+                                }
+                            }
+                        }
+                        else
+                            material.SetTexture(shaderParam.name, null);
 
 
                         EditorApplication.SetDirty(material);
                         EditorApplication.SetDirty(material);
                     };
                     };
@@ -701,7 +712,7 @@ namespace bs.Editor
                 case ShaderParameterType.Texture2D:
                 case ShaderParameterType.Texture2D:
                     RRef<SpriteTexture> spriteTex = material.GetSpriteTexture(shaderParam.name);
                     RRef<SpriteTexture> spriteTex = material.GetSpriteTexture(shaderParam.name);
 
 
-                    if (spriteTex != null && spriteTex.IsLoaded)
+                    if (spriteTex != null && spriteTex.UUID != UUID.Empty)
                         guiElem.SpriteTextureRef = spriteTex;
                         guiElem.SpriteTextureRef = spriteTex;
                     else
                     else
                     {
                     {

+ 3 - 3
Source/EditorScript/BsGUITextureField.cpp

@@ -158,12 +158,12 @@ namespace bs
 		if (!filePath.isEmpty())
 		if (!filePath.isEmpty())
 		{
 		{
 			SPtr<ProjectResourceMeta> meta = gProjectLibrary().findResourceMeta(filePath);
 			SPtr<ProjectResourceMeta> meta = gProjectLibrary().findResourceMeta(filePath);
-			if(meta)
+			if(meta && meta->getPreviewIcons().icon128.isLoaded())
 				previewIcon = SpriteTexture::create(meta->getPreviewIcons().icon128);
 				previewIcon = SpriteTexture::create(meta->getPreviewIcons().icon128);
 			else
 			else
 			{
 			{
 				// Not ideal. No cached texture so fall back on loading the original asset
 				// Not ideal. No cached texture so fall back on loading the original asset
-				HResource resource = gResources().load(filePath);
+				HResource resource = gProjectLibrary().load(filePath);
 				if(resource.isLoaded(false))
 				if(resource.isLoaded(false))
 				{
 				{
 					if (rtti_is_of_type<SpriteTexture>(resource.get()))
 					if (rtti_is_of_type<SpriteTexture>(resource.get()))
@@ -233,7 +233,7 @@ namespace bs
 			Path path = draggedResources->resourcePaths[i];
 			Path path = draggedResources->resourcePaths[i];
 
 
 			SPtr<ProjectResourceMeta> meta = gProjectLibrary().findResourceMeta(draggedResources->resourcePaths[i]);
 			SPtr<ProjectResourceMeta> meta = gProjectLibrary().findResourceMeta(draggedResources->resourcePaths[i]);
-			if (meta == nullptr || meta->getTypeID() != TID_Texture)
+			if (meta == nullptr || (meta->getTypeID() != TID_Texture && meta->getTypeID() != TID_SpriteTexture))
 				continue;
 				continue;
 
 
 			setUUID(meta->getUUID());
 			setUUID(meta->getUUID());

+ 1 - 1
Source/bsf

@@ -1 +1 @@
-Subproject commit 336ad446ab9b7ee7a56c3bd0602f9780b7701ce5
+Subproject commit 7b7150c41863f773073177efaffb7f0356c3cd1b