/// <summary> /// /// </summary> /// <param name="stream"></param> /// <param name="validateData">是否校验数据</param> /// <returns></returns> public static SceneChunkData Deserialize(Stream stream, bool validateData) { using (var reader = new TableStreamReader(stream, validateData)) { var chunkData = new SceneChunkData(); chunkData._Read(reader); return(chunkData); } }
/// <summary> /// /// </summary> /// <param name="stream"></param> /// <param name="validateData"></param> /// <param name="callback"></param> public static void DeserializeAsync(Stream stream, bool validateData, Action <SceneChunkData> callback) { var reader = new TableStreamAsyncReader(stream, validateData); var chunkData = new SceneChunkData(); chunkData._ReadAsync(reader); reader.StartAsync(READ_COUNT_PER_FRAME, () => { if (null != callback) { callback(chunkData); } }); }
public override void Enter(StateMachine stateMachine) { this.completed = false; var chunk = stateMachine.Model as SceneChunk; chunk._Objects = new List <SceneObject>(); ServiceCenter.GetService <IAssetManager>().LoadAsync(chunk._ChunkRefData.Path + ".bytes", AssetType.BYTES, asset => { if (null != asset) { var stream = new MemoryStream(asset.Cast <byte[]>()); SceneChunkData.DeserializeAsync(stream, chunk._ValidateData, chunkData => { stream.Close(); stream.Dispose(); for (var i = 0; i < chunkData.Objects.Count; ++i) { var go = new GameObject(); go.transform.SetParent(chunk._ChunkRoot.transform); var objectData = chunkData.Objects[i]; SceneObject obj = null; switch (objectData.Type) { case SceneObjectType.PREFAB: obj = new ScenePrefab(objectData, go); go.name = "_Prefab"; break; case SceneObjectType.LIGHTMODIFIER: obj = new SceneLightModifier(objectData, go); go.name = "_LightModifier"; break; default: go.name = "_SceneObject"; break; } chunk._Objects.Add(obj); } this.completed = true; }); } asset.Dispose(); }); }
public void Load() { using (var asset = ServiceCenter.GetService <IAssetManager>().Load(this.chunkRefData.Path + ".bytes", AssetType.BYTES)) { var bytes = asset.Cast <byte[]>(); if (null != bytes) { this.objects = new List <SceneObject>(); using (var stream = new MemoryStream(bytes)) { var chunkData = SceneChunkData.Deserialize(stream, this.validateData); for (var i = 0; i < chunkData.Objects.Count; ++i) { var go = new GameObject(); go.transform.SetParent(this.chunkRoot.transform); var objectData = chunkData.Objects[i]; SceneObject obj = null; switch (objectData.Type) { case SceneObjectType.PREFAB: obj = new ScenePrefab(objectData, go); go.name = "_Prefab"; break; case SceneObjectType.LIGHTMODIFIER: obj = new SceneLightModifier(objectData, go); go.name = "_LightModifier"; break; default: go.name = "_SceneObject"; break; } this.objects.Add(obj); obj.Load(); } } } } }
/// <summary> /// /// </summary> /// <param name="stream"></param> /// <param name="chunkData"></param> public static void Serialize(Stream stream, SceneChunkData chunkData) { using (var writer = new TableStreamWriter(stream)) { chunkData._Write(writer); } }