void Start() { itemPane = transform.Find("Panel"); playerInventory = GameObject.FindGameObjectWithTag("Player").GetComponent <Player_Inventory_Script>(); playerEquipment = playerInventory.GetComponent <Player_Equipment_Script>(); for (int i = 0; i < itemPane.childCount; i++) { for (int j = 0; j < itemPane.GetChild(i).childCount; j++) { Slot_Tracker scr = itemPane.GetChild(i).GetChild(j).gameObject.GetComponent <Slot_Tracker>(); scr.Slot = (i * itemPane.childCount) + j; scr.GetComponent <Button>().onClick.AddListener(scr.EquipItemFromSlot); scr.PlayerInventory = playerInventory; scr.PlayerEquipment = playerEquipment; } } }
private void Start() { if (instance == null) { instance = this; } else if (instance != this) { Destroy(gameObject); return; } Interface_Controller.instance.InterfaceEvents.Add("EquipWeapon", new UnityEngine.Events.UnityEvent()); Interface_Controller.instance.InterfaceEvents.Add("OpenInventory", new UnityEngine.Events.UnityEvent()); itemPane = transform.Find("Background/Inventory/Item_Pane/ItemSection"); characterPane = transform.Find("Background/Inventory/Character_Pane"); playerInventory = GameObject.FindGameObjectWithTag("Player").GetComponent <Player_Inventory_Script>(); playerEquipment = playerInventory.GetComponent <Player_Equipment_Script>(); emptySlotIcon = Resources.Load <Sprite>("ItemIcons/EmptySlot"); for (int i = 0; i < itemPane.childCount; i++) { for (int j = 0; j < itemPane.GetChild(i).childCount; j++) { Slot_Tracker scr = itemPane.GetChild(i).GetChild(j).gameObject.GetComponent <Slot_Tracker>(); scr.Slot = (i * itemPane.GetChild(i).childCount + j); scr.transform.name = scr.Slot.ToString(); //scr.GetComponent<Button>().onClick.AddListener(scr.EquipItemFromSlot); scr.PlayerInventory = playerInventory; scr.PlayerEquipment = playerEquipment; } } //Stat Icon References Sprite[] statIconSprites = Resources.LoadAll <Sprite>("StatIcons"); foreach (Sprite statSprite in statIconSprites) { statIcons.Add(statSprite.name, statSprite); } //Inventory Hovering & Comparison hoveredItemPanel = transform.Find("Background/HoverItems/Hovered"); hoveredReagentItemPanel = transform.Find("Background/HoverItems/HoveredReagent"); comparedItemPanel = transform.Find("Background/HoverItems/Current"); hoveredItemPanel.GetComponent <CanvasGroup>().alpha = 0; hoveredReagentItemPanel.GetComponent <CanvasGroup>().alpha = 0; comparedItemPanel.GetComponent <CanvasGroup>().alpha = 0; //Drag events for inventory items for (int i = 0; i < itemPane.childCount; i++) { Transform rowRef = itemPane.GetChild(i); for (int j = 0; j < rowRef.childCount; j++) { EventTrigger trigger = rowRef.GetChild(j).GetComponent <EventTrigger>(); EventTrigger.Entry entry = new EventTrigger.Entry(); entry.eventID = EventTriggerType.Drop; int temp = new int(); temp = i * rowRef.childCount + j; entry.callback.AddListener((data) => { DropActiveItem((PointerEventData)data, temp); }); trigger.triggers.Add(entry); entry = new EventTrigger.Entry(); entry.eventID = EventTriggerType.Drag; temp = new int(); temp = i * rowRef.childCount + j; entry.callback.AddListener((data) => { DragActiveItem((PointerEventData)data, temp); }); trigger.triggers.Add(entry); } } currentGearPanel = characterPane.Find("Equipment/Gear_Column"); for (int i = 1; i < 5; i++) { Transform section = currentGearPanel.GetChild(i); EventTrigger trigger = section.GetComponent <EventTrigger>(); EventTrigger.Entry entry = new EventTrigger.Entry(); entry.eventID = EventTriggerType.Drop; entry.callback.AddListener((data) => { EquipDraggedItem((PointerEventData)data, section.name); }); trigger.triggers.Add(entry); } currentGearPanel.GetChild(0).Find("Weapons").GetComponent <Button>().interactable = !displayEquippedWeaponTab; currentGearPanel.GetChild(0).Find("Armor").GetComponent <Button>().interactable = displayEquippedWeaponTab; //Reagent Cards for (int i = 0; i < EquipmentCrafting_Controller.instance.CraftableReagents.Count; i++) { GameObject reagentRef = Instantiate(reagentItemCard, resourcePanel.transform, false); if (playerInventory.GetResourceQuantity(EquipmentCrafting_Controller.instance.CraftableReagents[i].ItemName) > -1) { reagentRef.GetComponent <Image>().sprite = Resources.Load <Sprite>("ItemIcons/ResourceIcons/" + EquipmentCrafting_Controller.instance.CraftableReagents[i].SpritePath); } else { reagentRef.GetComponent <Image>().sprite = Resources.Load <Sprite>("ItemIcons/LockedSlot"); } reagentRef.name = EquipmentCrafting_Controller.instance.CraftableReagents[i].ItemName; reagentRef.GetComponent <Slot_Tracker>().Resource = true; } GetComponent <CanvasGroup>().alpha = 0; }