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; } } } }
public void DebugDeleteARLevel() { if (File.Exists(PersistentDataPath.Get() + "/ARLevel.idl")) { ARLevel.Value = null; File.Delete(PersistentDataPath.Get() + "/ARLevel.idl"); } }
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"); }
private void SaveBackup(BaseData baseData) { try { File.WriteAllText(PersistentDataPath.Get() + "/saveGameBak.idl", Encryptor.Encrypt(DataToJSON(baseData).ToString())); } catch (IOException) { ShowDiskFullDialog(); } }
public void Save(JSONObject json) { try { File.WriteAllText(PersistentDataPath.Get() + "/ARLevel.idl", Encryptor.Encrypt(json.ToString())); } catch (IOException) { SaveLoad.ShowDiskFullDialog(); } }
public void Save(FacebookAPIService service) { try { File.WriteAllText(PersistentDataPath.Get() + "/fbData.idl", FacebookDataToJSON(service).ToString()); } catch (IOException) { SaveLoad.ShowDiskFullDialog(); } }
private void SaveTournamentRuns(JSONObject json) { try { File.WriteAllText(PersistentDataPath.Get() + "/saveHelp.idl", Encryptor.Encrypt(json.ToString())); } catch (IOException) { SaveLoad.ShowDiskFullDialog(); } }
private void LoadFile(FacebookAPIService service, string fileName) { if (!File.Exists(PersistentDataPath.Get() + fileName)) { CreateEmptyData(service); } else { JSONToFacebookData(LoadToJSON(fileName), service); } }
public void WriteCustomInfo(JSONObject customInfo) { try { File.WriteAllText(PersistentDataPath.Get() + "/craftcustominfo.txt", Encryptor.Encrypt(customInfo.ToString())); } catch (IOException) { SaveLoad.ShowDiskFullDialog(); } }
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(); } }
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); }
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; } } }
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"); }
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); } } }
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); }
private string GetFilePath(string key) { return(PersistentDataPath.Get() + "/" + baseDir + "/" + MakeValidFileName(key)); }
public bool FileExists(string fileName) { string path = PersistentDataPath.Get() + "/" + fileName; return(File.Exists(path)); }