// Save asset public static void Snapshot(GameObject gameObject, bool compress, string assetName) { // Get all nested game objects List <Transform> tms = gameObject.GetComponentsInChildren <Transform>().ToList(); tms.Remove(gameObject.transform); // No asset if (tms.Count == 0) { Debug.Log("RayFire Snapshot: " + gameObject.name + " has no children", gameObject); return; } // Create asset data List <GameObject> list = tms.Select(t => t.gameObject).ToList(); RFSnapshotAsset data = new RFSnapshotAsset(list, compress); // Set Folder string fld = Application.dataPath + "/RayFireSnapshots/"; if (Directory.Exists(fld) == false) { Directory.CreateDirectory(fld); } string nm = assetName + "_snapshot.json"; string stringData = JsonUtility.ToJson(data, true); // Save data File.WriteAllText(fld + nm, stringData); AssetDatabase.SaveAssets(); AssetDatabase.Refresh(); }
// Load asset public static void Load(UnityEngine.Object snapshotAsset, GameObject gameObject, float sizeFilter) { // No asset if (snapshotAsset == null) { Debug.Log("RayFire Snapshot: " + gameObject.name + " Snapshot asset is not defined", gameObject); return; } // Get path string path1 = Application.dataPath; string path2 = AssetDatabase.GetAssetPath(snapshotAsset); path2 = path2.Remove(0, 6); // Read string dataString = File.ReadAllText(path1 + path2); RFSnapshotAsset assetData = JsonUtility.FromJson <RFSnapshotAsset> (dataString); // No asset if (assetData == null) { Debug.Log("RayFire Snapshot: " + gameObject.name + " Snapshot asset is not defined", gameObject); return; } // Create objects from asset if (assetData.assets.Count > 0) { foreach (var ast in assetData.assets) { RFSnapshot.Create(ast, sizeFilter); } } // Set parents foreach (var snap in assetData.assets) { RFSnapshot.SetParent(assetData.assets, snap.parentOldId, snap.newTm, gameObject.transform); } }
// Load asset public void Load() { RFSnapshotAsset.Load(snapshotAsset, gameObject, sizeFilter); }
// Save asset public void Snapshot() { RFSnapshotAsset.Snapshot(gameObject, compress, assetName); }