PackageVersionList.cs 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. //------------------------------------------------------------
  2. // Game Framework
  3. // Copyright © 2013-2021 Jiang Yin. All rights reserved.
  4. // Homepage: https://gameframework.cn/
  5. // Feedback: mailto:ellan@gameframework.cn
  6. //------------------------------------------------------------
  7. using System.Runtime.InteropServices;
  8. namespace GameFramework.Resource
  9. {
  10. /// <summary>
  11. /// 单机模式版本资源列表。
  12. /// </summary>
  13. [StructLayout(LayoutKind.Auto)]
  14. public partial struct PackageVersionList
  15. {
  16. private static readonly Asset[] EmptyAssetArray = new Asset[] { };
  17. private static readonly Resource[] EmptyResourceArray = new Resource[] { };
  18. private static readonly FileSystem[] EmptyFileSystemArray = new FileSystem[] { };
  19. private static readonly ResourceGroup[] EmptyResourceGroupArray = new ResourceGroup[] { };
  20. private readonly bool m_IsValid;
  21. private readonly string m_ApplicableGameVersion;
  22. private readonly int m_InternalResourceVersion;
  23. private readonly Asset[] m_Assets;
  24. private readonly Resource[] m_Resources;
  25. private readonly FileSystem[] m_FileSystems;
  26. private readonly ResourceGroup[] m_ResourceGroups;
  27. /// <summary>
  28. /// 初始化单机模式版本资源列表的新实例。
  29. /// </summary>
  30. /// <param name="applicableGameVersion">适配的游戏版本号。</param>
  31. /// <param name="internalResourceVersion">内部资源版本号。</param>
  32. /// <param name="assets">包含的资源集合。</param>
  33. /// <param name="resources">包含的资源集合。</param>
  34. /// <param name="fileSystems">包含的文件系统集合。</param>
  35. /// <param name="resourceGroups">包含的资源组集合。</param>
  36. public PackageVersionList(string applicableGameVersion, int internalResourceVersion, Asset[] assets, Resource[] resources, FileSystem[] fileSystems, ResourceGroup[] resourceGroups)
  37. {
  38. m_IsValid = true;
  39. m_ApplicableGameVersion = applicableGameVersion;
  40. m_InternalResourceVersion = internalResourceVersion;
  41. m_Assets = assets ?? EmptyAssetArray;
  42. m_Resources = resources ?? EmptyResourceArray;
  43. m_FileSystems = fileSystems ?? EmptyFileSystemArray;
  44. m_ResourceGroups = resourceGroups ?? EmptyResourceGroupArray;
  45. }
  46. /// <summary>
  47. /// 获取单机模式版本资源列表是否有效。
  48. /// </summary>
  49. public bool IsValid
  50. {
  51. get
  52. {
  53. return m_IsValid;
  54. }
  55. }
  56. /// <summary>
  57. /// 获取适配的游戏版本号。
  58. /// </summary>
  59. public string ApplicableGameVersion
  60. {
  61. get
  62. {
  63. if (!m_IsValid)
  64. {
  65. throw new GameFrameworkException("Data is invalid.");
  66. }
  67. return m_ApplicableGameVersion;
  68. }
  69. }
  70. /// <summary>
  71. /// 获取内部资源版本号。
  72. /// </summary>
  73. public int InternalResourceVersion
  74. {
  75. get
  76. {
  77. if (!m_IsValid)
  78. {
  79. throw new GameFrameworkException("Data is invalid.");
  80. }
  81. return m_InternalResourceVersion;
  82. }
  83. }
  84. /// <summary>
  85. /// 获取包含的资源集合。
  86. /// </summary>
  87. /// <returns>包含的资源集合。</returns>
  88. public Asset[] GetAssets()
  89. {
  90. if (!m_IsValid)
  91. {
  92. throw new GameFrameworkException("Data is invalid.");
  93. }
  94. return m_Assets;
  95. }
  96. /// <summary>
  97. /// 获取包含的资源集合。
  98. /// </summary>
  99. /// <returns>包含的资源集合。</returns>
  100. public Resource[] GetResources()
  101. {
  102. if (!m_IsValid)
  103. {
  104. throw new GameFrameworkException("Data is invalid.");
  105. }
  106. return m_Resources;
  107. }
  108. /// <summary>
  109. /// 获取包含的文件系统集合。
  110. /// </summary>
  111. /// <returns>包含的文件系统集合。</returns>
  112. public FileSystem[] GetFileSystems()
  113. {
  114. if (!m_IsValid)
  115. {
  116. throw new GameFrameworkException("Data is invalid.");
  117. }
  118. return m_FileSystems;
  119. }
  120. /// <summary>
  121. /// 获取包含的资源组集合。
  122. /// </summary>
  123. /// <returns>包含的资源组集合。</returns>
  124. public ResourceGroup[] GetResourceGroups()
  125. {
  126. if (!m_IsValid)
  127. {
  128. throw new GameFrameworkException("Data is invalid.");
  129. }
  130. return m_ResourceGroups;
  131. }
  132. }
  133. }