public static bool IsCurrentlyEquipped(UI_Menu_Inventory_Left_ItemIcon itemIcon) { InitEquippedArmorDic(); foreach (var a in equippedArmor) { if (itemIcon == a.Value) { return(true); } } foreach (var a in equippedAttachment) { if (itemIcon == a.Value) { return(true); } } if (itemIcon == equippedWeapon) { return(true); } return(false); }
public static void SetEquippedWeapon(UI_Menu_Inventory_Left_ItemIcon itemIcon) { if (equippedWeapon != null) { equippedWeapon.Background.UpdateColor(); equippedWeapon.Ring.UpdateColor(); } equippedWeapon = itemIcon; }
public static void SetAttachment(Item_Attachment.AttachmentPart key, UI_Menu_Inventory_Left_ItemIcon itemIcon) { InitEquippedAttachment(); if (equippedAttachment[key] != null) { equippedAttachment[key].Background.UpdateColor(); equippedAttachment[key].Ring.UpdateColor(); } equippedAttachment[key] = itemIcon; }
public static void SetArmor(Item_Armor.ArmorPart key, UI_Menu_Inventory_Left_ItemIcon itemIcon) { InitEquippedArmorDic(); if (equippedArmor[key] != null) { equippedArmor[key].Background.UpdateColor(); equippedArmor[key].Ring.UpdateColor(); } equippedArmor[key] = itemIcon; }
public static void MarkItemAsEquippedItem(UI_Menu_Inventory_Left_ItemIcon itemIcon) { var equipment = itemIcon.Item as Item_Equipment; if (equipment == null) { return; } if (GameManager.Player.Equipment.IsCurrentlyEquipped(equipment) == false) { return; } var weapon = equipment as Item_Weapon; if (weapon != null) { SetEquippedWeapon(itemIcon); return; } var armor = equipment as Item_Armor; if (armor != null) { SetArmor(armor.Type, itemIcon); return; } var attachment = equipment as Item_Attachment; if (attachment != null) { SetAttachment(attachment.Type, itemIcon); return; } }
public void Open(UI_Menu_Inventory_Left_ItemIcon itemIcon) { var verticalSpacing = 15; RectTransform.sizeDelta = new Vector2(WIDTH, (verticalSpacing * 2) + (GENERIC_HEIGHT * genericMenusList.Count) + (genericMenusList.Count - 1) * verticalSpacing); var defaultPosition = new Vector3(0, (RectTransform.sizeDelta.y * 0.5f) - verticalSpacing - (GENERIC_HEIGHT * 0.5f)); for (int i = 0; i < genericMenusList.Count; i++) { genericMenusList[i].RectTransform.SetParent(RectTransform); genericMenusList[i].RectTransform.localPosition = defaultPosition; defaultPosition -= new Vector3(0, verticalSpacing + GENERIC_HEIGHT); } gameObject.SetActive(true); RectTransform.position = itemIcon.RectTransform.position + new Vector3(RectTransform.sizeDelta.x * 0.5f, RectTransform.sizeDelta.y * -0.5f); }
private void InstantiateItemIconBackground() { var itemList = GameManager.Player.Inventory.GetItemListAsReadOnly(x => x.ItemType == UI_Menu.Instance.Inventory.Left.ItemTypeDrawer.CurrentlyActiveItemType); var itemCount = itemList.Count; var spacing = 10.0f; var iconSize = 128; var horizontalMaxSize = RectTransform.sizeDelta.x; var horizontalShowLimit = 1; var horizontalSize = (iconSize * horizontalShowLimit) + ((horizontalShowLimit - 1) * spacing); while (horizontalSize < (horizontalMaxSize - (spacing * 2))) { horizontalShowLimit++; horizontalSize = (iconSize * horizontalShowLimit) + ((horizontalShowLimit - 1) * spacing); } horizontalShowLimit--; horizontalSize = (iconSize * horizontalShowLimit) + ((horizontalShowLimit - 1) * spacing); var horizontalRemainingSlots = horizontalShowLimit; var position = new Vector3((horizontalSize * -0.5f) + (iconSize * 0.5f), (RectTransform.sizeDelta.y * 0.5f) - (iconSize * 0.5f) - spacing); float offsetY = 0; for (int i = 0; i < itemCount; i++) { UI_Menu_Inventory_Left_ItemIcon itemIcon = null; if (itemIconsPool.Count == 0) { // =============================================================================================== // Create Parent // =============================================================================================== var go = new GameObject(itemList[i].ItemName); var rt = go.AddComponent <RectTransform>(); rt.SetParent(RectTransform); rt.localPosition = position; rt.sizeDelta = new Vector2(iconSize, iconSize); itemIcon = go.AddComponent <UI_Menu_Inventory_Left_ItemIcon>(); } else { // =============================================================================================== // Load from pool // =============================================================================================== itemIcon = itemIconsPool.Pop(); itemIcon.gameObject.SetActive(true); itemIcon.RectTransform.SetParent(RectTransform); itemIcon.RectTransform.localPosition = position; } // =============================================================================================== // Init ItemIcon and register it to itemiconlist // =============================================================================================== itemIcon.Init(itemList[i]); itemIconsList.Add(itemIcon); var itemPreview = itemIcon.ItemRenderer.InstantiateItemPreview(new Vector2(i, offsetY)); instantiatedPrefabDic.Add(itemPreview, itemIcon.ItemRenderer.RawImage.texture as RenderTexture); // =============================================================================================== // Register this to EquippedItemIcon // =============================================================================================== UI_Menu_Inventory_Left_EquippedItemIcon.MarkItemAsEquippedItem(itemIcon); // =============================================================================================== // Update position // =============================================================================================== horizontalRemainingSlots--; if (horizontalRemainingSlots == 0) { horizontalRemainingSlots = horizontalShowLimit; position.y -= spacing + iconSize; position.x = (horizontalSize * -0.5f) + (iconSize * 0.5f); offsetY += 1.0f; } else { position.x += spacing + iconSize; } } // =============================================================================================== // Render texture for the first time after instantiation finished // =============================================================================================== RenderCameraForTheFirstTime(); }
public static void SetToNull() { equippedArmor?.Clear(); equippedAttachment?.Clear(); equippedWeapon = null; }