WWWHelper.cs 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using UnityEngine;
  6. using System.Collections;
  7. namespace CommonUI_Unity3D_Android
  8. {
  9. public class WWWHelper
  10. {
  11. #if UNITY_ANDROID
  12. private static AndroidJavaClass _helper;
  13. private static AndroidJavaClass helper
  14. {
  15. get
  16. {
  17. if (_helper != null) return _helper;
  18. _helper = new AndroidJavaClass("com.morefun.WWWHelper");
  19. using (AndroidJavaClass jc = new AndroidJavaClass("com.unity3d.player.UnityPlayer"))
  20. {
  21. object jo = jc.GetStatic<AndroidJavaObject>("currentActivity");
  22. _helper.CallStatic("init", jo);
  23. }
  24. return helper;
  25. }
  26. }
  27. #endif
  28. public static bool isFileExists(string path)
  29. {
  30. #if UNITY_ANDROID
  31. return helper.CallStatic<bool>("isFileExists", path);
  32. #else
  33. return false;
  34. #endif
  35. }
  36. public static byte[] getJavaData(string path)
  37. {
  38. #if UNITY_ANDROID
  39. byte[] imageByte = helper.CallStatic<byte[]>("getBytes", path);
  40. return imageByte;
  41. #else
  42. return null;
  43. #endif
  44. }
  45. }
  46. }