Пример #1
0
    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();
    }
Пример #2
0
 public void AddToBreedingSlot(int alienID)
 {
     if (!slot1Occupied || !slot2Occupied)
     {
         idManager.SetPosition(alienID, 3);
         itemParent.transform.GetChild(idManager.GetInventorySlot(alienID)).GetChild(0).GetComponent <Button>().interactable = false; // Make the aliens inventory slot un-interactable
         if (!slot1Occupied)
         {
             id1           = alienID;                                                                                                   // Set the first id slot variable to the alien ID
             slot1Occupied = true;                                                                                                      // Set the first slot variable to be occupied
             Alien1Slot.transform.GetChild(0).GetChild(0).GetComponent <Image>().enabled = true;                                        // Enable the image
             Alien1Slot.transform.GetChild(0).GetChild(0).GetComponent <Image>().sprite  = alienIcons[idManager.GetAlienType(alienID)]; // Set the sprite based on the alien type
         }
         else if (!slot2Occupied)
         {
             id2           = alienID;
             slot2Occupied = true;
             Alien2Slot.transform.GetChild(0).GetChild(0).GetComponent <Image>().enabled = true;
             Alien2Slot.transform.GetChild(0).GetChild(0).GetComponent <Image>().sprite  = alienIcons[idManager.GetAlienType(alienID)];
         }
         statPanel.ClosePanel();
     }
 }
Пример #3
0
    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;
        }
    }
Пример #4
0
    public void AddAlienToFloor(int id)
    {
        // Using it's data we know what type it is, so we instantiate it on the floor. this allows us to retain a ghost copy in the inventory
        createdAlien = Instantiate(aliensArray[idManager.GetAlienType(id)]);                                                                                                // Instantiate an alien based on it's type
        createdAlien.GetComponent <AlienBase>().SetID(id);                                                                                                                  // Set the id of the new alien to the id of the inventory alien

        GameObject.Find("DataManager").GetComponent <IDManager>().SetInventorySlot(id, idManager.GetInventorySlot(id));                                                     // Set the inventory slot to be the slot of the inventory alien
        GameObject.Find("DataManager").GetComponent <IDManager>().SetPosition(id, 2);                                                                                       // Set it's position to be on the floor

        createdAlien.transform.position = new Vector3(Random.Range(0.0f, 2.0f), Random.Range(0.0f, 3.0f), 0);                                                               // Randomize it's position

        GameObject.Find("Inventory").GetComponent <InventoryManager>().AlienOnFloor(false, GameObject.Find("DataManager").GetComponent <IDManager>().GetInventorySlot(id)); // Make it's inventory slot un-interactable
    }