Skip to content

Instantly share code, notes, and snippets.

@Zammy
Created January 4, 2019 19:54
Show Gist options
  • Save Zammy/12ab6d241eff410ead1535db4a2fc064 to your computer and use it in GitHub Desktop.
Save Zammy/12ab6d241eff410ead1535db4a2fc064 to your computer and use it in GitHub Desktop.
Loading json file from streamingAssets on Android using UniRx
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