public void CreatePanel(int alienID) { // Set the slider values; We divide by 2 as 2 is the cap at which no stat can surpass. This can be altered defenceBar.value = idManager.GetDefence(alienID) / 2; attackSpeedBar.value = idManager.GetAttackSpeed(alienID) / 2; movementSpeedBar.value = idManager.GetMovementSpeed(alienID) / 2; damageBar.value = idManager.GetDamage(alienID) / 2; healthBar.value = idManager.GetHealth(alienID) / 2; rangeBar.value = idManager.GetRange(alienID) / 2; alienImage.sprite = alienImages[idManager.GetAlienType(alienID)]; // Change the alien icon alienPosition = idManager.GetPosition(alienID); // Set the alienPosition variable to the aliens position so we know which button we are using if (scene == 0) { switch (alienPosition) { case 0: moveBtn.GetComponentInChildren <Text>().text = "Not Owned"; killBtn.interactable = false; // If we don't own the alien we can't kill it break; case 1: moveBtn.GetComponentInChildren <Text>().text = "Inv->Floor"; killBtn.interactable = true; // If we own the alien and it's in our inventory we can kill it break; case 2: moveBtn.GetComponentInChildren <Text>().text = "Floor->Inv"; killBtn.interactable = false; // As a precaution you have to move the alien to your inventory if you want to kill it break; } } else if (scene == 2) { switch (alienPosition) { case 1: moveBtn.GetComponentInChildren <Text>().text = "Inv->BrdSlot"; break; case 3: moveBtn.GetComponentInChildren <Text>().text = "BrdSlot->Inv"; break; } } clickedAlienID = alienID; // Saved so we know which alien we need to move in MoveButtonClicked() }
public void AddToInventory(int alienID) { if (idManager.GetInventorySlot(alienID) == -1) // If the alien doesn't have a pre-defined slot { // Get an empty slot index for (int i = 0; i < invSlots.Length; i++) { if (invSlots[i].IsEmpty()) { emptySlotIndex = i; break; } } // Set the inventory slot of the alien to the empty one we just found idManager.SetInventorySlot(alienID, emptySlotIndex); } else { // If the alien already has a slot then set the empty slot index to that slot emptySlotIndex = idManager.GetInventorySlot(alienID); } // Set slot value to a string of the aliens stats. Slot4 = "1/0/1/etc.." so we can retrieve anywhere PlayerPrefs.SetString("slot" + emptySlotIndex.ToString(), alienID.ToString()); // Set the image of the slot to be identical to the alien itemParent.transform.GetChild(emptySlotIndex).GetChild(0).GetChild(0).GetComponent <Image>().enabled = true; itemParent.transform.GetChild(emptySlotIndex).GetChild(0).GetChild(0).GetComponent <Image>().sprite = alienIcons[idManager.GetAlienType(alienID)]; if (idManager.GetPosition(alienID) == 2) // If the alien is on the floor make it's button un-interactable { itemParent.transform.GetChild(emptySlotIndex).GetChild(0).GetComponent <Button>().interactable = false; } // Set the inventory slot we're inserting into to be not empty invSlots[emptySlotIndex].MakeNotEmpty(); }
void Start() { invent = GameObject.Find("Inventory").GetComponent <InventoryManager>(); // Grab inventory so we can add to it idManager = GameObject.Find("DataManager").GetComponent <IDManager>(); alienIdsArray = PlayerPrefs.GetString("alienIdsString").Split('/'); // Give each of the ID's a place in an array foreach (string id in alienIdsArray) // Then pair the id's with it's corresponding string, which will hold the alien data { int.TryParse(id, out idStringToInt); // TryParse instead of just parsing (i don't know why) alienDataDict[idStringToInt] = PlayerPrefs.GetString(id); } if (alienDataDict.ContainsValue("")) // Removes initial value at the start which has no value { alienDataDict.Remove(0); } //PlayerPrefs.DeleteKey("alienIdsString"); // Useful for clearing both data structures //alienDataDict.Clear(); foreach (KeyValuePair <int, string> id in alienDataDict) // Add aliens to lists so we can load them into the correct scenes { if (idManager.GetPosition(id.Key) == 1) // If the alien's in the inventory add it to the inventory { ToAddToInvent.Add(id.Key); } else if (idManager.GetPosition(id.Key) == 2) // If the alien should b on the floor (2) { ToAddToFloor.Add(id.Key); } else if (idManager.GetPosition(id.Key) == 3) // If it was in the breeding slot, reset it so that it's in the inventory { idManager.SetPosition(id.Key, 1); ToAddToInvent.Add(id.Key); } } switch (SceneManager.GetActiveScene().buildIndex) // Decide which aliens to load and where to load them based on what scene we're in { case 0: // Home foreach (int item in ToAddToInvent) { invent.AddToInventory(item); } foreach (int item in ToAddToFloor) { invent.AddToInventory(item); AddAlienToFloor(item); } break; case 1: // Fighting scene break; case 2: // Breeding scene foreach (int item in ToAddToInvent) { invent.AddToInventory(item); } foreach (int item in ToAddToFloor) { invent.AddToInventory(item); GameObject.Find("DataManager").GetComponent <IDManager>().SetInventorySlot(item, idManager.GetInventorySlot(item)); // Set the inventory slot to be the slot of the inventory alien GameObject.Find("Inventory").GetComponent <InventoryManager>().AlienOnFloor(false, GameObject.Find("DataManager").GetComponent <IDManager>().GetInventorySlot(item)); // Make it's inventory slot un-interactable } break; case 3: // Shop scene break; case 4: // Evotree scene break; } }