[Unity][C#]回调函数的实际应用
发布日期:2021-05-09 11:42:55 浏览次数:55 分类:精选文章

本文共 1750 字,大约阅读时间需要 5 分钟。

������������������������������������������������������������������������������������������������������������������������������������Inventory.cs���ItemPickUp.cs���������������������������������������������������������������������������

1. Inventory.cs

// ������������������
public delegate void callback_pickUpItem(int a);
// ������������������������
public void addItemToInventory(ItemDropData itemDropData,callback_pickUpItem callback_)
{
callback_(0);
}
  • callback_pickUpItem������������������������������������������������������������������int a������������������������������������������������
  • addItemToInventory������������������ItemDropData���������������������������������������������������������������������������������������������������������0���

2. ItemPickUp.cs

// ItemDropData���
private ItemDropData dropData = null;
// ���������������������������
Inventory cb_Inventory = new Inventory();
// ���������������������������������
public void addItemIntoInventory()
{
if (uIInventoryManager != null
&& uIInventoryManager.canPickUpItem(dropData))
{
// ������������������
// ������������������
// ���������������������������
cb_Inventory.addItemToInventory(dropData, destoryItemDrop);
}
}
//������������������������������������
private void destoryItemDrop(int i)
{
Debug.Log(" destoryItemDrop ");
// ������������������������������������
}
  • ���addItemIntoInventory������������������������uIInventoryManager���������������������������������������������������������������������������cb_Inventory.addItemToInventory���������
  • destoryItemDrop���������������������������������������������������������������������������������������������������������������������������������������������
上一篇:[Unity]如何等比例缩放Sprite
下一篇:[Unity][C#]删除父物体所有含有特定组件的子物体

发表评论

最新留言

能坚持,总会有不一样的收获!
[***.219.124.196]2025年04月11日 08时43分47秒