本文整理汇总了C#中VRage.Game.Entity.MyInventoryBase.GetItemAmount方法的典型用法代码示例。如果您正苦于以下问题:C# MyInventoryBase.GetItemAmount方法的具体用法?C# MyInventoryBase.GetItemAmount怎么用?C# MyInventoryBase.GetItemAmount使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类VRage.Game.Entity.MyInventoryBase
的用法示例。
在下文中一共展示了MyInventoryBase.GetItemAmount方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetItemAmountCombined
public MyFixedPoint GetItemAmountCombined(MyInventoryBase inventory, MyDefinitionId contentId)
{
int amount = 0;
var group = MyDefinitionManager.Static.GetGroupForComponent(contentId, out amount);
if (group == null)
{
MyComponentSubstitutionDefinition substitutions;
if (MyDefinitionManager.Static.TryGetComponentSubstitutionDefinition(contentId, out substitutions))
{
foreach (var providingComponent in substitutions.ProvidingComponents)
{
amount += (int)inventory.GetItemAmount(providingComponent.Key) / providingComponent.Value;
}
return amount;
}
return inventory.GetItemAmount(contentId);
}
else
{
Clear();
inventory.CountItems(m_componentCounts);
AddItem(group.Id, amount, int.MaxValue);
Solve(m_componentCounts);
return GetSolvedItemCount();
}
}
示例2: BeforeContentsChanged
/*
private void BeforeContentsChanged(MyInventoryBase inventory) {
Log.Trace("BeforeContentsChanged called on inventory " + inventory.Entity.ToString(), "BeforeContentsChanged");
}
*/
private void OnContentsChanged(MyInventoryBase inventory)
{
Log.Trace("Updating inventory cache with inventory " + inventory.Entity.ToString(), "OnContentsChanged");
ItemCountsAggregate cachedCount;
if (!InventoryTotals.TryGetValue(inventory, out cachedCount)) {
Log.Error("Received an update for inventory we're not tracking.", "UpdateInventory");
return;
}
ItemCountsAggregate originalCounts = cachedCount.Copy();
Totals -= originalCounts;
if (WatchedItems != null) {
foreach (var id in WatchedItems) {
cachedCount.Set(id, inventory.GetItemAmount(id));
}
}
else {
foreach (var item in inventory.GetItems()) {
cachedCount.Set(item.Content.GetObjectId(), item.Amount);
}
}
Totals += cachedCount;
if (SkipNextNotify) {
SkipNextNotify = false;
}
else {
NotifyContentsChanged(cachedCount - originalCounts);
}
//DebugPrint();
}