mirror of
https://git.aaro.dev/VRCBoard/vrcboard-udon.git
synced 2026-03-17 01:09:45 +00:00
Enhance VRCBoardImage component with renderer initialization and property block handling
This commit is contained in:
@@ -44,7 +44,7 @@ MonoBehaviour:
|
||||
Data:
|
||||
- Name:
|
||||
Entry: 12
|
||||
Data: 11
|
||||
Data: 12
|
||||
- Name:
|
||||
Entry: 7
|
||||
Data:
|
||||
@@ -658,6 +658,60 @@ MonoBehaviour:
|
||||
- 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
|
||||
- Name:
|
||||
Entry: 1
|
||||
Data: UnityEngine.Renderer, UnityEngine.CoreModule
|
||||
- Name:
|
||||
Entry: 8
|
||||
Data:
|
||||
- Name: <SystemType>k__BackingField
|
||||
Entry: 9
|
||||
Data: 38
|
||||
- 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: 39|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:
|
||||
|
||||
@@ -5,6 +5,7 @@ using UnityEngine.Serialization;
|
||||
using VRC.SDK3.Data;
|
||||
|
||||
using UnityEditor;
|
||||
using VRC.SDKBase;
|
||||
|
||||
namespace VRCBoard.Components
|
||||
{
|
||||
@@ -25,9 +26,17 @@ namespace VRCBoard.Components
|
||||
private string _mainType = "";
|
||||
private string _uploaderId = "";
|
||||
|
||||
private Renderer _renderer;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
_renderer = GetComponent<Renderer>();
|
||||
}
|
||||
|
||||
protected override void OnRegister()
|
||||
{
|
||||
Debug.Log("Registering image component");
|
||||
OnImageLoaded();
|
||||
}
|
||||
|
||||
|
||||
@@ -87,6 +96,8 @@ namespace VRCBoard.Components
|
||||
string imageId = imageIds[i];
|
||||
RequestImageLoad(imageId, _uploaderId);
|
||||
}
|
||||
|
||||
OnImageLoaded();
|
||||
}
|
||||
protected override void OnInitialize()
|
||||
{
|
||||
@@ -104,7 +115,7 @@ namespace VRCBoard.Components
|
||||
|
||||
protected override void OnImageLoaded()
|
||||
{
|
||||
Debug.Log("Image loaded VRCBoardImage");
|
||||
//Debug.Log("Image loaded VRCBoardImage");
|
||||
|
||||
|
||||
//bool textureSuccess = GetImageAtlasTexture(albedoImageId, _uploaderId, out Texture2D texture, out int atlasPosition, out int atlasSize, out string type1);
|
||||
@@ -114,6 +125,7 @@ namespace VRCBoard.Components
|
||||
for (int i = 0; i < imageIds.Length; i++)
|
||||
{
|
||||
if (i >= texturePropertyMappings.Length) continue;
|
||||
if (i >= defaultTextures.Length) continue;
|
||||
|
||||
string propertyName = texturePropertyMappings[i];
|
||||
Texture2D texture = manager.GetTexture2D(_uploaderId, imageIds[i]);
|
||||
@@ -121,16 +133,14 @@ namespace VRCBoard.Components
|
||||
if (texture == null)
|
||||
{
|
||||
texture = defaultTextures[i];
|
||||
if (texture == null) continue;
|
||||
}
|
||||
if (string.IsNullOrEmpty(propertyName)) continue;
|
||||
|
||||
propertyBlock.SetTexture(propertyName, texture);
|
||||
if (texture != null) propertyBlock.SetTexture(propertyName, texture);
|
||||
if (materialOverride != null) materialOverride.SetTexture(propertyName, texture);
|
||||
}
|
||||
|
||||
|
||||
GetComponent<Renderer>().SetPropertyBlock(propertyBlock);
|
||||
if (materialOverride== null && _renderer) _renderer.SetPropertyBlock(propertyBlock);
|
||||
}
|
||||
}
|
||||
#if UNITY_EDITOR && !COMPILER_UDONSHARP
|
||||
@@ -139,19 +149,23 @@ namespace VRCBoard.Components
|
||||
{
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
base.OnInspectorGUI();
|
||||
|
||||
VRCBoardImage script = (VRCBoardImage)target;
|
||||
|
||||
Renderer renderer = script.GetComponent<Renderer>();
|
||||
Material material = renderer.sharedMaterial;
|
||||
if (script.materialOverride)
|
||||
{
|
||||
EditorGUILayout.HelpBox("Material override enabled", MessageType.Info);
|
||||
EditorGUILayout.HelpBox("Material override enabled, material may behave in odd ways", MessageType.Warning);
|
||||
material = script.materialOverride;
|
||||
} else if (renderer == null)
|
||||
{
|
||||
EditorGUILayout.HelpBox("No renderer, did you intend to use material override?", MessageType.Warning);
|
||||
return;
|
||||
}
|
||||
string[] materialPropertyNames = material.GetPropertyNames(MaterialPropertyType.Texture);
|
||||
|
||||
base.OnInspectorGUI();
|
||||
|
||||
|
||||
bool equals =
|
||||
Equals(script.imageIds.Length, script.defaultTextures.Length) &&
|
||||
Equals(script.imageIds.Length, script.defaultTextures.Length);
|
||||
@@ -229,8 +243,7 @@ namespace VRCBoard.Components
|
||||
}
|
||||
GUILayout.EndVertical();
|
||||
}
|
||||
|
||||
renderer.SetPropertyBlock(propertyBlock);
|
||||
if (script.materialOverride== null && renderer) renderer.SetPropertyBlock(propertyBlock);
|
||||
EditorGUILayout.EndHorizontal();
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user