Exemplo n.º 1
0
    void Start()
    {
        fullStats = ScenesManager.Instance.GetStatsFromJSON();


        FillStatsUI("level1");
    }
Exemplo n.º 2
0
    public float GetPlayerTime(string levelName, string difficulty)
    {
        LevelsStats totalStats = GetStatsFromJSON();

        if (totalStats != null)
        {
            return(totalStats.GetPlayerTime(levelName, difficulty));
        }
        return(0);
    }
Exemplo n.º 3
0
    public void SaveLevelData(GameStats newStat)
    {
        //SET SAVE
        LevelsStats totalStats = GetStatsFromJSON();

        //If there is no entries in the json create a new LevelStats

        if (totalStats == null)
        {
            totalStats = new LevelsStats();
            totalStats.Levels_Stats.Add(newStat);
        }
        //If there is entries in the json check whether the new entry is already added
        else
        {
            //GameStats copyStats = totalStats.GetStatsByLevelname(newStat.levelName);
            GameStats existingStats = totalStats.GetStats(newStat.levelName, newStat.difficulty);

            //if stats already stored just update the field :
            if (existingStats != null)
            {
                if (newStat.playerTime < existingStats.playerTime)
                {
                    existingStats.playerTime = newStat.playerTime;
                }
            }
            else
            {
                totalStats.Levels_Stats.Add(newStat);
            }
        }


        string statsText = JsonUtility.ToJson(totalStats);

        System.IO.File.WriteAllText(Application.persistentDataPath + "/LevelsStats.json", statsText);
    }