public bool hasInventory = false; // Has player crafted an inventory // Start function #region Generate slots and set references private void Start() { // Set references itemDescriptionContainerScript = itemDescriptionContainer.GetComponent <ItemDescriptionController>(); // Add event listeners EventManager.Instance.e_saveGame.AddListener(Save); EventManager.Instance.e_loadGame.AddListener(Load); // Generate arrays inventorySlots = new InventorySlot[1000]; quickSlotToggles = new Toggle[quickSlotSize]; // Generate inventory and quick slots UI // Generate quick slots Vector3[] quickSlotPositions = new[] { new Vector3(-605, -605, 0), new Vector3(-500, -605, 0), new Vector3(-395, -605, 0), new Vector3(-290, -605, 0), new Vector3(-185, -605, 0), new Vector3(185, -605, 0), new Vector3(290, -605, 0), new Vector3(395, -605, 0), new Vector3(500, -605, 0), new Vector3(605, -605, 0) }; var toggleGroup = quickSlotContainer.GetComponent <ToggleGroup>(); for (int i = 0; i < quickSlotSize; i++) { var newQuickSlot = Instantiate(PrefabManager.Instance.prefabDatabase["Quick Slot"], quickSlotContainer.transform); newQuickSlot.transform.localPosition = quickSlotPositions[i]; quickSlotToggles[i] = newQuickSlot.GetComponent <Toggle>(); quickSlotToggles[i].group = toggleGroup; // Set toggle group newQuickSlot.name = "Quick Slot " + i; inventorySlots[i] = newQuickSlot.GetComponent <InventorySlot>(); inventorySlots[i].slotNumber = i; if (i == 0) // First toggle quick slot, we turn it on { quickSlotToggles[i].isOn = true; currentlySelectedIndex = 0; currentlySelectedItem = inventorySlots[0].item; } } // Generate inventory slots for (int i = quickSlotSize; i < currentInventorySize + quickSlotSize; i++) { var newInventorySlot = Instantiate(PrefabManager.Instance.prefabDatabase["Inventory Slot"], inventorySlotContainer.transform); newInventorySlot.name = "Inventory Slot " + i; inventorySlots[i] = newInventorySlot.GetComponent <InventorySlot>(); inventorySlots[i].slotNumber = i; } // Generate equipment slots int num = currentInventorySize + quickSlotSize; string[] equipmentSlotNames = new string[] { "Helmet", "Chestgear", "Pants", "Shoes", "Gloves" }; for (int i = 0; i < 5; i++) { var newEquipmentSlot = Instantiate(PrefabManager.Instance.prefabDatabase["Equipment " + equipmentSlotNames[i] + " Slot"], equipmentSlotContainer.transform); newEquipmentSlot.name = "Equipment " + equipmentSlotNames[i] + " Slot"; inventorySlots[num + i] = newEquipmentSlot.GetComponent <InventorySlot>(); inventorySlots[num + i].slotNumber = num + i; } // Generate crafting slots // Set default variables currentlyOverSlotIndex = -1; draggedFromSlotIndex = -1; inventoryContainer.SetActive(false); equipmentSlotContainer.SetActive(false); numberOfFilledSlots = quickSlotSize + currentInventorySize + 5; // TESTING hasInventory = true; AddItem(Instantiate(ItemManager.Instance.itemDatabase["Stone Axe"]), "full inventory"); for (int i = 0; i < 100; i++) { AddItem(Instantiate(ItemManager.Instance.itemDatabase["Wood"]), "full inventory"); } AddItem(Instantiate(ItemManager.Instance.itemDatabase["Stone Axe"]), "full inventory"); AddItem(Instantiate(ItemManager.Instance.itemDatabase["Stone Axe"]), "full inventory"); AddItem(Instantiate(ItemManager.Instance.itemDatabase["Stone Axe"]), "full inventory"); AddItem(Instantiate(ItemManager.Instance.itemDatabase["Stone Axe"]), "full inventory"); }
private void Awake() { Shared = this; }