瀏覽代碼

Bugfix: Assigning a texture to a Material through the inspector will now properly trigger load for the texture

BearishSun 6 年之前
父節點
當前提交
bfc0b2bcaa

+ 13 - 3
Source/EditorManaged/Inspectors/MaterialInspector.cs

@@ -458,6 +458,10 @@ namespace bs.Editor
         /// <param name="component">Optional component the material is part of (if any).</param>
         /// <param name="component">Optional component the material is part of (if any).</param>
         /// <param name="material">Material the parameter is a part of.</param>
         /// <param name="material">Material the parameter is a part of.</param>
         /// <param name="layout">Layout to append the GUI elements to.</param>
         /// <param name="layout">Layout to append the GUI elements to.</param>
+        /// <param name="loadResources">
+        /// If true, any assigned texture resources will be loaded in memory. If false the resources will be just referenced
+        /// without loading.
+        /// </param>
         internal MaterialParamVec3GUI(ShaderParameter shaderParam, string path, Component component, Material material, 
         internal MaterialParamVec3GUI(ShaderParameter shaderParam, string path, Component component, Material material, 
             GUILayout layout)
             GUILayout layout)
             : base(shaderParam, path, component)
             : base(shaderParam, path, component)
@@ -935,11 +939,17 @@ namespace bs.Editor
                                 {
                                 {
                                     StartUndo();
                                     StartUndo();
 
 
+                                    // Note: Ideally we can avoid loading texture resources if the material is not
+                                    // referenced anywhere in the scene. But we don't have a good way to check that at
+                                    // the moment.
+                                    //    Resources.LoadAsync<Resource>(x.UUID);
+
                                     ResourceMeta meta = fileEntry.ResourceMetas[0];
                                     ResourceMeta meta = fileEntry.ResourceMetas[0];
                                     if (meta.ResType == ResourceType.SpriteTexture)
                                     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>());
+                                        material.SetSpriteTexture(shaderParam.name,
+                                            bs.Resources.LoadAsync<SpriteTexture>(x.UUID));//(SpriteTexture)x.Value);//x.As<SpriteTexture>());
+                                    else if (meta.ResType == ResourceType.Texture)
+                                        material.SetTexture(shaderParam.name, bs.Resources.LoadAsync<Texture>(x.UUID));//(Texture)x.Value); //x.As<Texture>());
 
 
                                     EndUndo();
                                     EndUndo();
                                 }
                                 }

+ 1 - 1
Source/EditorManaged/Inspectors/RenderableInspector.cs

@@ -170,7 +170,7 @@ namespace bs.Editor
                         continue;
                         continue;
                     }
                     }
 
 
-                    MaterialParamGUI[] matParams = MaterialInspector.CreateMaterialGUI(material, 
+                    MaterialParamGUI[] matParams = MaterialInspector.CreateMaterialGUI(material,
                         "materialParams[" + i + "]", null, materialLayout);
                         "materialParams[" + i + "]", null, materialLayout);
                     materialParams.Add(matParams);
                     materialParams.Add(matParams);
                 }
                 }

+ 1 - 1
Source/bsf

@@ -1 +1 @@
-Subproject commit 61136ef57b8d2ee505b6ba0f48eaa7fea73c0742
+Subproject commit dc6d8bf9aabd0bcc1ad82535d20bcf1632bca80e