public virtual void SaveLevel(LevelEditorSaveData saveData, string path) { string saveFolder = Path.GetDirectoryName(path); if (!Directory.Exists(saveFolder)) { Directory.CreateDirectory(saveFolder); } LevelSavingLoadingArgs args = new LevelSavingLoadingArgs(saveData, path); OnLevelSaving?.Invoke(this, args); if (args.Cancel) { LevelEditorLogger.Log("LevelEditorSaveManager saving was canceled."); return; } saveData.customData = args.GetAllCustomData(); switch (levelFormat) { case FormatType.JSON: string json = LevelEditorSerializer.SerializeJson(saveData); File.WriteAllText(path, json); break; case FormatType.Binary: byte[] bytes = LevelEditorSerializer.SerializeBinary(saveData, compress); File.WriteAllBytes(path, bytes); break; } OnLevelSaved?.Invoke(this, new LevelEventArgs(saveData)); }
private static void DeserializeFormat1(ref MessagePackReader reader, MessagePackSerializerOptions options, ref Type type, ref object value) { int count = reader.ReadArrayHeader(); for (int i = 0; i < count; i++) { switch (i) { case 0: type = LevelEditorSerializer.GetType(reader.ReadInt32()); break; case 1: if (type == null) { Debug.LogWarning("Can't deserialize some custom data because no type for it was found."); reader.Skip(); break; } ((LevelEditorResolver)LevelEditorResolver.instance).DeserializeDynamic(type, ref reader, out value, options); break; } } }
public virtual LevelEditorSaveData LoadLevel(string path) { loadLocation = path; LevelEditorSaveData data; if (!File.Exists(path)) { Debug.LogError($"There's no file with path '{path}'."); return(new LevelEditorSaveData()); } switch (levelFormat) { case FormatType.JSON: data = LevelEditorSerializer.DeserializeJson <LevelEditorSaveData>(File.ReadAllText(path)); break; case FormatType.Binary: data = LevelEditorSerializer.DeserializeBinary <LevelEditorSaveData>(File.ReadAllBytes(path), compress); break; default: data = new LevelEditorSaveData(); break; } return(LoadLevel(data)); }
private static void DeserializeFormat1(ref MessagePackReader reader, MessagePackSerializerOptions options, ref Type type, ref IExposedWrapper wrapper) { int count = reader.ReadArrayHeader(); for (int i = 0; i < count; i++) { switch (i) { case 0: var typeHash = reader.ReadInt32(); type = LevelEditorSerializer.GetType(typeHash); break; case 1: if (type == null) { reader.Skip(); continue; } ((LevelEditorResolver)LevelEditorResolver.instance).DeserializeWrapper(type, ref reader, options, out wrapper); break; } } }
private static void RegisterRigidbodyWrapper() { LevelEditorSerializer.RegisterType <Rigidbody>(); if (ALESettings.Get().ApplyRigidbodyWrapper) { RegisterWrapper <Rigidbody, RigidbodyWrapper>(); } }
private static void RegisterTransformWrapper() { LevelEditorSerializer.RegisterType <Transform>(); if (ALESettings.Get().ApplyTransformWrapper) { RegisterWrapper <Transform, TransformWrapper>(); } }
private static void DeserializeFormat0(ref MessagePackReader reader, MessagePackSerializerOptions options, ref Type type, ref IExposedWrapper wrapper) { int count = reader.ReadMapHeader(); int typeHash = 0; for (int i = 0; i < count; i++) { ReadOnlySpan <byte> stringKey = CodeGenHelpers.ReadStringSpan(ref reader); switch (stringKey.Length) { default: FAIL: reader.Skip(); continue; case 4: if (AutomataKeyGen.GetKey(ref stringKey) != 1701869940UL) { goto FAIL; } typeHash = reader.ReadInt32(); type = LevelEditorSerializer.GetType(typeHash); continue; case 10: if (!stringKey.SequenceEqual(SpanProperties.Slice(1))) { goto FAIL; } if (type == null) { Debug.LogWarning($"Couldn't find a wrapper for type hash {typeHash}."); reader.Skip(); continue; } ((LevelEditorResolver)LevelEditorResolver.instance).DeserializeWrapper(type, ref reader, options, out wrapper); continue; } } }
private static void DeserializeFormat0(ref MessagePackReader reader, MessagePackSerializerOptions options, ref Type type, ref object value) { int count = reader.ReadMapHeader(); int typeHash = 0; for (int i = 0; i < count; i++) { ReadOnlySpan <byte> stringKey = CodeGenHelpers.ReadStringSpan(ref reader); switch (stringKey.Length) { default: FAIL: reader.Skip(); continue; case 4: if (AutomataKeyGen.GetKey(ref stringKey) != 1701869940UL) { goto FAIL; } typeHash = reader.ReadInt32(); type = LevelEditorSerializer.GetType(typeHash); continue; case 5: if (AutomataKeyGen.GetKey(ref stringKey) != 435761734006UL) { goto FAIL; } if (type == null) { Debug.LogWarning($"Can't deserialize some custom data because there's no type with hash {typeHash}."); reader.Skip(); break; } ((LevelEditorResolver)LevelEditorResolver.instance).DeserializeDynamic(type, ref reader, out value, options); continue; } } }
public virtual LevelEditorSaveData LoadLevelFromJson(string json) { LevelEditorSaveData data = LevelEditorSerializer.DeserializeJson <LevelEditorSaveData>(json); return(LoadLevel(data)); }
public virtual LevelEditorSaveData LoadLevelFromBytes(byte[] levelBytes) { LevelEditorSaveData data = LevelEditorSerializer.DeserializeBinary <LevelEditorSaveData>(levelBytes, compress); return(LoadLevel(data)); }