ResourcePackVersionList.cs 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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 ResourcePackVersionList
  15. {
  16. private static readonly Resource[] EmptyResourceArray = new Resource[] { };
  17. private readonly bool m_IsValid;
  18. private readonly int m_Offset;
  19. private readonly long m_Length;
  20. private readonly int m_HashCode;
  21. private readonly Resource[] m_Resources;
  22. /// <summary>
  23. /// 初始化资源包版本资源列表的新实例。
  24. /// </summary>
  25. /// <param name="offset">资源数据偏移。</param>
  26. /// <param name="length">资源数据长度。</param>
  27. /// <param name="hashCode">资源数据哈希值。</param>
  28. /// <param name="resources">包含的资源集合。</param>
  29. public ResourcePackVersionList(int offset, long length, int hashCode, Resource[] resources)
  30. {
  31. m_IsValid = true;
  32. m_Offset = offset;
  33. m_Length = length;
  34. m_HashCode = hashCode;
  35. m_Resources = resources ?? EmptyResourceArray;
  36. }
  37. /// <summary>
  38. /// 获取资源包版本资源列表是否有效。
  39. /// </summary>
  40. public bool IsValid
  41. {
  42. get
  43. {
  44. return m_IsValid;
  45. }
  46. }
  47. /// <summary>
  48. /// 获取资源数据偏移。
  49. /// </summary>
  50. public int Offset
  51. {
  52. get
  53. {
  54. if (!m_IsValid)
  55. {
  56. throw new GameFrameworkException("Data is invalid.");
  57. }
  58. return m_Offset;
  59. }
  60. }
  61. /// <summary>
  62. /// 获取资源数据长度。
  63. /// </summary>
  64. public long Length
  65. {
  66. get
  67. {
  68. if (!m_IsValid)
  69. {
  70. throw new GameFrameworkException("Data is invalid.");
  71. }
  72. return m_Length;
  73. }
  74. }
  75. /// <summary>
  76. /// 获取资源数据哈希值。
  77. /// </summary>
  78. public int HashCode
  79. {
  80. get
  81. {
  82. if (!m_IsValid)
  83. {
  84. throw new GameFrameworkException("Data is invalid.");
  85. }
  86. return m_HashCode;
  87. }
  88. }
  89. /// <summary>
  90. /// 获取包含的资源集合。
  91. /// </summary>
  92. /// <returns>包含的资源集合。</returns>
  93. public Resource[] GetResources()
  94. {
  95. if (!m_IsValid)
  96. {
  97. throw new GameFrameworkException("Data is invalid.");
  98. }
  99. return m_Resources;
  100. }
  101. }
  102. }