using UdonSharp; using UnityEngine; using UnityEngine.Serialization; using VRC.SDK3.Data; namespace VRCBoard.Components { [UdonBehaviourSyncMode(BehaviourSyncMode.None)] public class VRCBoardImageBasic : VRCBoardImageBaseComponent { [Header("Image IDs")] public string albedoImageId; public string emissionImageId; public string normalImageId; [Header("Defaults")] public Texture2D defaultAlbedo; [ColorUsageAttribute(true,true)] public Color albedoColor = Color.white; public Texture2D defaultEmission; [ColorUsageAttribute(true,true)] public Color emissionColor = Color.white; public Texture2D defaultNormal; public float normalIntensity = 1.0f; private string _uploaderId = ""; protected override void OnRegister() { MaterialPropertyBlock _propertyBlock = new MaterialPropertyBlock(); Debug.Log("Registering image component"); if (defaultAlbedo) _propertyBlock.SetTexture("_MainTexAtlas", defaultAlbedo); if (defaultEmission) _propertyBlock.SetTexture("_EmissionMapAtlas", defaultEmission); if (defaultNormal) _propertyBlock.SetTexture("_NormalMapAtlas", defaultNormal); _propertyBlock.SetInteger("_MainTexAtlasIndex", 0); _propertyBlock.SetInteger("_MainTexAtlasSize", 1); _propertyBlock.SetInteger("_EmissionMapAtlasIndex", 0); _propertyBlock.SetInteger("_EmissionMapAtlasSize", 1); _propertyBlock.SetInteger("_NormalMapAtlasIndex", 0); _propertyBlock.SetInteger("_NormalMapAtlasSize", 1); _propertyBlock.SetColor("_EmissionColor", emissionColor); _propertyBlock.SetFloat("_NormalMapScale", normalIntensity); _propertyBlock.SetColor("_MainTexColor", albedoColor); GetComponent().SetPropertyBlock(_propertyBlock); } private void TryGetUploader() { if (!string.IsNullOrEmpty(_uploaderId)) return; _uploaderId = GetUploader(albedoImageId); if (string.IsNullOrEmpty(_uploaderId)) { Debug.LogError("Failed to get uploader ID"); return; } RequestImageLoad(albedoImageId, _uploaderId); RequestImageLoad(emissionImageId, _uploaderId); RequestImageLoad(normalImageId, _uploaderId); } protected override void OnInitialize() { TryGetUploader(); } protected override void OnImageDataUpdate() { TryGetUploader(); } protected override void OnSupporterDataUpdate() { TryGetUploader(); } protected override void OnImageLoaded() { Debug.Log("Image loaded VRCBoardImage"); Texture2D albedoTexture; int albedoAtlasPosition; int albedoAtlasSize; Texture2D emissionTexture; int emissionAtlasPosition; int emissionAtlasSize; Texture2D normalTexture; int normalAtlasPosition; int normalAtlasSize; bool albedoSuccess = GetImageAtlasTexture(albedoImageId, _uploaderId, out albedoTexture, out albedoAtlasPosition, out albedoAtlasSize, out string type1); bool emissionSuccess = GetImageAtlasTexture(emissionImageId, _uploaderId, out emissionTexture, out emissionAtlasPosition, out emissionAtlasSize, out string type2); bool normalSuccess = GetImageAtlasTexture(normalImageId, _uploaderId, out normalTexture, out normalAtlasPosition, out normalAtlasSize, out string type3); MaterialPropertyBlock _propertyBlock = new MaterialPropertyBlock(); if (albedoSuccess && albedoTexture) { _propertyBlock.SetTexture("_MainTexAtlas", albedoTexture); _propertyBlock.SetInteger("_MainTexAtlasIndex", albedoAtlasPosition); _propertyBlock.SetInteger("_MainTexAtlasSize", albedoAtlasSize); } else { return; } if (emissionSuccess && emissionTexture) { _propertyBlock.SetTexture("_EmissionMapAtlas", emissionTexture); _propertyBlock.SetInteger("_EmissionMapAtlasIndex", emissionAtlasPosition); _propertyBlock.SetInteger("_EmissionMapAtlasSize", emissionAtlasSize); } if (normalSuccess && normalTexture) { _propertyBlock.SetTexture("_NormalMapAtlas", normalTexture); _propertyBlock.SetInteger("_NormalMapAtlasIndex", normalAtlasPosition); _propertyBlock.SetInteger("_NormalMapAtlasSize", normalAtlasSize); } _propertyBlock.SetColor("_EmissionColor", emissionColor); _propertyBlock.SetFloat("_NormalMapScale", normalIntensity); _propertyBlock.SetColor("_MainTexColor", albedoColor); GetComponent().SetPropertyBlock(_propertyBlock); } } }