mirror of
https://git.aaro.dev/VRCBoard/vrcboard-udon.git
synced 2026-03-17 04:29:46 +00:00
62 lines
2.2 KiB
C#
62 lines
2.2 KiB
C#
|
|
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;
|
|
}
|
|
}
|
|
|
|
}
|