示例#1
0
    public void LoadGame()
    {
        if (File.Exists(Application.persistentDataPath + "/gamesave.save"))
        {
            ClearBullets();
            ClearRobots();
            RefreshRobots();

            BinaryFormatter bf   = new BinaryFormatter();
            FileStream      file = File.Open(Application.persistentDataPath + "/gamesave.save", FileMode.Open);
            Save            save = (Save)bf.Deserialize(file);
            file.Close();

            for (int i = 0; i < save.livingTargetPositions.Count; i++)
            {
                int    position = save.livingTargetPositions[i];
                Target target   = targets[position].GetComponent <Target>();
                target.ActivateRobot((RobotTypes)save.livingTargetTypes[i]);
                target.GetComponent <Target>().ResetDeathTimer();
            }

            shotsText.text = "Shots: " + save.shots;
            hitsText.text  = "Hits: " + save.hits;
            shots          = save.shots;
            hits           = save.hits;

            Debug.Log("Game Loaded");

            Unpause();
        }
        else
        {
            Debug.Log("No Game Saved");
        }
    }
示例#2
0
    public void LoadAsJSON()
    {
        if (File.Exists(Application.persistentDataPath + "/SaveJson.json"))
        {
            ClearBullets();
            ClearRobots();
            RefreshRobots();

            string jsonSave = File.ReadAllText(Application.persistentDataPath
                                               + "/SaveJson.json");
            Save save = JsonUtility.FromJson <Save>(jsonSave);

            for (int i = 0; i < save.livingTargetPositions.Count; i++)
            {
                int    position = save.livingTargetPositions[i];
                Target target   = targets[position].GetComponent <Target>();
                target.ActivateRobot((RobotTypes)save.livingTargetsTypes[i]);
                target.GetComponent <Target>().ResetDeathTimer();
            }

            shotsText.text = "Shots: " + save.shots;
            hitsText.text  = "Hits: " + save.hits;
            shots          = save.shots;
            hits           = save.hits;

            Debug.Log("Game Loaded");
            Unpause();
        }
        else
        {
            Debug.Log("No game saved!");
        }
    }
示例#3
0
    public void LoadGame()
    {
        //1
        //checks to see that save file exists
        if (File.Exists(Application.persistentDataPath + "/gamesave.save"))
        {
            ClearBullets();
            ClearRobots();
            RefreshRobots();

            //2
            //create a BinaryFormatter
            //creates Save object and closes FileStream
            BinaryFormatter bf   = new BinaryFormatter();
            FileStream      file = File.Open(Application.persistentDataPath +
                                             "/gamesave.save", FileMode.Open);
            Save save = (Save)bf.Deserialize(file);
            file.Close();

            //3
            //need to convert save info into game state
            //loops through saved robot position and adds a robot at that position
            for (int i = 0; i < save.livingTargetPositions.Count; i++)
            {
                int    position = save.livingTargetPositions[i];
                Target target   = targets[position].GetComponent <Target>();
                target.ActivateRobot((RobotTypes)save.livingTargetsTypes[i]);
                target.GetComponent <Target>().ResetDeathTimer();
            }

            //4
            //updates UI to have right hits and shots set
            shotsText.text = "Shots: " + save.shots;
            hitsText.text  = "Hits: " + save.hits;
            shots          = save.shots;
            hits           = save.hits;

            Debug.Log("Game Loaded");

            Unpause();
        }

        else
        {
            Debug.Log("No game saved!");
        }
    }
示例#4
0
    //设置游戏数值
    public void SetGame(Save save)
    {
        ClearBullets();
        ClearRobots();
        RefreshRobots();

        hits           = save.hits;
        shots          = save.shots;
        shotsText.text = "Shots: " + save.shots;
        hitsText.text  = "Hits: " + save.hits;

        for (int i = 0; i < save.livingTargetPositions.Count; i++)
        {
            int    position = save.livingTargetPositions[i];
            Target target   = targets[position].GetComponent <Target>();
            target.ActivateRobot((RobotTypes)save.livingTargetsTypes[i]);
            target.GetComponent <Target>().ResetDeathTimer();
        }
    }
示例#5
0
    public void LoadGame()
    {
        // Checksto see if the save file exists - if not says there is no saved game
        if (File.Exists(Application.persistentDataPath + "/gamesave.save"))
        {
            ClearBullets();
            ClearRobots();
            RefreshRobots();

            // Creates a binary formatter to read the bytes in the save file
            BinaryFormatter bf   = new BinaryFormatter();
            FileStream      file = File.Open(Application.persistentDataPath + "/gamesave.save", FileMode.Open);
            Save            save = (Save)bf.Deserialize(file);
            file.Close();

            // adds robots to the saved positions
            for (int i = 0; i < save.livingTargetPositions.Count; i++)
            {
                int    position = save.livingTargetPositions[i];
                Target target   = targets[position].GetComponent <Target>();
                target.ActivateRobot((RobotTypes)save.livingTargetsTypes[i]);
                target.GetComponent <Target>().ResetDeathTimer();
            }

            // updates hits and shots set
            shotsText.text = "Shots: " + save.shots;
            hitsText.text  = "Hits: " + save.hits;
            shots          = save.shots;
            hits           = save.hits;

            Debug.Log("Game Loaded");

            Unpause();
        }
        else
        {
            Debug.Log("No game saved!");
        }
    }