Image Component Updates

This commit is contained in:
2024-12-22 12:25:55 +02:00
parent a035902d8e
commit 7f3e851854
14 changed files with 369 additions and 230 deletions

View File

@@ -11,18 +11,14 @@ namespace VRCBoard.Components
{
[UdonBehaviourSyncMode(BehaviourSyncMode.None)]
public class VRCBoardImage : VRCBoardBaseComponent
public class VRCBoardImage : VRCBoardImageBaseComponent
{
[Header("Uploader ID (only applies to images of 'shared' or 'instance' type)")]
public string uploaderIdOverride;
[HideInInspector] public int materialIndex;
[HideInInspector] public string[] imageIds = new string[0];
[HideInInspector] public string[] texturePropertyMappings = new string[0];
[HideInInspector] public Texture2D[] defaultTextures = new Texture2D[0];
private string _mainType = "";
private string _uploaderId = "";
private Renderer _renderer;
@@ -40,52 +36,15 @@ namespace VRCBoard.Components
}
private string GetUploader()
{
string uploaderId = "";
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);
if (albedoType == null)
{
Debug.LogError("Failed to get image type for albedo image");
return "";
}
_mainType = albedoType;
if (_mainType == "shared")
{
uploaderId = GetRandomUploader(firstImageID);
}
else
{
DataDictionary ownerInfo = manager.GetSupporterDataFromPlayer(manager.InstanceOwner);
if (ownerInfo == null)
{
Debug.LogWarning("Failed to get owner info, user has likely not linked their account.");
return "";
}
bool ownerSuccess = ownerInfo.TryGetValue("id", out DataToken ownerToken);
if (!ownerSuccess || ownerToken.TokenType != TokenType.String)
{
Debug.LogWarning("Failed to get owner ID from owner info.");
return "";
}
uploaderId = ownerToken.String;
}
Debug.Log("image uploader: " + uploaderId);
} else
{
uploaderId = uploaderIdOverride;
}
return uploaderId;
}
private void TryGetUploader()
{
if (!string.IsNullOrEmpty(_uploaderId)) return;
_uploaderId = GetUploader();
if (imageIds.Length == 0) return;
_uploaderId = GetUploader(imageIds[0]);
if (string.IsNullOrEmpty(_uploaderId))
{
Debug.LogError("Failed to get uploader ID");