Created
January 4, 2019 19:54
-
-
Save Zammy/12ab6d241eff410ead1535db4a2fc064 to your computer and use it in GitHub Desktop.
Loading json file from streamingAssets on Android using UniRx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static IObservable<RoomData> LoadLevel(string gymRoom) | |
{ | |
string path = System.IO.Path.Combine(Application.streamingAssetsPath, "Levels"); | |
path = System.IO.Path.Combine(path, gymRoom + ".room"); | |
#if UNITY_ANDROID && !UNITY_EDITOR | |
return ObservableWWW.Get(path) | |
#else | |
return Observable.ReturnUnit() | |
.SubscribeOn(Scheduler.ThreadPool) | |
.Select(_ => System.IO.File.ReadAllText(path)) | |
#endif | |
.Select(roomJsonData => | |
{ | |
return JsonUtility.FromJson<RoomData>(roomJsonData); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment