ResourceManager.cs 92 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404
  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.Download;
  8. using GameFramework.FileSystem;
  9. using GameFramework.ObjectPool;
  10. using System;
  11. using System.Collections.Generic;
  12. using System.IO;
  13. namespace GameFramework.Resource
  14. {
  15. /// <summary>
  16. /// 资源管理器。
  17. /// </summary>
  18. internal sealed partial class ResourceManager : GameFrameworkModule, IResourceManager
  19. {
  20. private const string RemoteVersionListFileName = "GameFrameworkVersion.dat";
  21. private const string LocalVersionListFileName = "GameFrameworkList.dat";
  22. private const string DefaultExtension = "dat";
  23. private const string TempExtension = "tmp";
  24. private const int FileSystemMaxFileCount = 1024 * 16;
  25. private const int FileSystemMaxBlockCount = 1024 * 256;
  26. private Dictionary<string, AssetInfo> m_AssetInfos;
  27. private Dictionary<ResourceName, ResourceInfo> m_ResourceInfos;
  28. private SortedDictionary<ResourceName, ReadWriteResourceInfo> m_ReadWriteResourceInfos;
  29. private readonly Dictionary<string, IFileSystem> m_ReadOnlyFileSystems;
  30. private readonly Dictionary<string, IFileSystem> m_ReadWriteFileSystems;
  31. private readonly Dictionary<string, ResourceGroup> m_ResourceGroups;
  32. private PackageVersionListSerializer m_PackageVersionListSerializer;
  33. private UpdatableVersionListSerializer m_UpdatableVersionListSerializer;
  34. private ReadOnlyVersionListSerializer m_ReadOnlyVersionListSerializer;
  35. private ReadWriteVersionListSerializer m_ReadWriteVersionListSerializer;
  36. private ResourcePackVersionListSerializer m_ResourcePackVersionListSerializer;
  37. private IFileSystemManager m_FileSystemManager;
  38. private ResourceIniter m_ResourceIniter;
  39. private VersionListProcessor m_VersionListProcessor;
  40. private ResourceChecker m_ResourceChecker;
  41. private ResourceUpdater m_ResourceUpdater;
  42. private ResourceLoader m_ResourceLoader;
  43. private IResourceHelper m_ResourceHelper;
  44. private string m_ReadOnlyPath;
  45. private string m_ReadWritePath;
  46. private ResourceMode m_ResourceMode;
  47. private bool m_RefuseSetFlag;
  48. private string m_CurrentVariant;
  49. private string m_UpdatePrefixUri;
  50. private string m_ApplicableGameVersion;
  51. private int m_InternalResourceVersion;
  52. private MemoryStream m_DecompressCachedStream;
  53. private DecryptResourceCallback m_DecryptResourceCallback;
  54. private InitResourcesCompleteCallback m_InitResourcesCompleteCallback;
  55. private UpdateVersionListCallbacks m_UpdateVersionListCallbacks;
  56. private CheckResourcesCompleteCallback m_CheckResourcesCompleteCallback;
  57. private ApplyResourcesCompleteCallback m_ApplyResourcesCompleteCallback;
  58. private UpdateResourcesCompleteCallback m_UpdateResourcesCompleteCallback;
  59. private EventHandler<ResourceApplySuccessEventArgs> m_ResourceApplySuccessEventHandler;
  60. private EventHandler<ResourceApplyFailureEventArgs> m_ResourceApplyFailureEventHandler;
  61. private EventHandler<ResourceUpdateStartEventArgs> m_ResourceUpdateStartEventHandler;
  62. private EventHandler<ResourceUpdateChangedEventArgs> m_ResourceUpdateChangedEventHandler;
  63. private EventHandler<ResourceUpdateSuccessEventArgs> m_ResourceUpdateSuccessEventHandler;
  64. private EventHandler<ResourceUpdateFailureEventArgs> m_ResourceUpdateFailureEventHandler;
  65. private EventHandler<ResourceUpdateAllCompleteEventArgs> m_ResourceUpdateAllCompleteEventHandler;
  66. /// <summary>
  67. /// 初始化资源管理器的新实例。
  68. /// </summary>
  69. public ResourceManager()
  70. {
  71. m_AssetInfos = null;
  72. m_ResourceInfos = null;
  73. m_ReadWriteResourceInfos = null;
  74. m_ReadOnlyFileSystems = new Dictionary<string, IFileSystem>(StringComparer.Ordinal);
  75. m_ReadWriteFileSystems = new Dictionary<string, IFileSystem>(StringComparer.Ordinal);
  76. m_ResourceGroups = new Dictionary<string, ResourceGroup>(StringComparer.Ordinal);
  77. m_PackageVersionListSerializer = null;
  78. m_UpdatableVersionListSerializer = null;
  79. m_ReadOnlyVersionListSerializer = null;
  80. m_ReadWriteVersionListSerializer = null;
  81. m_ResourcePackVersionListSerializer = null;
  82. m_ResourceIniter = null;
  83. m_VersionListProcessor = null;
  84. m_ResourceChecker = null;
  85. m_ResourceUpdater = null;
  86. m_ResourceLoader = new ResourceLoader(this);
  87. m_ResourceHelper = null;
  88. m_ReadOnlyPath = null;
  89. m_ReadWritePath = null;
  90. m_ResourceMode = ResourceMode.Unspecified;
  91. m_RefuseSetFlag = false;
  92. m_CurrentVariant = null;
  93. m_UpdatePrefixUri = null;
  94. m_ApplicableGameVersion = null;
  95. m_InternalResourceVersion = 0;
  96. m_DecompressCachedStream = null;
  97. m_DecryptResourceCallback = null;
  98. m_InitResourcesCompleteCallback = null;
  99. m_UpdateVersionListCallbacks = null;
  100. m_CheckResourcesCompleteCallback = null;
  101. m_ApplyResourcesCompleteCallback = null;
  102. m_UpdateResourcesCompleteCallback = null;
  103. m_ResourceApplySuccessEventHandler = null;
  104. m_ResourceApplyFailureEventHandler = null;
  105. m_ResourceUpdateStartEventHandler = null;
  106. m_ResourceUpdateChangedEventHandler = null;
  107. m_ResourceUpdateSuccessEventHandler = null;
  108. m_ResourceUpdateFailureEventHandler = null;
  109. m_ResourceUpdateAllCompleteEventHandler = null;
  110. }
  111. /// <summary>
  112. /// 获取游戏框架模块优先级。
  113. /// </summary>
  114. /// <remarks>优先级较高的模块会优先轮询,并且关闭操作会后进行。</remarks>
  115. internal override int Priority
  116. {
  117. get
  118. {
  119. return 3;
  120. }
  121. }
  122. /// <summary>
  123. /// 获取资源只读区路径。
  124. /// </summary>
  125. public string ReadOnlyPath
  126. {
  127. get
  128. {
  129. return m_ReadOnlyPath;
  130. }
  131. }
  132. /// <summary>
  133. /// 获取资源读写区路径。
  134. /// </summary>
  135. public string ReadWritePath
  136. {
  137. get
  138. {
  139. return m_ReadWritePath;
  140. }
  141. }
  142. /// <summary>
  143. /// 获取资源模式。
  144. /// </summary>
  145. public ResourceMode ResourceMode
  146. {
  147. get
  148. {
  149. return m_ResourceMode;
  150. }
  151. }
  152. /// <summary>
  153. /// 获取当前变体。
  154. /// </summary>
  155. public string CurrentVariant
  156. {
  157. get
  158. {
  159. return m_CurrentVariant;
  160. }
  161. }
  162. /// <summary>
  163. /// 获取单机模式版本资源列表序列化器。
  164. /// </summary>
  165. public PackageVersionListSerializer PackageVersionListSerializer
  166. {
  167. get
  168. {
  169. return m_PackageVersionListSerializer;
  170. }
  171. }
  172. /// <summary>
  173. /// 获取可更新模式版本资源列表序列化器。
  174. /// </summary>
  175. public UpdatableVersionListSerializer UpdatableVersionListSerializer
  176. {
  177. get
  178. {
  179. return m_UpdatableVersionListSerializer;
  180. }
  181. }
  182. /// <summary>
  183. /// 获取本地只读区版本资源列表序列化器。
  184. /// </summary>
  185. public ReadOnlyVersionListSerializer ReadOnlyVersionListSerializer
  186. {
  187. get
  188. {
  189. return m_ReadOnlyVersionListSerializer;
  190. }
  191. }
  192. /// <summary>
  193. /// 获取本地读写区版本资源列表序列化器。
  194. /// </summary>
  195. public ReadWriteVersionListSerializer ReadWriteVersionListSerializer
  196. {
  197. get
  198. {
  199. return m_ReadWriteVersionListSerializer;
  200. }
  201. }
  202. /// <summary>
  203. /// 获取资源包版本资源列表序列化器。
  204. /// </summary>
  205. public ResourcePackVersionListSerializer ResourcePackVersionListSerializer
  206. {
  207. get
  208. {
  209. return m_ResourcePackVersionListSerializer;
  210. }
  211. }
  212. /// <summary>
  213. /// 获取当前资源适用的游戏版本号。
  214. /// </summary>
  215. public string ApplicableGameVersion
  216. {
  217. get
  218. {
  219. return m_ApplicableGameVersion;
  220. }
  221. }
  222. /// <summary>
  223. /// 获取当前内部资源版本号。
  224. /// </summary>
  225. public int InternalResourceVersion
  226. {
  227. get
  228. {
  229. return m_InternalResourceVersion;
  230. }
  231. }
  232. /// <summary>
  233. /// 获取资源数量。
  234. /// </summary>
  235. public int AssetCount
  236. {
  237. get
  238. {
  239. return m_AssetInfos != null ? m_AssetInfos.Count : 0;
  240. }
  241. }
  242. /// <summary>
  243. /// 获取资源数量。
  244. /// </summary>
  245. public int ResourceCount
  246. {
  247. get
  248. {
  249. return m_ResourceInfos != null ? m_ResourceInfos.Count : 0;
  250. }
  251. }
  252. /// <summary>
  253. /// 获取资源组数量。
  254. /// </summary>
  255. public int ResourceGroupCount
  256. {
  257. get
  258. {
  259. return m_ResourceGroups.Count;
  260. }
  261. }
  262. /// <summary>
  263. /// 获取或设置资源更新下载地址前缀。
  264. /// </summary>
  265. public string UpdatePrefixUri
  266. {
  267. get
  268. {
  269. return m_UpdatePrefixUri;
  270. }
  271. set
  272. {
  273. m_UpdatePrefixUri = value;
  274. }
  275. }
  276. /// <summary>
  277. /// 获取或设置每更新多少字节的资源,重新生成一次版本资源列表。
  278. /// </summary>
  279. public int GenerateReadWriteVersionListLength
  280. {
  281. get
  282. {
  283. return m_ResourceUpdater != null ? m_ResourceUpdater.GenerateReadWriteVersionListLength : 0;
  284. }
  285. set
  286. {
  287. if (m_ResourceUpdater == null)
  288. {
  289. throw new GameFrameworkException("You can not use GenerateReadWriteVersionListLength at this time.");
  290. }
  291. m_ResourceUpdater.GenerateReadWriteVersionListLength = value;
  292. }
  293. }
  294. /// <summary>
  295. /// 获取正在应用的资源包路径。
  296. /// </summary>
  297. public string ApplyingResourcePackPath
  298. {
  299. get
  300. {
  301. return m_ResourceUpdater != null ? m_ResourceUpdater.ApplyingResourcePackPath : null;
  302. }
  303. }
  304. /// <summary>
  305. /// 获取等待应用资源数量。
  306. /// </summary>
  307. public int ApplyWaitingCount
  308. {
  309. get
  310. {
  311. return m_ResourceUpdater != null ? m_ResourceUpdater.ApplyWaitingCount : 0;
  312. }
  313. }
  314. /// <summary>
  315. /// 获取或设置资源更新重试次数。
  316. /// </summary>
  317. public int UpdateRetryCount
  318. {
  319. get
  320. {
  321. return m_ResourceUpdater != null ? m_ResourceUpdater.UpdateRetryCount : 0;
  322. }
  323. set
  324. {
  325. if (m_ResourceUpdater == null)
  326. {
  327. throw new GameFrameworkException("You can not use UpdateRetryCount at this time.");
  328. }
  329. m_ResourceUpdater.UpdateRetryCount = value;
  330. }
  331. }
  332. /// <summary>
  333. /// 获取正在更新的资源组。
  334. /// </summary>
  335. public IResourceGroup UpdatingResourceGroup
  336. {
  337. get
  338. {
  339. return m_ResourceUpdater != null ? m_ResourceUpdater.UpdatingResourceGroup : null;
  340. }
  341. }
  342. /// <summary>
  343. /// 获取等待更新资源数量。
  344. /// </summary>
  345. public int UpdateWaitingCount
  346. {
  347. get
  348. {
  349. return m_ResourceUpdater != null ? m_ResourceUpdater.UpdateWaitingCount : 0;
  350. }
  351. }
  352. /// <summary>
  353. /// 获取使用时下载的等待更新资源数量。
  354. /// </summary>
  355. public int UpdateWaitingWhilePlayingCount
  356. {
  357. get
  358. {
  359. return m_ResourceUpdater != null ? m_ResourceUpdater.UpdateWaitingWhilePlayingCount : 0;
  360. }
  361. }
  362. /// <summary>
  363. /// 获取候选更新资源数量。
  364. /// </summary>
  365. public int UpdateCandidateCount
  366. {
  367. get
  368. {
  369. return m_ResourceUpdater != null ? m_ResourceUpdater.UpdateCandidateCount : 0;
  370. }
  371. }
  372. /// <summary>
  373. /// 获取加载资源代理总数量。
  374. /// </summary>
  375. public int LoadTotalAgentCount
  376. {
  377. get
  378. {
  379. return m_ResourceLoader.TotalAgentCount;
  380. }
  381. }
  382. /// <summary>
  383. /// 获取可用加载资源代理数量。
  384. /// </summary>
  385. public int LoadFreeAgentCount
  386. {
  387. get
  388. {
  389. return m_ResourceLoader.FreeAgentCount;
  390. }
  391. }
  392. /// <summary>
  393. /// 获取工作中加载资源代理数量。
  394. /// </summary>
  395. public int LoadWorkingAgentCount
  396. {
  397. get
  398. {
  399. return m_ResourceLoader.WorkingAgentCount;
  400. }
  401. }
  402. /// <summary>
  403. /// 获取等待加载资源任务数量。
  404. /// </summary>
  405. public int LoadWaitingTaskCount
  406. {
  407. get
  408. {
  409. return m_ResourceLoader.WaitingTaskCount;
  410. }
  411. }
  412. /// <summary>
  413. /// 获取或设置资源对象池自动释放可释放对象的间隔秒数。
  414. /// </summary>
  415. public float AssetAutoReleaseInterval
  416. {
  417. get
  418. {
  419. return m_ResourceLoader.AssetAutoReleaseInterval;
  420. }
  421. set
  422. {
  423. m_ResourceLoader.AssetAutoReleaseInterval = value;
  424. }
  425. }
  426. /// <summary>
  427. /// 获取或设置资源对象池的容量。
  428. /// </summary>
  429. public int AssetCapacity
  430. {
  431. get
  432. {
  433. return m_ResourceLoader.AssetCapacity;
  434. }
  435. set
  436. {
  437. m_ResourceLoader.AssetCapacity = value;
  438. }
  439. }
  440. /// <summary>
  441. /// 获取或设置资源对象池对象过期秒数。
  442. /// </summary>
  443. public float AssetExpireTime
  444. {
  445. get
  446. {
  447. return m_ResourceLoader.AssetExpireTime;
  448. }
  449. set
  450. {
  451. m_ResourceLoader.AssetExpireTime = value;
  452. }
  453. }
  454. /// <summary>
  455. /// 获取或设置资源对象池的优先级。
  456. /// </summary>
  457. public int AssetPriority
  458. {
  459. get
  460. {
  461. return m_ResourceLoader.AssetPriority;
  462. }
  463. set
  464. {
  465. m_ResourceLoader.AssetPriority = value;
  466. }
  467. }
  468. /// <summary>
  469. /// 获取或设置资源对象池自动释放可释放对象的间隔秒数。
  470. /// </summary>
  471. public float ResourceAutoReleaseInterval
  472. {
  473. get
  474. {
  475. return m_ResourceLoader.ResourceAutoReleaseInterval;
  476. }
  477. set
  478. {
  479. m_ResourceLoader.ResourceAutoReleaseInterval = value;
  480. }
  481. }
  482. /// <summary>
  483. /// 获取或设置资源对象池的容量。
  484. /// </summary>
  485. public int ResourceCapacity
  486. {
  487. get
  488. {
  489. return m_ResourceLoader.ResourceCapacity;
  490. }
  491. set
  492. {
  493. m_ResourceLoader.ResourceCapacity = value;
  494. }
  495. }
  496. /// <summary>
  497. /// 获取或设置资源对象池对象过期秒数。
  498. /// </summary>
  499. public float ResourceExpireTime
  500. {
  501. get
  502. {
  503. return m_ResourceLoader.ResourceExpireTime;
  504. }
  505. set
  506. {
  507. m_ResourceLoader.ResourceExpireTime = value;
  508. }
  509. }
  510. /// <summary>
  511. /// 获取或设置资源对象池的优先级。
  512. /// </summary>
  513. public int ResourcePriority
  514. {
  515. get
  516. {
  517. return m_ResourceLoader.ResourcePriority;
  518. }
  519. set
  520. {
  521. m_ResourceLoader.ResourcePriority = value;
  522. }
  523. }
  524. /// <summary>
  525. /// 资源应用成功事件。
  526. /// </summary>
  527. public event EventHandler<ResourceApplySuccessEventArgs> ResourceApplySuccess
  528. {
  529. add
  530. {
  531. m_ResourceApplySuccessEventHandler += value;
  532. }
  533. remove
  534. {
  535. m_ResourceApplySuccessEventHandler -= value;
  536. }
  537. }
  538. /// <summary>
  539. /// 资源应用失败事件。
  540. /// </summary>
  541. public event EventHandler<ResourceApplyFailureEventArgs> ResourceApplyFailure
  542. {
  543. add
  544. {
  545. m_ResourceApplyFailureEventHandler += value;
  546. }
  547. remove
  548. {
  549. m_ResourceApplyFailureEventHandler -= value;
  550. }
  551. }
  552. /// <summary>
  553. /// 资源更新开始事件。
  554. /// </summary>
  555. public event EventHandler<ResourceUpdateStartEventArgs> ResourceUpdateStart
  556. {
  557. add
  558. {
  559. m_ResourceUpdateStartEventHandler += value;
  560. }
  561. remove
  562. {
  563. m_ResourceUpdateStartEventHandler -= value;
  564. }
  565. }
  566. /// <summary>
  567. /// 资源更新改变事件。
  568. /// </summary>
  569. public event EventHandler<ResourceUpdateChangedEventArgs> ResourceUpdateChanged
  570. {
  571. add
  572. {
  573. m_ResourceUpdateChangedEventHandler += value;
  574. }
  575. remove
  576. {
  577. m_ResourceUpdateChangedEventHandler -= value;
  578. }
  579. }
  580. /// <summary>
  581. /// 资源更新成功事件。
  582. /// </summary>
  583. public event EventHandler<ResourceUpdateSuccessEventArgs> ResourceUpdateSuccess
  584. {
  585. add
  586. {
  587. m_ResourceUpdateSuccessEventHandler += value;
  588. }
  589. remove
  590. {
  591. m_ResourceUpdateSuccessEventHandler -= value;
  592. }
  593. }
  594. /// <summary>
  595. /// 资源更新失败事件。
  596. /// </summary>
  597. public event EventHandler<ResourceUpdateFailureEventArgs> ResourceUpdateFailure
  598. {
  599. add
  600. {
  601. m_ResourceUpdateFailureEventHandler += value;
  602. }
  603. remove
  604. {
  605. m_ResourceUpdateFailureEventHandler -= value;
  606. }
  607. }
  608. /// <summary>
  609. /// 资源更新全部完成事件。
  610. /// </summary>
  611. public event EventHandler<ResourceUpdateAllCompleteEventArgs> ResourceUpdateAllComplete
  612. {
  613. add
  614. {
  615. m_ResourceUpdateAllCompleteEventHandler += value;
  616. }
  617. remove
  618. {
  619. m_ResourceUpdateAllCompleteEventHandler -= value;
  620. }
  621. }
  622. /// <summary>
  623. /// 资源管理器轮询。
  624. /// </summary>
  625. /// <param name="elapseSeconds">逻辑流逝时间,以秒为单位。</param>
  626. /// <param name="realElapseSeconds">真实流逝时间,以秒为单位。</param>
  627. internal override void Update(float elapseSeconds, float realElapseSeconds)
  628. {
  629. if (m_ResourceUpdater != null)
  630. {
  631. m_ResourceUpdater.Update(elapseSeconds, realElapseSeconds);
  632. }
  633. m_ResourceLoader.Update(elapseSeconds, realElapseSeconds);
  634. }
  635. /// <summary>
  636. /// 关闭并清理资源管理器。
  637. /// </summary>
  638. internal override void Shutdown()
  639. {
  640. if (m_ResourceIniter != null)
  641. {
  642. m_ResourceIniter.Shutdown();
  643. m_ResourceIniter = null;
  644. }
  645. if (m_VersionListProcessor != null)
  646. {
  647. m_VersionListProcessor.VersionListUpdateSuccess -= OnVersionListProcessorUpdateSuccess;
  648. m_VersionListProcessor.VersionListUpdateFailure -= OnVersionListProcessorUpdateFailure;
  649. m_VersionListProcessor.Shutdown();
  650. m_VersionListProcessor = null;
  651. }
  652. if (m_ResourceChecker != null)
  653. {
  654. m_ResourceChecker.ResourceNeedUpdate -= OnCheckerResourceNeedUpdate;
  655. m_ResourceChecker.ResourceCheckComplete -= OnCheckerResourceCheckComplete;
  656. m_ResourceChecker.Shutdown();
  657. m_ResourceChecker = null;
  658. }
  659. if (m_ResourceUpdater != null)
  660. {
  661. m_ResourceUpdater.ResourceApplySuccess -= OnUpdaterResourceApplySuccess;
  662. m_ResourceUpdater.ResourceApplyFailure -= OnUpdaterResourceApplyFailure;
  663. m_ResourceUpdater.ResourceApplyComplete -= OnUpdaterResourceApplyComplete;
  664. m_ResourceUpdater.ResourceUpdateStart -= OnUpdaterResourceUpdateStart;
  665. m_ResourceUpdater.ResourceUpdateChanged -= OnUpdaterResourceUpdateChanged;
  666. m_ResourceUpdater.ResourceUpdateSuccess -= OnUpdaterResourceUpdateSuccess;
  667. m_ResourceUpdater.ResourceUpdateFailure -= OnUpdaterResourceUpdateFailure;
  668. m_ResourceUpdater.ResourceUpdateComplete -= OnUpdaterResourceUpdateComplete;
  669. m_ResourceUpdater.ResourceUpdateAllComplete -= OnUpdaterResourceUpdateAllComplete;
  670. m_ResourceUpdater.Shutdown();
  671. m_ResourceUpdater = null;
  672. if (m_ReadWriteResourceInfos != null)
  673. {
  674. m_ReadWriteResourceInfos.Clear();
  675. m_ReadWriteResourceInfos = null;
  676. }
  677. if (m_DecompressCachedStream != null)
  678. {
  679. m_DecompressCachedStream.Dispose();
  680. m_DecompressCachedStream = null;
  681. }
  682. }
  683. if (m_ResourceLoader != null)
  684. {
  685. m_ResourceLoader.Shutdown();
  686. m_ResourceLoader = null;
  687. }
  688. if (m_AssetInfos != null)
  689. {
  690. m_AssetInfos.Clear();
  691. m_AssetInfos = null;
  692. }
  693. if (m_ResourceInfos != null)
  694. {
  695. m_ResourceInfos.Clear();
  696. m_ResourceInfos = null;
  697. }
  698. m_ReadOnlyFileSystems.Clear();
  699. m_ReadWriteFileSystems.Clear();
  700. m_ResourceGroups.Clear();
  701. }
  702. /// <summary>
  703. /// 设置资源只读区路径。
  704. /// </summary>
  705. /// <param name="readOnlyPath">资源只读区路径。</param>
  706. public void SetReadOnlyPath(string readOnlyPath)
  707. {
  708. if (string.IsNullOrEmpty(readOnlyPath))
  709. {
  710. throw new GameFrameworkException("Read-only path is invalid.");
  711. }
  712. if (m_RefuseSetFlag)
  713. {
  714. throw new GameFrameworkException("You can not set read-only path at this time.");
  715. }
  716. if (m_ResourceLoader.TotalAgentCount > 0)
  717. {
  718. throw new GameFrameworkException("You must set read-only path before add load resource agent helper.");
  719. }
  720. m_ReadOnlyPath = readOnlyPath;
  721. }
  722. /// <summary>
  723. /// 设置资源读写区路径。
  724. /// </summary>
  725. /// <param name="readWritePath">资源读写区路径。</param>
  726. public void SetReadWritePath(string readWritePath)
  727. {
  728. if (string.IsNullOrEmpty(readWritePath))
  729. {
  730. throw new GameFrameworkException("Read-write path is invalid.");
  731. }
  732. if (m_RefuseSetFlag)
  733. {
  734. throw new GameFrameworkException("You can not set read-write path at this time.");
  735. }
  736. if (m_ResourceLoader.TotalAgentCount > 0)
  737. {
  738. throw new GameFrameworkException("You must set read-write path before add load resource agent helper.");
  739. }
  740. m_ReadWritePath = readWritePath;
  741. }
  742. /// <summary>
  743. /// 设置资源模式。
  744. /// </summary>
  745. /// <param name="resourceMode">资源模式。</param>
  746. public void SetResourceMode(ResourceMode resourceMode)
  747. {
  748. if (resourceMode == ResourceMode.Unspecified)
  749. {
  750. throw new GameFrameworkException("Resource mode is invalid.");
  751. }
  752. if (m_RefuseSetFlag)
  753. {
  754. throw new GameFrameworkException("You can not set resource mode at this time.");
  755. }
  756. if (m_ResourceMode == ResourceMode.Unspecified)
  757. {
  758. m_ResourceMode = resourceMode;
  759. if (m_ResourceMode == ResourceMode.Package)
  760. {
  761. m_PackageVersionListSerializer = new PackageVersionListSerializer();
  762. m_ResourceIniter = new ResourceIniter(this);
  763. m_ResourceIniter.ResourceInitComplete += OnIniterResourceInitComplete;
  764. }
  765. else if (m_ResourceMode == ResourceMode.Updatable || m_ResourceMode == ResourceMode.UpdatableWhilePlaying)
  766. {
  767. m_UpdatableVersionListSerializer = new UpdatableVersionListSerializer();
  768. m_ReadOnlyVersionListSerializer = new ReadOnlyVersionListSerializer();
  769. m_ReadWriteVersionListSerializer = new ReadWriteVersionListSerializer();
  770. m_ResourcePackVersionListSerializer = new ResourcePackVersionListSerializer();
  771. m_VersionListProcessor = new VersionListProcessor(this);
  772. m_VersionListProcessor.VersionListUpdateSuccess += OnVersionListProcessorUpdateSuccess;
  773. m_VersionListProcessor.VersionListUpdateFailure += OnVersionListProcessorUpdateFailure;
  774. m_ResourceChecker = new ResourceChecker(this);
  775. m_ResourceChecker.ResourceNeedUpdate += OnCheckerResourceNeedUpdate;
  776. m_ResourceChecker.ResourceCheckComplete += OnCheckerResourceCheckComplete;
  777. m_ResourceUpdater = new ResourceUpdater(this);
  778. m_ResourceUpdater.ResourceApplySuccess += OnUpdaterResourceApplySuccess;
  779. m_ResourceUpdater.ResourceApplyFailure += OnUpdaterResourceApplyFailure;
  780. m_ResourceUpdater.ResourceApplyComplete += OnUpdaterResourceApplyComplete;
  781. m_ResourceUpdater.ResourceUpdateStart += OnUpdaterResourceUpdateStart;
  782. m_ResourceUpdater.ResourceUpdateChanged += OnUpdaterResourceUpdateChanged;
  783. m_ResourceUpdater.ResourceUpdateSuccess += OnUpdaterResourceUpdateSuccess;
  784. m_ResourceUpdater.ResourceUpdateFailure += OnUpdaterResourceUpdateFailure;
  785. m_ResourceUpdater.ResourceUpdateComplete += OnUpdaterResourceUpdateComplete;
  786. m_ResourceUpdater.ResourceUpdateAllComplete += OnUpdaterResourceUpdateAllComplete;
  787. }
  788. }
  789. else if (m_ResourceMode != resourceMode)
  790. {
  791. throw new GameFrameworkException("You can not change resource mode at this time.");
  792. }
  793. }
  794. /// <summary>
  795. /// 设置当前变体。
  796. /// </summary>
  797. /// <param name="currentVariant">当前变体。</param>
  798. public void SetCurrentVariant(string currentVariant)
  799. {
  800. if (m_RefuseSetFlag)
  801. {
  802. throw new GameFrameworkException("You can not set current variant at this time.");
  803. }
  804. m_CurrentVariant = currentVariant;
  805. }
  806. /// <summary>
  807. /// 设置对象池管理器。
  808. /// </summary>
  809. /// <param name="objectPoolManager">对象池管理器。</param>
  810. public void SetObjectPoolManager(IObjectPoolManager objectPoolManager)
  811. {
  812. if (objectPoolManager == null)
  813. {
  814. throw new GameFrameworkException("Object pool manager is invalid.");
  815. }
  816. m_ResourceLoader.SetObjectPoolManager(objectPoolManager);
  817. }
  818. /// <summary>
  819. /// 设置文件系统管理器。
  820. /// </summary>
  821. /// <param name="fileSystemManager">文件系统管理器。</param>
  822. public void SetFileSystemManager(IFileSystemManager fileSystemManager)
  823. {
  824. if (fileSystemManager == null)
  825. {
  826. throw new GameFrameworkException("File system manager is invalid.");
  827. }
  828. m_FileSystemManager = fileSystemManager;
  829. }
  830. /// <summary>
  831. /// 设置下载管理器。
  832. /// </summary>
  833. /// <param name="downloadManager">下载管理器。</param>
  834. public void SetDownloadManager(IDownloadManager downloadManager)
  835. {
  836. if (downloadManager == null)
  837. {
  838. throw new GameFrameworkException("Download manager is invalid.");
  839. }
  840. if (m_VersionListProcessor != null)
  841. {
  842. m_VersionListProcessor.SetDownloadManager(downloadManager);
  843. }
  844. if (m_ResourceUpdater != null)
  845. {
  846. m_ResourceUpdater.SetDownloadManager(downloadManager);
  847. }
  848. }
  849. /// <summary>
  850. /// 设置解密资源回调函数。
  851. /// </summary>
  852. /// <param name="decryptResourceCallback">要设置的解密资源回调函数。</param>
  853. /// <remarks>如果不设置,将使用默认的解密资源回调函数。</remarks>
  854. public void SetDecryptResourceCallback(DecryptResourceCallback decryptResourceCallback)
  855. {
  856. if (m_ResourceLoader.TotalAgentCount > 0)
  857. {
  858. throw new GameFrameworkException("You must set decrypt resource callback before add load resource agent helper.");
  859. }
  860. m_DecryptResourceCallback = decryptResourceCallback;
  861. }
  862. /// <summary>
  863. /// 设置资源辅助器。
  864. /// </summary>
  865. /// <param name="resourceHelper">资源辅助器。</param>
  866. public void SetResourceHelper(IResourceHelper resourceHelper)
  867. {
  868. if (resourceHelper == null)
  869. {
  870. throw new GameFrameworkException("Resource helper is invalid.");
  871. }
  872. if (m_ResourceLoader.TotalAgentCount > 0)
  873. {
  874. throw new GameFrameworkException("You must set resource helper before add load resource agent helper.");
  875. }
  876. m_ResourceHelper = resourceHelper;
  877. }
  878. /// <summary>
  879. /// 增加加载资源代理辅助器。
  880. /// </summary>
  881. /// <param name="loadResourceAgentHelper">要增加的加载资源代理辅助器。</param>
  882. public void AddLoadResourceAgentHelper(ILoadResourceAgentHelper loadResourceAgentHelper)
  883. {
  884. if (m_ResourceHelper == null)
  885. {
  886. throw new GameFrameworkException("Resource helper is invalid.");
  887. }
  888. if (string.IsNullOrEmpty(m_ReadOnlyPath))
  889. {
  890. throw new GameFrameworkException("Read-only path is invalid.");
  891. }
  892. if (string.IsNullOrEmpty(m_ReadWritePath))
  893. {
  894. throw new GameFrameworkException("Read-write path is invalid.");
  895. }
  896. m_ResourceLoader.AddLoadResourceAgentHelper(loadResourceAgentHelper, m_ResourceHelper, m_ReadOnlyPath, m_ReadWritePath, m_DecryptResourceCallback);
  897. }
  898. /// <summary>
  899. /// 使用单机模式并初始化资源。
  900. /// </summary>
  901. /// <param name="initResourcesCompleteCallback">使用单机模式并初始化资源完成时的回调函数。</param>
  902. public void InitResources(InitResourcesCompleteCallback initResourcesCompleteCallback)
  903. {
  904. if (initResourcesCompleteCallback == null)
  905. {
  906. throw new GameFrameworkException("Init resources complete callback is invalid.");
  907. }
  908. if (m_ResourceMode == ResourceMode.Unspecified)
  909. {
  910. throw new GameFrameworkException("You must set resource mode first.");
  911. }
  912. if (m_ResourceMode != ResourceMode.Package)
  913. {
  914. throw new GameFrameworkException("You can not use InitResources without package resource mode.");
  915. }
  916. if (m_ResourceIniter == null)
  917. {
  918. throw new GameFrameworkException("You can not use InitResources at this time.");
  919. }
  920. m_RefuseSetFlag = true;
  921. m_InitResourcesCompleteCallback = initResourcesCompleteCallback;
  922. m_ResourceIniter.InitResources(m_CurrentVariant);
  923. }
  924. /// <summary>
  925. /// 使用可更新模式并检查版本资源列表。
  926. /// </summary>
  927. /// <param name="latestInternalResourceVersion">最新的内部资源版本号。</param>
  928. /// <returns>检查版本资源列表结果。</returns>
  929. public CheckVersionListResult CheckVersionList(int latestInternalResourceVersion)
  930. {
  931. if (m_ResourceMode == ResourceMode.Unspecified)
  932. {
  933. throw new GameFrameworkException("You must set resource mode first.");
  934. }
  935. if (m_ResourceMode != ResourceMode.Updatable && m_ResourceMode != ResourceMode.UpdatableWhilePlaying)
  936. {
  937. throw new GameFrameworkException("You can not use CheckVersionList without updatable resource mode.");
  938. }
  939. if (m_VersionListProcessor == null)
  940. {
  941. throw new GameFrameworkException("You can not use CheckVersionList at this time.");
  942. }
  943. return m_VersionListProcessor.CheckVersionList(latestInternalResourceVersion);
  944. }
  945. /// <summary>
  946. /// 使用可更新模式并更新版本资源列表。
  947. /// </summary>
  948. /// <param name="versionListLength">版本资源列表大小。</param>
  949. /// <param name="versionListHashCode">版本资源列表哈希值。</param>
  950. /// <param name="versionListCompressedLength">版本资源列表压缩后大小。</param>
  951. /// <param name="versionListCompressedHashCode">版本资源列表压缩后哈希值。</param>
  952. /// <param name="updateVersionListCallbacks">版本资源列表更新回调函数集。</param>
  953. public void UpdateVersionList(int versionListLength, int versionListHashCode, int versionListCompressedLength, int versionListCompressedHashCode, UpdateVersionListCallbacks updateVersionListCallbacks)
  954. {
  955. if (updateVersionListCallbacks == null)
  956. {
  957. throw new GameFrameworkException("Update version list callbacks is invalid.");
  958. }
  959. if (m_ResourceMode == ResourceMode.Unspecified)
  960. {
  961. throw new GameFrameworkException("You must set resource mode first.");
  962. }
  963. if (m_ResourceMode != ResourceMode.Updatable && m_ResourceMode != ResourceMode.UpdatableWhilePlaying)
  964. {
  965. throw new GameFrameworkException("You can not use UpdateVersionList without updatable resource mode.");
  966. }
  967. if (m_VersionListProcessor == null)
  968. {
  969. throw new GameFrameworkException("You can not use UpdateVersionList at this time.");
  970. }
  971. m_UpdateVersionListCallbacks = updateVersionListCallbacks;
  972. m_VersionListProcessor.UpdateVersionList(versionListLength, versionListHashCode, versionListCompressedLength, versionListCompressedHashCode);
  973. }
  974. /// <summary>
  975. /// 使用可更新模式并检查资源。
  976. /// </summary>
  977. /// <param name="ignoreOtherVariant">是否忽略处理其它变体的资源,若不忽略,将会移除其它变体的资源。</param>
  978. /// <param name="checkResourcesCompleteCallback">使用可更新模式并检查资源完成时的回调函数。</param>
  979. public void CheckResources(bool ignoreOtherVariant, CheckResourcesCompleteCallback checkResourcesCompleteCallback)
  980. {
  981. if (checkResourcesCompleteCallback == null)
  982. {
  983. throw new GameFrameworkException("Check resources complete callback is invalid.");
  984. }
  985. if (m_ResourceMode == ResourceMode.Unspecified)
  986. {
  987. throw new GameFrameworkException("You must set resource mode first.");
  988. }
  989. if (m_ResourceMode != ResourceMode.Updatable && m_ResourceMode != ResourceMode.UpdatableWhilePlaying)
  990. {
  991. throw new GameFrameworkException("You can not use CheckResources without updatable resource mode.");
  992. }
  993. if (m_ResourceChecker == null)
  994. {
  995. throw new GameFrameworkException("You can not use CheckResources at this time.");
  996. }
  997. m_RefuseSetFlag = true;
  998. m_CheckResourcesCompleteCallback = checkResourcesCompleteCallback;
  999. m_ResourceChecker.CheckResources(m_CurrentVariant, ignoreOtherVariant);
  1000. }
  1001. /// <summary>
  1002. /// 使用可更新模式并应用资源包资源。
  1003. /// </summary>
  1004. /// <param name="resourcePackPath">要应用的资源包路径。</param>
  1005. /// <param name="applyResourcesCompleteCallback">使用可更新模式并应用资源包资源完成时的回调函数。</param>
  1006. public void ApplyResources(string resourcePackPath, ApplyResourcesCompleteCallback applyResourcesCompleteCallback)
  1007. {
  1008. if (string.IsNullOrEmpty(resourcePackPath))
  1009. {
  1010. throw new GameFrameworkException("Resource pack path is invalid.");
  1011. }
  1012. if (!File.Exists(resourcePackPath))
  1013. {
  1014. throw new GameFrameworkException(Utility.Text.Format("Resource pack '{0}' is not exist.", resourcePackPath));
  1015. }
  1016. if (applyResourcesCompleteCallback == null)
  1017. {
  1018. throw new GameFrameworkException("Apply resources complete callback is invalid.");
  1019. }
  1020. if (m_ResourceMode == ResourceMode.Unspecified)
  1021. {
  1022. throw new GameFrameworkException("You must set resource mode first.");
  1023. }
  1024. if (m_ResourceMode != ResourceMode.Updatable && m_ResourceMode != ResourceMode.UpdatableWhilePlaying)
  1025. {
  1026. throw new GameFrameworkException("You can not use ApplyResources without updatable resource mode.");
  1027. }
  1028. if (m_ResourceUpdater == null)
  1029. {
  1030. throw new GameFrameworkException("You can not use ApplyResources at this time.");
  1031. }
  1032. m_ApplyResourcesCompleteCallback = applyResourcesCompleteCallback;
  1033. m_ResourceUpdater.ApplyResources(resourcePackPath);
  1034. }
  1035. /// <summary>
  1036. /// 使用可更新模式并更新所有资源。
  1037. /// </summary>
  1038. /// <param name="updateResourcesCompleteCallback">使用可更新模式并更新默认资源组完成时的回调函数。</param>
  1039. public void UpdateResources(UpdateResourcesCompleteCallback updateResourcesCompleteCallback)
  1040. {
  1041. UpdateResources(string.Empty, updateResourcesCompleteCallback);
  1042. }
  1043. /// <summary>
  1044. /// 使用可更新模式并更新指定资源组的资源。
  1045. /// </summary>
  1046. /// <param name="resourceGroupName">要更新的资源组名称。</param>
  1047. /// <param name="updateResourcesCompleteCallback">使用可更新模式并更新指定资源组完成时的回调函数。</param>
  1048. public void UpdateResources(string resourceGroupName, UpdateResourcesCompleteCallback updateResourcesCompleteCallback)
  1049. {
  1050. if (updateResourcesCompleteCallback == null)
  1051. {
  1052. throw new GameFrameworkException("Update resources complete callback is invalid.");
  1053. }
  1054. if (m_ResourceMode == ResourceMode.Unspecified)
  1055. {
  1056. throw new GameFrameworkException("You must set resource mode first.");
  1057. }
  1058. if (m_ResourceMode != ResourceMode.Updatable && m_ResourceMode != ResourceMode.UpdatableWhilePlaying)
  1059. {
  1060. throw new GameFrameworkException("You can not use UpdateResources without updatable resource mode.");
  1061. }
  1062. if (m_ResourceUpdater == null)
  1063. {
  1064. throw new GameFrameworkException("You can not use UpdateResources at this time.");
  1065. }
  1066. ResourceGroup resourceGroup = (ResourceGroup)GetResourceGroup(resourceGroupName);
  1067. if (resourceGroup == null)
  1068. {
  1069. throw new GameFrameworkException(Utility.Text.Format("Can not find resource group '{0}'.", resourceGroupName));
  1070. }
  1071. m_UpdateResourcesCompleteCallback = updateResourcesCompleteCallback;
  1072. m_ResourceUpdater.UpdateResources(resourceGroup);
  1073. }
  1074. /// <summary>
  1075. /// 停止更新资源。
  1076. /// </summary>
  1077. public void StopUpdateResources()
  1078. {
  1079. if (m_ResourceMode == ResourceMode.Unspecified)
  1080. {
  1081. throw new GameFrameworkException("You must set resource mode first.");
  1082. }
  1083. if (m_ResourceMode != ResourceMode.Updatable && m_ResourceMode != ResourceMode.UpdatableWhilePlaying)
  1084. {
  1085. throw new GameFrameworkException("You can not use StopUpdateResources without updatable resource mode.");
  1086. }
  1087. if (m_ResourceUpdater == null)
  1088. {
  1089. throw new GameFrameworkException("You can not use StopUpdateResources at this time.");
  1090. }
  1091. m_ResourceUpdater.StopUpdateResources();
  1092. m_UpdateResourcesCompleteCallback = null;
  1093. }
  1094. /// <summary>
  1095. /// 校验资源包。
  1096. /// </summary>
  1097. /// <param name="resourcePackPath">要校验的资源包路径。</param>
  1098. /// <returns>是否校验资源包成功。</returns>
  1099. public bool VerifyResourcePack(string resourcePackPath)
  1100. {
  1101. if (string.IsNullOrEmpty(resourcePackPath))
  1102. {
  1103. throw new GameFrameworkException("Resource pack path is invalid.");
  1104. }
  1105. if (!File.Exists(resourcePackPath))
  1106. {
  1107. throw new GameFrameworkException(Utility.Text.Format("Resource pack '{0}' is not exist.", resourcePackPath));
  1108. }
  1109. if (m_ResourceMode == ResourceMode.Unspecified)
  1110. {
  1111. throw new GameFrameworkException("You must set resource mode first.");
  1112. }
  1113. if (m_ResourceMode != ResourceMode.Updatable && m_ResourceMode != ResourceMode.UpdatableWhilePlaying)
  1114. {
  1115. throw new GameFrameworkException("You can not use VerifyResourcePack without updatable resource mode.");
  1116. }
  1117. if (m_ResourcePackVersionListSerializer == null)
  1118. {
  1119. throw new GameFrameworkException("You can not use VerifyResourcePack at this time.");
  1120. }
  1121. try
  1122. {
  1123. long length = 0L;
  1124. ResourcePackVersionList versionList = default(ResourcePackVersionList);
  1125. using (FileStream fileStream = new FileStream(resourcePackPath, FileMode.Open, FileAccess.Read))
  1126. {
  1127. length = fileStream.Length;
  1128. versionList = m_ResourcePackVersionListSerializer.Deserialize(fileStream);
  1129. }
  1130. if (!versionList.IsValid)
  1131. {
  1132. return false;
  1133. }
  1134. if (versionList.Offset + versionList.Length != length)
  1135. {
  1136. return false;
  1137. }
  1138. int hashCode = 0;
  1139. using (FileStream fileStream = new FileStream(resourcePackPath, FileMode.Open, FileAccess.Read))
  1140. {
  1141. fileStream.Position = versionList.Offset;
  1142. hashCode = Utility.Verifier.GetCrc32(fileStream);
  1143. }
  1144. if (versionList.HashCode != hashCode)
  1145. {
  1146. return false;
  1147. }
  1148. return true;
  1149. }
  1150. catch
  1151. {
  1152. return false;
  1153. }
  1154. }
  1155. /// <summary>
  1156. /// 获取所有加载资源任务的信息。
  1157. /// </summary>
  1158. /// <returns>所有加载资源任务的信息。</returns>
  1159. public TaskInfo[] GetAllLoadAssetInfos()
  1160. {
  1161. return m_ResourceLoader.GetAllLoadAssetInfos();
  1162. }
  1163. /// <summary>
  1164. /// 获取所有加载资源任务的信息。
  1165. /// </summary>
  1166. /// <param name="results">所有加载资源任务的信息。</param>
  1167. public void GetAllLoadAssetInfos(List<TaskInfo> results)
  1168. {
  1169. m_ResourceLoader.GetAllLoadAssetInfos(results);
  1170. }
  1171. /// <summary>
  1172. /// 检查资源是否存在。
  1173. /// </summary>
  1174. /// <param name="assetName">要检查资源的名称。</param>
  1175. /// <returns>检查资源是否存在的结果。</returns>
  1176. public HasAssetResult HasAsset(string assetName)
  1177. {
  1178. if (string.IsNullOrEmpty(assetName))
  1179. {
  1180. throw new GameFrameworkException("Asset name is invalid.");
  1181. }
  1182. return m_ResourceLoader.HasAsset(assetName);
  1183. }
  1184. /// <summary>
  1185. /// 异步加载资源。
  1186. /// </summary>
  1187. /// <param name="assetName">要加载资源的名称。</param>
  1188. /// <param name="loadAssetCallbacks">加载资源回调函数集。</param>
  1189. public void LoadAsset(string assetName, LoadAssetCallbacks loadAssetCallbacks)
  1190. {
  1191. if (string.IsNullOrEmpty(assetName))
  1192. {
  1193. throw new GameFrameworkException("Asset name is invalid.");
  1194. }
  1195. if (loadAssetCallbacks == null)
  1196. {
  1197. throw new GameFrameworkException("Load asset callbacks is invalid.");
  1198. }
  1199. m_ResourceLoader.LoadAsset(assetName, null, Constant.DefaultPriority, loadAssetCallbacks, null);
  1200. }
  1201. /// <summary>
  1202. /// 异步加载资源。
  1203. /// </summary>
  1204. /// <param name="assetName">要加载资源的名称。</param>
  1205. /// <param name="assetType">要加载资源的类型。</param>
  1206. /// <param name="loadAssetCallbacks">加载资源回调函数集。</param>
  1207. public void LoadAsset(string assetName, Type assetType, LoadAssetCallbacks loadAssetCallbacks)
  1208. {
  1209. if (string.IsNullOrEmpty(assetName))
  1210. {
  1211. throw new GameFrameworkException("Asset name is invalid.");
  1212. }
  1213. if (loadAssetCallbacks == null)
  1214. {
  1215. throw new GameFrameworkException("Load asset callbacks is invalid.");
  1216. }
  1217. m_ResourceLoader.LoadAsset(assetName, assetType, Constant.DefaultPriority, loadAssetCallbacks, null);
  1218. }
  1219. /// <summary>
  1220. /// 异步加载资源。
  1221. /// </summary>
  1222. /// <param name="assetName">要加载资源的名称。</param>
  1223. /// <param name="priority">加载资源的优先级。</param>
  1224. /// <param name="loadAssetCallbacks">加载资源回调函数集。</param>
  1225. public void LoadAsset(string assetName, int priority, LoadAssetCallbacks loadAssetCallbacks)
  1226. {
  1227. if (string.IsNullOrEmpty(assetName))
  1228. {
  1229. throw new GameFrameworkException("Asset name is invalid.");
  1230. }
  1231. if (loadAssetCallbacks == null)
  1232. {
  1233. throw new GameFrameworkException("Load asset callbacks is invalid.");
  1234. }
  1235. m_ResourceLoader.LoadAsset(assetName, null, priority, loadAssetCallbacks, null);
  1236. }
  1237. /// <summary>
  1238. /// 异步加载资源。
  1239. /// </summary>
  1240. /// <param name="assetName">要加载资源的名称。</param>
  1241. /// <param name="loadAssetCallbacks">加载资源回调函数集。</param>
  1242. /// <param name="userData">用户自定义数据。</param>
  1243. public void LoadAsset(string assetName, LoadAssetCallbacks loadAssetCallbacks, object userData)
  1244. {
  1245. if (string.IsNullOrEmpty(assetName))
  1246. {
  1247. throw new GameFrameworkException("Asset name is invalid.");
  1248. }
  1249. if (loadAssetCallbacks == null)
  1250. {
  1251. throw new GameFrameworkException("Load asset callbacks is invalid.");
  1252. }
  1253. m_ResourceLoader.LoadAsset(assetName, null, Constant.DefaultPriority, loadAssetCallbacks, userData);
  1254. }
  1255. /// <summary>
  1256. /// 异步加载资源。
  1257. /// </summary>
  1258. /// <param name="assetName">要加载资源的名称。</param>
  1259. /// <param name="assetType">要加载资源的类型。</param>
  1260. /// <param name="priority">加载资源的优先级。</param>
  1261. /// <param name="loadAssetCallbacks">加载资源回调函数集。</param>
  1262. public void LoadAsset(string assetName, Type assetType, int priority, LoadAssetCallbacks loadAssetCallbacks)
  1263. {
  1264. if (string.IsNullOrEmpty(assetName))
  1265. {
  1266. throw new GameFrameworkException("Asset name is invalid.");
  1267. }
  1268. if (loadAssetCallbacks == null)
  1269. {
  1270. throw new GameFrameworkException("Load asset callbacks is invalid.");
  1271. }
  1272. m_ResourceLoader.LoadAsset(assetName, assetType, priority, loadAssetCallbacks, null);
  1273. }
  1274. /// <summary>
  1275. /// 异步加载资源。
  1276. /// </summary>
  1277. /// <param name="assetName">要加载资源的名称。</param>
  1278. /// <param name="assetType">要加载资源的类型。</param>
  1279. /// <param name="loadAssetCallbacks">加载资源回调函数集。</param>
  1280. /// <param name="userData">用户自定义数据。</param>
  1281. public void LoadAsset(string assetName, Type assetType, LoadAssetCallbacks loadAssetCallbacks, object userData)
  1282. {
  1283. if (string.IsNullOrEmpty(assetName))
  1284. {
  1285. throw new GameFrameworkException("Asset name is invalid.");
  1286. }
  1287. if (loadAssetCallbacks == null)
  1288. {
  1289. throw new GameFrameworkException("Load asset callbacks is invalid.");
  1290. }
  1291. m_ResourceLoader.LoadAsset(assetName, assetType, Constant.DefaultPriority, loadAssetCallbacks, userData);
  1292. }
  1293. /// <summary>
  1294. /// 异步加载资源。
  1295. /// </summary>
  1296. /// <param name="assetName">要加载资源的名称。</param>
  1297. /// <param name="priority">加载资源的优先级。</param>
  1298. /// <param name="loadAssetCallbacks">加载资源回调函数集。</param>
  1299. /// <param name="userData">用户自定义数据。</param>
  1300. public void LoadAsset(string assetName, int priority, LoadAssetCallbacks loadAssetCallbacks, object userData)
  1301. {
  1302. if (string.IsNullOrEmpty(assetName))
  1303. {
  1304. throw new GameFrameworkException("Asset name is invalid.");
  1305. }
  1306. if (loadAssetCallbacks == null)
  1307. {
  1308. throw new GameFrameworkException("Load asset callbacks is invalid.");
  1309. }
  1310. m_ResourceLoader.LoadAsset(assetName, null, priority, loadAssetCallbacks, userData);
  1311. }
  1312. /// <summary>
  1313. /// 异步加载资源。
  1314. /// </summary>
  1315. /// <param name="assetName">要加载资源的名称。</param>
  1316. /// <param name="assetType">要加载资源的类型。</param>
  1317. /// <param name="priority">加载资源的优先级。</param>
  1318. /// <param name="loadAssetCallbacks">加载资源回调函数集。</param>
  1319. /// <param name="userData">用户自定义数据。</param>
  1320. public void LoadAsset(string assetName, Type assetType, int priority, LoadAssetCallbacks loadAssetCallbacks, object userData)
  1321. {
  1322. if (string.IsNullOrEmpty(assetName))
  1323. {
  1324. throw new GameFrameworkException("Asset name is invalid.");
  1325. }
  1326. if (loadAssetCallbacks == null)
  1327. {
  1328. throw new GameFrameworkException("Load asset callbacks is invalid.");
  1329. }
  1330. m_ResourceLoader.LoadAsset(assetName, assetType, priority, loadAssetCallbacks, userData);
  1331. }
  1332. /// <summary>
  1333. /// 卸载资源。
  1334. /// </summary>
  1335. /// <param name="asset">要卸载的资源。</param>
  1336. public void UnloadAsset(object asset)
  1337. {
  1338. if (asset == null)
  1339. {
  1340. throw new GameFrameworkException("Asset is invalid.");
  1341. }
  1342. if (m_ResourceLoader == null)
  1343. {
  1344. return;
  1345. }
  1346. m_ResourceLoader.UnloadAsset(asset);
  1347. }
  1348. /// <summary>
  1349. /// 异步加载场景。
  1350. /// </summary>
  1351. /// <param name="sceneAssetName">要加载场景资源的名称。</param>
  1352. /// <param name="loadSceneCallbacks">加载场景回调函数集。</param>
  1353. public void LoadScene(string sceneAssetName, LoadSceneCallbacks loadSceneCallbacks)
  1354. {
  1355. if (string.IsNullOrEmpty(sceneAssetName))
  1356. {
  1357. throw new GameFrameworkException("Scene asset name is invalid.");
  1358. }
  1359. if (loadSceneCallbacks == null)
  1360. {
  1361. throw new GameFrameworkException("Load scene callbacks is invalid.");
  1362. }
  1363. m_ResourceLoader.LoadScene(sceneAssetName, Constant.DefaultPriority, loadSceneCallbacks, null);
  1364. }
  1365. /// <summary>
  1366. /// 异步加载场景。
  1367. /// </summary>
  1368. /// <param name="sceneAssetName">要加载场景资源的名称。</param>
  1369. /// <param name="priority">加载场景资源的优先级。</param>
  1370. /// <param name="loadSceneCallbacks">加载场景回调函数集。</param>
  1371. public void LoadScene(string sceneAssetName, int priority, LoadSceneCallbacks loadSceneCallbacks)
  1372. {
  1373. if (string.IsNullOrEmpty(sceneAssetName))
  1374. {
  1375. throw new GameFrameworkException("Scene asset name is invalid.");
  1376. }
  1377. if (loadSceneCallbacks == null)
  1378. {
  1379. throw new GameFrameworkException("Load scene callbacks is invalid.");
  1380. }
  1381. m_ResourceLoader.LoadScene(sceneAssetName, priority, loadSceneCallbacks, null);
  1382. }
  1383. /// <summary>
  1384. /// 异步加载场景。
  1385. /// </summary>
  1386. /// <param name="sceneAssetName">要加载场景资源的名称。</param>
  1387. /// <param name="loadSceneCallbacks">加载场景回调函数集。</param>
  1388. /// <param name="userData">用户自定义数据。</param>
  1389. public void LoadScene(string sceneAssetName, LoadSceneCallbacks loadSceneCallbacks, object userData)
  1390. {
  1391. if (string.IsNullOrEmpty(sceneAssetName))
  1392. {
  1393. throw new GameFrameworkException("Scene asset name is invalid.");
  1394. }
  1395. if (loadSceneCallbacks == null)
  1396. {
  1397. throw new GameFrameworkException("Load scene callbacks is invalid.");
  1398. }
  1399. m_ResourceLoader.LoadScene(sceneAssetName, Constant.DefaultPriority, loadSceneCallbacks, userData);
  1400. }
  1401. /// <summary>
  1402. /// 异步加载场景。
  1403. /// </summary>
  1404. /// <param name="sceneAssetName">要加载场景资源的名称。</param>
  1405. /// <param name="priority">加载场景资源的优先级。</param>
  1406. /// <param name="loadSceneCallbacks">加载场景回调函数集。</param>
  1407. /// <param name="userData">用户自定义数据。</param>
  1408. public void LoadScene(string sceneAssetName, int priority, LoadSceneCallbacks loadSceneCallbacks, object userData)
  1409. {
  1410. if (string.IsNullOrEmpty(sceneAssetName))
  1411. {
  1412. throw new GameFrameworkException("Scene asset name is invalid.");
  1413. }
  1414. if (loadSceneCallbacks == null)
  1415. {
  1416. throw new GameFrameworkException("Load scene callbacks is invalid.");
  1417. }
  1418. m_ResourceLoader.LoadScene(sceneAssetName, priority, loadSceneCallbacks, userData);
  1419. }
  1420. /// <summary>
  1421. /// 异步卸载场景。
  1422. /// </summary>
  1423. /// <param name="sceneAssetName">要卸载场景资源的名称。</param>
  1424. /// <param name="unloadSceneCallbacks">卸载场景回调函数集。</param>
  1425. public void UnloadScene(string sceneAssetName, UnloadSceneCallbacks unloadSceneCallbacks)
  1426. {
  1427. if (string.IsNullOrEmpty(sceneAssetName))
  1428. {
  1429. throw new GameFrameworkException("Scene asset name is invalid.");
  1430. }
  1431. if (unloadSceneCallbacks == null)
  1432. {
  1433. throw new GameFrameworkException("Unload scene callbacks is invalid.");
  1434. }
  1435. m_ResourceLoader.UnloadScene(sceneAssetName, unloadSceneCallbacks, null);
  1436. }
  1437. /// <summary>
  1438. /// 异步卸载场景。
  1439. /// </summary>
  1440. /// <param name="sceneAssetName">要卸载场景资源的名称。</param>
  1441. /// <param name="unloadSceneCallbacks">卸载场景回调函数集。</param>
  1442. /// <param name="userData">用户自定义数据。</param>
  1443. public void UnloadScene(string sceneAssetName, UnloadSceneCallbacks unloadSceneCallbacks, object userData)
  1444. {
  1445. if (string.IsNullOrEmpty(sceneAssetName))
  1446. {
  1447. throw new GameFrameworkException("Scene asset name is invalid.");
  1448. }
  1449. if (unloadSceneCallbacks == null)
  1450. {
  1451. throw new GameFrameworkException("Unload scene callbacks is invalid.");
  1452. }
  1453. m_ResourceLoader.UnloadScene(sceneAssetName, unloadSceneCallbacks, userData);
  1454. }
  1455. /// <summary>
  1456. /// 获取二进制资源的实际路径。
  1457. /// </summary>
  1458. /// <param name="binaryAssetName">要获取实际路径的二进制资源的名称。</param>
  1459. /// <returns>二进制资源的实际路径。</returns>
  1460. /// <remarks>此方法仅适用于二进制资源存储在磁盘(而非文件系统)中的情况。若二进制资源存储在文件系统中时,返回值将始终为空。</remarks>
  1461. public string GetBinaryPath(string binaryAssetName)
  1462. {
  1463. if (string.IsNullOrEmpty(binaryAssetName))
  1464. {
  1465. throw new GameFrameworkException("Binary asset name is invalid.");
  1466. }
  1467. return m_ResourceLoader.GetBinaryPath(binaryAssetName);
  1468. }
  1469. /// <summary>
  1470. /// 获取二进制资源的实际路径。
  1471. /// </summary>
  1472. /// <param name="binaryAssetName">要获取实际路径的二进制资源的名称。</param>
  1473. /// <param name="storageInReadOnly">二进制资源是否存储在只读区中。</param>
  1474. /// <param name="storageInFileSystem">二进制资源是否存储在文件系统中。</param>
  1475. /// <param name="relativePath">二进制资源或存储二进制资源的文件系统,相对于只读区或者读写区的相对路径。</param>
  1476. /// <param name="fileName">若二进制资源存储在文件系统中,则指示二进制资源在文件系统中的名称,否则此参数返回空。</param>
  1477. /// <returns>是否获取二进制资源的实际路径成功。</returns>
  1478. public bool GetBinaryPath(string binaryAssetName, out bool storageInReadOnly, out bool storageInFileSystem, out string relativePath, out string fileName)
  1479. {
  1480. return m_ResourceLoader.GetBinaryPath(binaryAssetName, out storageInReadOnly, out storageInFileSystem, out relativePath, out fileName);
  1481. }
  1482. /// <summary>
  1483. /// 获取二进制资源的长度。
  1484. /// </summary>
  1485. /// <param name="binaryAssetName">要获取长度的二进制资源的名称。</param>
  1486. /// <returns>二进制资源的长度。</returns>
  1487. public int GetBinaryLength(string binaryAssetName)
  1488. {
  1489. return m_ResourceLoader.GetBinaryLength(binaryAssetName);
  1490. }
  1491. /// <summary>
  1492. /// 异步加载二进制资源。
  1493. /// </summary>
  1494. /// <param name="binaryAssetName">要加载二进制资源的名称。</param>
  1495. /// <param name="loadBinaryCallbacks">加载二进制资源回调函数集。</param>
  1496. public void LoadBinary(string binaryAssetName, LoadBinaryCallbacks loadBinaryCallbacks)
  1497. {
  1498. if (string.IsNullOrEmpty(binaryAssetName))
  1499. {
  1500. throw new GameFrameworkException("Binary asset name is invalid.");
  1501. }
  1502. if (loadBinaryCallbacks == null)
  1503. {
  1504. throw new GameFrameworkException("Load binary callbacks is invalid.");
  1505. }
  1506. m_ResourceLoader.LoadBinary(binaryAssetName, loadBinaryCallbacks, null);
  1507. }
  1508. /// <summary>
  1509. /// 异步加载二进制资源。
  1510. /// </summary>
  1511. /// <param name="binaryAssetName">要加载二进制资源的名称。</param>
  1512. /// <param name="loadBinaryCallbacks">加载二进制资源回调函数集。</param>
  1513. /// <param name="userData">用户自定义数据。</param>
  1514. public void LoadBinary(string binaryAssetName, LoadBinaryCallbacks loadBinaryCallbacks, object userData)
  1515. {
  1516. if (string.IsNullOrEmpty(binaryAssetName))
  1517. {
  1518. throw new GameFrameworkException("Binary asset name is invalid.");
  1519. }
  1520. if (loadBinaryCallbacks == null)
  1521. {
  1522. throw new GameFrameworkException("Load binary callbacks is invalid.");
  1523. }
  1524. m_ResourceLoader.LoadBinary(binaryAssetName, loadBinaryCallbacks, userData);
  1525. }
  1526. /// <summary>
  1527. /// 从文件系统中加载二进制资源。
  1528. /// </summary>
  1529. /// <param name="binaryAssetName">要加载二进制资源的名称。</param>
  1530. /// <returns>存储加载二进制资源的二进制流。</returns>
  1531. public byte[] LoadBinaryFromFileSystem(string binaryAssetName)
  1532. {
  1533. if (string.IsNullOrEmpty(binaryAssetName))
  1534. {
  1535. throw new GameFrameworkException("Binary asset name is invalid.");
  1536. }
  1537. return m_ResourceLoader.LoadBinaryFromFileSystem(binaryAssetName);
  1538. }
  1539. /// <summary>
  1540. /// 从文件系统中加载二进制资源。
  1541. /// </summary>
  1542. /// <param name="binaryAssetName">要加载二进制资源的名称。</param>
  1543. /// <param name="buffer">存储加载二进制资源的二进制流。</param>
  1544. /// <returns>实际加载了多少字节。</returns>
  1545. public int LoadBinaryFromFileSystem(string binaryAssetName, byte[] buffer)
  1546. {
  1547. if (string.IsNullOrEmpty(binaryAssetName))
  1548. {
  1549. throw new GameFrameworkException("Binary asset name is invalid.");
  1550. }
  1551. if (buffer == null)
  1552. {
  1553. throw new GameFrameworkException("Buffer is invalid.");
  1554. }
  1555. return m_ResourceLoader.LoadBinaryFromFileSystem(binaryAssetName, buffer, 0, buffer.Length);
  1556. }
  1557. /// <summary>
  1558. /// 从文件系统中加载二进制资源。
  1559. /// </summary>
  1560. /// <param name="binaryAssetName">要加载二进制资源的名称。</param>
  1561. /// <param name="buffer">存储加载二进制资源的二进制流。</param>
  1562. /// <param name="startIndex">存储加载二进制资源的二进制流的起始位置。</param>
  1563. /// <returns>实际加载了多少字节。</returns>
  1564. public int LoadBinaryFromFileSystem(string binaryAssetName, byte[] buffer, int startIndex)
  1565. {
  1566. if (string.IsNullOrEmpty(binaryAssetName))
  1567. {
  1568. throw new GameFrameworkException("Binary asset name is invalid.");
  1569. }
  1570. if (buffer == null)
  1571. {
  1572. throw new GameFrameworkException("Buffer is invalid.");
  1573. }
  1574. return m_ResourceLoader.LoadBinaryFromFileSystem(binaryAssetName, buffer, startIndex, buffer.Length - startIndex);
  1575. }
  1576. /// <summary>
  1577. /// 从文件系统中加载二进制资源。
  1578. /// </summary>
  1579. /// <param name="binaryAssetName">要加载二进制资源的名称。</param>
  1580. /// <param name="buffer">存储加载二进制资源的二进制流。</param>
  1581. /// <param name="startIndex">存储加载二进制资源的二进制流的起始位置。</param>
  1582. /// <param name="length">存储加载二进制资源的二进制流的长度。</param>
  1583. /// <returns>实际加载了多少字节。</returns>
  1584. public int LoadBinaryFromFileSystem(string binaryAssetName, byte[] buffer, int startIndex, int length)
  1585. {
  1586. if (string.IsNullOrEmpty(binaryAssetName))
  1587. {
  1588. throw new GameFrameworkException("Binary asset name is invalid.");
  1589. }
  1590. if (buffer == null)
  1591. {
  1592. throw new GameFrameworkException("Buffer is invalid.");
  1593. }
  1594. return m_ResourceLoader.LoadBinaryFromFileSystem(binaryAssetName, buffer, startIndex, length);
  1595. }
  1596. /// <summary>
  1597. /// 从文件系统中加载二进制资源的片段。
  1598. /// </summary>
  1599. /// <param name="binaryAssetName">要加载片段的二进制资源的名称。</param>
  1600. /// <param name="length">要加载片段的长度。</param>
  1601. /// <returns>存储加载二进制资源片段内容的二进制流。</returns>
  1602. public byte[] LoadBinarySegmentFromFileSystem(string binaryAssetName, int length)
  1603. {
  1604. if (string.IsNullOrEmpty(binaryAssetName))
  1605. {
  1606. throw new GameFrameworkException("Binary asset name is invalid.");
  1607. }
  1608. return m_ResourceLoader.LoadBinarySegmentFromFileSystem(binaryAssetName, 0, length);
  1609. }
  1610. /// <summary>
  1611. /// 从文件系统中加载二进制资源的片段。
  1612. /// </summary>
  1613. /// <param name="binaryAssetName">要加载片段的二进制资源的名称。</param>
  1614. /// <param name="offset">要加载片段的偏移。</param>
  1615. /// <param name="length">要加载片段的长度。</param>
  1616. /// <returns>存储加载二进制资源片段内容的二进制流。</returns>
  1617. public byte[] LoadBinarySegmentFromFileSystem(string binaryAssetName, int offset, int length)
  1618. {
  1619. if (string.IsNullOrEmpty(binaryAssetName))
  1620. {
  1621. throw new GameFrameworkException("Binary asset name is invalid.");
  1622. }
  1623. return m_ResourceLoader.LoadBinarySegmentFromFileSystem(binaryAssetName, offset, length);
  1624. }
  1625. /// <summary>
  1626. /// 从文件系统中加载二进制资源的片段。
  1627. /// </summary>
  1628. /// <param name="binaryAssetName">要加载片段的二进制资源的名称。</param>
  1629. /// <param name="buffer">存储加载二进制资源片段内容的二进制流。</param>
  1630. /// <returns>实际加载了多少字节。</returns>
  1631. public int LoadBinarySegmentFromFileSystem(string binaryAssetName, byte[] buffer)
  1632. {
  1633. if (string.IsNullOrEmpty(binaryAssetName))
  1634. {
  1635. throw new GameFrameworkException("Binary asset name is invalid.");
  1636. }
  1637. if (buffer == null)
  1638. {
  1639. throw new GameFrameworkException("Buffer is invalid.");
  1640. }
  1641. return m_ResourceLoader.LoadBinarySegmentFromFileSystem(binaryAssetName, 0, buffer, 0, buffer.Length);
  1642. }
  1643. /// <summary>
  1644. /// 从文件系统中加载二进制资源的片段。
  1645. /// </summary>
  1646. /// <param name="binaryAssetName">要加载片段的二进制资源的名称。</param>
  1647. /// <param name="buffer">存储加载二进制资源片段内容的二进制流。</param>
  1648. /// <param name="length">要加载片段的长度。</param>
  1649. /// <returns>实际加载了多少字节。</returns>
  1650. public int LoadBinarySegmentFromFileSystem(string binaryAssetName, byte[] buffer, int length)
  1651. {
  1652. if (string.IsNullOrEmpty(binaryAssetName))
  1653. {
  1654. throw new GameFrameworkException("Binary asset name is invalid.");
  1655. }
  1656. if (buffer == null)
  1657. {
  1658. throw new GameFrameworkException("Buffer is invalid.");
  1659. }
  1660. return m_ResourceLoader.LoadBinarySegmentFromFileSystem(binaryAssetName, 0, buffer, 0, length);
  1661. }
  1662. /// <summary>
  1663. /// 从文件系统中加载二进制资源的片段。
  1664. /// </summary>
  1665. /// <param name="binaryAssetName">要加载片段的二进制资源的名称。</param>
  1666. /// <param name="buffer">存储加载二进制资源片段内容的二进制流。</param>
  1667. /// <param name="startIndex">存储加载二进制资源片段内容的二进制流的起始位置。</param>
  1668. /// <param name="length">要加载片段的长度。</param>
  1669. /// <returns>实际加载了多少字节。</returns>
  1670. public int LoadBinarySegmentFromFileSystem(string binaryAssetName, byte[] buffer, int startIndex, int length)
  1671. {
  1672. if (string.IsNullOrEmpty(binaryAssetName))
  1673. {
  1674. throw new GameFrameworkException("Binary asset name is invalid.");
  1675. }
  1676. if (buffer == null)
  1677. {
  1678. throw new GameFrameworkException("Buffer is invalid.");
  1679. }
  1680. return m_ResourceLoader.LoadBinarySegmentFromFileSystem(binaryAssetName, 0, buffer, startIndex, length);
  1681. }
  1682. /// <summary>
  1683. /// 从文件系统中加载二进制资源的片段。
  1684. /// </summary>
  1685. /// <param name="binaryAssetName">要加载片段的二进制资源的名称。</param>
  1686. /// <param name="offset">要加载片段的偏移。</param>
  1687. /// <param name="buffer">存储加载二进制资源片段内容的二进制流。</param>
  1688. /// <returns>实际加载了多少字节。</returns>
  1689. public int LoadBinarySegmentFromFileSystem(string binaryAssetName, int offset, byte[] buffer)
  1690. {
  1691. if (string.IsNullOrEmpty(binaryAssetName))
  1692. {
  1693. throw new GameFrameworkException("Binary asset name is invalid.");
  1694. }
  1695. if (buffer == null)
  1696. {
  1697. throw new GameFrameworkException("Buffer is invalid.");
  1698. }
  1699. return m_ResourceLoader.LoadBinarySegmentFromFileSystem(binaryAssetName, offset, buffer, 0, buffer.Length);
  1700. }
  1701. /// <summary>
  1702. /// 从文件系统中加载二进制资源的片段。
  1703. /// </summary>
  1704. /// <param name="binaryAssetName">要加载片段的二进制资源的名称。</param>
  1705. /// <param name="offset">要加载片段的偏移。</param>
  1706. /// <param name="buffer">存储加载二进制资源片段内容的二进制流。</param>
  1707. /// <param name="length">要加载片段的长度。</param>
  1708. /// <returns>实际加载了多少字节。</returns>
  1709. public int LoadBinarySegmentFromFileSystem(string binaryAssetName, int offset, byte[] buffer, int length)
  1710. {
  1711. if (string.IsNullOrEmpty(binaryAssetName))
  1712. {
  1713. throw new GameFrameworkException("Binary asset name is invalid.");
  1714. }
  1715. if (buffer == null)
  1716. {
  1717. throw new GameFrameworkException("Buffer is invalid.");
  1718. }
  1719. return m_ResourceLoader.LoadBinarySegmentFromFileSystem(binaryAssetName, offset, buffer, 0, length);
  1720. }
  1721. /// <summary>
  1722. /// 从文件系统中加载二进制资源的片段。
  1723. /// </summary>
  1724. /// <param name="binaryAssetName">要加载片段的二进制资源的名称。</param>
  1725. /// <param name="offset">要加载片段的偏移。</param>
  1726. /// <param name="buffer">存储加载二进制资源片段内容的二进制流。</param>
  1727. /// <param name="startIndex">存储加载二进制资源片段内容的二进制流的起始位置。</param>
  1728. /// <param name="length">要加载片段的长度。</param>
  1729. /// <returns>实际加载了多少字节。</returns>
  1730. public int LoadBinarySegmentFromFileSystem(string binaryAssetName, int offset, byte[] buffer, int startIndex, int length)
  1731. {
  1732. if (string.IsNullOrEmpty(binaryAssetName))
  1733. {
  1734. throw new GameFrameworkException("Binary asset name is invalid.");
  1735. }
  1736. if (buffer == null)
  1737. {
  1738. throw new GameFrameworkException("Buffer is invalid.");
  1739. }
  1740. return m_ResourceLoader.LoadBinarySegmentFromFileSystem(binaryAssetName, offset, buffer, startIndex, length);
  1741. }
  1742. /// <summary>
  1743. /// 检查资源组是否存在。
  1744. /// </summary>
  1745. /// <param name="resourceGroupName">要检查资源组的名称。</param>
  1746. /// <returns>资源组是否存在。</returns>
  1747. public bool HasResourceGroup(string resourceGroupName)
  1748. {
  1749. return m_ResourceGroups.ContainsKey(resourceGroupName ?? string.Empty);
  1750. }
  1751. /// <summary>
  1752. /// 获取默认资源组。
  1753. /// </summary>
  1754. /// <returns>默认资源组。</returns>
  1755. public IResourceGroup GetResourceGroup()
  1756. {
  1757. return GetResourceGroup(string.Empty);
  1758. }
  1759. /// <summary>
  1760. /// 获取资源组。
  1761. /// </summary>
  1762. /// <param name="resourceGroupName">要获取的资源组名称。</param>
  1763. /// <returns>要获取的资源组。</returns>
  1764. public IResourceGroup GetResourceGroup(string resourceGroupName)
  1765. {
  1766. ResourceGroup resourceGroup = null;
  1767. if (m_ResourceGroups.TryGetValue(resourceGroupName ?? string.Empty, out resourceGroup))
  1768. {
  1769. return resourceGroup;
  1770. }
  1771. return null;
  1772. }
  1773. /// <summary>
  1774. /// 获取所有资源组。
  1775. /// </summary>
  1776. /// <returns>所有资源组。</returns>
  1777. public IResourceGroup[] GetAllResourceGroups()
  1778. {
  1779. int index = 0;
  1780. IResourceGroup[] results = new IResourceGroup[m_ResourceGroups.Count];
  1781. foreach (KeyValuePair<string, ResourceGroup> resourceGroup in m_ResourceGroups)
  1782. {
  1783. results[index++] = resourceGroup.Value;
  1784. }
  1785. return results;
  1786. }
  1787. /// <summary>
  1788. /// 获取所有资源组。
  1789. /// </summary>
  1790. /// <param name="results">所有资源组。</param>
  1791. public void GetAllResourceGroups(List<IResourceGroup> results)
  1792. {
  1793. if (results == null)
  1794. {
  1795. throw new GameFrameworkException("Results is invalid.");
  1796. }
  1797. results.Clear();
  1798. foreach (KeyValuePair<string, ResourceGroup> resourceGroup in m_ResourceGroups)
  1799. {
  1800. results.Add(resourceGroup.Value);
  1801. }
  1802. }
  1803. /// <summary>
  1804. /// 获取资源组集合。
  1805. /// </summary>
  1806. /// <param name="resourceGroupNames">要获取的资源组名称的集合。</param>
  1807. /// <returns>要获取的资源组集合。</returns>
  1808. public IResourceGroupCollection GetResourceGroupCollection(params string[] resourceGroupNames)
  1809. {
  1810. if (resourceGroupNames == null || resourceGroupNames.Length < 1)
  1811. {
  1812. throw new GameFrameworkException("Resource group names is invalid.");
  1813. }
  1814. ResourceGroup[] resourceGroups = new ResourceGroup[resourceGroupNames.Length];
  1815. for (int i = 0; i < resourceGroupNames.Length; i++)
  1816. {
  1817. if (string.IsNullOrEmpty(resourceGroupNames[i]))
  1818. {
  1819. throw new GameFrameworkException("Resource group name is invalid.");
  1820. }
  1821. resourceGroups[i] = (ResourceGroup)GetResourceGroup(resourceGroupNames[i]);
  1822. if (resourceGroups[i] == null)
  1823. {
  1824. throw new GameFrameworkException(Utility.Text.Format("Resource group '{0}' is not exist.", resourceGroupNames[i]));
  1825. }
  1826. }
  1827. return new ResourceGroupCollection(resourceGroups, m_ResourceInfos);
  1828. }
  1829. /// <summary>
  1830. /// 获取资源组集合。
  1831. /// </summary>
  1832. /// <param name="resourceGroupNames">要获取的资源组名称的集合。</param>
  1833. /// <returns>要获取的资源组集合。</returns>
  1834. public IResourceGroupCollection GetResourceGroupCollection(List<string> resourceGroupNames)
  1835. {
  1836. if (resourceGroupNames == null || resourceGroupNames.Count < 1)
  1837. {
  1838. throw new GameFrameworkException("Resource group names is invalid.");
  1839. }
  1840. ResourceGroup[] resourceGroups = new ResourceGroup[resourceGroupNames.Count];
  1841. for (int i = 0; i < resourceGroupNames.Count; i++)
  1842. {
  1843. if (string.IsNullOrEmpty(resourceGroupNames[i]))
  1844. {
  1845. throw new GameFrameworkException("Resource group name is invalid.");
  1846. }
  1847. resourceGroups[i] = (ResourceGroup)GetResourceGroup(resourceGroupNames[i]);
  1848. if (resourceGroups[i] == null)
  1849. {
  1850. throw new GameFrameworkException(Utility.Text.Format("Resource group '{0}' is not exist.", resourceGroupNames[i]));
  1851. }
  1852. }
  1853. return new ResourceGroupCollection(resourceGroups, m_ResourceInfos);
  1854. }
  1855. private void UpdateResource(ResourceName resourceName)
  1856. {
  1857. m_ResourceUpdater.UpdateResource(resourceName);
  1858. }
  1859. private ResourceGroup GetOrAddResourceGroup(string resourceGroupName)
  1860. {
  1861. if (resourceGroupName == null)
  1862. {
  1863. resourceGroupName = string.Empty;
  1864. }
  1865. ResourceGroup resourceGroup = null;
  1866. if (!m_ResourceGroups.TryGetValue(resourceGroupName, out resourceGroup))
  1867. {
  1868. resourceGroup = new ResourceGroup(resourceGroupName, m_ResourceInfos);
  1869. m_ResourceGroups.Add(resourceGroupName, resourceGroup);
  1870. }
  1871. return resourceGroup;
  1872. }
  1873. private AssetInfo GetAssetInfo(string assetName)
  1874. {
  1875. if (string.IsNullOrEmpty(assetName))
  1876. {
  1877. throw new GameFrameworkException("Asset name is invalid.");
  1878. }
  1879. if (m_AssetInfos == null)
  1880. {
  1881. return null;
  1882. }
  1883. AssetInfo assetInfo = null;
  1884. if (m_AssetInfos.TryGetValue(assetName, out assetInfo))
  1885. {
  1886. return assetInfo;
  1887. }
  1888. return null;
  1889. }
  1890. private ResourceInfo GetResourceInfo(ResourceName resourceName)
  1891. {
  1892. if (m_ResourceInfos == null)
  1893. {
  1894. return null;
  1895. }
  1896. ResourceInfo resourceInfo = null;
  1897. if (m_ResourceInfos.TryGetValue(resourceName, out resourceInfo))
  1898. {
  1899. return resourceInfo;
  1900. }
  1901. return null;
  1902. }
  1903. private IFileSystem GetFileSystem(string fileSystemName, bool storageInReadOnly)
  1904. {
  1905. if (string.IsNullOrEmpty(fileSystemName))
  1906. {
  1907. throw new GameFrameworkException("File system name is invalid.");
  1908. }
  1909. IFileSystem fileSystem = null;
  1910. if (storageInReadOnly)
  1911. {
  1912. if (!m_ReadOnlyFileSystems.TryGetValue(fileSystemName, out fileSystem))
  1913. {
  1914. string fullPath = Utility.Path.GetRegularPath(Path.Combine(m_ReadOnlyPath, Utility.Text.Format("{0}.{1}", fileSystemName, DefaultExtension)));
  1915. fileSystem = m_FileSystemManager.GetFileSystem(fullPath);
  1916. if (fileSystem == null)
  1917. {
  1918. fileSystem = m_FileSystemManager.LoadFileSystem(fullPath, FileSystemAccess.Read);
  1919. m_ReadOnlyFileSystems.Add(fileSystemName, fileSystem);
  1920. }
  1921. }
  1922. }
  1923. else
  1924. {
  1925. if (!m_ReadWriteFileSystems.TryGetValue(fileSystemName, out fileSystem))
  1926. {
  1927. string fullPath = Utility.Path.GetRegularPath(Path.Combine(m_ReadWritePath, Utility.Text.Format("{0}.{1}", fileSystemName, DefaultExtension)));
  1928. fileSystem = m_FileSystemManager.GetFileSystem(fullPath);
  1929. if (fileSystem == null)
  1930. {
  1931. if (File.Exists(fullPath))
  1932. {
  1933. fileSystem = m_FileSystemManager.LoadFileSystem(fullPath, FileSystemAccess.ReadWrite);
  1934. }
  1935. else
  1936. {
  1937. string directory = Path.GetDirectoryName(fullPath);
  1938. if (!Directory.Exists(directory))
  1939. {
  1940. Directory.CreateDirectory(directory);
  1941. }
  1942. fileSystem = m_FileSystemManager.CreateFileSystem(fullPath, FileSystemAccess.ReadWrite, FileSystemMaxFileCount, FileSystemMaxBlockCount);
  1943. }
  1944. m_ReadWriteFileSystems.Add(fileSystemName, fileSystem);
  1945. }
  1946. }
  1947. }
  1948. return fileSystem;
  1949. }
  1950. private void OnIniterResourceInitComplete()
  1951. {
  1952. m_ResourceIniter.ResourceInitComplete -= OnIniterResourceInitComplete;
  1953. m_ResourceIniter.Shutdown();
  1954. m_ResourceIniter = null;
  1955. m_InitResourcesCompleteCallback();
  1956. m_InitResourcesCompleteCallback = null;
  1957. }
  1958. private void OnVersionListProcessorUpdateSuccess(string downloadPath, string downloadUri)
  1959. {
  1960. m_UpdateVersionListCallbacks.UpdateVersionListSuccessCallback(downloadPath, downloadUri);
  1961. }
  1962. private void OnVersionListProcessorUpdateFailure(string downloadUri, string errorMessage)
  1963. {
  1964. if (m_UpdateVersionListCallbacks.UpdateVersionListFailureCallback != null)
  1965. {
  1966. m_UpdateVersionListCallbacks.UpdateVersionListFailureCallback(downloadUri, errorMessage);
  1967. }
  1968. }
  1969. private void OnCheckerResourceNeedUpdate(ResourceName resourceName, string fileSystemName, LoadType loadType, int length, int hashCode, int compressedLength, int compressedHashCode)
  1970. {
  1971. m_ResourceUpdater.AddResourceUpdate(resourceName, fileSystemName, loadType, length, hashCode, compressedLength, compressedHashCode, Utility.Path.GetRegularPath(Path.Combine(m_ReadWritePath, resourceName.FullName)));
  1972. }
  1973. private void OnCheckerResourceCheckComplete(int movedCount, int removedCount, int updateCount, long updateTotalLength, long updateTotalCompressedLength)
  1974. {
  1975. m_VersionListProcessor.VersionListUpdateSuccess -= OnVersionListProcessorUpdateSuccess;
  1976. m_VersionListProcessor.VersionListUpdateFailure -= OnVersionListProcessorUpdateFailure;
  1977. m_VersionListProcessor.Shutdown();
  1978. m_VersionListProcessor = null;
  1979. m_UpdateVersionListCallbacks = null;
  1980. m_ResourceChecker.ResourceNeedUpdate -= OnCheckerResourceNeedUpdate;
  1981. m_ResourceChecker.ResourceCheckComplete -= OnCheckerResourceCheckComplete;
  1982. m_ResourceChecker.Shutdown();
  1983. m_ResourceChecker = null;
  1984. m_ResourceUpdater.CheckResourceComplete(movedCount > 0 || removedCount > 0);
  1985. if (updateCount <= 0)
  1986. {
  1987. m_ResourceUpdater.ResourceApplySuccess -= OnUpdaterResourceApplySuccess;
  1988. m_ResourceUpdater.ResourceApplyFailure -= OnUpdaterResourceApplyFailure;
  1989. m_ResourceUpdater.ResourceApplyComplete -= OnUpdaterResourceApplyComplete;
  1990. m_ResourceUpdater.ResourceUpdateStart -= OnUpdaterResourceUpdateStart;
  1991. m_ResourceUpdater.ResourceUpdateChanged -= OnUpdaterResourceUpdateChanged;
  1992. m_ResourceUpdater.ResourceUpdateSuccess -= OnUpdaterResourceUpdateSuccess;
  1993. m_ResourceUpdater.ResourceUpdateFailure -= OnUpdaterResourceUpdateFailure;
  1994. m_ResourceUpdater.ResourceUpdateComplete -= OnUpdaterResourceUpdateComplete;
  1995. m_ResourceUpdater.ResourceUpdateAllComplete -= OnUpdaterResourceUpdateAllComplete;
  1996. m_ResourceUpdater.Shutdown();
  1997. m_ResourceUpdater = null;
  1998. m_ReadWriteResourceInfos.Clear();
  1999. m_ReadWriteResourceInfos = null;
  2000. if (m_DecompressCachedStream != null)
  2001. {
  2002. m_DecompressCachedStream.Dispose();
  2003. m_DecompressCachedStream = null;
  2004. }
  2005. }
  2006. m_CheckResourcesCompleteCallback(movedCount, removedCount, updateCount, updateTotalLength, updateTotalCompressedLength);
  2007. m_CheckResourcesCompleteCallback = null;
  2008. }
  2009. private void OnUpdaterResourceApplySuccess(ResourceName resourceName, string applyPath, string resourcePackPath, int length, int compressedLength)
  2010. {
  2011. if (m_ResourceApplySuccessEventHandler != null)
  2012. {
  2013. ResourceApplySuccessEventArgs resourceApplySuccessEventArgs = ResourceApplySuccessEventArgs.Create(resourceName.FullName, applyPath, resourcePackPath, length, compressedLength);
  2014. m_ResourceApplySuccessEventHandler(this, resourceApplySuccessEventArgs);
  2015. ReferencePool.Release(resourceApplySuccessEventArgs);
  2016. }
  2017. }
  2018. private void OnUpdaterResourceApplyFailure(ResourceName resourceName, string resourcePackPath, string errorMessage)
  2019. {
  2020. if (m_ResourceApplyFailureEventHandler != null)
  2021. {
  2022. ResourceApplyFailureEventArgs resourceApplyFailureEventArgs = ResourceApplyFailureEventArgs.Create(resourceName.FullName, resourcePackPath, errorMessage);
  2023. m_ResourceApplyFailureEventHandler(this, resourceApplyFailureEventArgs);
  2024. ReferencePool.Release(resourceApplyFailureEventArgs);
  2025. }
  2026. }
  2027. private void OnUpdaterResourceApplyComplete(string resourcePackPath, bool result)
  2028. {
  2029. ApplyResourcesCompleteCallback applyResourcesCompleteCallback = m_ApplyResourcesCompleteCallback;
  2030. m_ApplyResourcesCompleteCallback = null;
  2031. applyResourcesCompleteCallback(resourcePackPath, result);
  2032. }
  2033. private void OnUpdaterResourceUpdateStart(ResourceName resourceName, string downloadPath, string downloadUri, int currentLength, int compressedLength, int retryCount)
  2034. {
  2035. if (m_ResourceUpdateStartEventHandler != null)
  2036. {
  2037. ResourceUpdateStartEventArgs resourceUpdateStartEventArgs = ResourceUpdateStartEventArgs.Create(resourceName.FullName, downloadPath, downloadUri, currentLength, compressedLength, retryCount);
  2038. m_ResourceUpdateStartEventHandler(this, resourceUpdateStartEventArgs);
  2039. ReferencePool.Release(resourceUpdateStartEventArgs);
  2040. }
  2041. }
  2042. private void OnUpdaterResourceUpdateChanged(ResourceName resourceName, string downloadPath, string downloadUri, int currentLength, int compressedLength)
  2043. {
  2044. if (m_ResourceUpdateChangedEventHandler != null)
  2045. {
  2046. ResourceUpdateChangedEventArgs resourceUpdateChangedEventArgs = ResourceUpdateChangedEventArgs.Create(resourceName.FullName, downloadPath, downloadUri, currentLength, compressedLength);
  2047. m_ResourceUpdateChangedEventHandler(this, resourceUpdateChangedEventArgs);
  2048. ReferencePool.Release(resourceUpdateChangedEventArgs);
  2049. }
  2050. }
  2051. private void OnUpdaterResourceUpdateSuccess(ResourceName resourceName, string downloadPath, string downloadUri, int length, int compressedLength)
  2052. {
  2053. if (m_ResourceUpdateSuccessEventHandler != null)
  2054. {
  2055. ResourceUpdateSuccessEventArgs resourceUpdateSuccessEventArgs = ResourceUpdateSuccessEventArgs.Create(resourceName.FullName, downloadPath, downloadUri, length, compressedLength);
  2056. m_ResourceUpdateSuccessEventHandler(this, resourceUpdateSuccessEventArgs);
  2057. ReferencePool.Release(resourceUpdateSuccessEventArgs);
  2058. }
  2059. }
  2060. private void OnUpdaterResourceUpdateFailure(ResourceName resourceName, string downloadUri, int retryCount, int totalRetryCount, string errorMessage)
  2061. {
  2062. if (m_ResourceUpdateFailureEventHandler != null)
  2063. {
  2064. ResourceUpdateFailureEventArgs resourceUpdateFailureEventArgs = ResourceUpdateFailureEventArgs.Create(resourceName.FullName, downloadUri, retryCount, totalRetryCount, errorMessage);
  2065. m_ResourceUpdateFailureEventHandler(this, resourceUpdateFailureEventArgs);
  2066. ReferencePool.Release(resourceUpdateFailureEventArgs);
  2067. }
  2068. }
  2069. private void OnUpdaterResourceUpdateComplete(ResourceGroup resourceGroup, bool result)
  2070. {
  2071. Utility.Path.RemoveEmptyDirectory(m_ReadWritePath);
  2072. UpdateResourcesCompleteCallback updateResourcesCompleteCallback = m_UpdateResourcesCompleteCallback;
  2073. m_UpdateResourcesCompleteCallback = null;
  2074. updateResourcesCompleteCallback(resourceGroup, result);
  2075. }
  2076. private void OnUpdaterResourceUpdateAllComplete()
  2077. {
  2078. m_ResourceUpdater.ResourceApplySuccess -= OnUpdaterResourceApplySuccess;
  2079. m_ResourceUpdater.ResourceApplyFailure -= OnUpdaterResourceApplyFailure;
  2080. m_ResourceUpdater.ResourceApplyComplete -= OnUpdaterResourceApplyComplete;
  2081. m_ResourceUpdater.ResourceUpdateStart -= OnUpdaterResourceUpdateStart;
  2082. m_ResourceUpdater.ResourceUpdateChanged -= OnUpdaterResourceUpdateChanged;
  2083. m_ResourceUpdater.ResourceUpdateSuccess -= OnUpdaterResourceUpdateSuccess;
  2084. m_ResourceUpdater.ResourceUpdateFailure -= OnUpdaterResourceUpdateFailure;
  2085. m_ResourceUpdater.ResourceUpdateComplete -= OnUpdaterResourceUpdateComplete;
  2086. m_ResourceUpdater.ResourceUpdateAllComplete -= OnUpdaterResourceUpdateAllComplete;
  2087. m_ResourceUpdater.Shutdown();
  2088. m_ResourceUpdater = null;
  2089. m_ReadWriteResourceInfos.Clear();
  2090. m_ReadWriteResourceInfos = null;
  2091. if (m_DecompressCachedStream != null)
  2092. {
  2093. m_DecompressCachedStream.Dispose();
  2094. m_DecompressCachedStream = null;
  2095. }
  2096. Utility.Path.RemoveEmptyDirectory(m_ReadWritePath);
  2097. if (m_ResourceUpdateAllCompleteEventHandler != null)
  2098. {
  2099. ResourceUpdateAllCompleteEventArgs resourceUpdateAllCompleteEventArgs = ResourceUpdateAllCompleteEventArgs.Create();
  2100. m_ResourceUpdateAllCompleteEventHandler(this, resourceUpdateAllCompleteEventArgs);
  2101. ReferencePool.Release(resourceUpdateAllCompleteEventArgs);
  2102. }
  2103. }
  2104. }
  2105. }