Inheritance: UnityEngine.ScriptableObject
示例#1
0
    //Will print an examepl of use of the localization system.
	void Awake()
	{
#if UNITY_EDITOR
		savedData = AssetDatabase.LoadAssetAtPath<SavedData>(SAVE_PATH);
		
		if (savedData == null) {
			savedData = ScriptableObject.CreateInstance<SavedData> ();
			AssetDatabase.CreateAsset (savedData, SAVE_PATH);
		}
#endif

        if (g_instance == null)
        {
            g_instance = this;
        }
        else
        {
            Debug.Log("Localizater already initialized... Destroying duplicate.");
        }

        DontDestroyOnLoad(this.gameObject);

#if UNITY_EDITOR
        Debug.Log("Attempt at translating unrecognized word: " + IDToWord("StartMessage"));
#endif
    }
示例#2
0
 // Use this for initialization
 void Start()
 {
     gold = save.stats;
     gold.boolArraySize("skins", images.Length);
     gold.getBought("skins", images);
     selected = gold.getSelected("skins");
 }
示例#3
0
    // Use this for initialization
    void Start()
    {
        //DELETE THIS BEFORE RELEASE

        Data temp = GameObject.FindGameObjectWithTag("Load").GetComponent<Data>();
        Debug.Log("1");
        if (!temp.loaded)
        {
            Debug.Log("2");
            string s = PlayerPrefs.GetString(ADDRESS, "FIRST!");
            Debug.Log(s);
            if (!s.Equals("FIRST!"))
            {

                StringReader status = new StringReader(s);
                stats = (SavedData)serialize.Deserialize(status);
                Debug.Log(stats.gold);
            }
            else
            {
                stats = new SavedData();
                Debug.Log("no");
            }
            temp.setStats(stats);
        }
    }
示例#4
0
    // BE SURE TO PUT THIS IN AWAKE SO IT CAN BE INITIALIZED BEFORE BEING USED.
    void Awake()
    {
        DontDestroyOnLoad(this);
        savedData = AssetDatabase.LoadAssetAtPath<SavedData>(SAVE_PATH);

        if (savedData == null)
        {
            savedData = ScriptableObject.CreateInstance<SavedData>();
            AssetDatabase.CreateAsset(savedData, SAVE_PATH);
        }
    }
    //Will print an examepl of use of the localization system.
    void Start()
    {
        GameObject.DontDestroyOnLoad (gameObject);

        savedData = AssetDatabase.LoadAssetAtPath<SavedData>(SAVE_PATH);

        if (savedData == null) {
            savedData = ScriptableObject.CreateInstance<SavedData> ();
            AssetDatabase.CreateAsset (savedData, SAVE_PATH);
        }
    }
示例#6
0
	public static bool Load()
	{
		string filePath = Application.persistentDataPath + "/savedGame.sav";
		if(File.Exists(filePath)) {
			BinaryFormatter bf = new BinaryFormatter();
			FileStream file = File.Open(Application.persistentDataPath + "/savedGame.sav", FileMode.Open);
			SavedData.Data = (SavedData)bf.Deserialize(file);
			file.Close();
			return true;
		}
		return false;
	}
示例#7
0
 void Awake()
 {
     Data temp=GameObject.FindGameObjectWithTag("Load").GetComponent<Data>();
     if (temp == null)
     {
         Debug.Log("Failed");
     }
     else
     {
         Debug.Log("Success");
         this.stats = temp.get();
         Debug.Log(stats);
     }
 }
示例#8
0
    //Will print an examepl of use of the localization system.
    void Awake()
    {
        savedData = AssetDatabase.LoadAssetAtPath<SavedData>(SAVE_PATH);

        if (savedData == null) {
            savedData = ScriptableObject.CreateInstance<SavedData> ();
            AssetDatabase.CreateAsset (savedData, SAVE_PATH);
        }

        Debug.Log ("Untranslated word: Meow [Invalid]");
        Debug.Log ("Attempt at translating unrecognized word: " + IDToWord("Meow"));

        Debug.Log ("Untranslated word: Banane [Valid]");
        Debug.Log ("Attempt at translating unrecognized word: " + IDToWord("Banane"));

        Debug.Log ("Untranslated word: Fraise [Fallback]");
        Debug.Log ("Attempt at translating unrecognized word: " + IDToWord("Fraise"));
    }
 private void Awake()
 {
     SavedData.LoadGame();
 }
示例#10
0
 /// <summary>
 /// Award the player a daily play reward and set the next reward timestamp to the next day.
 /// </summary>
 public void ClaimDailyPlayReward(SaveLoadManager saveLoadManager, SavedData savedData)
 {
     saveLoadManager.SetLastRewardTime(System.DateTime.Today.ToString());
     totalScore += dailyPlayRewardScore;
 }
示例#11
0
 // Update is called once per frame
 void Update()
 {
     gold = save.stats;
     t.text = "Current Gold: " + gold.get();
 }
示例#12
0
 public static void ShowWindow()
 {
     SavedData.DeleteData();
 }
示例#13
0
 /// <summary>
 /// Save data persistently on device.
 /// </summary>
 public void SaveData(SavedData savedData)
 {
     PlayerPrefs.SetInt(saveFileExistsKey, 1);
     PlayerPrefs.SetString(saveFileKey, savedData.CreateSavedString());
     PlayerPrefs.Save();
 }
示例#14
0
        /// <summary>
        /// Расчет маршрутов для маячка
        /// </summary>
        /// <param name="landmark_index">Маяк</param>
        /// <param name="file_name">Файл для маршрутов из маяка</param>
        /// <param name="distans">Максимальное расстояние от маяка</param>
        /// <returns>Кол-во просмотренных вершин</returns>
        public long FullInfo(long landmark_index, string file_name, double distans = -1)
        {
            long       count = 0;
            FileStream fs    = new FileStream(file_name + "_" + landmark_index + ".txt", FileMode.OpenOrCreate, FileAccess.Write);

            using (StreamWriter writer = new StreamWriter(fs))
            {
                string value = "< landmar=" + landmark_index + ">" + Environment.NewLine;
                writer.Write(value);
                List <SavedData> Not_Look = new List <SavedData>();
                //List<SavedData> Look = new List<SavedData>();
                Dictionary <long, List <Dict_data> > Look_D = new Dictionary <long, List <Dict_data> >();
                Dictionary <long, double>            check  = new Dictionary <long, double>();
                AddOutData(ref Not_Look, landmark_index, -1, ref check);
                SavedData temp = GetMin(Not_Look);
                SetCost(temp.index, temp.real_cost);
                //double distans = 0;
                long last_ind      = -1;
                long last_ind_root = -1;
                //Look.Add(temp);
                Look_D.Add(temp.index, new List <Dict_data>());
                Look_D[temp.index].Add(new Dict_data(temp.index_root, temp.real_cost));
                last_ind      = temp.index;
                last_ind_root = temp.index_root;
                Not_Look.Remove(temp);
                while (Not_Look.Count > 0)
                {
                    AddOutData(ref Not_Look, last_ind, last_ind_root, ref check);
                    temp = GetMin(Not_Look);
                    if (distans > -1)
                    {
                        if (temp.cost > distans)
                        {
                            Not_Look.Remove(temp);
                            break;
                        }
                    }
                    SetCost(temp.index, temp.real_cost);
                    if (Look_D.ContainsKey(temp.index))
                    {
                        Look_D[temp.index].Add(new Dict_data(temp.index_root, temp.real_cost));
                    }
                    else
                    {
                        Look_D.Add(temp.index, new List <Dict_data>());
                        Look_D[temp.index].Add(new Dict_data(temp.index_root, temp.real_cost));
                    }
                    last_ind      = temp.index;
                    last_ind_root = temp.index_root;
                    Not_Look.Remove(temp);
                }
                long[] index = new long[Look_D.Keys.Count];
                Look_D.Keys.CopyTo(index, 0);
                string path_id = landmark_index + "_";
                //long id = 0;
                Dictionary <long, string> paths = new Dictionary <long, string>();
                for (int i = 0; i < index.Length; i++)
                {
                    // List<Dict_data> somelist = Look_D[index[index.Length - 1]];
                    if (index[i] != landmark_index)
                    {
                        count++;
                        value = "\t< " + index[i] + " / " + Look_D[index[i]][Dict_data.GetMin(Look_D[index[i]])].index_root
                                + " >" + Environment.NewLine;
                        //Устарело

                        /*paths.Add(index[i], path_id + id.ToString());
                         * value = "\t< " + path_id + id.ToString() + " " + index[i] + " way=\"";
                         * id++;
                         * List<long> way = new List<long>();
                         * way.Add(index[i]);
                         * while (way.Last() != landmark_index)
                         * {
                         *  long next_index = Look_D[way.Last()][Dict_data.GetMin(Look_D[way.Last()])].index_root;
                         *  if (paths.ContainsKey(next_index))
                         *  {
                         *      value += paths[next_index] + ",";
                         *      break;
                         *  }
                         *  else
                         *      way.Add(next_index);
                         * }
                         * way.Reverse();
                         * foreach (long ind in way)
                         *  value += ind + ",";
                         * value.TrimEnd(',');
                         * value += "\" >" + Environment.NewLine;
                         */
                        writer.Write(value);
                    }
                }
                //writer.Write(Environment.NewLine+"Кол-во вершин"+count);
            }
            fs.Dispose();
            return(count);
        }
示例#15
0
 public void Init(SavedData savedData)
 {
     totalScore = savedData.GetTotalScore();
 }
示例#16
0
    public SavedData GetSavedData()
    {
        SavedData savedData = JsonUtility.FromJson <SavedData>(PlayerPrefs.GetString("data"));

        return(savedData);
    }
示例#17
0
    private void Awake()
    {
        if (SaveGame.instance != null)
        {
            return;
        }

        instance = this;

        if (_deleteSaveData)
        {
            DeleteSaveGame();
            return;
        }

        SavedData savedData = JsonUtility.FromJson <SavedData>(PlayerPrefs.GetString("data"));

        _savedData = savedData;

        List <InventoryAmmoMount>       ammos       = new List <InventoryAmmoMount>();
        List <InventoryConsumableMount> consumables = new List <InventoryConsumableMount>();
        List <Messages> messages = new List <Messages>();

        if (_playerInventory != null && savedData != null)
        {
            if (savedData.rifle1.index != -1)
            {
                _playerInventory.rifle1.item   = _inventoryWeapons[savedData.rifle1.index];
                _playerInventory.rifle1.rounds = savedData.rifle1.rounds;
            }

            if (savedData.rifle2.index != -1 && _inventoryWeapons.Count > savedData.rifle2.index)
            {
                _playerInventory.rifle2.item   = _inventoryWeapons[savedData.rifle2.index];
                _playerInventory.rifle2.rounds = savedData.rifle2.rounds;
            }

            if (savedData.handgun.index != -1 && _inventoryWeapons.Count > savedData.handgun.index)
            {
                _playerInventory.handgun.item   = _inventoryWeapons[savedData.handgun.index];
                _playerInventory.handgun.rounds = savedData.handgun.rounds;
            }

            if (savedData.melee.index != -1 && _inventoryWeapons.Count > savedData.melee.index)
            {
                _playerInventory.melee.item = _inventoryWeapons[savedData.melee.index];
            }

            foreach (SavedSingleData savedSingleData in savedData.inventoryList)
            {
                switch (savedSingleData.type)
                {
                case DataType.Ammo:
                    if (_inventoryAmmos.Count > savedSingleData.index)
                    {
                        InventoryAmmoMount ammoMount = new InventoryAmmoMount();
                        ammoMount.rounds = savedSingleData.rounds;
                        ammoMount.item   = _inventoryAmmos[savedSingleData.index];
                        ammos.Add(ammoMount);
                    }
                    break;

                case DataType.Consumable:
                    if (_inventoryConsumables.Count > savedSingleData.index &&
                        _inventoryConsumables[savedSingleData.index] != null &&
                        _inventoryConsumables[savedSingleData.index].collectableConsumable.canSave)
                    {
                        InventoryConsumableMount consumableMount = new InventoryConsumableMount();
                        consumableMount.item = _inventoryConsumables[savedSingleData.index];

                        // Now we alter the game progress
                        // Before adding each consumable, we need to make sure that the progress states associated with the mare registered
                        List <GameProgress> progressStates  = consumableMount.item.collectableConsumable.progressStates;
                        ProgressManager     progressManager = FindObjectOfType <ProgressManager>();
                        if (progressStates.Count > 0 && progressManager != null)
                        {
                            foreach (GameProgress gameProgress in progressStates)
                            {
                                progressManager.SetProgress(gameProgress.key, gameProgress.value);
                            }
                        }

                        consumables.Add(consumableMount);
                    }
                    break;

                case DataType.Message:
                    if (_messages.Count > savedSingleData.index)
                    {
                        Messages message = _messages[savedSingleData.index];
                        messages.Add(message);
                    }
                    break;
                }

                _playerInventory.ammo        = ammos;
                _playerInventory.consumables = consumables;
                _playerInventory.messages    = messages;
            }

            if (_healthSharedFloat != null)
            {
                _healthSharedFloat.value = savedData.health;
            }

            if (_staminaSharedFloat != null)
            {
                _staminaSharedFloat.value = savedData.stamina;
            }

            if (_infectionSharedFloat != null)
            {
                _infectionSharedFloat.value = savedData.infection;
            }

            // We only load the player position if the last saved scene is the same as the current scene
            // So that we dont load the player in a random position when he just entered the map from another map
            // We can only load the player's positon when we are in wasteland
            GoneWrong.Player player = FindObjectOfType <GoneWrong.Player>();
            if (player != null && _savedData.currentScene == SceneManager.GetActiveScene().buildIndex &&
                SceneManager.GetActiveScene().name == "Wasteland")
            {
                CharacterController playerCharacterController = player.GetComponent <CharacterController>();
                playerCharacterController.enabled = false;

                if (savedData.playerPosition != Vector3.zero)
                {
                    FlashlightLight flashLight = FindObjectOfType <FlashlightLight>();
                    // We should also put the flash light in place
                    Vector3 differenceWithFlashLight = player.transform.position - flashLight.transform.position;
                    player.transform.position     = savedData.playerPosition;
                    flashLight.transform.position = player.transform.position - differenceWithFlashLight;
                }

                if (savedData.playerRotation != Quaternion.identity)
                {
                    player.transform.rotation = savedData.playerRotation;
                }

                playerCharacterController.enabled = true;
            }

            // Now for the collectable items
            // We check if we already saved the data for the current scene:
            SceneData sceneData = null;
            switch (SceneManager.GetActiveScene().name)
            {
            case "Hospital":
                sceneData = savedData.hospitalSceneData;
                break;

            case "Wasteland":
                sceneData = savedData.wasteLandData;
                break;

            case "Tunnels":
                sceneData = savedData.tunnelsSceneData;
                break;

            case "Underground":
                sceneData = savedData.undergroundSceneData;
                break;
            }

            if (sceneData != null && sceneData.savedBefore)
            {
                // We change the skybox and the fog depending on what is stored in the sceneData
                switch (sceneData.dayTime)
                {
                case DayTime.Night:
                    RenderSettings.fogDensity = 0f;
                    RenderSettings.skybox     = null;
                    break;

                case DayTime.Mist:
                    if (_fogSkyBox != null)
                    {
                        RenderSettings.fogDensity = 0.35f;
                        RenderSettings.skybox     = _fogSkyBox;
                    }
                    break;
                }

                // We already saved the scene before. So we destroy all the collectableItems in the scene
                CollectableConsumable[] collectableConsumables = FindObjectsOfType <CollectableConsumable>();
                foreach (CollectableConsumable collectableConsumable in collectableConsumables)
                {
                    if (collectableConsumable.canSave)
                    {
                        Destroy(collectableConsumable.gameObject);
                    }
                }

                CollectableAmmo[] colectableAmmos = FindObjectsOfType <CollectableAmmo>();
                foreach (CollectableAmmo collectableAmmo in colectableAmmos)
                {
                    if (collectableAmmo.canSave)
                    {
                        Destroy(collectableAmmo.gameObject);
                    }
                }

                // Then we instantiate all the remaining collectable Items that were present when saving the data
                foreach (SceneCollectableItem sceneCollectableItem in sceneData.collectableItems)
                {
                    // If we have the collectable item in list of collectable items
                    if (sceneCollectableItem.index != -1)
                    {
                        // Then we instantiate the collectable item from the inventory scriptable object in our list
                        if (sceneCollectableItem.type == DataType.Consumable)
                        {
                            if (_inventoryConsumables[sceneCollectableItem.index].collectableConsumable != null
                                // check if we can instantiate it in the first place
                                && _inventoryConsumables[sceneCollectableItem.index].collectableConsumable.canSave)
                            {
                                CollectableConsumable tmp = Instantiate(_inventoryConsumables[sceneCollectableItem.index].collectableConsumable);
                                if (sceneCollectableItem.parentName != "")
                                {
                                    Transform parent = GameObject.Find(sceneCollectableItem.parentName).transform;
                                    if (parent != null)
                                    {
                                        tmp.transform.parent = parent;
                                    }

                                    tmp.transform.localPosition = sceneCollectableItem.localPosition;
                                    tmp.transform.localRotation = sceneCollectableItem.localRotation;
                                }
                            }
                        }
                        else if (sceneCollectableItem.type == DataType.Ammo)
                        {
                            if (_inventoryConsumables[sceneCollectableItem.index].collectableConsumable != null)
                            {
                                CollectableAmmo tmp = Instantiate(_inventoryAmmos[sceneCollectableItem.index].collectableAmmo);
                                if (sceneCollectableItem.parentName != "")
                                {
                                    Transform parent = GameObject.Find(sceneCollectableItem.parentName).transform;
                                    if (parent != null)
                                    {
                                        tmp.transform.parent = parent;
                                    }

                                    tmp.transform.localPosition = sceneCollectableItem.localPosition;
                                    tmp.transform.localRotation = sceneCollectableItem.localRotation;
                                }
                            }
                        }
                    }
                }

                // Now we check the remaining zombies
                // Each zombie whose name doesn't belong to the list of the remaining zombies, will be deactivated
                if (_saveZombies)
                {
                    AIStateMachine[] stateMachines = FindObjectsOfType <AIStateMachine>();
                    foreach (AIStateMachine stateMachine in stateMachines)
                    {
                        int  index       = 0;
                        bool foundZombie = false;
                        do
                        {
                            if (sceneData.remainingZombies.Count > index && stateMachine.transform.name == sceneData.remainingZombies[index])
                            {
                                foundZombie = true;
                            }
                            index++;
                        } while (index < sceneData.remainingZombies.Count && !foundZombie);

                        // If we didn't find the zombie in our list, we destroy him
                        if (!foundZombie)
                        {
                            Destroy(stateMachine.gameObject);
                            //stateMachine.gameObject.SetActive(false);
                        }
                    }
                }

                // Handling progress objects (activating and deactivating them, then setting their position)
                foreach (ProgressObject progressObject in sceneData.progressObjects)
                {
                    if (progressObject.index != -1 && _progressObjects.Count > progressObject.index)
                    {
                        Transform sceneProgressObject = _progressObjects[progressObject.index];
                        if (sceneProgressObject != null)
                        {
                            sceneProgressObject.gameObject.SetActive(progressObject.active);
                            sceneProgressObject.transform.position = progressObject.position;
                            sceneProgressObject.transform.rotation = progressObject.rotation;
                        }
                    }
                }

                PlayerHUD playerHud = PlayerHUD.instance;
                if (playerHud == null)
                {
                    playerHud = FindObjectOfType <PlayerHUD>();
                }

                if (playerHud != null)
                {
                    playerHud.ChangeLevelObjectiveText(sceneData.nextObjective);
                }

                CarHUD carHUD = CarHUD.instance;
                if (carHUD == null)
                {
                    carHUD = FindObjectOfType <CarHUD>();
                }

                if (carHUD != null)
                {
                    carHUD.ChangeLevelObjectiveText(sceneData.nextObjective);
                }
            }
        }
    }
 public void ResetData()
 {
     SavedData.data = new SaveFile();
     SavedData.SaveGame();
 }
 public void CloseApplication()
 {
     SavedData.SaveGame();
     Application.Quit();
 }
 public void SaveReturn()
 {
     SetCountdownSettings();
     SavedData.SaveGame();
     SceneManager.LoadScene("Main");
 }
示例#21
0
    public void Save(int nextSceneIndex = -1)
    {
        SavedData savedData = new SavedData();

        // We save the current scene (or the last scene) instead of the next one when the scene index is either not set or when we are going back to main menu
        // Or when the next scene is nightmare
        // Or when it's the end chapter or the final suicide scene
        // When the next scene index is not set, it means we are saving data in wasteland, so we save the data for the current scene.
        int nightmareSceneIndex   = SceneManager.GetSceneByName("Nightmare").buildIndex;
        int chapter1EndSceneIndex = SceneManager.GetSceneByName("Chapter 1 End").buildIndex;
        int suicideSceneIndex     = SceneManager.GetSceneByName("Suicide Scene ").buildIndex;

        if (nextSceneIndex == -1 || nextSceneIndex == 0 ||
            nextSceneIndex == nightmareSceneIndex ||
            nextSceneIndex == chapter1EndSceneIndex ||
            nextSceneIndex == suicideSceneIndex)
        {
            savedData.currentScene = SceneManager.GetActiveScene().buildIndex;
        }
        else
        {
            savedData.currentScene = nextSceneIndex;
        }

        // We get the corresponding scene items first
        SceneData sceneData = null;

        switch (SceneManager.GetActiveScene().name)
        {
        case "Hospital":
            sceneData = savedData.hospitalSceneData;
            break;

        case "Wasteland":
            sceneData = savedData.wasteLandData;
            break;

        case "Tunnels":
            sceneData = savedData.tunnelsSceneData;
            break;

        case "Underground":
            sceneData = savedData.undergroundSceneData;
            break;
        }

        if (_playerInventory != null)
        {
            List <InventoryWeaponMount> weaponMounts = new List <InventoryWeaponMount>();
            weaponMounts.Add(_playerInventory.rifle1);
            weaponMounts.Add(_playerInventory.rifle2);
            weaponMounts.Add(_playerInventory.handgun);
            weaponMounts.Add(_playerInventory.melee);

            for (int i = 0; i < weaponMounts.Count; i++)
            {
                if (weaponMounts[i].item == null)
                {
                    continue;
                }

                bool foundWeapon = false;
                int  index       = 0;
                do
                {
                    if (weaponMounts[i].item == _inventoryWeapons[index])
                    {
                        foundWeapon = true;
                        SavedSingleData savedSingleData = new SavedSingleData();
                        savedSingleData.type   = DataType.Weapon;
                        savedSingleData.index  = index;
                        savedSingleData.rounds = weaponMounts[i].rounds;
                        if (i == 0)
                        {
                            savedData.rifle1 = savedSingleData;
                        }
                        else if (i == 1)
                        {
                            savedData.rifle2 = savedSingleData;
                        }
                        else if (i == 2)
                        {
                            savedData.handgun = savedSingleData;
                        }
                        else if (i == 3)
                        {
                            savedData.melee = savedSingleData;
                        }
                    }

                    index++;
                } while (!foundWeapon && index < _inventoryWeapons.Count);
            }

            foreach (InventoryAmmoMount ammoMount in _playerInventory.ammo)
            {
                bool foundAmmo = false;
                int  index     = 0;
                do
                {
                    if (ammoMount.item == _inventoryAmmos[index])
                    {
                        foundAmmo = true;
                        if (ammoMount.item.collectableAmmo.canSave)
                        {
                            SavedSingleData savedSingleData = new SavedSingleData();
                            savedSingleData.type   = DataType.Ammo;
                            savedSingleData.index  = index;
                            savedSingleData.rounds = ammoMount.rounds;
                            savedData.inventoryList.Add(savedSingleData);
                        }
                    }

                    index++;
                } while (!foundAmmo && index < _inventoryAmmos.Count);
            }

            foreach (InventoryConsumableMount consumableMount in _playerInventory.consumables)
            {
                bool foundConsumable = false;
                int  index           = 0;
                do
                {
                    if (consumableMount.item == _inventoryConsumables[index])
                    {
                        foundConsumable = true;
                        if (consumableMount.item.collectableConsumable.canSave)
                        {
                            SavedSingleData savedSingleData = new SavedSingleData();
                            savedSingleData.type  = DataType.Consumable;
                            savedSingleData.index = index;
                            savedData.inventoryList.Add(savedSingleData);
                        }
                    }

                    index++;
                } while (!foundConsumable && index < _inventoryConsumables.Count);
            }

            foreach (Messages message in _playerInventory.messages)
            {
                bool foundMessage = false;
                int  index        = 0;
                do
                {
                    if (message == _messages[index])
                    {
                        foundMessage = true;
                        SavedSingleData savedSingleData = new SavedSingleData();
                        savedSingleData.type  = DataType.Message;
                        savedSingleData.index = index;
                        savedData.inventoryList.Add(savedSingleData);
                    }

                    index++;
                } while (!foundMessage && index < _messages.Count);
            }

            if (_healthSharedFloat != null)
            {
                savedData.health = _healthSharedFloat.value;
            }

            if (_staminaSharedFloat != null)
            {
                savedData.stamina = _staminaSharedFloat.value;
            }

            if (_infectionSharedFloat != null)
            {
                savedData.infection = _infectionSharedFloat.value;
            }
        }

        // Now we are about to save the scene items:
        if (sceneData != null && sceneData.collectableItems != null)
        {
            // Now saving the night sky and the fog
            sceneData.dayTime = RenderSettings.fog ? DayTime.Mist : DayTime.Night;

            CollectableConsumable[] consumables = FindObjectsOfType <CollectableConsumable>();
            // We save the remaining collectable consumables
            foreach (CollectableConsumable consumable in consumables)
            {
                // Some key items are set to never be saved. They are managed by progress states
                if (!consumable.canSave)
                {
                    continue;
                }

                SceneCollectableItem sceneCollectableItem = new SceneCollectableItem();
                sceneCollectableItem.type          = DataType.Consumable;
                sceneCollectableItem.localPosition = consumable.transform.localPosition;
                sceneCollectableItem.localRotation = consumable.transform.localRotation;
                if (consumable.transform.parent != null)
                {
                    sceneCollectableItem.parentName = consumable.transform.parent.name;
                }

                bool foundConsumable = false;
                int  index           = 0;
                do
                {
                    if (consumable.consumableMount.item == _inventoryConsumables[index])
                    {
                        foundConsumable            = true;
                        sceneCollectableItem.index = index;
                    }

                    index++;
                } while (!foundConsumable && index < _inventoryConsumables.Count);

                // Now that we got our scene collectable item data stored in an object, we add them to the corresponding scene
                sceneData.collectableItems.Add(sceneCollectableItem);
            }

            // Now we save the remaining collectable ammos:
            CollectableAmmo[] ammos = FindObjectsOfType <CollectableAmmo>();
            foreach (CollectableAmmo ammo in ammos)
            {
                SceneCollectableItem sceneCollectableItem = new SceneCollectableItem();
                sceneCollectableItem.type          = DataType.Ammo;
                sceneCollectableItem.localPosition = ammo.transform.localPosition;
                sceneCollectableItem.localRotation = ammo.transform.localRotation;
                if (ammo.transform.parent != null)
                {
                    sceneCollectableItem.parentName = ammo.transform.parent.name;
                }

                bool foundAmmo = false;
                int  index     = 0;
                do
                {
                    if (ammo.ammoMount.item == _inventoryAmmos[index])
                    {
                        foundAmmo = true;
                        sceneCollectableItem.index = index;
                    }

                    index++;
                } while (!foundAmmo && index < _inventoryAmmos.Count);

                // Now that we got our scene collectable item data stored in an object, we add them to the corresponding scene
                sceneData.collectableItems.Add(sceneCollectableItem);
            }

            // Now we check for the remaining zombies:
            if (_saveZombies)
            {
                AIStateMachine[] stateMachines = FindObjectsOfType <AIStateMachine>();
                foreach (AIStateMachine stateMachine in stateMachines)
                {
                    // If the zombie is activated and he is not dead, then we save him
                    if (stateMachine.gameObject.activeSelf && !stateMachine.dead)
                    {
                        sceneData.remainingZombies.Add(stateMachine.transform.name);
                    }
                }
            }

            // Now saving progress objects for in sceneData
            for (int i = 0; i < _progressObjects.Count; i++)
            {
                ProgressObject progressObject = new ProgressObject();
                progressObject.index = i;
                if (_progressObjects[i] != null)
                {
                    progressObject.active   = _progressObjects[i].gameObject.activeSelf;
                    progressObject.position = _progressObjects[i].transform.position;
                    progressObject.rotation = _progressObjects[i].transform.rotation;
                }
                else
                {
                    progressObject.active = false;
                }

                sceneData.progressObjects.Add(progressObject);
            }

            // Now saving the next level objective text
            if (PlayerHUD.instance != null)
            {
                sceneData.nextObjective = PlayerHUD.instance.nextObjective;
            }

            // Then we set the scene saved state to true
            sceneData.savedBefore = true;

            Notifications.instance.EnqueNotification("Progress Saved!");
            if (ProgressSavedUI.instance != null)
            {
                ProgressSavedUI.instance.Show();
            }
        }


        // Now we save the player position
        // We only save the player's position when we are in wasteland
        GoneWrong.Player player = GoneWrong.Player.instance;
        if (player != null && SceneManager.GetActiveScene().name == "Wasteland")
        {
            savedData.playerPosition = player.transform.position;
            savedData.playerRotation = player.transform.rotation;
        }

        // Now we save in player prefs:
        string data = JsonUtility.ToJson(savedData);

        PlayerPrefs.SetString("data", data);
    }
示例#22
0
    private void LoadSettings()
    {
        savedData = AssetDatabase.LoadAssetAtPath<SavedData>(SAVE_PATH);

        if (savedData == null) {
            savedData = ScriptableObject.CreateInstance<SavedData>();
            AssetDatabase.CreateAsset(savedData, SAVE_PATH);
        }
        ids = savedData.savedIDs;
        languages = savedData.savedLanguages;
    }
示例#23
0
    // =========================================================================================== //
    // in continue game, load from save file of the current player
    public void LoadDataFromSaveFile()
    {
        //Debug.Log("load game - load from save file");

        Saved = Utils.ReadFromBinaryFile <SavedData>(SAVE_FILE_PATH);
    }
 public void Save()
 {
     SavedData save = new SavedData(gestures, highScore);
     save.Save();
 }
示例#25
0
 public static bool IsRecordNotExpired(this SavedData savedData)
 {
     return(savedData.EndTime is null || savedData.EndTime > DateTime.UtcNow);
 }
示例#26
0
 public static IMessage GetMessage(this SavedData savedData)
 {
     return(LinkMessage.TryCreateLinkMessageIfNeeded(savedData.Message, savedData.IsLink));
 }
示例#27
0
文件: Data.cs 项目: Zror/DatRepo
 public void setStats(SavedData s)
 {
     Stats = s;
     loaded = true;
 }
示例#28
0
    void Awake()
    {
        Data temp = GameObject.FindGameObjectWithTag("Load").GetComponent<Data>();
        if (temp != null)
        {
            saveStuff = temp.get();

            perks = saveStuff.perks;
            breaths = saveStuff.breath;
            wings = saveStuff.wings;
            skins = saveStuff.skins;

            perks_i = saveStuff.perkSelected;
            breaths_i = saveStuff.breathSelected;
            wings_i = saveStuff.wingSelected;
            skins_i = saveStuff.skinSelected;

            Debug.Log(perks_i + ", " + breaths_i + ", " + wings_i + ", " + skins_i);
        }
    }
示例#29
0
 void Start()
 {
     savedData = GameObject.Find("SavedData").GetComponent<SavedData>();
     _currentGameData = this;
     //_currentRequiredPresentCount = giftGoal[savedData.currentLevel];
     //PresentRequiredGUI.text = " /" + giftGoal[savedData.currentLevel].ToString(); //moved to StartGame
     _givenTimeOnThisLevel = 60;
 }