Files
Studio/Assets/Scripts/ExternalAssets/TriLib/TriLibSamples/UserPropertiesLoading/Utils/SampleUserPropertiesMapper.cs
2025-06-11 16:50:56 +09:00

54 lines
2.2 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using System;
using TriLibCore.Interfaces;
using TriLibCore.Mappers;
using UnityEngine;
namespace TriLibCore.Samples
{
/// <summary>
/// A custom <see cref="UserPropertiesMapper"/> that forwards user properties
/// (attached to model GameObjects) to a user-specified callback.
/// </summary>
public class SampleUserPropertiesMapper : UserPropertiesMapper
{
/// <summary>
/// A callback invoked for each user property discovered during model loading.
/// </summary>
/// <remarks>
/// This <see cref="Action{GameObject, String, Object}"/> receives the following parameters:
/// <list type="bullet">
/// <item>
/// <description><c>GameObject</c>: The GameObject to which the user property is attached.</description>
/// </item>
/// <item>
/// <description><c>string</c>: The propertys name.</description>
/// </item>
/// <item>
/// <description><c>object</c>: The propertys value (may be various types, such as <see cref="float"/>, <see cref="int"/>, <see cref="string"/>, etc.).</description>
/// </item>
/// </list>
/// </remarks>
public Action<GameObject, string, object> OnUserDataProcessed;
/// <summary>
/// Overrides the default TriLib user property processing to invoke
/// the <see cref="OnUserDataProcessed"/> callback (if not null).
/// </summary>
/// <param name="assetLoaderContext">Contains context about the current model loading process.</param>
/// <param name="gameObject">The <see cref="GameObject"/> that owns the current user property.</param>
/// <param name="propertyName">The name of the user property.</param>
/// <param name="propertyValue">The value of the user property, potentially in various types.</param>
public override void OnProcessUserData(
AssetLoaderContext assetLoaderContext,
GameObject gameObject,
string propertyName,
object propertyValue)
{
if (OnUserDataProcessed != null)
{
OnUserDataProcessed(gameObject, propertyName, propertyValue);
}
}
}
}