Пример #1
0
    void LoadSavedObjects(GameObjectStateData data)
    {
        //gets a list of all objects with the Savable script attached
        List <Saveable> savableObjects = new List <Saveable>(FindObjectsOfType <Saveable>());
        //A list to hold all the objects from the save fole
        List <Saveable> objsFromSave = new List <Saveable>();

        //loop through all savableObjects
        foreach (var obj in savableObjects)
        {
            //check is savableObject is in saved data and if soo add it to the objects from save list
            if (data.SavableObjects.Contains(obj.startSqrMag))
            {
                objsFromSave.Add(obj);
            }
        }
        //A list of objects to remove that are not both in savableObjects AND objsFromSave
        var objsToRemove = savableObjects.Except(objsFromSave);

        foreach (var obj in objsToRemove)
        {
            //destroy object
            Destroy(obj.gameObject);
        }
    }
Пример #2
0
    //Loads all the saved game objects and returns it
    GameObjectStateData LoadGameObjects()
    {
        string path = Application.persistentDataPath + "/Saves/" + SceneManager.GetActiveScene().name + ".json";
        string json = File.ReadAllText(path);

        gameStateData = JsonUtility.FromJson <GameObjectStateData>(json);
        return(gameStateData);
    }