Пример #1
0
    public void savePlayerDataToFile()
    {
        //fetching and creating references to players current scripts
        player_log       = gameObject.GetComponent <Player_Log>();
        characterStats   = gameObject.GetComponent <CharacterStats>();
        player_Inventory = gameObject.GetComponent <Player_Inventory>();
        skillsManager    = gameObject.GetComponent <SkillsManager>();

        //creating scriptable instance of the PlayerObjectData that will be saved as JSON
        Data = (PlayerObjectData)ScriptableObject.CreateInstance("PlayerObjectData");

        //adding Data from different classes

        //adding Data from CharacterStats
        Data.saveCharacterStatData(characterStats.getStatBaseValue("HP"), characterStats.getCurrentHP(), characterStats.getStatBaseValue("Attack"), characterStats.getStatBaseValue("Defence"),
                                   characterStats.getStatBaseValue("Agility"), characterStats.CharacterLevel, characterStats.getExperiencePoints(), characterStats.Level_Experience_Required);

        //adding Data from inventory
        Data.saveInventoryItems(player_Inventory.getInventory());

        //Adding Data from SkillManager
        Data.saveSkillManager(skillsManager.getAllPlayerSkills(), skillsManager.getSlot1Skill(), skillsManager.getSlot2Skill());

        //Adding Data from Attacklog
        Data.savePlayerLog(player_log);

        //Saving instance to new file
        File.WriteAllText(Application.dataPath + "/Resources/SaveData/FloorTransitionData.txt",
                          JsonUtility.ToJson(Data));

        if (!transitionFloorInt.Equals(-1))
        {
            SceneManager.LoadScene(transitionFloorInt, LoadSceneMode.Single);
        }
    }