190 - API文档汉化 - 道具

Updated a week ago

道具

自定义道具

本API支持添加自定义的消耗品道具。 要创建一个道具,您需要新建一个继承自ConsumableItem的类。

指定您的道具类及其使用时的效果。

public class CustomConsumableItem : ConsumableItem
{
    public override IEnumerator ActivateSequence()
    {
        base.PlayExitAnimation();
        yield return new WaitForSeconds(0.25f);
        yield return base.StartCoroutine(Singleton<ResourcesManager>.Instance.AddBones(4, null));
        yield break;
    }

    public override bool ExtraActivationPrerequisitesMet()
    {
        if (!base.ExtraActivationPrerequisitesMet())
        {
            return false;
        }

        // 可选:阻止玩家使用该道具!
        return true;
    }
}

添加新道具

若您没有自定义模型,可使用API提供的ConsumableItemManager.ModelType中的默认类型之一。

ConsumableItemManager.ModelType modelType = ConsumableItemManager.ModelType.Basic;
ConsumableItemManager.New(Plugin.PluginGuid, "Custom Item", "Does a thing!", textureOrSprite, typeof(CustomConsumableItem), modelType)
		        .SetDescription(learnText)
		        .SetAct1();

若要创建简单的“瓶中卡牌”类道具,可使用如下预设方法:

ConsumableItemManager.NewCardInABottle(PluginGuid, cardInfo.name)
			        .SetAct1();

若您拥有道具的自定义模型,可在不同构造函数中指定:

GameObject prefab = ...
ConsumableItemManager.New(Plugin.PluginGuid, "Custom Item", "Does a thing!", textureOrSprite, typeof(CustomConsumableItem), prefab)
		        .SetDescription(learnText)
		        .SetAct1();

若希望道具在多个章节的规则书中出现,可对返回的ConsumableItemData使用扩展方法AddExtraRulebookCategories