public static CargoCapacityIndicatorItem GetInstance(Transform parent) { if (_template == null) { _template = CreateTemplate(); } CargoCapacityIndicatorItem item = UnityEngine.Object.Instantiate <CargoCapacityIndicatorItem>(_template, parent); item.gameObject.name = "CargoCapacityItem"; return(item); }
private static CargoCapacityIndicatorItem CreateTemplate() { DepotWindowVehicleListItemStoragesViewTooltipItem item = UnityEngine.Object.Instantiate <DepotWindowVehicleListItemStoragesViewTooltipItem>(R.Game.UI.DepotWindow.DepotWindowVehicleListItemStoragesViewTooltipItem); Transform itemTransform = item.transform; UnityEngine.Object.DestroyImmediate(item); CargoCapacityIndicatorItem result = itemTransform.gameObject.AddComponent <CargoCapacityIndicatorItem>(); LayoutElement layout = itemTransform.GetComponent <LayoutElement>(); layout.flexibleWidth = 0.00f; return(result); }
public void UpdateItems(IReadOnlyDictionary <Item, TransferData> items, float?multiplier, IReadOnlyDictionary <Item, TransferData> routeTotal = null, TransferDirection transfDirection = TransferDirection.both, int itemsLimit = 0) { int origCount = indicatorItems.Count; int index = 0; int overflowCount = 0; if (items != null && multiplier != null) { IReadOnlyDictionary <Item, TransferData> itemsToDisplay = routeTotal ?? items; foreach (KeyValuePair <Item, TransferData> itemData in itemsToDisplay) { if ((transfDirection == TransferDirection.loading && itemData.Value.load == 0) || (transfDirection == TransferDirection.unloading && itemData.Value.unload == 0)) { continue; } float?routeTotalCount = null; float itemsCountValue = 0; if (routeTotal != null) { routeTotalCount = itemData.Value.Get(transfDirection); if (items.TryGetValue(itemData.Key, out TransferData i)) { itemsCountValue = i.Get(transfDirection); } } else { itemsCountValue = Math.Abs(itemData.Value.Get(transfDirection)); } if (itemsCountValue == 0 && (routeTotalCount == null || routeTotalCount.Value == 0)) { continue; //do not display zero values } if (itemsLimit > 0 && index >= itemsLimit) { overflowCount++; continue; } if (index < origCount) { indicatorItems[index].UpdateItemData(itemData.Key, itemsCountValue * multiplier.Value, routeTotalCount); indicatorItems[index].SetActive(true); } else { CargoCapacityIndicatorItem indicatorItem = CargoCapacityIndicatorItem.GetInstance(transform); indicatorItems.Add(indicatorItem); indicatorItem.Initialize(itemData.Key, itemsCountValue * multiplier.Value, routeTotalCount); indicatorItem.gameObject.SetActive(true); } index++; } } ItemsCount = index; if (overflowCount > 0) { indicatorItems[index - 1].UpdateAsOverflowCount(overflowCount + 1); indicatorItems[index - 1].SetActive(true); } else { _overflowCont.SetActive(false); } for (; index < origCount; index++) { indicatorItems[index].gameObject.SetActive(false); } }