1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404 |
- //------------------------------------------------------------
- // Game Framework
- // Copyright © 2013-2021 loyalsoft. All rights reserved.
- // Homepage: http://www.game7000.com/
- // Feedback: http://www.game7000.com/
- //------------------------------------------------------------
- using GameFramework.Download;
- using GameFramework.FileSystem;
- using GameFramework.ObjectPool;
- using System;
- using System.Collections.Generic;
- using System.IO;
- namespace GameFramework.Resource
- {
- /// <summary>
- /// 资源管理器。
- /// </summary>
- internal sealed partial class ResourceManager : GameFrameworkModule, IResourceManager
- {
- private const string RemoteVersionListFileName = "GameFrameworkVersion.dat";
- private const string LocalVersionListFileName = "GameFrameworkList.dat";
- private const string DefaultExtension = "dat";
- private const string TempExtension = "tmp";
- private const int FileSystemMaxFileCount = 1024 * 16;
- private const int FileSystemMaxBlockCount = 1024 * 256;
- private Dictionary<string, AssetInfo> m_AssetInfos;
- private Dictionary<ResourceName, ResourceInfo> m_ResourceInfos;
- private SortedDictionary<ResourceName, ReadWriteResourceInfo> m_ReadWriteResourceInfos;
- private readonly Dictionary<string, IFileSystem> m_ReadOnlyFileSystems;
- private readonly Dictionary<string, IFileSystem> m_ReadWriteFileSystems;
- private readonly Dictionary<string, ResourceGroup> m_ResourceGroups;
- private PackageVersionListSerializer m_PackageVersionListSerializer;
- private UpdatableVersionListSerializer m_UpdatableVersionListSerializer;
- private ReadOnlyVersionListSerializer m_ReadOnlyVersionListSerializer;
- private ReadWriteVersionListSerializer m_ReadWriteVersionListSerializer;
- private ResourcePackVersionListSerializer m_ResourcePackVersionListSerializer;
- private IFileSystemManager m_FileSystemManager;
- private ResourceIniter m_ResourceIniter;
- private VersionListProcessor m_VersionListProcessor;
- private ResourceChecker m_ResourceChecker;
- private ResourceUpdater m_ResourceUpdater;
- private ResourceLoader m_ResourceLoader;
- private IResourceHelper m_ResourceHelper;
- private string m_ReadOnlyPath;
- private string m_ReadWritePath;
- private ResourceMode m_ResourceMode;
- private bool m_RefuseSetFlag;
- private string m_CurrentVariant;
- private string m_UpdatePrefixUri;
- private string m_ApplicableGameVersion;
- private int m_InternalResourceVersion;
- private MemoryStream m_DecompressCachedStream;
- private DecryptResourceCallback m_DecryptResourceCallback;
- private InitResourcesCompleteCallback m_InitResourcesCompleteCallback;
- private UpdateVersionListCallbacks m_UpdateVersionListCallbacks;
- private CheckResourcesCompleteCallback m_CheckResourcesCompleteCallback;
- private ApplyResourcesCompleteCallback m_ApplyResourcesCompleteCallback;
- private UpdateResourcesCompleteCallback m_UpdateResourcesCompleteCallback;
- private EventHandler<ResourceApplySuccessEventArgs> m_ResourceApplySuccessEventHandler;
- private EventHandler<ResourceApplyFailureEventArgs> m_ResourceApplyFailureEventHandler;
- private EventHandler<ResourceUpdateStartEventArgs> m_ResourceUpdateStartEventHandler;
- private EventHandler<ResourceUpdateChangedEventArgs> m_ResourceUpdateChangedEventHandler;
- private EventHandler<ResourceUpdateSuccessEventArgs> m_ResourceUpdateSuccessEventHandler;
- private EventHandler<ResourceUpdateFailureEventArgs> m_ResourceUpdateFailureEventHandler;
- private EventHandler<ResourceUpdateAllCompleteEventArgs> m_ResourceUpdateAllCompleteEventHandler;
- /// <summary>
- /// 初始化资源管理器的新实例。
- /// </summary>
- public ResourceManager()
- {
- m_AssetInfos = null;
- m_ResourceInfos = null;
- m_ReadWriteResourceInfos = null;
- m_ReadOnlyFileSystems = new Dictionary<string, IFileSystem>(StringComparer.Ordinal);
- m_ReadWriteFileSystems = new Dictionary<string, IFileSystem>(StringComparer.Ordinal);
- m_ResourceGroups = new Dictionary<string, ResourceGroup>(StringComparer.Ordinal);
- m_PackageVersionListSerializer = null;
- m_UpdatableVersionListSerializer = null;
- m_ReadOnlyVersionListSerializer = null;
- m_ReadWriteVersionListSerializer = null;
- m_ResourcePackVersionListSerializer = null;
- m_ResourceIniter = null;
- m_VersionListProcessor = null;
- m_ResourceChecker = null;
- m_ResourceUpdater = null;
- m_ResourceLoader = new ResourceLoader(this);
- m_ResourceHelper = null;
- m_ReadOnlyPath = null;
- m_ReadWritePath = null;
- m_ResourceMode = ResourceMode.Unspecified;
- m_RefuseSetFlag = false;
- m_CurrentVariant = null;
- m_UpdatePrefixUri = null;
- m_ApplicableGameVersion = null;
- m_InternalResourceVersion = 0;
- m_DecompressCachedStream = null;
- m_DecryptResourceCallback = null;
- m_InitResourcesCompleteCallback = null;
- m_UpdateVersionListCallbacks = null;
- m_CheckResourcesCompleteCallback = null;
- m_ApplyResourcesCompleteCallback = null;
- m_UpdateResourcesCompleteCallback = null;
- m_ResourceApplySuccessEventHandler = null;
- m_ResourceApplyFailureEventHandler = null;
- m_ResourceUpdateStartEventHandler = null;
- m_ResourceUpdateChangedEventHandler = null;
- m_ResourceUpdateSuccessEventHandler = null;
- m_ResourceUpdateFailureEventHandler = null;
- m_ResourceUpdateAllCompleteEventHandler = null;
- }
- /// <summary>
- /// 获取游戏框架模块优先级。
- /// </summary>
- /// <remarks>优先级较高的模块会优先轮询,并且关闭操作会后进行。</remarks>
- internal override int Priority
- {
- get
- {
- return 3;
- }
- }
- /// <summary>
- /// 获取资源只读区路径。
- /// </summary>
- public string ReadOnlyPath
- {
- get
- {
- return m_ReadOnlyPath;
- }
- }
- /// <summary>
- /// 获取资源读写区路径。
- /// </summary>
- public string ReadWritePath
- {
- get
- {
- return m_ReadWritePath;
- }
- }
- /// <summary>
- /// 获取资源模式。
- /// </summary>
- public ResourceMode ResourceMode
- {
- get
- {
- return m_ResourceMode;
- }
- }
- /// <summary>
- /// 获取当前变体。
- /// </summary>
- public string CurrentVariant
- {
- get
- {
- return m_CurrentVariant;
- }
- }
- /// <summary>
- /// 获取单机模式版本资源列表序列化器。
- /// </summary>
- public PackageVersionListSerializer PackageVersionListSerializer
- {
- get
- {
- return m_PackageVersionListSerializer;
- }
- }
- /// <summary>
- /// 获取可更新模式版本资源列表序列化器。
- /// </summary>
- public UpdatableVersionListSerializer UpdatableVersionListSerializer
- {
- get
- {
- return m_UpdatableVersionListSerializer;
- }
- }
- /// <summary>
- /// 获取本地只读区版本资源列表序列化器。
- /// </summary>
- public ReadOnlyVersionListSerializer ReadOnlyVersionListSerializer
- {
- get
- {
- return m_ReadOnlyVersionListSerializer;
- }
- }
- /// <summary>
- /// 获取本地读写区版本资源列表序列化器。
- /// </summary>
- public ReadWriteVersionListSerializer ReadWriteVersionListSerializer
- {
- get
- {
- return m_ReadWriteVersionListSerializer;
- }
- }
- /// <summary>
- /// 获取资源包版本资源列表序列化器。
- /// </summary>
- public ResourcePackVersionListSerializer ResourcePackVersionListSerializer
- {
- get
- {
- return m_ResourcePackVersionListSerializer;
- }
- }
- /// <summary>
- /// 获取当前资源适用的游戏版本号。
- /// </summary>
- public string ApplicableGameVersion
- {
- get
- {
- return m_ApplicableGameVersion;
- }
- }
- /// <summary>
- /// 获取当前内部资源版本号。
- /// </summary>
- public int InternalResourceVersion
- {
- get
- {
- return m_InternalResourceVersion;
- }
- }
- /// <summary>
- /// 获取资源数量。
- /// </summary>
- public int AssetCount
- {
- get
- {
- return m_AssetInfos != null ? m_AssetInfos.Count : 0;
- }
- }
- /// <summary>
- /// 获取资源数量。
- /// </summary>
- public int ResourceCount
- {
- get
- {
- return m_ResourceInfos != null ? m_ResourceInfos.Count : 0;
- }
- }
- /// <summary>
- /// 获取资源组数量。
- /// </summary>
- public int ResourceGroupCount
- {
- get
- {
- return m_ResourceGroups.Count;
- }
- }
- /// <summary>
- /// 获取或设置资源更新下载地址前缀。
- /// </summary>
- public string UpdatePrefixUri
- {
- get
- {
- return m_UpdatePrefixUri;
- }
- set
- {
- m_UpdatePrefixUri = value;
- }
- }
- /// <summary>
- /// 获取或设置每更新多少字节的资源,重新生成一次版本资源列表。
- /// </summary>
- public int GenerateReadWriteVersionListLength
- {
- get
- {
- return m_ResourceUpdater != null ? m_ResourceUpdater.GenerateReadWriteVersionListLength : 0;
- }
- set
- {
- if (m_ResourceUpdater == null)
- {
- throw new GameFrameworkException("You can not use GenerateReadWriteVersionListLength at this time.");
- }
- m_ResourceUpdater.GenerateReadWriteVersionListLength = value;
- }
- }
- /// <summary>
- /// 获取正在应用的资源包路径。
- /// </summary>
- public string ApplyingResourcePackPath
- {
- get
- {
- return m_ResourceUpdater != null ? m_ResourceUpdater.ApplyingResourcePackPath : null;
- }
- }
- /// <summary>
- /// 获取等待应用资源数量。
- /// </summary>
- public int ApplyWaitingCount
- {
- get
- {
- return m_ResourceUpdater != null ? m_ResourceUpdater.ApplyWaitingCount : 0;
- }
- }
- /// <summary>
- /// 获取或设置资源更新重试次数。
- /// </summary>
- public int UpdateRetryCount
- {
- get
- {
- return m_ResourceUpdater != null ? m_ResourceUpdater.UpdateRetryCount : 0;
- }
- set
- {
- if (m_ResourceUpdater == null)
- {
- throw new GameFrameworkException("You can not use UpdateRetryCount at this time.");
- }
- m_ResourceUpdater.UpdateRetryCount = value;
- }
- }
- /// <summary>
- /// 获取正在更新的资源组。
- /// </summary>
- public IResourceGroup UpdatingResourceGroup
- {
- get
- {
- return m_ResourceUpdater != null ? m_ResourceUpdater.UpdatingResourceGroup : null;
- }
- }
- /// <summary>
- /// 获取等待更新资源数量。
- /// </summary>
- public int UpdateWaitingCount
- {
- get
- {
- return m_ResourceUpdater != null ? m_ResourceUpdater.UpdateWaitingCount : 0;
- }
- }
- /// <summary>
- /// 获取使用时下载的等待更新资源数量。
- /// </summary>
- public int UpdateWaitingWhilePlayingCount
- {
- get
- {
- return m_ResourceUpdater != null ? m_ResourceUpdater.UpdateWaitingWhilePlayingCount : 0;
- }
- }
- /// <summary>
- /// 获取候选更新资源数量。
- /// </summary>
- public int UpdateCandidateCount
- {
- get
- {
- return m_ResourceUpdater != null ? m_ResourceUpdater.UpdateCandidateCount : 0;
- }
- }
- /// <summary>
- /// 获取加载资源代理总数量。
- /// </summary>
- public int LoadTotalAgentCount
- {
- get
- {
- return m_ResourceLoader.TotalAgentCount;
- }
- }
- /// <summary>
- /// 获取可用加载资源代理数量。
- /// </summary>
- public int LoadFreeAgentCount
- {
- get
- {
- return m_ResourceLoader.FreeAgentCount;
- }
- }
- /// <summary>
- /// 获取工作中加载资源代理数量。
- /// </summary>
- public int LoadWorkingAgentCount
- {
- get
- {
- return m_ResourceLoader.WorkingAgentCount;
- }
- }
- /// <summary>
- /// 获取等待加载资源任务数量。
- /// </summary>
- public int LoadWaitingTaskCount
- {
- get
- {
- return m_ResourceLoader.WaitingTaskCount;
- }
- }
- /// <summary>
- /// 获取或设置资源对象池自动释放可释放对象的间隔秒数。
- /// </summary>
- public float AssetAutoReleaseInterval
- {
- get
- {
- return m_ResourceLoader.AssetAutoReleaseInterval;
- }
- set
- {
- m_ResourceLoader.AssetAutoReleaseInterval = value;
- }
- }
- /// <summary>
- /// 获取或设置资源对象池的容量。
- /// </summary>
- public int AssetCapacity
- {
- get
- {
- return m_ResourceLoader.AssetCapacity;
- }
- set
- {
- m_ResourceLoader.AssetCapacity = value;
- }
- }
- /// <summary>
- /// 获取或设置资源对象池对象过期秒数。
- /// </summary>
- public float AssetExpireTime
- {
- get
- {
- return m_ResourceLoader.AssetExpireTime;
- }
- set
- {
- m_ResourceLoader.AssetExpireTime = value;
- }
- }
- /// <summary>
- /// 获取或设置资源对象池的优先级。
- /// </summary>
- public int AssetPriority
- {
- get
- {
- return m_ResourceLoader.AssetPriority;
- }
- set
- {
- m_ResourceLoader.AssetPriority = value;
- }
- }
- /// <summary>
- /// 获取或设置资源对象池自动释放可释放对象的间隔秒数。
- /// </summary>
- public float ResourceAutoReleaseInterval
- {
- get
- {
- return m_ResourceLoader.ResourceAutoReleaseInterval;
- }
- set
- {
- m_ResourceLoader.ResourceAutoReleaseInterval = value;
- }
- }
- /// <summary>
- /// 获取或设置资源对象池的容量。
- /// </summary>
- public int ResourceCapacity
- {
- get
- {
- return m_ResourceLoader.ResourceCapacity;
- }
- set
- {
- m_ResourceLoader.ResourceCapacity = value;
- }
- }
- /// <summary>
- /// 获取或设置资源对象池对象过期秒数。
- /// </summary>
- public float ResourceExpireTime
- {
- get
- {
- return m_ResourceLoader.ResourceExpireTime;
- }
- set
- {
- m_ResourceLoader.ResourceExpireTime = value;
- }
- }
- /// <summary>
- /// 获取或设置资源对象池的优先级。
- /// </summary>
- public int ResourcePriority
- {
- get
- {
- return m_ResourceLoader.ResourcePriority;
- }
- set
- {
- m_ResourceLoader.ResourcePriority = value;
- }
- }
- /// <summary>
- /// 资源应用成功事件。
- /// </summary>
- public event EventHandler<ResourceApplySuccessEventArgs> ResourceApplySuccess
- {
- add
- {
- m_ResourceApplySuccessEventHandler += value;
- }
- remove
- {
- m_ResourceApplySuccessEventHandler -= value;
- }
- }
- /// <summary>
- /// 资源应用失败事件。
- /// </summary>
- public event EventHandler<ResourceApplyFailureEventArgs> ResourceApplyFailure
- {
- add
- {
- m_ResourceApplyFailureEventHandler += value;
- }
- remove
- {
- m_ResourceApplyFailureEventHandler -= value;
- }
- }
- /// <summary>
- /// 资源更新开始事件。
- /// </summary>
- public event EventHandler<ResourceUpdateStartEventArgs> ResourceUpdateStart
- {
- add
- {
- m_ResourceUpdateStartEventHandler += value;
- }
- remove
- {
- m_ResourceUpdateStartEventHandler -= value;
- }
- }
- /// <summary>
- /// 资源更新改变事件。
- /// </summary>
- public event EventHandler<ResourceUpdateChangedEventArgs> ResourceUpdateChanged
- {
- add
- {
- m_ResourceUpdateChangedEventHandler += value;
- }
- remove
- {
- m_ResourceUpdateChangedEventHandler -= value;
- }
- }
- /// <summary>
- /// 资源更新成功事件。
- /// </summary>
- public event EventHandler<ResourceUpdateSuccessEventArgs> ResourceUpdateSuccess
- {
- add
- {
- m_ResourceUpdateSuccessEventHandler += value;
- }
- remove
- {
- m_ResourceUpdateSuccessEventHandler -= value;
- }
- }
- /// <summary>
- /// 资源更新失败事件。
- /// </summary>
- public event EventHandler<ResourceUpdateFailureEventArgs> ResourceUpdateFailure
- {
- add
- {
- m_ResourceUpdateFailureEventHandler += value;
- }
- remove
- {
- m_ResourceUpdateFailureEventHandler -= value;
- }
- }
- /// <summary>
- /// 资源更新全部完成事件。
- /// </summary>
- public event EventHandler<ResourceUpdateAllCompleteEventArgs> ResourceUpdateAllComplete
- {
- add
- {
- m_ResourceUpdateAllCompleteEventHandler += value;
- }
- remove
- {
- m_ResourceUpdateAllCompleteEventHandler -= value;
- }
- }
- /// <summary>
- /// 资源管理器轮询。
- /// </summary>
- /// <param name="elapseSeconds">逻辑流逝时间,以秒为单位。</param>
- /// <param name="realElapseSeconds">真实流逝时间,以秒为单位。</param>
- internal override void Update(float elapseSeconds, float realElapseSeconds)
- {
- if (m_ResourceUpdater != null)
- {
- m_ResourceUpdater.Update(elapseSeconds, realElapseSeconds);
- }
- m_ResourceLoader.Update(elapseSeconds, realElapseSeconds);
- }
- /// <summary>
- /// 关闭并清理资源管理器。
- /// </summary>
- internal override void Shutdown()
- {
- if (m_ResourceIniter != null)
- {
- m_ResourceIniter.Shutdown();
- m_ResourceIniter = null;
- }
- if (m_VersionListProcessor != null)
- {
- m_VersionListProcessor.VersionListUpdateSuccess -= OnVersionListProcessorUpdateSuccess;
- m_VersionListProcessor.VersionListUpdateFailure -= OnVersionListProcessorUpdateFailure;
- m_VersionListProcessor.Shutdown();
- m_VersionListProcessor = null;
- }
- if (m_ResourceChecker != null)
- {
- m_ResourceChecker.ResourceNeedUpdate -= OnCheckerResourceNeedUpdate;
- m_ResourceChecker.ResourceCheckComplete -= OnCheckerResourceCheckComplete;
- m_ResourceChecker.Shutdown();
- m_ResourceChecker = null;
- }
- if (m_ResourceUpdater != null)
- {
- m_ResourceUpdater.ResourceApplySuccess -= OnUpdaterResourceApplySuccess;
- m_ResourceUpdater.ResourceApplyFailure -= OnUpdaterResourceApplyFailure;
- m_ResourceUpdater.ResourceApplyComplete -= OnUpdaterResourceApplyComplete;
- m_ResourceUpdater.ResourceUpdateStart -= OnUpdaterResourceUpdateStart;
- m_ResourceUpdater.ResourceUpdateChanged -= OnUpdaterResourceUpdateChanged;
- m_ResourceUpdater.ResourceUpdateSuccess -= OnUpdaterResourceUpdateSuccess;
- m_ResourceUpdater.ResourceUpdateFailure -= OnUpdaterResourceUpdateFailure;
- m_ResourceUpdater.ResourceUpdateComplete -= OnUpdaterResourceUpdateComplete;
- m_ResourceUpdater.ResourceUpdateAllComplete -= OnUpdaterResourceUpdateAllComplete;
- m_ResourceUpdater.Shutdown();
- m_ResourceUpdater = null;
- if (m_ReadWriteResourceInfos != null)
- {
- m_ReadWriteResourceInfos.Clear();
- m_ReadWriteResourceInfos = null;
- }
- if (m_DecompressCachedStream != null)
- {
- m_DecompressCachedStream.Dispose();
- m_DecompressCachedStream = null;
- }
- }
- if (m_ResourceLoader != null)
- {
- m_ResourceLoader.Shutdown();
- m_ResourceLoader = null;
- }
- if (m_AssetInfos != null)
- {
- m_AssetInfos.Clear();
- m_AssetInfos = null;
- }
- if (m_ResourceInfos != null)
- {
- m_ResourceInfos.Clear();
- m_ResourceInfos = null;
- }
- m_ReadOnlyFileSystems.Clear();
- m_ReadWriteFileSystems.Clear();
- m_ResourceGroups.Clear();
- }
- /// <summary>
- /// 设置资源只读区路径。
- /// </summary>
- /// <param name="readOnlyPath">资源只读区路径。</param>
- public void SetReadOnlyPath(string readOnlyPath)
- {
- if (string.IsNullOrEmpty(readOnlyPath))
- {
- throw new GameFrameworkException("Read-only path is invalid.");
- }
- if (m_RefuseSetFlag)
- {
- throw new GameFrameworkException("You can not set read-only path at this time.");
- }
- if (m_ResourceLoader.TotalAgentCount > 0)
- {
- throw new GameFrameworkException("You must set read-only path before add load resource agent helper.");
- }
- m_ReadOnlyPath = readOnlyPath;
- }
- /// <summary>
- /// 设置资源读写区路径。
- /// </summary>
- /// <param name="readWritePath">资源读写区路径。</param>
- public void SetReadWritePath(string readWritePath)
- {
- if (string.IsNullOrEmpty(readWritePath))
- {
- throw new GameFrameworkException("Read-write path is invalid.");
- }
- if (m_RefuseSetFlag)
- {
- throw new GameFrameworkException("You can not set read-write path at this time.");
- }
- if (m_ResourceLoader.TotalAgentCount > 0)
- {
- throw new GameFrameworkException("You must set read-write path before add load resource agent helper.");
- }
- m_ReadWritePath = readWritePath;
- }
- /// <summary>
- /// 设置资源模式。
- /// </summary>
- /// <param name="resourceMode">资源模式。</param>
- public void SetResourceMode(ResourceMode resourceMode)
- {
- if (resourceMode == ResourceMode.Unspecified)
- {
- throw new GameFrameworkException("Resource mode is invalid.");
- }
- if (m_RefuseSetFlag)
- {
- throw new GameFrameworkException("You can not set resource mode at this time.");
- }
- if (m_ResourceMode == ResourceMode.Unspecified)
- {
- m_ResourceMode = resourceMode;
- if (m_ResourceMode == ResourceMode.Package)
- {
- m_PackageVersionListSerializer = new PackageVersionListSerializer();
- m_ResourceIniter = new ResourceIniter(this);
- m_ResourceIniter.ResourceInitComplete += OnIniterResourceInitComplete;
- }
- else if (m_ResourceMode == ResourceMode.Updatable || m_ResourceMode == ResourceMode.UpdatableWhilePlaying)
- {
- m_UpdatableVersionListSerializer = new UpdatableVersionListSerializer();
- m_ReadOnlyVersionListSerializer = new ReadOnlyVersionListSerializer();
- m_ReadWriteVersionListSerializer = new ReadWriteVersionListSerializer();
- m_ResourcePackVersionListSerializer = new ResourcePackVersionListSerializer();
- m_VersionListProcessor = new VersionListProcessor(this);
- m_VersionListProcessor.VersionListUpdateSuccess += OnVersionListProcessorUpdateSuccess;
- m_VersionListProcessor.VersionListUpdateFailure += OnVersionListProcessorUpdateFailure;
- m_ResourceChecker = new ResourceChecker(this);
- m_ResourceChecker.ResourceNeedUpdate += OnCheckerResourceNeedUpdate;
- m_ResourceChecker.ResourceCheckComplete += OnCheckerResourceCheckComplete;
- m_ResourceUpdater = new ResourceUpdater(this);
- m_ResourceUpdater.ResourceApplySuccess += OnUpdaterResourceApplySuccess;
- m_ResourceUpdater.ResourceApplyFailure += OnUpdaterResourceApplyFailure;
- m_ResourceUpdater.ResourceApplyComplete += OnUpdaterResourceApplyComplete;
- m_ResourceUpdater.ResourceUpdateStart += OnUpdaterResourceUpdateStart;
- m_ResourceUpdater.ResourceUpdateChanged += OnUpdaterResourceUpdateChanged;
- m_ResourceUpdater.ResourceUpdateSuccess += OnUpdaterResourceUpdateSuccess;
- m_ResourceUpdater.ResourceUpdateFailure += OnUpdaterResourceUpdateFailure;
- m_ResourceUpdater.ResourceUpdateComplete += OnUpdaterResourceUpdateComplete;
- m_ResourceUpdater.ResourceUpdateAllComplete += OnUpdaterResourceUpdateAllComplete;
- }
- }
- else if (m_ResourceMode != resourceMode)
- {
- throw new GameFrameworkException("You can not change resource mode at this time.");
- }
- }
- /// <summary>
- /// 设置当前变体。
- /// </summary>
- /// <param name="currentVariant">当前变体。</param>
- public void SetCurrentVariant(string currentVariant)
- {
- if (m_RefuseSetFlag)
- {
- throw new GameFrameworkException("You can not set current variant at this time.");
- }
- m_CurrentVariant = currentVariant;
- }
- /// <summary>
- /// 设置对象池管理器。
- /// </summary>
- /// <param name="objectPoolManager">对象池管理器。</param>
- public void SetObjectPoolManager(IObjectPoolManager objectPoolManager)
- {
- if (objectPoolManager == null)
- {
- throw new GameFrameworkException("Object pool manager is invalid.");
- }
- m_ResourceLoader.SetObjectPoolManager(objectPoolManager);
- }
- /// <summary>
- /// 设置文件系统管理器。
- /// </summary>
- /// <param name="fileSystemManager">文件系统管理器。</param>
- public void SetFileSystemManager(IFileSystemManager fileSystemManager)
- {
- if (fileSystemManager == null)
- {
- throw new GameFrameworkException("File system manager is invalid.");
- }
- m_FileSystemManager = fileSystemManager;
- }
- /// <summary>
- /// 设置下载管理器。
- /// </summary>
- /// <param name="downloadManager">下载管理器。</param>
- public void SetDownloadManager(IDownloadManager downloadManager)
- {
- if (downloadManager == null)
- {
- throw new GameFrameworkException("Download manager is invalid.");
- }
- if (m_VersionListProcessor != null)
- {
- m_VersionListProcessor.SetDownloadManager(downloadManager);
- }
- if (m_ResourceUpdater != null)
- {
- m_ResourceUpdater.SetDownloadManager(downloadManager);
- }
- }
- /// <summary>
- /// 设置解密资源回调函数。
- /// </summary>
- /// <param name="decryptResourceCallback">要设置的解密资源回调函数。</param>
- /// <remarks>如果不设置,将使用默认的解密资源回调函数。</remarks>
- public void SetDecryptResourceCallback(DecryptResourceCallback decryptResourceCallback)
- {
- if (m_ResourceLoader.TotalAgentCount > 0)
- {
- throw new GameFrameworkException("You must set decrypt resource callback before add load resource agent helper.");
- }
- m_DecryptResourceCallback = decryptResourceCallback;
- }
- /// <summary>
- /// 设置资源辅助器。
- /// </summary>
- /// <param name="resourceHelper">资源辅助器。</param>
- public void SetResourceHelper(IResourceHelper resourceHelper)
- {
- if (resourceHelper == null)
- {
- throw new GameFrameworkException("Resource helper is invalid.");
- }
- if (m_ResourceLoader.TotalAgentCount > 0)
- {
- throw new GameFrameworkException("You must set resource helper before add load resource agent helper.");
- }
- m_ResourceHelper = resourceHelper;
- }
- /// <summary>
- /// 增加加载资源代理辅助器。
- /// </summary>
- /// <param name="loadResourceAgentHelper">要增加的加载资源代理辅助器。</param>
- public void AddLoadResourceAgentHelper(ILoadResourceAgentHelper loadResourceAgentHelper)
- {
- if (m_ResourceHelper == null)
- {
- throw new GameFrameworkException("Resource helper is invalid.");
- }
- if (string.IsNullOrEmpty(m_ReadOnlyPath))
- {
- throw new GameFrameworkException("Read-only path is invalid.");
- }
- if (string.IsNullOrEmpty(m_ReadWritePath))
- {
- throw new GameFrameworkException("Read-write path is invalid.");
- }
- m_ResourceLoader.AddLoadResourceAgentHelper(loadResourceAgentHelper, m_ResourceHelper, m_ReadOnlyPath, m_ReadWritePath, m_DecryptResourceCallback);
- }
- /// <summary>
- /// 使用单机模式并初始化资源。
- /// </summary>
- /// <param name="initResourcesCompleteCallback">使用单机模式并初始化资源完成时的回调函数。</param>
- public void InitResources(InitResourcesCompleteCallback initResourcesCompleteCallback)
- {
- if (initResourcesCompleteCallback == null)
- {
- throw new GameFrameworkException("Init resources complete callback is invalid.");
- }
- if (m_ResourceMode == ResourceMode.Unspecified)
- {
- throw new GameFrameworkException("You must set resource mode first.");
- }
- if (m_ResourceMode != ResourceMode.Package)
- {
- throw new GameFrameworkException("You can not use InitResources without package resource mode.");
- }
- if (m_ResourceIniter == null)
- {
- throw new GameFrameworkException("You can not use InitResources at this time.");
- }
- m_RefuseSetFlag = true;
- m_InitResourcesCompleteCallback = initResourcesCompleteCallback;
- m_ResourceIniter.InitResources(m_CurrentVariant);
- }
- /// <summary>
- /// 使用可更新模式并检查版本资源列表。
- /// </summary>
- /// <param name="latestInternalResourceVersion">最新的内部资源版本号。</param>
- /// <returns>检查版本资源列表结果。</returns>
- public CheckVersionListResult CheckVersionList(int latestInternalResourceVersion)
- {
- if (m_ResourceMode == ResourceMode.Unspecified)
- {
- throw new GameFrameworkException("You must set resource mode first.");
- }
- if (m_ResourceMode != ResourceMode.Updatable && m_ResourceMode != ResourceMode.UpdatableWhilePlaying)
- {
- throw new GameFrameworkException("You can not use CheckVersionList without updatable resource mode.");
- }
- if (m_VersionListProcessor == null)
- {
- throw new GameFrameworkException("You can not use CheckVersionList at this time.");
- }
- return m_VersionListProcessor.CheckVersionList(latestInternalResourceVersion);
- }
- /// <summary>
- /// 使用可更新模式并更新版本资源列表。
- /// </summary>
- /// <param name="versionListLength">版本资源列表大小。</param>
- /// <param name="versionListHashCode">版本资源列表哈希值。</param>
- /// <param name="versionListCompressedLength">版本资源列表压缩后大小。</param>
- /// <param name="versionListCompressedHashCode">版本资源列表压缩后哈希值。</param>
- /// <param name="updateVersionListCallbacks">版本资源列表更新回调函数集。</param>
- public void UpdateVersionList(int versionListLength, int versionListHashCode, int versionListCompressedLength, int versionListCompressedHashCode, UpdateVersionListCallbacks updateVersionListCallbacks)
- {
- if (updateVersionListCallbacks == null)
- {
- throw new GameFrameworkException("Update version list callbacks is invalid.");
- }
- if (m_ResourceMode == ResourceMode.Unspecified)
- {
- throw new GameFrameworkException("You must set resource mode first.");
- }
- if (m_ResourceMode != ResourceMode.Updatable && m_ResourceMode != ResourceMode.UpdatableWhilePlaying)
- {
- throw new GameFrameworkException("You can not use UpdateVersionList without updatable resource mode.");
- }
- if (m_VersionListProcessor == null)
- {
- throw new GameFrameworkException("You can not use UpdateVersionList at this time.");
- }
- m_UpdateVersionListCallbacks = updateVersionListCallbacks;
- m_VersionListProcessor.UpdateVersionList(versionListLength, versionListHashCode, versionListCompressedLength, versionListCompressedHashCode);
- }
- /// <summary>
- /// 使用可更新模式并检查资源。
- /// </summary>
- /// <param name="ignoreOtherVariant">是否忽略处理其它变体的资源,若不忽略,将会移除其它变体的资源。</param>
- /// <param name="checkResourcesCompleteCallback">使用可更新模式并检查资源完成时的回调函数。</param>
- public void CheckResources(bool ignoreOtherVariant, CheckResourcesCompleteCallback checkResourcesCompleteCallback)
- {
- if (checkResourcesCompleteCallback == null)
- {
- throw new GameFrameworkException("Check resources complete callback is invalid.");
- }
- if (m_ResourceMode == ResourceMode.Unspecified)
- {
- throw new GameFrameworkException("You must set resource mode first.");
- }
- if (m_ResourceMode != ResourceMode.Updatable && m_ResourceMode != ResourceMode.UpdatableWhilePlaying)
- {
- throw new GameFrameworkException("You can not use CheckResources without updatable resource mode.");
- }
- if (m_ResourceChecker == null)
- {
- throw new GameFrameworkException("You can not use CheckResources at this time.");
- }
- m_RefuseSetFlag = true;
- m_CheckResourcesCompleteCallback = checkResourcesCompleteCallback;
- m_ResourceChecker.CheckResources(m_CurrentVariant, ignoreOtherVariant);
- }
- /// <summary>
- /// 使用可更新模式并应用资源包资源。
- /// </summary>
- /// <param name="resourcePackPath">要应用的资源包路径。</param>
- /// <param name="applyResourcesCompleteCallback">使用可更新模式并应用资源包资源完成时的回调函数。</param>
- public void ApplyResources(string resourcePackPath, ApplyResourcesCompleteCallback applyResourcesCompleteCallback)
- {
- if (string.IsNullOrEmpty(resourcePackPath))
- {
- throw new GameFrameworkException("Resource pack path is invalid.");
- }
- if (!File.Exists(resourcePackPath))
- {
- throw new GameFrameworkException(Utility.Text.Format("Resource pack '{0}' is not exist.", resourcePackPath));
- }
- if (applyResourcesCompleteCallback == null)
- {
- throw new GameFrameworkException("Apply resources complete callback is invalid.");
- }
- if (m_ResourceMode == ResourceMode.Unspecified)
- {
- throw new GameFrameworkException("You must set resource mode first.");
- }
- if (m_ResourceMode != ResourceMode.Updatable && m_ResourceMode != ResourceMode.UpdatableWhilePlaying)
- {
- throw new GameFrameworkException("You can not use ApplyResources without updatable resource mode.");
- }
- if (m_ResourceUpdater == null)
- {
- throw new GameFrameworkException("You can not use ApplyResources at this time.");
- }
- m_ApplyResourcesCompleteCallback = applyResourcesCompleteCallback;
- m_ResourceUpdater.ApplyResources(resourcePackPath);
- }
- /// <summary>
- /// 使用可更新模式并更新所有资源。
- /// </summary>
- /// <param name="updateResourcesCompleteCallback">使用可更新模式并更新默认资源组完成时的回调函数。</param>
- public void UpdateResources(UpdateResourcesCompleteCallback updateResourcesCompleteCallback)
- {
- UpdateResources(string.Empty, updateResourcesCompleteCallback);
- }
- /// <summary>
- /// 使用可更新模式并更新指定资源组的资源。
- /// </summary>
- /// <param name="resourceGroupName">要更新的资源组名称。</param>
- /// <param name="updateResourcesCompleteCallback">使用可更新模式并更新指定资源组完成时的回调函数。</param>
- public void UpdateResources(string resourceGroupName, UpdateResourcesCompleteCallback updateResourcesCompleteCallback)
- {
- if (updateResourcesCompleteCallback == null)
- {
- throw new GameFrameworkException("Update resources complete callback is invalid.");
- }
- if (m_ResourceMode == ResourceMode.Unspecified)
- {
- throw new GameFrameworkException("You must set resource mode first.");
- }
- if (m_ResourceMode != ResourceMode.Updatable && m_ResourceMode != ResourceMode.UpdatableWhilePlaying)
- {
- throw new GameFrameworkException("You can not use UpdateResources without updatable resource mode.");
- }
- if (m_ResourceUpdater == null)
- {
- throw new GameFrameworkException("You can not use UpdateResources at this time.");
- }
- ResourceGroup resourceGroup = (ResourceGroup)GetResourceGroup(resourceGroupName);
- if (resourceGroup == null)
- {
- throw new GameFrameworkException(Utility.Text.Format("Can not find resource group '{0}'.", resourceGroupName));
- }
- m_UpdateResourcesCompleteCallback = updateResourcesCompleteCallback;
- m_ResourceUpdater.UpdateResources(resourceGroup);
- }
- /// <summary>
- /// 停止更新资源。
- /// </summary>
- public void StopUpdateResources()
- {
- if (m_ResourceMode == ResourceMode.Unspecified)
- {
- throw new GameFrameworkException("You must set resource mode first.");
- }
- if (m_ResourceMode != ResourceMode.Updatable && m_ResourceMode != ResourceMode.UpdatableWhilePlaying)
- {
- throw new GameFrameworkException("You can not use StopUpdateResources without updatable resource mode.");
- }
- if (m_ResourceUpdater == null)
- {
- throw new GameFrameworkException("You can not use StopUpdateResources at this time.");
- }
- m_ResourceUpdater.StopUpdateResources();
- m_UpdateResourcesCompleteCallback = null;
- }
- /// <summary>
- /// 校验资源包。
- /// </summary>
- /// <param name="resourcePackPath">要校验的资源包路径。</param>
- /// <returns>是否校验资源包成功。</returns>
- public bool VerifyResourcePack(string resourcePackPath)
- {
- if (string.IsNullOrEmpty(resourcePackPath))
- {
- throw new GameFrameworkException("Resource pack path is invalid.");
- }
- if (!File.Exists(resourcePackPath))
- {
- throw new GameFrameworkException(Utility.Text.Format("Resource pack '{0}' is not exist.", resourcePackPath));
- }
- if (m_ResourceMode == ResourceMode.Unspecified)
- {
- throw new GameFrameworkException("You must set resource mode first.");
- }
- if (m_ResourceMode != ResourceMode.Updatable && m_ResourceMode != ResourceMode.UpdatableWhilePlaying)
- {
- throw new GameFrameworkException("You can not use VerifyResourcePack without updatable resource mode.");
- }
- if (m_ResourcePackVersionListSerializer == null)
- {
- throw new GameFrameworkException("You can not use VerifyResourcePack at this time.");
- }
- try
- {
- long length = 0L;
- ResourcePackVersionList versionList = default(ResourcePackVersionList);
- using (FileStream fileStream = new FileStream(resourcePackPath, FileMode.Open, FileAccess.Read))
- {
- length = fileStream.Length;
- versionList = m_ResourcePackVersionListSerializer.Deserialize(fileStream);
- }
- if (!versionList.IsValid)
- {
- return false;
- }
- if (versionList.Offset + versionList.Length != length)
- {
- return false;
- }
- int hashCode = 0;
- using (FileStream fileStream = new FileStream(resourcePackPath, FileMode.Open, FileAccess.Read))
- {
- fileStream.Position = versionList.Offset;
- hashCode = Utility.Verifier.GetCrc32(fileStream);
- }
- if (versionList.HashCode != hashCode)
- {
- return false;
- }
- return true;
- }
- catch
- {
- return false;
- }
- }
- /// <summary>
- /// 获取所有加载资源任务的信息。
- /// </summary>
- /// <returns>所有加载资源任务的信息。</returns>
- public TaskInfo[] GetAllLoadAssetInfos()
- {
- return m_ResourceLoader.GetAllLoadAssetInfos();
- }
- /// <summary>
- /// 获取所有加载资源任务的信息。
- /// </summary>
- /// <param name="results">所有加载资源任务的信息。</param>
- public void GetAllLoadAssetInfos(List<TaskInfo> results)
- {
- m_ResourceLoader.GetAllLoadAssetInfos(results);
- }
- /// <summary>
- /// 检查资源是否存在。
- /// </summary>
- /// <param name="assetName">要检查资源的名称。</param>
- /// <returns>检查资源是否存在的结果。</returns>
- public HasAssetResult HasAsset(string assetName)
- {
- if (string.IsNullOrEmpty(assetName))
- {
- throw new GameFrameworkException("Asset name is invalid.");
- }
- return m_ResourceLoader.HasAsset(assetName);
- }
- /// <summary>
- /// 异步加载资源。
- /// </summary>
- /// <param name="assetName">要加载资源的名称。</param>
- /// <param name="loadAssetCallbacks">加载资源回调函数集。</param>
- public void LoadAsset(string assetName, LoadAssetCallbacks loadAssetCallbacks)
- {
- if (string.IsNullOrEmpty(assetName))
- {
- throw new GameFrameworkException("Asset name is invalid.");
- }
- if (loadAssetCallbacks == null)
- {
- throw new GameFrameworkException("Load asset callbacks is invalid.");
- }
- m_ResourceLoader.LoadAsset(assetName, null, Constant.DefaultPriority, loadAssetCallbacks, null);
- }
- /// <summary>
- /// 异步加载资源。
- /// </summary>
- /// <param name="assetName">要加载资源的名称。</param>
- /// <param name="assetType">要加载资源的类型。</param>
- /// <param name="loadAssetCallbacks">加载资源回调函数集。</param>
- public void LoadAsset(string assetName, Type assetType, LoadAssetCallbacks loadAssetCallbacks)
- {
- if (string.IsNullOrEmpty(assetName))
- {
- throw new GameFrameworkException("Asset name is invalid.");
- }
- if (loadAssetCallbacks == null)
- {
- throw new GameFrameworkException("Load asset callbacks is invalid.");
- }
- m_ResourceLoader.LoadAsset(assetName, assetType, Constant.DefaultPriority, loadAssetCallbacks, null);
- }
- /// <summary>
- /// 异步加载资源。
- /// </summary>
- /// <param name="assetName">要加载资源的名称。</param>
- /// <param name="priority">加载资源的优先级。</param>
- /// <param name="loadAssetCallbacks">加载资源回调函数集。</param>
- public void LoadAsset(string assetName, int priority, LoadAssetCallbacks loadAssetCallbacks)
- {
- if (string.IsNullOrEmpty(assetName))
- {
- throw new GameFrameworkException("Asset name is invalid.");
- }
- if (loadAssetCallbacks == null)
- {
- throw new GameFrameworkException("Load asset callbacks is invalid.");
- }
- m_ResourceLoader.LoadAsset(assetName, null, priority, loadAssetCallbacks, null);
- }
- /// <summary>
- /// 异步加载资源。
- /// </summary>
- /// <param name="assetName">要加载资源的名称。</param>
- /// <param name="loadAssetCallbacks">加载资源回调函数集。</param>
- /// <param name="userData">用户自定义数据。</param>
- public void LoadAsset(string assetName, LoadAssetCallbacks loadAssetCallbacks, object userData)
- {
- if (string.IsNullOrEmpty(assetName))
- {
- throw new GameFrameworkException("Asset name is invalid.");
- }
- if (loadAssetCallbacks == null)
- {
- throw new GameFrameworkException("Load asset callbacks is invalid.");
- }
- m_ResourceLoader.LoadAsset(assetName, null, Constant.DefaultPriority, loadAssetCallbacks, userData);
- }
- /// <summary>
- /// 异步加载资源。
- /// </summary>
- /// <param name="assetName">要加载资源的名称。</param>
- /// <param name="assetType">要加载资源的类型。</param>
- /// <param name="priority">加载资源的优先级。</param>
- /// <param name="loadAssetCallbacks">加载资源回调函数集。</param>
- public void LoadAsset(string assetName, Type assetType, int priority, LoadAssetCallbacks loadAssetCallbacks)
- {
- if (string.IsNullOrEmpty(assetName))
- {
- throw new GameFrameworkException("Asset name is invalid.");
- }
- if (loadAssetCallbacks == null)
- {
- throw new GameFrameworkException("Load asset callbacks is invalid.");
- }
- m_ResourceLoader.LoadAsset(assetName, assetType, priority, loadAssetCallbacks, null);
- }
- /// <summary>
- /// 异步加载资源。
- /// </summary>
- /// <param name="assetName">要加载资源的名称。</param>
- /// <param name="assetType">要加载资源的类型。</param>
- /// <param name="loadAssetCallbacks">加载资源回调函数集。</param>
- /// <param name="userData">用户自定义数据。</param>
- public void LoadAsset(string assetName, Type assetType, LoadAssetCallbacks loadAssetCallbacks, object userData)
- {
- if (string.IsNullOrEmpty(assetName))
- {
- throw new GameFrameworkException("Asset name is invalid.");
- }
- if (loadAssetCallbacks == null)
- {
- throw new GameFrameworkException("Load asset callbacks is invalid.");
- }
- m_ResourceLoader.LoadAsset(assetName, assetType, Constant.DefaultPriority, loadAssetCallbacks, userData);
- }
- /// <summary>
- /// 异步加载资源。
- /// </summary>
- /// <param name="assetName">要加载资源的名称。</param>
- /// <param name="priority">加载资源的优先级。</param>
- /// <param name="loadAssetCallbacks">加载资源回调函数集。</param>
- /// <param name="userData">用户自定义数据。</param>
- public void LoadAsset(string assetName, int priority, LoadAssetCallbacks loadAssetCallbacks, object userData)
- {
- if (string.IsNullOrEmpty(assetName))
- {
- throw new GameFrameworkException("Asset name is invalid.");
- }
- if (loadAssetCallbacks == null)
- {
- throw new GameFrameworkException("Load asset callbacks is invalid.");
- }
- m_ResourceLoader.LoadAsset(assetName, null, priority, loadAssetCallbacks, userData);
- }
- /// <summary>
- /// 异步加载资源。
- /// </summary>
- /// <param name="assetName">要加载资源的名称。</param>
- /// <param name="assetType">要加载资源的类型。</param>
- /// <param name="priority">加载资源的优先级。</param>
- /// <param name="loadAssetCallbacks">加载资源回调函数集。</param>
- /// <param name="userData">用户自定义数据。</param>
- public void LoadAsset(string assetName, Type assetType, int priority, LoadAssetCallbacks loadAssetCallbacks, object userData)
- {
- if (string.IsNullOrEmpty(assetName))
- {
- throw new GameFrameworkException("Asset name is invalid.");
- }
- if (loadAssetCallbacks == null)
- {
- throw new GameFrameworkException("Load asset callbacks is invalid.");
- }
- m_ResourceLoader.LoadAsset(assetName, assetType, priority, loadAssetCallbacks, userData);
- }
- /// <summary>
- /// 卸载资源。
- /// </summary>
- /// <param name="asset">要卸载的资源。</param>
- public void UnloadAsset(object asset)
- {
- if (asset == null)
- {
- throw new GameFrameworkException("Asset is invalid.");
- }
- if (m_ResourceLoader == null)
- {
- return;
- }
- m_ResourceLoader.UnloadAsset(asset);
- }
- /// <summary>
- /// 异步加载场景。
- /// </summary>
- /// <param name="sceneAssetName">要加载场景资源的名称。</param>
- /// <param name="loadSceneCallbacks">加载场景回调函数集。</param>
- public void LoadScene(string sceneAssetName, LoadSceneCallbacks loadSceneCallbacks)
- {
- if (string.IsNullOrEmpty(sceneAssetName))
- {
- throw new GameFrameworkException("Scene asset name is invalid.");
- }
- if (loadSceneCallbacks == null)
- {
- throw new GameFrameworkException("Load scene callbacks is invalid.");
- }
- m_ResourceLoader.LoadScene(sceneAssetName, Constant.DefaultPriority, loadSceneCallbacks, null);
- }
- /// <summary>
- /// 异步加载场景。
- /// </summary>
- /// <param name="sceneAssetName">要加载场景资源的名称。</param>
- /// <param name="priority">加载场景资源的优先级。</param>
- /// <param name="loadSceneCallbacks">加载场景回调函数集。</param>
- public void LoadScene(string sceneAssetName, int priority, LoadSceneCallbacks loadSceneCallbacks)
- {
- if (string.IsNullOrEmpty(sceneAssetName))
- {
- throw new GameFrameworkException("Scene asset name is invalid.");
- }
- if (loadSceneCallbacks == null)
- {
- throw new GameFrameworkException("Load scene callbacks is invalid.");
- }
- m_ResourceLoader.LoadScene(sceneAssetName, priority, loadSceneCallbacks, null);
- }
- /// <summary>
- /// 异步加载场景。
- /// </summary>
- /// <param name="sceneAssetName">要加载场景资源的名称。</param>
- /// <param name="loadSceneCallbacks">加载场景回调函数集。</param>
- /// <param name="userData">用户自定义数据。</param>
- public void LoadScene(string sceneAssetName, LoadSceneCallbacks loadSceneCallbacks, object userData)
- {
- if (string.IsNullOrEmpty(sceneAssetName))
- {
- throw new GameFrameworkException("Scene asset name is invalid.");
- }
- if (loadSceneCallbacks == null)
- {
- throw new GameFrameworkException("Load scene callbacks is invalid.");
- }
- m_ResourceLoader.LoadScene(sceneAssetName, Constant.DefaultPriority, loadSceneCallbacks, userData);
- }
- /// <summary>
- /// 异步加载场景。
- /// </summary>
- /// <param name="sceneAssetName">要加载场景资源的名称。</param>
- /// <param name="priority">加载场景资源的优先级。</param>
- /// <param name="loadSceneCallbacks">加载场景回调函数集。</param>
- /// <param name="userData">用户自定义数据。</param>
- public void LoadScene(string sceneAssetName, int priority, LoadSceneCallbacks loadSceneCallbacks, object userData)
- {
- if (string.IsNullOrEmpty(sceneAssetName))
- {
- throw new GameFrameworkException("Scene asset name is invalid.");
- }
- if (loadSceneCallbacks == null)
- {
- throw new GameFrameworkException("Load scene callbacks is invalid.");
- }
- m_ResourceLoader.LoadScene(sceneAssetName, priority, loadSceneCallbacks, userData);
- }
- /// <summary>
- /// 异步卸载场景。
- /// </summary>
- /// <param name="sceneAssetName">要卸载场景资源的名称。</param>
- /// <param name="unloadSceneCallbacks">卸载场景回调函数集。</param>
- public void UnloadScene(string sceneAssetName, UnloadSceneCallbacks unloadSceneCallbacks)
- {
- if (string.IsNullOrEmpty(sceneAssetName))
- {
- throw new GameFrameworkException("Scene asset name is invalid.");
- }
- if (unloadSceneCallbacks == null)
- {
- throw new GameFrameworkException("Unload scene callbacks is invalid.");
- }
- m_ResourceLoader.UnloadScene(sceneAssetName, unloadSceneCallbacks, null);
- }
- /// <summary>
- /// 异步卸载场景。
- /// </summary>
- /// <param name="sceneAssetName">要卸载场景资源的名称。</param>
- /// <param name="unloadSceneCallbacks">卸载场景回调函数集。</param>
- /// <param name="userData">用户自定义数据。</param>
- public void UnloadScene(string sceneAssetName, UnloadSceneCallbacks unloadSceneCallbacks, object userData)
- {
- if (string.IsNullOrEmpty(sceneAssetName))
- {
- throw new GameFrameworkException("Scene asset name is invalid.");
- }
- if (unloadSceneCallbacks == null)
- {
- throw new GameFrameworkException("Unload scene callbacks is invalid.");
- }
- m_ResourceLoader.UnloadScene(sceneAssetName, unloadSceneCallbacks, userData);
- }
- /// <summary>
- /// 获取二进制资源的实际路径。
- /// </summary>
- /// <param name="binaryAssetName">要获取实际路径的二进制资源的名称。</param>
- /// <returns>二进制资源的实际路径。</returns>
- /// <remarks>此方法仅适用于二进制资源存储在磁盘(而非文件系统)中的情况。若二进制资源存储在文件系统中时,返回值将始终为空。</remarks>
- public string GetBinaryPath(string binaryAssetName)
- {
- if (string.IsNullOrEmpty(binaryAssetName))
- {
- throw new GameFrameworkException("Binary asset name is invalid.");
- }
- return m_ResourceLoader.GetBinaryPath(binaryAssetName);
- }
- /// <summary>
- /// 获取二进制资源的实际路径。
- /// </summary>
- /// <param name="binaryAssetName">要获取实际路径的二进制资源的名称。</param>
- /// <param name="storageInReadOnly">二进制资源是否存储在只读区中。</param>
- /// <param name="storageInFileSystem">二进制资源是否存储在文件系统中。</param>
- /// <param name="relativePath">二进制资源或存储二进制资源的文件系统,相对于只读区或者读写区的相对路径。</param>
- /// <param name="fileName">若二进制资源存储在文件系统中,则指示二进制资源在文件系统中的名称,否则此参数返回空。</param>
- /// <returns>是否获取二进制资源的实际路径成功。</returns>
- public bool GetBinaryPath(string binaryAssetName, out bool storageInReadOnly, out bool storageInFileSystem, out string relativePath, out string fileName)
- {
- return m_ResourceLoader.GetBinaryPath(binaryAssetName, out storageInReadOnly, out storageInFileSystem, out relativePath, out fileName);
- }
- /// <summary>
- /// 获取二进制资源的长度。
- /// </summary>
- /// <param name="binaryAssetName">要获取长度的二进制资源的名称。</param>
- /// <returns>二进制资源的长度。</returns>
- public int GetBinaryLength(string binaryAssetName)
- {
- return m_ResourceLoader.GetBinaryLength(binaryAssetName);
- }
- /// <summary>
- /// 异步加载二进制资源。
- /// </summary>
- /// <param name="binaryAssetName">要加载二进制资源的名称。</param>
- /// <param name="loadBinaryCallbacks">加载二进制资源回调函数集。</param>
- public void LoadBinary(string binaryAssetName, LoadBinaryCallbacks loadBinaryCallbacks)
- {
- if (string.IsNullOrEmpty(binaryAssetName))
- {
- throw new GameFrameworkException("Binary asset name is invalid.");
- }
- if (loadBinaryCallbacks == null)
- {
- throw new GameFrameworkException("Load binary callbacks is invalid.");
- }
- m_ResourceLoader.LoadBinary(binaryAssetName, loadBinaryCallbacks, null);
- }
- /// <summary>
- /// 异步加载二进制资源。
- /// </summary>
- /// <param name="binaryAssetName">要加载二进制资源的名称。</param>
- /// <param name="loadBinaryCallbacks">加载二进制资源回调函数集。</param>
- /// <param name="userData">用户自定义数据。</param>
- public void LoadBinary(string binaryAssetName, LoadBinaryCallbacks loadBinaryCallbacks, object userData)
- {
- if (string.IsNullOrEmpty(binaryAssetName))
- {
- throw new GameFrameworkException("Binary asset name is invalid.");
- }
- if (loadBinaryCallbacks == null)
- {
- throw new GameFrameworkException("Load binary callbacks is invalid.");
- }
- m_ResourceLoader.LoadBinary(binaryAssetName, loadBinaryCallbacks, userData);
- }
- /// <summary>
- /// 从文件系统中加载二进制资源。
- /// </summary>
- /// <param name="binaryAssetName">要加载二进制资源的名称。</param>
- /// <returns>存储加载二进制资源的二进制流。</returns>
- public byte[] LoadBinaryFromFileSystem(string binaryAssetName)
- {
- if (string.IsNullOrEmpty(binaryAssetName))
- {
- throw new GameFrameworkException("Binary asset name is invalid.");
- }
- return m_ResourceLoader.LoadBinaryFromFileSystem(binaryAssetName);
- }
- /// <summary>
- /// 从文件系统中加载二进制资源。
- /// </summary>
- /// <param name="binaryAssetName">要加载二进制资源的名称。</param>
- /// <param name="buffer">存储加载二进制资源的二进制流。</param>
- /// <returns>实际加载了多少字节。</returns>
- public int LoadBinaryFromFileSystem(string binaryAssetName, byte[] buffer)
- {
- if (string.IsNullOrEmpty(binaryAssetName))
- {
- throw new GameFrameworkException("Binary asset name is invalid.");
- }
- if (buffer == null)
- {
- throw new GameFrameworkException("Buffer is invalid.");
- }
- return m_ResourceLoader.LoadBinaryFromFileSystem(binaryAssetName, buffer, 0, buffer.Length);
- }
- /// <summary>
- /// 从文件系统中加载二进制资源。
- /// </summary>
- /// <param name="binaryAssetName">要加载二进制资源的名称。</param>
- /// <param name="buffer">存储加载二进制资源的二进制流。</param>
- /// <param name="startIndex">存储加载二进制资源的二进制流的起始位置。</param>
- /// <returns>实际加载了多少字节。</returns>
- public int LoadBinaryFromFileSystem(string binaryAssetName, byte[] buffer, int startIndex)
- {
- if (string.IsNullOrEmpty(binaryAssetName))
- {
- throw new GameFrameworkException("Binary asset name is invalid.");
- }
- if (buffer == null)
- {
- throw new GameFrameworkException("Buffer is invalid.");
- }
- return m_ResourceLoader.LoadBinaryFromFileSystem(binaryAssetName, buffer, startIndex, buffer.Length - startIndex);
- }
- /// <summary>
- /// 从文件系统中加载二进制资源。
- /// </summary>
- /// <param name="binaryAssetName">要加载二进制资源的名称。</param>
- /// <param name="buffer">存储加载二进制资源的二进制流。</param>
- /// <param name="startIndex">存储加载二进制资源的二进制流的起始位置。</param>
- /// <param name="length">存储加载二进制资源的二进制流的长度。</param>
- /// <returns>实际加载了多少字节。</returns>
- public int LoadBinaryFromFileSystem(string binaryAssetName, byte[] buffer, int startIndex, int length)
- {
- if (string.IsNullOrEmpty(binaryAssetName))
- {
- throw new GameFrameworkException("Binary asset name is invalid.");
- }
- if (buffer == null)
- {
- throw new GameFrameworkException("Buffer is invalid.");
- }
- return m_ResourceLoader.LoadBinaryFromFileSystem(binaryAssetName, buffer, startIndex, length);
- }
- /// <summary>
- /// 从文件系统中加载二进制资源的片段。
- /// </summary>
- /// <param name="binaryAssetName">要加载片段的二进制资源的名称。</param>
- /// <param name="length">要加载片段的长度。</param>
- /// <returns>存储加载二进制资源片段内容的二进制流。</returns>
- public byte[] LoadBinarySegmentFromFileSystem(string binaryAssetName, int length)
- {
- if (string.IsNullOrEmpty(binaryAssetName))
- {
- throw new GameFrameworkException("Binary asset name is invalid.");
- }
- return m_ResourceLoader.LoadBinarySegmentFromFileSystem(binaryAssetName, 0, length);
- }
- /// <summary>
- /// 从文件系统中加载二进制资源的片段。
- /// </summary>
- /// <param name="binaryAssetName">要加载片段的二进制资源的名称。</param>
- /// <param name="offset">要加载片段的偏移。</param>
- /// <param name="length">要加载片段的长度。</param>
- /// <returns>存储加载二进制资源片段内容的二进制流。</returns>
- public byte[] LoadBinarySegmentFromFileSystem(string binaryAssetName, int offset, int length)
- {
- if (string.IsNullOrEmpty(binaryAssetName))
- {
- throw new GameFrameworkException("Binary asset name is invalid.");
- }
- return m_ResourceLoader.LoadBinarySegmentFromFileSystem(binaryAssetName, offset, length);
- }
- /// <summary>
- /// 从文件系统中加载二进制资源的片段。
- /// </summary>
- /// <param name="binaryAssetName">要加载片段的二进制资源的名称。</param>
- /// <param name="buffer">存储加载二进制资源片段内容的二进制流。</param>
- /// <returns>实际加载了多少字节。</returns>
- public int LoadBinarySegmentFromFileSystem(string binaryAssetName, byte[] buffer)
- {
- if (string.IsNullOrEmpty(binaryAssetName))
- {
- throw new GameFrameworkException("Binary asset name is invalid.");
- }
- if (buffer == null)
- {
- throw new GameFrameworkException("Buffer is invalid.");
- }
- return m_ResourceLoader.LoadBinarySegmentFromFileSystem(binaryAssetName, 0, buffer, 0, buffer.Length);
- }
- /// <summary>
- /// 从文件系统中加载二进制资源的片段。
- /// </summary>
- /// <param name="binaryAssetName">要加载片段的二进制资源的名称。</param>
- /// <param name="buffer">存储加载二进制资源片段内容的二进制流。</param>
- /// <param name="length">要加载片段的长度。</param>
- /// <returns>实际加载了多少字节。</returns>
- public int LoadBinarySegmentFromFileSystem(string binaryAssetName, byte[] buffer, int length)
- {
- if (string.IsNullOrEmpty(binaryAssetName))
- {
- throw new GameFrameworkException("Binary asset name is invalid.");
- }
- if (buffer == null)
- {
- throw new GameFrameworkException("Buffer is invalid.");
- }
- return m_ResourceLoader.LoadBinarySegmentFromFileSystem(binaryAssetName, 0, buffer, 0, length);
- }
- /// <summary>
- /// 从文件系统中加载二进制资源的片段。
- /// </summary>
- /// <param name="binaryAssetName">要加载片段的二进制资源的名称。</param>
- /// <param name="buffer">存储加载二进制资源片段内容的二进制流。</param>
- /// <param name="startIndex">存储加载二进制资源片段内容的二进制流的起始位置。</param>
- /// <param name="length">要加载片段的长度。</param>
- /// <returns>实际加载了多少字节。</returns>
- public int LoadBinarySegmentFromFileSystem(string binaryAssetName, byte[] buffer, int startIndex, int length)
- {
- if (string.IsNullOrEmpty(binaryAssetName))
- {
- throw new GameFrameworkException("Binary asset name is invalid.");
- }
- if (buffer == null)
- {
- throw new GameFrameworkException("Buffer is invalid.");
- }
- return m_ResourceLoader.LoadBinarySegmentFromFileSystem(binaryAssetName, 0, buffer, startIndex, length);
- }
- /// <summary>
- /// 从文件系统中加载二进制资源的片段。
- /// </summary>
- /// <param name="binaryAssetName">要加载片段的二进制资源的名称。</param>
- /// <param name="offset">要加载片段的偏移。</param>
- /// <param name="buffer">存储加载二进制资源片段内容的二进制流。</param>
- /// <returns>实际加载了多少字节。</returns>
- public int LoadBinarySegmentFromFileSystem(string binaryAssetName, int offset, byte[] buffer)
- {
- if (string.IsNullOrEmpty(binaryAssetName))
- {
- throw new GameFrameworkException("Binary asset name is invalid.");
- }
- if (buffer == null)
- {
- throw new GameFrameworkException("Buffer is invalid.");
- }
- return m_ResourceLoader.LoadBinarySegmentFromFileSystem(binaryAssetName, offset, buffer, 0, buffer.Length);
- }
- /// <summary>
- /// 从文件系统中加载二进制资源的片段。
- /// </summary>
- /// <param name="binaryAssetName">要加载片段的二进制资源的名称。</param>
- /// <param name="offset">要加载片段的偏移。</param>
- /// <param name="buffer">存储加载二进制资源片段内容的二进制流。</param>
- /// <param name="length">要加载片段的长度。</param>
- /// <returns>实际加载了多少字节。</returns>
- public int LoadBinarySegmentFromFileSystem(string binaryAssetName, int offset, byte[] buffer, int length)
- {
- if (string.IsNullOrEmpty(binaryAssetName))
- {
- throw new GameFrameworkException("Binary asset name is invalid.");
- }
- if (buffer == null)
- {
- throw new GameFrameworkException("Buffer is invalid.");
- }
- return m_ResourceLoader.LoadBinarySegmentFromFileSystem(binaryAssetName, offset, buffer, 0, length);
- }
- /// <summary>
- /// 从文件系统中加载二进制资源的片段。
- /// </summary>
- /// <param name="binaryAssetName">要加载片段的二进制资源的名称。</param>
- /// <param name="offset">要加载片段的偏移。</param>
- /// <param name="buffer">存储加载二进制资源片段内容的二进制流。</param>
- /// <param name="startIndex">存储加载二进制资源片段内容的二进制流的起始位置。</param>
- /// <param name="length">要加载片段的长度。</param>
- /// <returns>实际加载了多少字节。</returns>
- public int LoadBinarySegmentFromFileSystem(string binaryAssetName, int offset, byte[] buffer, int startIndex, int length)
- {
- if (string.IsNullOrEmpty(binaryAssetName))
- {
- throw new GameFrameworkException("Binary asset name is invalid.");
- }
- if (buffer == null)
- {
- throw new GameFrameworkException("Buffer is invalid.");
- }
- return m_ResourceLoader.LoadBinarySegmentFromFileSystem(binaryAssetName, offset, buffer, startIndex, length);
- }
- /// <summary>
- /// 检查资源组是否存在。
- /// </summary>
- /// <param name="resourceGroupName">要检查资源组的名称。</param>
- /// <returns>资源组是否存在。</returns>
- public bool HasResourceGroup(string resourceGroupName)
- {
- return m_ResourceGroups.ContainsKey(resourceGroupName ?? string.Empty);
- }
- /// <summary>
- /// 获取默认资源组。
- /// </summary>
- /// <returns>默认资源组。</returns>
- public IResourceGroup GetResourceGroup()
- {
- return GetResourceGroup(string.Empty);
- }
- /// <summary>
- /// 获取资源组。
- /// </summary>
- /// <param name="resourceGroupName">要获取的资源组名称。</param>
- /// <returns>要获取的资源组。</returns>
- public IResourceGroup GetResourceGroup(string resourceGroupName)
- {
- ResourceGroup resourceGroup = null;
- if (m_ResourceGroups.TryGetValue(resourceGroupName ?? string.Empty, out resourceGroup))
- {
- return resourceGroup;
- }
- return null;
- }
- /// <summary>
- /// 获取所有资源组。
- /// </summary>
- /// <returns>所有资源组。</returns>
- public IResourceGroup[] GetAllResourceGroups()
- {
- int index = 0;
- IResourceGroup[] results = new IResourceGroup[m_ResourceGroups.Count];
- foreach (KeyValuePair<string, ResourceGroup> resourceGroup in m_ResourceGroups)
- {
- results[index++] = resourceGroup.Value;
- }
- return results;
- }
- /// <summary>
- /// 获取所有资源组。
- /// </summary>
- /// <param name="results">所有资源组。</param>
- public void GetAllResourceGroups(List<IResourceGroup> results)
- {
- if (results == null)
- {
- throw new GameFrameworkException("Results is invalid.");
- }
- results.Clear();
- foreach (KeyValuePair<string, ResourceGroup> resourceGroup in m_ResourceGroups)
- {
- results.Add(resourceGroup.Value);
- }
- }
- /// <summary>
- /// 获取资源组集合。
- /// </summary>
- /// <param name="resourceGroupNames">要获取的资源组名称的集合。</param>
- /// <returns>要获取的资源组集合。</returns>
- public IResourceGroupCollection GetResourceGroupCollection(params string[] resourceGroupNames)
- {
- if (resourceGroupNames == null || resourceGroupNames.Length < 1)
- {
- throw new GameFrameworkException("Resource group names is invalid.");
- }
- ResourceGroup[] resourceGroups = new ResourceGroup[resourceGroupNames.Length];
- for (int i = 0; i < resourceGroupNames.Length; i++)
- {
- if (string.IsNullOrEmpty(resourceGroupNames[i]))
- {
- throw new GameFrameworkException("Resource group name is invalid.");
- }
- resourceGroups[i] = (ResourceGroup)GetResourceGroup(resourceGroupNames[i]);
- if (resourceGroups[i] == null)
- {
- throw new GameFrameworkException(Utility.Text.Format("Resource group '{0}' is not exist.", resourceGroupNames[i]));
- }
- }
- return new ResourceGroupCollection(resourceGroups, m_ResourceInfos);
- }
- /// <summary>
- /// 获取资源组集合。
- /// </summary>
- /// <param name="resourceGroupNames">要获取的资源组名称的集合。</param>
- /// <returns>要获取的资源组集合。</returns>
- public IResourceGroupCollection GetResourceGroupCollection(List<string> resourceGroupNames)
- {
- if (resourceGroupNames == null || resourceGroupNames.Count < 1)
- {
- throw new GameFrameworkException("Resource group names is invalid.");
- }
- ResourceGroup[] resourceGroups = new ResourceGroup[resourceGroupNames.Count];
- for (int i = 0; i < resourceGroupNames.Count; i++)
- {
- if (string.IsNullOrEmpty(resourceGroupNames[i]))
- {
- throw new GameFrameworkException("Resource group name is invalid.");
- }
- resourceGroups[i] = (ResourceGroup)GetResourceGroup(resourceGroupNames[i]);
- if (resourceGroups[i] == null)
- {
- throw new GameFrameworkException(Utility.Text.Format("Resource group '{0}' is not exist.", resourceGroupNames[i]));
- }
- }
- return new ResourceGroupCollection(resourceGroups, m_ResourceInfos);
- }
- private void UpdateResource(ResourceName resourceName)
- {
- m_ResourceUpdater.UpdateResource(resourceName);
- }
- private ResourceGroup GetOrAddResourceGroup(string resourceGroupName)
- {
- if (resourceGroupName == null)
- {
- resourceGroupName = string.Empty;
- }
- ResourceGroup resourceGroup = null;
- if (!m_ResourceGroups.TryGetValue(resourceGroupName, out resourceGroup))
- {
- resourceGroup = new ResourceGroup(resourceGroupName, m_ResourceInfos);
- m_ResourceGroups.Add(resourceGroupName, resourceGroup);
- }
- return resourceGroup;
- }
- private AssetInfo GetAssetInfo(string assetName)
- {
- if (string.IsNullOrEmpty(assetName))
- {
- throw new GameFrameworkException("Asset name is invalid.");
- }
- if (m_AssetInfos == null)
- {
- return null;
- }
- AssetInfo assetInfo = null;
- if (m_AssetInfos.TryGetValue(assetName, out assetInfo))
- {
- return assetInfo;
- }
- return null;
- }
- private ResourceInfo GetResourceInfo(ResourceName resourceName)
- {
- if (m_ResourceInfos == null)
- {
- return null;
- }
- ResourceInfo resourceInfo = null;
- if (m_ResourceInfos.TryGetValue(resourceName, out resourceInfo))
- {
- return resourceInfo;
- }
- return null;
- }
- private IFileSystem GetFileSystem(string fileSystemName, bool storageInReadOnly)
- {
- if (string.IsNullOrEmpty(fileSystemName))
- {
- throw new GameFrameworkException("File system name is invalid.");
- }
- IFileSystem fileSystem = null;
- if (storageInReadOnly)
- {
- if (!m_ReadOnlyFileSystems.TryGetValue(fileSystemName, out fileSystem))
- {
- string fullPath = Utility.Path.GetRegularPath(Path.Combine(m_ReadOnlyPath, Utility.Text.Format("{0}.{1}", fileSystemName, DefaultExtension)));
- fileSystem = m_FileSystemManager.GetFileSystem(fullPath);
- if (fileSystem == null)
- {
- fileSystem = m_FileSystemManager.LoadFileSystem(fullPath, FileSystemAccess.Read);
- m_ReadOnlyFileSystems.Add(fileSystemName, fileSystem);
- }
- }
- }
- else
- {
- if (!m_ReadWriteFileSystems.TryGetValue(fileSystemName, out fileSystem))
- {
- string fullPath = Utility.Path.GetRegularPath(Path.Combine(m_ReadWritePath, Utility.Text.Format("{0}.{1}", fileSystemName, DefaultExtension)));
- fileSystem = m_FileSystemManager.GetFileSystem(fullPath);
- if (fileSystem == null)
- {
- if (File.Exists(fullPath))
- {
- fileSystem = m_FileSystemManager.LoadFileSystem(fullPath, FileSystemAccess.ReadWrite);
- }
- else
- {
- string directory = Path.GetDirectoryName(fullPath);
- if (!Directory.Exists(directory))
- {
- Directory.CreateDirectory(directory);
- }
- fileSystem = m_FileSystemManager.CreateFileSystem(fullPath, FileSystemAccess.ReadWrite, FileSystemMaxFileCount, FileSystemMaxBlockCount);
- }
- m_ReadWriteFileSystems.Add(fileSystemName, fileSystem);
- }
- }
- }
- return fileSystem;
- }
- private void OnIniterResourceInitComplete()
- {
- m_ResourceIniter.ResourceInitComplete -= OnIniterResourceInitComplete;
- m_ResourceIniter.Shutdown();
- m_ResourceIniter = null;
- m_InitResourcesCompleteCallback();
- m_InitResourcesCompleteCallback = null;
- }
- private void OnVersionListProcessorUpdateSuccess(string downloadPath, string downloadUri)
- {
- m_UpdateVersionListCallbacks.UpdateVersionListSuccessCallback(downloadPath, downloadUri);
- }
- private void OnVersionListProcessorUpdateFailure(string downloadUri, string errorMessage)
- {
- if (m_UpdateVersionListCallbacks.UpdateVersionListFailureCallback != null)
- {
- m_UpdateVersionListCallbacks.UpdateVersionListFailureCallback(downloadUri, errorMessage);
- }
- }
- private void OnCheckerResourceNeedUpdate(ResourceName resourceName, string fileSystemName, LoadType loadType, int length, int hashCode, int compressedLength, int compressedHashCode)
- {
- m_ResourceUpdater.AddResourceUpdate(resourceName, fileSystemName, loadType, length, hashCode, compressedLength, compressedHashCode, Utility.Path.GetRegularPath(Path.Combine(m_ReadWritePath, resourceName.FullName)));
- }
- private void OnCheckerResourceCheckComplete(int movedCount, int removedCount, int updateCount, long updateTotalLength, long updateTotalCompressedLength)
- {
- m_VersionListProcessor.VersionListUpdateSuccess -= OnVersionListProcessorUpdateSuccess;
- m_VersionListProcessor.VersionListUpdateFailure -= OnVersionListProcessorUpdateFailure;
- m_VersionListProcessor.Shutdown();
- m_VersionListProcessor = null;
- m_UpdateVersionListCallbacks = null;
- m_ResourceChecker.ResourceNeedUpdate -= OnCheckerResourceNeedUpdate;
- m_ResourceChecker.ResourceCheckComplete -= OnCheckerResourceCheckComplete;
- m_ResourceChecker.Shutdown();
- m_ResourceChecker = null;
- m_ResourceUpdater.CheckResourceComplete(movedCount > 0 || removedCount > 0);
- if (updateCount <= 0)
- {
- m_ResourceUpdater.ResourceApplySuccess -= OnUpdaterResourceApplySuccess;
- m_ResourceUpdater.ResourceApplyFailure -= OnUpdaterResourceApplyFailure;
- m_ResourceUpdater.ResourceApplyComplete -= OnUpdaterResourceApplyComplete;
- m_ResourceUpdater.ResourceUpdateStart -= OnUpdaterResourceUpdateStart;
- m_ResourceUpdater.ResourceUpdateChanged -= OnUpdaterResourceUpdateChanged;
- m_ResourceUpdater.ResourceUpdateSuccess -= OnUpdaterResourceUpdateSuccess;
- m_ResourceUpdater.ResourceUpdateFailure -= OnUpdaterResourceUpdateFailure;
- m_ResourceUpdater.ResourceUpdateComplete -= OnUpdaterResourceUpdateComplete;
- m_ResourceUpdater.ResourceUpdateAllComplete -= OnUpdaterResourceUpdateAllComplete;
- m_ResourceUpdater.Shutdown();
- m_ResourceUpdater = null;
- m_ReadWriteResourceInfos.Clear();
- m_ReadWriteResourceInfos = null;
- if (m_DecompressCachedStream != null)
- {
- m_DecompressCachedStream.Dispose();
- m_DecompressCachedStream = null;
- }
- }
- m_CheckResourcesCompleteCallback(movedCount, removedCount, updateCount, updateTotalLength, updateTotalCompressedLength);
- m_CheckResourcesCompleteCallback = null;
- }
- private void OnUpdaterResourceApplySuccess(ResourceName resourceName, string applyPath, string resourcePackPath, int length, int compressedLength)
- {
- if (m_ResourceApplySuccessEventHandler != null)
- {
- ResourceApplySuccessEventArgs resourceApplySuccessEventArgs = ResourceApplySuccessEventArgs.Create(resourceName.FullName, applyPath, resourcePackPath, length, compressedLength);
- m_ResourceApplySuccessEventHandler(this, resourceApplySuccessEventArgs);
- ReferencePool.Release(resourceApplySuccessEventArgs);
- }
- }
- private void OnUpdaterResourceApplyFailure(ResourceName resourceName, string resourcePackPath, string errorMessage)
- {
- if (m_ResourceApplyFailureEventHandler != null)
- {
- ResourceApplyFailureEventArgs resourceApplyFailureEventArgs = ResourceApplyFailureEventArgs.Create(resourceName.FullName, resourcePackPath, errorMessage);
- m_ResourceApplyFailureEventHandler(this, resourceApplyFailureEventArgs);
- ReferencePool.Release(resourceApplyFailureEventArgs);
- }
- }
- private void OnUpdaterResourceApplyComplete(string resourcePackPath, bool result)
- {
- ApplyResourcesCompleteCallback applyResourcesCompleteCallback = m_ApplyResourcesCompleteCallback;
- m_ApplyResourcesCompleteCallback = null;
- applyResourcesCompleteCallback(resourcePackPath, result);
- }
- private void OnUpdaterResourceUpdateStart(ResourceName resourceName, string downloadPath, string downloadUri, int currentLength, int compressedLength, int retryCount)
- {
- if (m_ResourceUpdateStartEventHandler != null)
- {
- ResourceUpdateStartEventArgs resourceUpdateStartEventArgs = ResourceUpdateStartEventArgs.Create(resourceName.FullName, downloadPath, downloadUri, currentLength, compressedLength, retryCount);
- m_ResourceUpdateStartEventHandler(this, resourceUpdateStartEventArgs);
- ReferencePool.Release(resourceUpdateStartEventArgs);
- }
- }
- private void OnUpdaterResourceUpdateChanged(ResourceName resourceName, string downloadPath, string downloadUri, int currentLength, int compressedLength)
- {
- if (m_ResourceUpdateChangedEventHandler != null)
- {
- ResourceUpdateChangedEventArgs resourceUpdateChangedEventArgs = ResourceUpdateChangedEventArgs.Create(resourceName.FullName, downloadPath, downloadUri, currentLength, compressedLength);
- m_ResourceUpdateChangedEventHandler(this, resourceUpdateChangedEventArgs);
- ReferencePool.Release(resourceUpdateChangedEventArgs);
- }
- }
- private void OnUpdaterResourceUpdateSuccess(ResourceName resourceName, string downloadPath, string downloadUri, int length, int compressedLength)
- {
- if (m_ResourceUpdateSuccessEventHandler != null)
- {
- ResourceUpdateSuccessEventArgs resourceUpdateSuccessEventArgs = ResourceUpdateSuccessEventArgs.Create(resourceName.FullName, downloadPath, downloadUri, length, compressedLength);
- m_ResourceUpdateSuccessEventHandler(this, resourceUpdateSuccessEventArgs);
- ReferencePool.Release(resourceUpdateSuccessEventArgs);
- }
- }
- private void OnUpdaterResourceUpdateFailure(ResourceName resourceName, string downloadUri, int retryCount, int totalRetryCount, string errorMessage)
- {
- if (m_ResourceUpdateFailureEventHandler != null)
- {
- ResourceUpdateFailureEventArgs resourceUpdateFailureEventArgs = ResourceUpdateFailureEventArgs.Create(resourceName.FullName, downloadUri, retryCount, totalRetryCount, errorMessage);
- m_ResourceUpdateFailureEventHandler(this, resourceUpdateFailureEventArgs);
- ReferencePool.Release(resourceUpdateFailureEventArgs);
- }
- }
- private void OnUpdaterResourceUpdateComplete(ResourceGroup resourceGroup, bool result)
- {
- Utility.Path.RemoveEmptyDirectory(m_ReadWritePath);
- UpdateResourcesCompleteCallback updateResourcesCompleteCallback = m_UpdateResourcesCompleteCallback;
- m_UpdateResourcesCompleteCallback = null;
- updateResourcesCompleteCallback(resourceGroup, result);
- }
- private void OnUpdaterResourceUpdateAllComplete()
- {
- m_ResourceUpdater.ResourceApplySuccess -= OnUpdaterResourceApplySuccess;
- m_ResourceUpdater.ResourceApplyFailure -= OnUpdaterResourceApplyFailure;
- m_ResourceUpdater.ResourceApplyComplete -= OnUpdaterResourceApplyComplete;
- m_ResourceUpdater.ResourceUpdateStart -= OnUpdaterResourceUpdateStart;
- m_ResourceUpdater.ResourceUpdateChanged -= OnUpdaterResourceUpdateChanged;
- m_ResourceUpdater.ResourceUpdateSuccess -= OnUpdaterResourceUpdateSuccess;
- m_ResourceUpdater.ResourceUpdateFailure -= OnUpdaterResourceUpdateFailure;
- m_ResourceUpdater.ResourceUpdateComplete -= OnUpdaterResourceUpdateComplete;
- m_ResourceUpdater.ResourceUpdateAllComplete -= OnUpdaterResourceUpdateAllComplete;
- m_ResourceUpdater.Shutdown();
- m_ResourceUpdater = null;
- m_ReadWriteResourceInfos.Clear();
- m_ReadWriteResourceInfos = null;
- if (m_DecompressCachedStream != null)
- {
- m_DecompressCachedStream.Dispose();
- m_DecompressCachedStream = null;
- }
- Utility.Path.RemoveEmptyDirectory(m_ReadWritePath);
- if (m_ResourceUpdateAllCompleteEventHandler != null)
- {
- ResourceUpdateAllCompleteEventArgs resourceUpdateAllCompleteEventArgs = ResourceUpdateAllCompleteEventArgs.Create();
- m_ResourceUpdateAllCompleteEventHandler(this, resourceUpdateAllCompleteEventArgs);
- ReferencePool.Release(resourceUpdateAllCompleteEventArgs);
- }
- }
- }
- }
|