Exemplo n.º 1
0
    public Bag_SO Clone()
    {
        Bag_SO newBag = CreateInstance <Bag_SO>();

        for (int i = 0; i < slots.Length; i++)
        {
            newBag.slots[i] = slots[i].Clone();
        }

        return(newBag);
    }
Exemplo n.º 2
0
    /*
     * Sub method that save the player bag of items
     */
    private static void SaveBag()
    {
        Bag_SO gameBag = GameObject.FindGameObjectWithTag("Player").GetComponent <Bag>().bag;
        string sBag    = "";

        for (int i = 0; i < gameBag.slots.Length; i++)
        {
            sBag += ((gameBag.slots[i].item != null) ? gameBag.slots[i].item.name : " ") + "/" + gameBag.slots[i].amount + "|";
        }

        PlayerPrefs.SetString("SavedBag", sBag);
    }
Exemplo n.º 3
0
    /*
     * Counterpart of the method before, loads the player bag of items
     */
    public static void LoadBag()
    {
        Bag_SO gameBag = GameObject.FindGameObjectWithTag("Player").GetComponent <Bag>().bag;
        string sBag    = PlayerPrefs.GetString("SavedBag");

        string[] slots = sBag.Split('|');

        for (int i = 0; i < gameBag.slots.Length; i++)
        {
            string[] item = slots[i].Split('/');
            if (item[0].Length > 1)
            {
                gameBag.slots[i].item   = Resources.Load <Item>(GetPath(item[0]) + item[0]);
                gameBag.slots[i].amount = int.Parse(item[1]);
            }
        }
    }