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

@@ -0,0 +1,61 @@

using UdonSharp;
using UnityEngine;
using VRC.SDKBase;
using VRC.Udon;
using UnityEngine.Serialization;
using VRC.SDK3.Data;
namespace VRCBoard.Components
{
public abstract class VRCBoardImageBaseComponent : VRCBoardBaseComponent
{
[Header("Uploader ID (only applies to images of 'shared' or 'instance' type)")]
public string uploaderIdOverride;
internal string GetUploader(string imageId)
{
string uploaderId = "";
if (string.IsNullOrEmpty(uploaderIdOverride))
{
GetImageAtlasTexture(imageId, 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 "";
}
string _mainType = albedoType;
if (_mainType == "shared")
{
uploaderId = GetRandomUploader(imageId);
}
else if (_mainType == "global")
{
uploaderId = null;
}
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;
}
}
}