コード例 #1
0
    /// <summary>
    /// Collect the thing, creating a unique identification (calculated in Awake). When the scene is loaded, look at uID's we've collected and add it to our list
    /// to not spawn, as we've already collected it.
    /// </summary>
    public void Collect()
    {
        //Collect a dummy collectible item into local inventory, to hold until saved
        CollectiblePlaced collectible = new CollectiblePlaced();

        //Attach this object's uID to the collectible we would like to add
        collectible.uID = uID;
        //Add the collectible to our unsaved list
        playerManager.GetUnsavedListForScene().placedCollectibles.Add(collectible);
    }
コード例 #2
0
    //Copy the player's unsaved list of collected items into our Game Manager permanent list
    public void SavePlayerInventory()
    {
        //Create reference to player's unsaved collected objects list
        playerManager = FindObjectOfType <PlayerManager>();
        //Create a new local list, and fill it with the collectibles from our saved list
        CollectiblePlacedList localList = playerManager.GetUnsavedListForScene();

        //Save and clear the player's Small Collectible List
        //Iterate through all of the objects in the list, adding each one, and then removing it from the list
        CollectiblePlaced collectible = new CollectiblePlaced();

        for (int i = 0; i < localList.placedCollectibles.Count; i++)
        {
            //Get a reference to the current object in our unsaved list iteration
            collectible = localList.placedCollectibles[i];
            //Debug.Log("Saving " + collectible.uID + " into GameManager");
            //Add this object to the GameManager saved list
            GetListForScene().placedCollectibles.Add(collectible);
        }
        //Now that we've iterated through our list, it's time to clear this list. We've passed the items to permanence, no longer need to hold on to them
        playerManager.GetUnsavedListForScene().placedCollectibles.Clear();
    }