Пример #1
0
 public void LoadARLevel()
 {
     if (File.Exists(PersistentDataPath.Get() + "/ARLevel.idl"))
     {
         string     cipherText = File.ReadAllText(PersistentDataPath.Get() + "/ARLevel.idl");
         string     str        = Encryptor.Decrypt(cipherText);
         JSONObject jSONObject = new JSONObject(str);
         if (jSONObject.HasField("Blocks"))
         {
             Transform blockContainer = ARBindingManager.Instance.BlockContainer;
             blockContainer.DestroyChildrenImmediate();
             List <JSONObject> list = jSONObject.GetField("Blocks").list;
             foreach (JSONObject item in list)
             {
                 string     text          = item.asString("Type", () => string.Empty);
                 int        num           = item.asInt("Size", () => 0);
                 Vector3    localPosition = new Vector3(item.asFloat("X", () => 0f), item.asFloat("Y", () => 0f), item.asFloat("Z", () => 0f));
                 Quaternion rotation      = ARBindingManager.Instance.World.transform.rotation;
                 GameObject gameObject    = GameObjectExtensions.InstantiateFromResources("Blocks/AR/" + text + "Cube_" + num + "x" + num, Vector3.zero, rotation);
                 Transform  transform     = gameObject.transform;
                 Vector3    one           = Vector3.one;
                 Vector3    localScale    = ARBindingManager.Instance.World.transform.localScale;
                 transform.localScale = one * localScale.x;
                 gameObject.transform.SetParent(blockContainer);
                 gameObject.transform.localPosition = localPosition;
             }
         }
     }
 }
Пример #2
0
 public void DebugDeleteARLevel()
 {
     if (File.Exists(PersistentDataPath.Get() + "/ARLevel.idl"))
     {
         ARLevel.Value = null;
         File.Delete(PersistentDataPath.Get() + "/ARLevel.idl");
     }
 }
Пример #3
0
    private JSONObject LoadToJSON(string fileName)
    {
        string text = File.ReadAllText(PersistentDataPath.Get() + fileName);

        if (text.Contains("FBPlayers"))
        {
            return(JSONObject.Create(text));
        }
        throw new Exception("Could not find FBPlayers in save file");
    }
Пример #4
0
 private void SaveBackup(BaseData baseData)
 {
     try
     {
         File.WriteAllText(PersistentDataPath.Get() + "/saveGameBak.idl", Encryptor.Encrypt(DataToJSON(baseData).ToString()));
     }
     catch (IOException)
     {
         ShowDiskFullDialog();
     }
 }
Пример #5
0
 public void Save(JSONObject json)
 {
     try
     {
         File.WriteAllText(PersistentDataPath.Get() + "/ARLevel.idl", Encryptor.Encrypt(json.ToString()));
     }
     catch (IOException)
     {
         SaveLoad.ShowDiskFullDialog();
     }
 }
Пример #6
0
 public void Save(FacebookAPIService service)
 {
     try
     {
         File.WriteAllText(PersistentDataPath.Get() + "/fbData.idl", FacebookDataToJSON(service).ToString());
     }
     catch (IOException)
     {
         SaveLoad.ShowDiskFullDialog();
     }
 }
Пример #7
0
 private void SaveTournamentRuns(JSONObject json)
 {
     try
     {
         File.WriteAllText(PersistentDataPath.Get() + "/saveHelp.idl", Encryptor.Encrypt(json.ToString()));
     }
     catch (IOException)
     {
         SaveLoad.ShowDiskFullDialog();
     }
 }
Пример #8
0
 private void LoadFile(FacebookAPIService service, string fileName)
 {
     if (!File.Exists(PersistentDataPath.Get() + fileName))
     {
         CreateEmptyData(service);
     }
     else
     {
         JSONToFacebookData(LoadToJSON(fileName), service);
     }
 }
Пример #9
0
 public void WriteCustomInfo(JSONObject customInfo)
 {
     try
     {
         File.WriteAllText(PersistentDataPath.Get() + "/craftcustominfo.txt", Encryptor.Encrypt(customInfo.ToString()));
     }
     catch (IOException)
     {
         SaveLoad.ShowDiskFullDialog();
     }
 }
Пример #10
0
 public void DebugSaveTo(BaseData data, string filename, string reason)
 {
     data.LastSaved   = ServerTimeService.NowTicks();
     data.LastSavedBy = reason;
     try
     {
         File.WriteAllText(PersistentDataPath.Get() + filename, Encryptor.Encrypt(DataToJSON(data).ToString()));
     }
     catch (IOException)
     {
         ShowDiskFullDialog();
     }
 }
Пример #11
0
    public static bool SaveTexture2DAsPNG(Texture2D tex, string fileName)
    {
        byte[] bytes = tex.EncodeToPNG();
        string path  = PersistentDataPath.Get() + "/" + fileName;

        try
        {
            File.WriteAllBytes(path, bytes);
        }
        catch (Exception ex)
        {
            UnityEngine.Debug.LogWarning("Caught serializationException: " + ex.Message + " while writing PNG data.");
            return(false);
        }
        return(true);
    }
Пример #12
0
 private void LoadARLevel(string fileName)
 {
     if (File.Exists(PersistentDataPath.Get() + fileName))
     {
         string     cipherText = File.ReadAllText(PersistentDataPath.Get() + "/ARLevel.idl");
         string     str        = Encryptor.Decrypt(cipherText);
         JSONObject jSONObject = new JSONObject(str);
         int        num        = jSONObject.asInt("Amount", () => 0);
         if (num < 30 || num > 500)
         {
             ARLevel.Value = null;
         }
         else if (jSONObject.HasField("Blocks"))
         {
             List <JSONObject> list = jSONObject.GetField("Blocks").list;
             ARLevel.Value = list;
         }
     }
 }
Пример #13
0
    private JSONObject LoadToJSON(string fileName)
    {
        string text  = File.ReadAllText(PersistentDataPath.Get() + fileName);
        string text2 = Encryptor.Decrypt(text);

        if (text2.Contains("PlayerId"))
        {
            return(JSONObject.Create(text2));
        }
        TrackLoadingError(GetPlayerId(text2), new Dictionary <string, object>
        {
            {
                "encrypted",
                text
            },
            {
                "decrypted",
                text2
            }
        });
        throw new Exception("Could not find PlayerId in save file");
    }
Пример #14
0
 private void LoadFile(BaseData data, string fileName, bool shouldSaveBackup, Action <BaseData> funcLoadDefault)
 {
     if (!File.Exists(PersistentDataPath.Get() + fileName))
     {
         funcLoadDefault(data);
     }
     else
     {
         try
         {
             JSONToData(LoadToJSON(fileName), data);
             if (shouldSaveBackup)
             {
                 SaveBackup(data);
             }
         }
         catch (Exception)
         {
             funcLoadDefault(data);
         }
     }
 }
Пример #15
0
    public static Texture2D LoadPNGAsTexture2D(string fileName, int width, int height)
    {
        Texture2D texture2D = null;
        string    path      = PersistentDataPath.Get() + "/" + fileName;

        if (File.Exists(path))
        {
            byte[] data;
            try
            {
                data = File.ReadAllBytes(path);
            }
            catch (Exception ex)
            {
                UnityEngine.Debug.LogWarning("Caught serializationException: " + ex.Message + " while reading PNG file.");
                return(texture2D);
            }
            texture2D = new Texture2D(width, height);
            texture2D.LoadImage(data);
        }
        return(texture2D);
    }
Пример #16
0
 private string GetFilePath(string key)
 {
     return(PersistentDataPath.Get() + "/" + baseDir + "/" + MakeValidFileName(key));
 }
Пример #17
0
    public bool FileExists(string fileName)
    {
        string path = PersistentDataPath.Get() + "/" + fileName;

        return(File.Exists(path));
    }