public LoadResult <T> Load <T>(string filename) { byte[] bytes; try { var result = Resolver.LoadBytes(filename); if (!result.Succeeded) { return(result.CreateFailed <T>()); } bytes = result.value; } catch (System.Exception ex) { Debug.LogException(ex); return(LoadResult <T> .CreateError(ex)); } try { var t = SerialzieResolver.Deserialize <T>(bytes); return(new LoadResult <T>(t)); } catch (System.Exception ex) { Debug.LogError(filename + " broken"); Debug.LogException(ex); return(LoadResult <T> .CreateFailedDeserialize(ex)); } }
public async UniTask <LoadResult <T> > LoadAsync <T>(string filename) { var progress = LoadingProgress.Instance.Add(); try { byte[] bytes; try { var result = await Resolver.LoadBytesAsync(filename); if (!result.Succeeded) { return(result.CreateFailed <T>()); } bytes = result.value; } catch (System.Exception ex) { Debug.LogException(ex); return(LoadResult <T> .CreateError(ex)); } progress.Report(0.5f); try { #if UNITY_WEBGL var t = SerialzieResolver.Deserialize <T>(bytes); #else var t = await UniTask.Run(() => SerialzieResolver.Deserialize <T>(bytes)); #endif return(new LoadResult <T>(t)); } catch (System.Exception ex) { Debug.LogError(filename + " broken"); Debug.LogException(ex); return(LoadResult <T> .CreateFailedDeserialize(ex)); } } finally { progress.Report(1f); } }