Exemple #1
0
    //Populate the grid with blocks from save data.
    public void LoadFromSaveData(Save_Data a_SaveData)
    {
        ClearAllBlocks();

        Save_Data.BlockData[] savedGrid = a_SaveData.m_AllBlockData.m_BlockData;
        for (int i = 0; i < 100; i++)
        {
            //Debug.Log(savedGrid[i].path);
            if (savedGrid[i].path != "")
            {
                //Obtain the block's prefab from saved filepath.
                GameObject newBlock = Resources.Load <GameObject>(savedGrid[i].path);

                //Instantiate block at proper location.
                newBlock = Instantiate(newBlock, squareGrid[(int)Mathf.Floor(i / 5), i % 5].transform.position, transform.rotation);

                //Add the block to the nodeGrid and the corresponding square.
                nodeGrid[(int)Mathf.Floor(i / 5), i % 5] = newBlock;
                squareGrid[(int)Mathf.Floor(i / 5), i % 5].GetComponent <Grid_Square>().NodeBlock = newBlock.GetComponent <Node_Block>();

                //Set block properties.
                //newBlock.GetComponent<Node_Block>().BlockRotation = savedGrid[i].rotation;
                squareGrid[(int)Mathf.Floor(i / 5), i % 5].GetComponent <Grid_Square>().NodeBlock.BlockRotation = savedGrid[i].rotation;
                squareGrid[(int)Mathf.Floor(i / 5), i % 5].GetComponent <Grid_Square>().NodeBlock.UpdateEnterDirections();
                //newBlock.GetComponent<Node_Block>().UpdateEnterDirections();
                //squareGrid[(int)Mathf.Floor(i / 5), i % 5].GetComponent<Grid_Square>().NodeBlock.GridPosition = savedGrid[i].gridPosition; (gridPosition isn't actually used from Save_Data for now, it's just for reference when editing the file itself)
                newBlock.GetComponent <Node_Block>().GridPosition = savedGrid[i].gridPosition;
            }
            else
            {
                //Leave square empty. (This is different from being locked)
            }
        }
        Debug.Log("Setting Fire Rotation...");
    }
Exemple #2
0
 //Save data on each block in the grid.
 public void PopulateSaveData(Save_Data a_SaveData)
 {
     for (int i = 0; i < 20; i++)
     {
         for (int j = 0; j < 5; j++)
         {
             Debug.Log("Attempting block [" + i + ", " + j + "]");
             Debug.Log(nodeGrid[i, j]);
             if (nodeGrid[i, j] != null)
             {
                 //Pass necessary data from the block to the save data, then save it.
                 Node_Block          blockScript = nodeGrid[i, j].GetComponent <Node_Block>();
                 Save_Data.BlockData blockData   = new Save_Data.BlockData();
                 blockData.path         = blockScript.BlockPath;
                 blockData.gridPosition = blockScript.GridPosition;
                 blockData.rotation     = blockScript.BlockRotation;
                 a_SaveData.m_AllBlockData.m_BlockData[5 * i + j] = blockData;
                 Debug.Log("[" + i + ", " + j + "] Saved block to data!");
                 a_SaveData.m_Score = 4;
             }
             //Set default data for empty squares.
             else
             {
                 Save_Data.BlockData blockData = new Save_Data.BlockData();
                 blockData.path         = "";
                 blockData.gridPosition = new Vector2(i, j);
                 blockData.rotation     = 0;
                 a_SaveData.m_AllBlockData.m_BlockData[5 * i + j] = blockData;
             }
         }
     }
 }
Exemple #3
0
    private static string path = Application.persistentDataPath + "/save1.json"; // THIS IS THE SAVE LOCATION AND NAME OF THE SAVE FILE

    public static void saveGameToJson(FPSMovement player)
    {
        Save_Data data = new Save_Data(player);             // CREATES A NEW PLAYER_DATA INSTANCE PASSING IN THE PLAYER VARIABLE

        string dataAsJson = JsonUtility.ToJson(data, true); // THIS CREATES A NEW STRING CALLED DATAASJSON AND CONVERTS THE PLAYER_DATA WITH PRETTY PRINT ENABLED

        File.WriteAllText(path, dataAsJson);                // THIS THEN WRITES THE CONVERTED DATA TO THE PREVIOUSLY CREATED JSON FILE
    }
Exemple #4
0
    private static void LoadJsonData(Battle_Manager a_Battle_Manager)
    {
        if (File_Manager.LoadFromFile("SaveData.dat", out var json))
        {
            Save_Data sd = new Save_Data();
            sd.LoadFromJson(json);

            a_Battle_Manager.LoadFromSaveData(sd);
        }
    }
Exemple #5
0
    private static void SaveJsonData(Battle_Manager a_Battle_Manager)
    {
        Save_Data sd = gridSaveData;

        //a_Battle_Manager.PopulateSaveData(sd);

        if (File_Manager.WriteToFile("SaveData.dat", sd.ToJson()))
        {
            Debug.Log("Save successful!");
            Debug.Log(Application.persistentDataPath);
        }
    }
Exemple #6
0
 private void loadProgressFromSave()
 {
     if (SaveGame.foundSaveGame())                                                          // IF THERE IS A SAVE FILE STORED IN THE USERS COMPUTER
     {
         Save_Data p = SaveGame.loadGameFromJson();                                         // INSTATIATES A NEW PLAYER_DATA OBJECT AND ACCESSES THE INFORMATION STORED IN THE SAVE FILES
         createNewDialogue(p.currentDialogueIndex, 1, p.character, dialogueStrings_player); // SETS THE CURRENT DIALOGUE TEXT TO THE SAVED ARRAY INDEX STORED IN THE .JSON FILE
     }
     else if (!SaveGame.foundSaveGame())                                                    // IF THERE IS NO SAVE FILE FOUND
     {
         createNewDialogue(0, 1, "SpaceTeam", dialogueStrings_spaceteam);                   // START THE DIALOGUE FROM THE BEGINNING
     }
 }
Exemple #7
0
 public static Save_Data loadGameFromJson()
 {
     if (File.Exists(path))                                                   // IF THE FILE EXISTS WHEN THIS METHOD IS CALLED
     {
         string    dataAsJson = File.ReadAllText(path);                       // CREATE A NEW STRING CALLED DATAASJSON AND READ ALL THE VALUES IN THE SAVED JSON FILE LOCATED AT THE SPECIFIED PATH
         Save_Data data       = JsonUtility.FromJson <Save_Data>(dataAsJson); // CREATE A NEW PLAYER_DATA INSTANCE AND PASS IN THE VARIABLES FROM THE JSON FILE
         return(data);                                                        // RETURNS THE NEW PLAYER_DATA CLASS FOR USE
     }
     else // IF THE FILE DOESN'T EXIST WHEN THIS METHOD IS CALLED
     {
         saveFound = false; // SET SAVEFOUND TO FALSE
         return(null);      // RETURN NULL
     }
 }
    private void Awake()
    {
        if (DataSaver != this)
        {
            if (DataSaver == null)
            {
                DataSaver = this;
                DontDestroyOnLoad(this);

                PrepararCaminho();
            }
            else
            {
                Destroy(this);
            }
        }
    }
Exemple #9
0
    public void continueGame()                            // THIS METHOD WILL BE CALLED BY THE CONTINUE BUTTON ON THE MAIN MENU
    {
        checkifSaveExists();                              // CALLS THE CHECKIFSAVE EXISTS METHOD

        bool saveFilePresent = SaveGame.foundSaveGame();  // STORES THE BOOL FOUNDSAVEGAME IN SAVEFILEPRESENT

        if (saveFilePresent)                              // IF THE GAME HAS A SAVE FILE ALREADY
        {
            Save_Data data = SaveGame.loadGameFromJson(); // CREATE A NEW PLAYER_DATA CALLED DATA AND INITIALISE IT TO THE SAVEGAME.LOADGAMES METHOD
            SceneManager.LoadScene(data.level);           // CALLS THE SCENEMANAGER.LOADSCENE TO LOAD THE SAVED LEVEL STORE IN THE PLAYER DATA CLASS
            Time.timeScale = 1;                           // SETS THE TIMESCALE TO 1 TO RESOLVE ANY PROBLEMS WITH TIME
        }
        else // IF THERE IS NO SAVE FILE FOUND
        {
            noSaveFound(); // CALL THE NOSAVEFOUND METHOD
        }
    }
Exemple #10
0
    public void overwriteOldGame()                                               // CREATES A NEW GAME USING THE SLOT 1-5
    {
        if (SaveGame.foundSaveGame())                                            // IF THERE IS A SAVEGAME WHICH HAS BEEN FOUND AND THE PLAYER PRESSES THE NEW GAME BUTTON
        {
            Save_Data data = SaveGame.loadGameFromJson();                        // CREATES A NEW SAVE_DATA INSTANCE CALLED DATA
            overWriteMenu.SetActive(true);                                       // SETS THE OVERWRITEMENU TO ACTIVE
            mainMenu.SetActive(false);                                           // SETS THE MAINMENU TO DEACTIVE

            currentMenu = overWriteMenu.name;                                    // SETS THE CURRENTMENU TO EQUAL THE OVERRIDEMENU.NAME

            saveFileText.text = "Game saved: " + data.date + " at " + data.time; // SETS THE SAVEFILETEXT TO THE DATE AND TIME THE GAME WAS LAST SAVED
        }
        else
        {
            SceneManager.LoadScene(2); // LOADS THE LOADING SCREEN FOR THE CUTSCENE
        }
    }
Exemple #11
0
    // Start is called before the first frame update
    void Start()
    {
        pulseTravelSpeed  = 1f;
        pulseCycleSpeed   = 3.0f;
        pulseCycleTimer   = 0f;
        energyTravelSpeed = 1f;
        pulseStartPos     = new Vector3(-3.35f, -1.735f, 0);
        pulseEndPos       = new Vector3(1.765f, -1.735f, 0);

        gridSaveData = new Save_Data();

        //Load grid once on startup
        testLoad = true;

        //Creating a pulse immediately for testing
        CreatePulse();
    }
Exemple #12
0
 public void LoadFromSaveData(Save_Data a_SaveData)
 {
     grid.GetComponent <Grid>().LoadFromSaveData(a_SaveData);
 }
Exemple #13
0
 public void PopulateSaveData(Save_Data a_SaveData)
 {
     //a_SaveData.m_Score = CurrentScore;
 }