AssetInfo.cs 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. 
  2. namespace YooAsset
  3. {
  4. public class AssetInfo
  5. {
  6. private readonly PatchAsset _patchAsset;
  7. private string _providerGUID;
  8. /// <summary>
  9. /// 唯一标识符
  10. /// </summary>
  11. internal string GUID
  12. {
  13. get
  14. {
  15. if (string.IsNullOrEmpty(_providerGUID) == false)
  16. return _providerGUID;
  17. if (AssetType == null)
  18. _providerGUID = $"{AssetPath}[null]";
  19. else
  20. _providerGUID = $"{AssetPath}[{AssetType.Name}]";
  21. return _providerGUID;
  22. }
  23. }
  24. /// <summary>
  25. /// 身份是否无效
  26. /// </summary>
  27. internal bool IsInvalid
  28. {
  29. get
  30. {
  31. return _patchAsset == null;
  32. }
  33. }
  34. /// <summary>
  35. /// 错误信息
  36. /// </summary>
  37. internal string Error { private set; get; }
  38. /// <summary>
  39. /// 可寻址地址
  40. /// </summary>
  41. public string Address { private set; get; }
  42. /// <summary>
  43. /// 资源路径
  44. /// </summary>
  45. public string AssetPath { private set; get; }
  46. /// <summary>
  47. /// 资源类型
  48. /// </summary>
  49. public System.Type AssetType { private set; get; }
  50. // 注意:这是一个内部类,严格限制外部创建。
  51. private AssetInfo()
  52. {
  53. }
  54. internal AssetInfo(PatchAsset patchAsset, System.Type assetType)
  55. {
  56. if (patchAsset == null)
  57. throw new System.Exception("Should never get here !");
  58. _patchAsset = patchAsset;
  59. AssetType = assetType;
  60. Address = patchAsset.Address;
  61. AssetPath = patchAsset.AssetPath;
  62. Error = string.Empty;
  63. }
  64. internal AssetInfo(PatchAsset patchAsset)
  65. {
  66. if (patchAsset == null)
  67. throw new System.Exception("Should never get here !");
  68. _patchAsset = patchAsset;
  69. AssetType = null;
  70. Address = patchAsset.Address;
  71. AssetPath = patchAsset.AssetPath;
  72. Error = string.Empty;
  73. }
  74. internal AssetInfo(string error)
  75. {
  76. _patchAsset = null;
  77. AssetType = null;
  78. Address = string.Empty;
  79. AssetPath = string.Empty;
  80. Error = error;
  81. }
  82. }
  83. }