mirror of
https://git.aaro.dev/VRCBoard/vrcboard-udon.git
synced 2026-03-17 04:49:45 +00:00
Update VRCBoardImage component to include material override functionality and adjust related properties
This commit is contained in:
@@ -15,7 +15,9 @@ namespace VRCBoard.Components
|
||||
[Header("Uploader ID (only applies to images of 'shared' or 'instance' type)")]
|
||||
public string uploaderIdOverride;
|
||||
|
||||
[Header("Uploader Image Mappings")]
|
||||
[Header("Material Override (Optional, if set the properties are applied globally to all renderers using the material)")]
|
||||
public Material materialOverride;
|
||||
|
||||
[HideInInspector] public string[] imageIds = new string[0];
|
||||
[HideInInspector] public string[] texturePropertyMappings = new string[0];
|
||||
[HideInInspector] public Texture2D[] defaultTextures = new Texture2D[0];
|
||||
@@ -32,7 +34,7 @@ namespace VRCBoard.Components
|
||||
private string GetUploader()
|
||||
{
|
||||
string uploaderId = "";
|
||||
if (string.IsNullOrEmpty(uploaderIdOverride))
|
||||
if (string.IsNullOrEmpty(uploaderIdOverride) && imageIds.Length > 0)
|
||||
{
|
||||
string firstImageID = imageIds[0];
|
||||
GetImageAtlasTexture(firstImageID, null, out Texture2D albedoTexture, out int albedoAtlasPosition, out int albedoAtlasSize, out string albedoType);
|
||||
@@ -115,11 +117,16 @@ namespace VRCBoard.Components
|
||||
|
||||
string propertyName = texturePropertyMappings[i];
|
||||
Texture2D texture = manager.GetTexture2D(_uploaderId, imageIds[i]);
|
||||
|
||||
if (texture == null) continue;
|
||||
|
||||
if (texture == null)
|
||||
{
|
||||
texture = defaultTextures[i];
|
||||
if (texture == null) continue;
|
||||
}
|
||||
if (string.IsNullOrEmpty(propertyName)) continue;
|
||||
|
||||
propertyBlock.SetTexture(propertyName, texture);
|
||||
if (materialOverride != null) materialOverride.SetTexture(propertyName, texture);
|
||||
}
|
||||
|
||||
|
||||
@@ -136,6 +143,11 @@ namespace VRCBoard.Components
|
||||
|
||||
Renderer renderer = script.GetComponent<Renderer>();
|
||||
Material material = renderer.sharedMaterial;
|
||||
if (script.materialOverride)
|
||||
{
|
||||
EditorGUILayout.HelpBox("Material override enabled", MessageType.Info);
|
||||
material = script.materialOverride;
|
||||
}
|
||||
string[] materialPropertyNames = material.GetPropertyNames(MaterialPropertyType.Texture);
|
||||
|
||||
base.OnInspectorGUI();
|
||||
@@ -195,6 +207,7 @@ namespace VRCBoard.Components
|
||||
defaultImage = EditorGUILayout.ObjectField(defaultImage, typeof(Texture2D), false) as Texture2D;
|
||||
EditorGUILayout.EndHorizontal();
|
||||
if (defaultImage != null) propertyBlock.SetTexture(propertyName, defaultImage);
|
||||
if (script.materialOverride != null) script.materialOverride.SetTexture(propertyName, defaultImage);
|
||||
}
|
||||
|
||||
if (script.defaultTextures[i] != defaultImage)
|
||||
|
||||
Reference in New Issue
Block a user