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

@@ -81,7 +81,7 @@ namespace VRCBoard.Components
internal bool GetImageAtlasTexture(string imageId, string uploader, out Texture2D texture,
out int position, out int size, out string type) {
return manager._GetImageAtlasTexture(imageId, uploader, out int atlasIndex, out texture, out position, out size,
out type);
out type, out string hash);
}

View File

@@ -12,7 +12,7 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: c333ccfdd0cbdbc4ca30cef2dd6e6b9b, type: 3}
m_Name: VRCBoardImage
m_EditorClassIdentifier:
serializedUdonProgramAsset: {fileID: 11400000, guid: f83f88ce349d298438a783df6b33c10f,
serializedUdonProgramAsset: {fileID: 11400000, guid: 19ae0697d87c22c40b5eceb361997922,
type: 2}
udonAssembly:
assemblyError:
@@ -44,7 +44,7 @@ MonoBehaviour:
Data:
- Name:
Entry: 12
Data: 12
Data: 11
- Name:
Entry: 7
Data:
@@ -563,13 +563,13 @@ MonoBehaviour:
Data:
- Name: $k
Entry: 1
Data: _mainType
Data: _uploaderId
- Name: $v
Entry: 7
Data: 33|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: _mainType
Data: _uploaderId
- Name: <UserType>k__BackingField
Entry: 9
Data: 15
@@ -611,64 +611,16 @@ MonoBehaviour:
Data:
- Name: $k
Entry: 1
Data: _uploaderId
Data: _renderer
- Name: $v
Entry: 7
Data: 35|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: _uploaderId
- Name: <UserType>k__BackingField
Entry: 9
Data: 15
- Name: <SystemType>k__BackingField
Entry: 9
Data: 15
- Name: <SyncMode>k__BackingField
Entry: 7
Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib
- Name:
Entry: 6
Data:
- Name:
Entry: 8
Data:
- Name: <IsSerialized>k__BackingField
Entry: 5
Data: false
- Name: _fieldAttributes
Entry: 7
Data: 36|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
- Name:
Entry: 12
Data: 0
- Name:
Entry: 13
Data:
- Name:
Entry: 8
Data:
- Name:
Entry: 8
Data:
- Name:
Entry: 8
Data:
- Name:
Entry: 7
Data:
- Name: $k
Entry: 1
Data: _renderer
- Name: $v
Entry: 7
Data: 37|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: _renderer
- Name: <UserType>k__BackingField
Entry: 7
Data: 38|System.RuntimeType, mscorlib
Data: 36|System.RuntimeType, mscorlib
- Name:
Entry: 1
Data: UnityEngine.Renderer, UnityEngine.CoreModule
@@ -677,7 +629,7 @@ MonoBehaviour:
Data:
- Name: <SystemType>k__BackingField
Entry: 9
Data: 38
Data: 36
- Name: <SyncMode>k__BackingField
Entry: 7
Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib
@@ -692,7 +644,7 @@ MonoBehaviour:
Data: false
- Name: _fieldAttributes
Entry: 7
Data: 39|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
Data: 37|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
- Name:
Entry: 12
Data: 0

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");

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;
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 43df2736f0176d743827643f443578f3
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -12,7 +12,7 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: c333ccfdd0cbdbc4ca30cef2dd6e6b9b, type: 3}
m_Name: VRCBoardImageBasic
m_EditorClassIdentifier:
serializedUdonProgramAsset: {fileID: 11400000, guid: dfe93a97c46c4cf4c95cfe80dcaa0d3e,
serializedUdonProgramAsset: {fileID: 11400000, guid: 7111a5f4b78f7a94fb3d6ae9aef3b9d4,
type: 2}
udonAssembly:
assemblyError:
@@ -44,7 +44,7 @@ MonoBehaviour:
Data:
- Name:
Entry: 12
Data: 16
Data: 15
- Name:
Entry: 7
Data:
@@ -845,13 +845,13 @@ MonoBehaviour:
Data:
- Name: $k
Entry: 1
Data: _mainType
Data: _uploaderId
- Name: $v
Entry: 7
Data: 43|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: _mainType
Data: _uploaderId
- Name: <UserType>k__BackingField
Entry: 9
Data: 15
@@ -888,54 +888,6 @@ MonoBehaviour:
- Name:
Entry: 8
Data:
- Name:
Entry: 7
Data:
- Name: $k
Entry: 1
Data: _uploaderId
- Name: $v
Entry: 7
Data: 45|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: _uploaderId
- Name: <UserType>k__BackingField
Entry: 9
Data: 15
- Name: <SystemType>k__BackingField
Entry: 9
Data: 15
- Name: <SyncMode>k__BackingField
Entry: 7
Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib
- Name:
Entry: 6
Data:
- Name:
Entry: 8
Data:
- Name: <IsSerialized>k__BackingField
Entry: 5
Data: false
- Name: _fieldAttributes
Entry: 7
Data: 46|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
- Name:
Entry: 12
Data: 0
- Name:
Entry: 13
Data:
- Name:
Entry: 8
Data:
- Name:
Entry: 8
Data:
- Name:
Entry: 8
Data:
- Name:
Entry: 13
Data:

View File

@@ -6,11 +6,8 @@ using VRC.SDK3.Data;
namespace VRCBoard.Components
{
[UdonBehaviourSyncMode(BehaviourSyncMode.None)]
public class VRCBoardImageBasic : VRCBoardBaseComponent
public class VRCBoardImageBasic : VRCBoardImageBaseComponent
{
[Header("Uploader ID (only applies to images of 'shared' or 'instance' type)")]
public string uploaderIdOverride;
[Header("Image IDs")]
public string albedoImageId;
public string emissionImageId;
@@ -24,8 +21,6 @@ namespace VRCBoard.Components
public Texture2D defaultNormal;
public float normalIntensity = 1.0f;
private string _mainType = "";
private string _uploaderId = "";
protected override void OnRegister()
@@ -55,52 +50,10 @@ namespace VRCBoard.Components
GetComponent<Renderer>().SetPropertyBlock(_propertyBlock);
}
private string GetUploader()
{
string uploaderId = "";
if (string.IsNullOrEmpty(uploaderIdOverride))
{
GetImageAtlasTexture(albedoImageId, 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(albedoImageId);
}
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();
_uploaderId = GetUploader(albedoImageId);
if (string.IsNullOrEmpty(_uploaderId))
{
Debug.LogError("Failed to get uploader ID");

View File

@@ -12,7 +12,7 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: c333ccfdd0cbdbc4ca30cef2dd6e6b9b, type: 3}
m_Name: VRCBoardOverheadIcons
m_EditorClassIdentifier:
serializedUdonProgramAsset: {fileID: 11400000, guid: 4d130d8e384312146b0f690571220be5,
serializedUdonProgramAsset: {fileID: 11400000, guid: 9b52c5e5b2955fa468b15a65e066455d,
type: 2}
udonAssembly:
assemblyError:

View File

@@ -12,7 +12,7 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: c333ccfdd0cbdbc4ca30cef2dd6e6b9b, type: 3}
m_Name: VRCBoardSupporterBoardTMP
m_EditorClassIdentifier:
serializedUdonProgramAsset: {fileID: 11400000, guid: e758930ddabc47d499d718189a2787b5,
serializedUdonProgramAsset: {fileID: 11400000, guid: cb7ba44e9b1599548a81a4691eb88bb4,
type: 2}
udonAssembly:
assemblyError: