DownloadBundleDevice.cs 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. using UnityEngine;
  2. using System.Collections;
  3. using System.IO;
  4. public class DownloadBundleDevice : MonoBehaviour
  5. {
  6. private static string[] _files =new []{ "default_background", "default_hd" , "default_scenery", "default_sd", "default_shd" };
  7. private static string Platform
  8. {
  9. get
  10. {
  11. #if UNITY_ANDROID
  12. return "Android";
  13. #endif
  14. #if UNITY_IPHONE
  15. return "iPhone";
  16. #endif
  17. return "";
  18. }
  19. }
  20. public static void Extract()
  21. {
  22. var path = Application.persistentDataPath.TrimEnd('/') + "/" + Platform;
  23. if (!Directory.Exists(path))
  24. {
  25. Directory.CreateDirectory(path);
  26. }
  27. foreach (var file in _files)
  28. {
  29. var data = Resources.Load<TextAsset>(Platform + "/" + file).bytes;
  30. var manifest = Resources.Load<TextAsset>(Platform + "/" + file + ".bytes").text;
  31. File.WriteAllBytes(path + "/" + file + ".unity3d", data);
  32. File.WriteAllText(path + "/" + file + ".unity3d.manifest", manifest);
  33. Debug.Log("Path " + path);
  34. //Debug.Log(path + "/" + file + ".unity3d");
  35. }
  36. /*for (int i = 0; i < _files.Length; i++)
  37. {
  38. }*/
  39. }
  40. }