in MREUnityRuntimeLib/Core/Actor.cs [1124:1203]
private void PatchAppearance(AppearancePatch appearance)
{
if (appearance == null)
{
return;
}
bool forceUpdateRenderer = false;
// update renderers
if (appearance.MaterialId != null || appearance.MeshId != null)
{
// patch mesh
if (appearance.MeshId != null)
{
MeshId = appearance.MeshId.Value;
}
// apply mesh/material to game object
if (MeshId != Guid.Empty)
{
// guarantee renderer component
if (renderer == null)
{
renderer = gameObject.AddComponent<MeshRenderer>();
renderer.sharedMaterial = MREAPI.AppsAPI.DefaultMaterial;
forceUpdateRenderer = true;
}
// guarantee mesh filter (unless it has a skinned mesh renderer)
if (renderer is MeshRenderer && meshFilter == null)
{
meshFilter = gameObject.AddComponent<MeshFilter>();
}
// look up and assign mesh
var updatedMeshId = MeshId;
App.AssetManager.OnSet(MeshId, sharedMesh =>
{
if (!this || MeshId != updatedMeshId) return;
UnityMesh = (Mesh)sharedMesh.Asset;
if (Collider != null && Collider.Shape == ColliderType.Auto)
{
SetCollider(new ColliderPatch()
{
Geometry = new AutoColliderGeometry()
});
}
});
// patch material
if (appearance.MaterialId != null)
{
MaterialId = appearance.MaterialId.Value;
}
}
// clean up unused components
else
{
Destroy(Renderer);
Destroy(MeshFilter);
if (Collider != null && Collider.Shape == ColliderType.Auto)
{
Destroy(_collider);
Destroy(Collider);
_collider = null;
Collider = null;
}
}
}
// apply visibility after renderer updated
if (appearance.Enabled != null || forceUpdateRenderer)
{
if (appearance.Enabled != null)
{
appearanceEnabled = appearance.Enabled.Value;
}
ApplyVisibilityUpdate(this);
}
}