コード例 #1
0
    public static void SaveProfile(this Profile _pr)
    {
        var encrypting = MainGameManager.Instance.usingEncryption;

        var    startTime   = DateTime.UtcNow;
        string profilePath = Path.Combine(Application.persistentDataPath, ConstantsResourcesPath.FILE_PROFILE);

        Debug.Log("[GLOBAL.PROFILE] Starting save profile: " + profilePath);

        string json = JsonUtility.ToJson((Profile)_pr, true);

        if (!File.Exists(profilePath + ".json"))
        {
            File.Create(profilePath + ".json").Dispose();
        }

        //Шифруем
        if (encrypting)
        {
            json = SimpleEncrypting.Encode(json);
        }

        File.WriteAllText(profilePath + ".json", json);

        Debug.Log("<color=#FFD800>[GLOBAL.PROFILE] Save profile complete</color>");
        Debug.Log("[GLOBAL.PROFILE] TOTAL TIME (ms): " + (DateTime.UtcNow - startTime).TotalMilliseconds);
    }
コード例 #2
0
    public static Profile LoadProfile()
    {
        var encrypting = MainGameManager.Instance.usingEncryption;

        var    startTime   = DateTime.UtcNow;
        string profilePath = Path.Combine(Application.persistentDataPath, ConstantsResourcesPath.FILE_PROFILE);

        Debug.Log("[GLOBAL.PROFILE] Starting load profile: " + profilePath);

        if (File.Exists(profilePath + ".json"))
        {
            string json = File.ReadAllText(profilePath + ".json");

            try
            {
                //Дешифруем
                if (encrypting)
                {
                    json = SimpleEncrypting.Decode(json);
                }

                Debug.Log("[GLOBAL.PROFILE] Load profile complete");
                Debug.Log("[GLOBAL.PROFILE] TOTAL TIME (ms): " + (DateTime.UtcNow - startTime).TotalMilliseconds);

                return(JsonUtility.FromJson <Profile>(json));
            }
            catch
            {
                Debug.LogError("<color=#FF0000>[GLOBAL.PROFILE] File failed to decrypt! Profile is delete</color>");

                File.Delete(profilePath + ".json");
                return(LoadProfile());
            }
        }
        else
        {
            Profile profile = new Profile();
            profile.ApplyDefaultSettings();

            Debug.LogWarning("<color=#FF0000>[GLOBAL.PROFILE] File not found. Apply default profile</color>");
            Debug.Log("[GLOBAL.PROFILE] TOTAL TIME (ms): " + (DateTime.UtcNow - startTime).TotalMilliseconds);

            return(profile);
        }
    }
コード例 #3
0
 private void OnDecode()
 {
     //Дешифруем
     secondData = SimpleEncrypting.Decode(firstData);
 }
コード例 #4
0
 private void OnCode()
 {
     //Шифруем
     secondData = SimpleEncrypting.Encode(firstData);
 }