180 - API文档汉化 - 图腾

Updated a week ago

图腾

自定义图腾顶部组件

创建自定义族群时,通常需要使其能与图腾系统兼容。虽然API提供了默认的自定义图腾顶部模型,但若需使用自制模型,本API同样支持。

如需为顶部添加自定义模型,可参考以下示例:

TotemManager.NewTopPiece<CustomIconTotemTopPiece>("图腾名称", Plugin.PluginGuid, 族群类型, prefab);

若使用自制模型,可通过资产包按如下方式加载:

if (AssetBundleHelper.TryGet("资产包路径", "资产包内预制体名称", out GameObject prefab))
{
    TotemManager.NewTopPiece<CustomIconTotemTopPiece>("图腾名称", Plugin.PluginGuid, 族群类型, prefab);
}

“我的图腾顶部没有可显示的图标!”

此时需创建新类来避免从族群中检索图标:

public class MyCustomTotemTopPiece : CompositeTotemPiece
{
    protected virtual string EmissionGameObjectName => "发光体游戏对象名称";
    
    public override void SetData(ItemData data)
    {
        base.SetData(data);

        // 设置emissiveRenderer以便游戏识别鼠标悬停时的高亮对象
        emissiveRenderer = this.gameObject.FindChild(EmissionGameObjectName);
        if (emissiveRenderer != null)
        {
            emissiveRenderer = icon.GetComponent<Renderer>();
        }
        
        if (emissiveRenderer == null)
        {
            InscryptionAPIPlugin.Logger.LogError($"图腾顶部未分配emissiveRenderer!");
        }
    }
}

随后使用新类添加图腾:

if (AssetBundleHelper.TryGet("资产包路径", "资产包内预制体名称", out GameObject prefab))
{
    TotemManager.NewTopPiece<MyCustomTotemTopPiece>("图腾名称", Plugin.PluginGuid, 族群类型, prefab);
}