[Opsive - ultimate inventory system] Item Objects(项目对象)

英文原文:https://opsive.com/support/documentation/ultimate-inventory-system/item-objects/

项目对象组件将特定项目链接到游戏对象。 游戏世界中可见的任何项目都应该有一个项目对象组件。 例如,物品拾取和装备物品都是物品在游戏世界中成形的方式。

ItemObject 组件非常灵活,因为它允许您将项目绑定/取消绑定到它。 因此,您可以轻松地将一些游戏对象与 ItemObject 合并在一起,并重用它们来生成场景中的任何项目。

在这里插入图片描述

当Item附加到项目对象或从项目对象分离时,会触发事件。 某些组件侦听该事件以更改 ItemObject 在游戏世界中的外观。

Item Object API

注册事件

// Register to the event of the Item changing on the Item Object
EventHandler.RegisterEvent(m_ItemObject, EventNames.c_ItemObject_OnItemChanged, HandleItemChanged);

private void HandleItemChanged(){
	//The item changed
	var itemInfo = m_ItemObject.ItemInfo;
}

将项目附加到项目对象

// Set the item to the Item Object
var newItem = InventorySystemManager.CreateItem("MyItemName");

// By default it will add 1 unit of the item.
m_ItemObject.SetItem(newItem);

// You may change the amount at any time.
m_ItemObject.SetAmount(5);

// Alternatively you may set an Item Info.
var itemInfo = (ItemInfo)(5, newItem);
m_ItemObject.SetItem(itemInfo);

从 Item 中获取 Item 对象

//如果您的项目是唯一的,您可以从项目中获取项目对象
var itemObject = newItem.GetLastItemObject();

// 您可以轻松检查项目是否绑定到项目对象。
if(newItem.IsBoundToItemObject(itemObject)){
	//该 Item 绑定到该项目对象。
}

// 如果它不是唯一的,则该项目可能有多个项目对象:
// 循环遍历所有 item 对象
var count = newItem.GetItemObjectCount();
for(int i =0; i < count; i++){
	var itemObjectAtIndex = newItem.GetItemObjectAt(i);
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值