本文整理汇总了C#中MyInventory.GetInventoryItemsCount方法的典型用法代码示例。如果您正苦于以下问题:C# MyInventory.GetInventoryItemsCount方法的具体用法?C# MyInventory.GetInventoryItemsCount怎么用?C# MyInventory.GetInventoryItemsCount使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MyInventory
的用法示例。
在下文中一共展示了MyInventory.GetInventoryItemsCount方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: InventoryContentChanged
private void InventoryContentChanged(MyInventory sender, MyInventoryItem inventoryItem, float amountChanged)
{
float oreAmount = sender.GetInventoryItemsCount(MyMwcObjectBuilderTypeEnum.Ore, null);
if (oreAmount >= 50)
{
m_objectives.Find(submission => submission.ID == MyMissionID.M01_Intro_Mining).Success();
}
}
示例2: RefillInventory
public void RefillInventory(MyInventory inventory)
{
foreach (MyInventoryTemplateItem templateItem in TemplateItems)
{
// test chance to refill
if (MyMwcUtils.GetRandomFloat(0.0001f, 1f) > templateItem.ChanceToRefill)
{
continue;
}
// get count to refill
int existingCount = inventory.GetInventoryItemsCount(templateItem.ObjectBuilderType, templateItem.ObjectBuilderId);
int countToRefill = MyMwcUtils.GetRandomInt(templateItem.CountToRefillMin, templateItem.CountToRefillMax) - existingCount;
for (int i = 0; i < countToRefill; i++)
{
if (inventory.IsFull)
{
return;
}
// get amount ratio to refill
float amountRatio = MyMwcUtils.GetRandomFloat(templateItem.AmountRatioMin, templateItem.AmountRatioMax);
if(amountRatio > 0f)
{
MyMwcObjectBuilder_Base objectBuilder = MyMwcObjectBuilder_Base.CreateNewObject(templateItem.ObjectBuilderType, templateItem.ObjectBuilderId);
MyInventoryItem inventoryItem = MyInventory.CreateInventoryItemFromObjectBuilder(objectBuilder);
inventoryItem.Amount = (float)(int)(amountRatio * inventoryItem.MaxAmount);
inventory.AddInventoryItem(inventoryItem);
}
}
}
}