FileSystemComponent.cs 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. //------------------------------------------------------------
  2. // Game Framework
  3. // Copyright © 2013-2021 loyalsoft. All rights reserved.
  4. // Homepage: http://www.game7000.com/
  5. // Feedback: http://www.game7000.com/
  6. //------------------------------------------------------------
  7. using GameFramework;
  8. using GameFramework.FileSystem;
  9. using System.Collections.Generic;
  10. using UnityEngine;
  11. namespace UnityGameFramework.Runtime
  12. {
  13. /// <summary>
  14. /// 文件系统件。
  15. /// </summary>
  16. [DisallowMultipleComponent]
  17. [AddComponentMenu("Game Framework/File System")]
  18. public sealed class FileSystemComponent : GameFrameworkComponent
  19. {
  20. private IFileSystemManager m_FileSystemManager = null;
  21. [SerializeField]
  22. private string m_FileSystemHelperTypeName = "UnityGameFramework.Runtime.DefaultFileSystemHelper";
  23. [SerializeField]
  24. private FileSystemHelperBase m_CustomFileSystemHelper = null;
  25. /// <summary>
  26. /// 获取文件系统数量。
  27. /// </summary>
  28. public int Count
  29. {
  30. get
  31. {
  32. return m_FileSystemManager.Count;
  33. }
  34. }
  35. /// <summary>
  36. /// 游戏框架组件初始化。
  37. /// </summary>
  38. protected override void Awake()
  39. {
  40. base.Awake();
  41. m_FileSystemManager = GameFrameworkEntry.GetModule<IFileSystemManager>();
  42. if (m_FileSystemManager == null)
  43. {
  44. Log.Fatal("File system manager is invalid.");
  45. return;
  46. }
  47. FileSystemHelperBase fileSystemHelper = Helper.CreateHelper(m_FileSystemHelperTypeName, m_CustomFileSystemHelper);
  48. if (fileSystemHelper == null)
  49. {
  50. Log.Error("Can not create fileSystem helper.");
  51. return;
  52. }
  53. fileSystemHelper.name = "FileSystem Helper";
  54. Transform transform = fileSystemHelper.transform;
  55. transform.SetParent(this.transform);
  56. transform.localScale = Vector3.one;
  57. m_FileSystemManager.SetFileSystemHelper(fileSystemHelper);
  58. }
  59. private void Start()
  60. {
  61. }
  62. /// <summary>
  63. /// 检查是否存在文件系统。
  64. /// </summary>
  65. /// <param name="fullPath">要检查的文件系统的完整路径。</param>
  66. /// <returns>是否存在文件系统。</returns>
  67. public bool HasFileSystem(string fullPath)
  68. {
  69. return m_FileSystemManager.HasFileSystem(fullPath);
  70. }
  71. /// <summary>
  72. /// 获取文件系统。
  73. /// </summary>
  74. /// <param name="fullPath">要获取的文件系统的完整路径。</param>
  75. /// <returns>获取的文件系统。</returns>
  76. public IFileSystem GetFileSystem(string fullPath)
  77. {
  78. return m_FileSystemManager.GetFileSystem(fullPath);
  79. }
  80. /// <summary>
  81. /// 创建文件系统。
  82. /// </summary>
  83. /// <param name="fullPath">要创建的文件系统的完整路径。</param>
  84. /// <param name="access">要创建的文件系统的访问方式。</param>
  85. /// <param name="maxFileCount">要创建的文件系统的最大文件数量。</param>
  86. /// <param name="maxBlockCount">要创建的文件系统的最大块数据数量。</param>
  87. /// <returns>创建的文件系统。</returns>
  88. public IFileSystem CreateFileSystem(string fullPath, FileSystemAccess access, int maxFileCount, int maxBlockCount)
  89. {
  90. return m_FileSystemManager.CreateFileSystem(fullPath, access, maxFileCount, maxBlockCount);
  91. }
  92. /// <summary>
  93. /// 加载文件系统。
  94. /// </summary>
  95. /// <param name="fullPath">要加载的文件系统的完整路径。</param>
  96. /// <param name="access">要加载的文件系统的访问方式。</param>
  97. /// <returns>加载的文件系统。</returns>
  98. public IFileSystem LoadFileSystem(string fullPath, FileSystemAccess access)
  99. {
  100. return m_FileSystemManager.LoadFileSystem(fullPath, access);
  101. }
  102. /// <summary>
  103. /// 销毁文件系统。
  104. /// </summary>
  105. /// <param name="fileSystem">要销毁的文件系统。</param>
  106. /// <param name="deletePhysicalFile">是否删除文件系统对应的物理文件。</param>
  107. public void DestroyFileSystem(IFileSystem fileSystem, bool deletePhysicalFile)
  108. {
  109. m_FileSystemManager.DestroyFileSystem(fileSystem, deletePhysicalFile);
  110. }
  111. /// <summary>
  112. /// 获取所有文件系统集合。
  113. /// </summary>
  114. /// <returns>获取的所有文件系统集合。</returns>
  115. public IFileSystem[] GetAllFileSystems()
  116. {
  117. return m_FileSystemManager.GetAllFileSystems();
  118. }
  119. /// <summary>
  120. /// 获取所有文件系统集合。
  121. /// </summary>
  122. /// <param name="results">获取的所有文件系统集合。</param>
  123. public void GetAllFileSystems(List<IFileSystem> results)
  124. {
  125. m_FileSystemManager.GetAllFileSystems(results);
  126. }
  127. }
  128. }