DownloadData.cs 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. using LitJson;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.IO;
  5. using UnityEngine;
  6. public class DownloadData
  7. {
  8. /// <summary>
  9. /// 素材名称
  10. /// </summary>
  11. public string name;
  12. /// <summary>
  13. /// 素材类型
  14. /// </summary>
  15. public int type;
  16. /// <summary>
  17. /// 素材下载地址
  18. /// </summary>
  19. public string downloadPath;
  20. /// <summary>
  21. /// 本地保存地址
  22. /// </summary>
  23. public string localSavePath;
  24. /// <summary>
  25. /// 更新时间
  26. /// </summary>
  27. public int updateTime;
  28. public DownloadData()
  29. {
  30. name = "";
  31. type = 0;
  32. downloadPath = "";
  33. localSavePath = "";
  34. updateTime = 0;
  35. }
  36. public DownloadData(MaterialObjValue mat)
  37. {
  38. type = int.Parse(mat.type);
  39. downloadPath = string.IsNullOrWhiteSpace(mat.DownloadPath) ? "" : mat.DownloadPath;
  40. string filename = Path.GetFileName(downloadPath);
  41. name = string.IsNullOrWhiteSpace(mat.name) ? filename : mat.name;
  42. if (string.IsNullOrWhiteSpace(mat.localSavePath))
  43. {
  44. //localSavePath = FileManager.CalFilePath(Path.Combine(DownloadManager.Instance.LocaDataPath, filename));
  45. switch (type)
  46. {
  47. case 1: //image
  48. localSavePath = DownloadManager.Instance.LocaDataPath + "/Image/" + filename;
  49. break;
  50. case 2: //video
  51. localSavePath = DownloadManager.Instance.LocaDataPath + "/video/" + filename;
  52. break;
  53. case 3: //model
  54. localSavePath = DownloadManager.Instance.LocaDataPath + "/Model/" + filename;
  55. name = filename;
  56. break;
  57. default:
  58. break;
  59. }
  60. //Debug.Log(localSavePath);
  61. }
  62. else
  63. {
  64. localSavePath = mat.localSavePath;
  65. }
  66. }
  67. public DownloadData(JsonData json)
  68. {
  69. name = (string)json["name"];
  70. type = (int)json["type"];
  71. downloadPath = (string)json["downloadPath"];
  72. localSavePath = (string)json["localSavePath"];
  73. updateTime = (int)json["updateTime"];
  74. }
  75. public JsonData ToJsonData()
  76. {
  77. JsonData data = new JsonData();
  78. data["name"] = name;
  79. data["type"] = type;
  80. data["downloadPath"] = downloadPath;
  81. data["localSavePath"] = localSavePath;
  82. data["updateTime"] = updateTime;
  83. return data;
  84. }
  85. }