LocalVersionList.cs 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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 LocalVersionList
  15. {
  16. private static readonly Resource[] EmptyResourceArray = new Resource[] { };
  17. private static readonly FileSystem[] EmptyFileSystemArray = new FileSystem[] { };
  18. private readonly bool m_IsValid;
  19. private readonly Resource[] m_Resources;
  20. private readonly FileSystem[] m_FileSystems;
  21. /// <summary>
  22. /// 初始化本地版本资源列表的新实例。
  23. /// </summary>
  24. /// <param name="resources">包含的资源集合。</param>
  25. /// <param name="fileSystems">包含的文件系统集合。</param>
  26. public LocalVersionList(Resource[] resources, FileSystem[] fileSystems)
  27. {
  28. m_IsValid = true;
  29. m_Resources = resources ?? EmptyResourceArray;
  30. m_FileSystems = fileSystems ?? EmptyFileSystemArray;
  31. }
  32. /// <summary>
  33. /// 获取本地版本资源列表是否有效。
  34. /// </summary>
  35. public bool IsValid
  36. {
  37. get
  38. {
  39. return m_IsValid;
  40. }
  41. }
  42. /// <summary>
  43. /// 获取包含的资源集合。
  44. /// </summary>
  45. /// <returns>包含的资源集合。</returns>
  46. public Resource[] GetResources()
  47. {
  48. if (!m_IsValid)
  49. {
  50. throw new GameFrameworkException("Data is invalid.");
  51. }
  52. return m_Resources;
  53. }
  54. /// <summary>
  55. /// 获取包含的文件系统集合。
  56. /// </summary>
  57. /// <returns>包含的文件系统集合。</returns>
  58. public FileSystem[] GetFileSystems()
  59. {
  60. if (!m_IsValid)
  61. {
  62. throw new GameFrameworkException("Data is invalid.");
  63. }
  64. return m_FileSystems;
  65. }
  66. }
  67. }