//Save, Load and New methods #region public static string SaveGame(string prefix) { string year = (System.DateTime.Now.Year - 2000).ToString("D2"); string month = System.DateTime.Now.Month.ToString("D2"); string day = System.DateTime.Now.Day.ToString("D2"); string hour = System.DateTime.Now.TimeOfDay.Hours.ToString("D2"); string minute = System.DateTime.Now.TimeOfDay.Minutes.ToString("D2"); string timeCode = prefix + year + month + day + "_" + hour + "-" + minute + ".json"; string path = SavePath + "\\"; int i = 2; while (ContainsFile(timeCode, path)) { timeCode = prefix + year + month + day + "_" + hour + "-" + minute + "_" + i.ToString() + ".json"; ++i; } path = path + timeCode; AssemblyIO.Save(GlobalReferences.FrozenParts, 10, path); return(timeCode); }
//Save, Load and New methods #region public static string SaveGame(string prefix, bool export = false, string subFolder = "") { string timeCode = prefix + BuildDateString() + ".json"; string path = SavePath + "/" + subFolder; try { Directory.CreateDirectory(path + "/"); } catch { } int i = 2; while (ContainsFile(timeCode, path)) { timeCode = prefix + BuildDateString() + "_" + i.ToString() + ".json"; ++i; } if (!export) { path = path + timeCode; } else { path = path + prefix + "export.json"; } AssemblyIO.Save(GlobalReferences.FrozenParts, 10, path); return(timeCode); }
public static void ParentAndSimulate(TextMeshPro tm) { List <Rigidbody> rbs = new List <Rigidbody>(); AssemblyIO.Save(GlobalReferences.FrozenParts, 1, tempPath); foreach (GameObject go in GlobalReferences.FrozenParts.Values) { int?parentId = go.GetComponent <Part>().Parent; Destroy(go.GetComponent <ConstantForce>()); if (parentId != null && GlobalReferences.FrozenParts.ContainsKey((int)parentId)) { go.transform.parent = GlobalReferences.FrozenParts[(int)parentId].transform; Destroy(go.GetComponent <Rigidbody>()); } else { rbs.Add(go.GetComponent <Rigidbody>()); SimulationProcessHandler handler = go.AddComponent <SimulationProcessHandler>(); handlers.Add(handler); handler.TM = tm; handler.SimulationTerminated += new SimulationProcessHandler.SimulationHandler(AfterSimulation); } } foreach (Rigidbody rb in rbs) { rb.useGravity = true; rb.constraints = RigidbodyConstraints.None; } ChangeColliders(false); }
public static void AfterSimulation(TextMeshPro tm) { ++handlerCallBack; if (handlerCallBack == handlers.Count) { SaveLoadTool.SaveGame("Sim_"); List <GameObject> tempGos = new List <GameObject>(); foreach (GameObject go in GlobalReferences.FrozenParts.Values) { tempGos.Add(go); } GlobalReferences.FrozenParts.Clear(); ChangeColliders(true); for (int i = tempGos.Count - 1; i >= 0; --i) { Destroy(tempGos[i]); } AssemblyIO.Load(tempPath); GlobalReferences.RebuildIndices(); tm.text = "Run\nSimulation"; tm.faceColor = GlobalReferences.UnaffectedColor; simulationInProgress = false; handlers.Clear(); handlerCallBack = 0; } }
static void Export(TIExportAR exportItem) { if (GlobalReferences.FrozenParts.Count > 1) { int k = 0; foreach (int kk in GlobalReferences.FrozenParts.Keys) { if (kk > k) { k = kk; } } GlobalReferences.DeletePart(k); ParentAndSimulate(exportItem, true); --expCount; } else { exportItem.ResetTool(); simulationInProgress = false; int k = 0; foreach (int i in GlobalReferences.FrozenParts.Keys) { k = i; } GlobalReferences.DeletePart(k); expCount = 0; AssemblyIO.Load(expTempPath); ControllerReferences.ControllerTarget.SetActive(true); } }
public static void LoadGame(string path) { Debug.Log(SavePath + "/" + path); AssemblyIO.Load(SavePath + "/" + path); GlobalReferences.RebuildIndices(); }
public static JsonAssembly SaveExportTemp() { return(AssemblyIO.Save(GlobalReferences.FrozenParts, 1, expTempPath)); }