| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207 |
- using System.Text;
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.IO;
- using UnityEngine;
- using UnityEngine.Playables;
- using UnityEngine.SceneManagement;
- using UnityEngine.Video;
- using UnityEngine.Networking;
- using Object = UnityEngine.Object;
- using Game.Config;
- public enum ELoadType : int
- {
- OTHER = 0,
- UI = 1,
- ACTOR = 2,
- FX = 3,
- AssetBundle = 4,
- }
- public delegate void AssetCallback<T>(T callback);
- public delegate void AssetCallbackWithParams<T>(T callback, long seqId, string assetPath, params string[] assetName);
- class Bundle
- {
- AssetBundle mAsset;
- public AssetBundle Asset
- {
- get { return mAsset; }
- }
- float mLastUsedTime;
- public float LastUsedTime
- {
- get { return mLastUsedTime; }
- set
- {
- mLastUsedTime = value;
- Priority = 0;
- }
- }
- public string mBundleName = string.Empty;
- public string BundleName
- {
- get { return mBundleName; }
- }
- public int mPriority = 0;
- public int Priority
- {
- get { return mPriority; }
- set
- {
- mPriority = value;
- mLastUsedTime = Time.realtimeSinceStartup;
- }
- }
- public Bundle(AssetBundle bundle, string bundleName)
- {
- mBundleName = bundleName;
- mAsset = bundle;
- mPriority = 0;
- mLastUsedTime = Time.realtimeSinceStartup;
- }
- public void Unload()
- {
- if (mAsset != null)
- {
- mAsset.Unload(false);
- mAsset = null;
- }
- }
- }
- public class LoadAssetsTask
- {
- bool hasReturnParam = false;
- public bool HasReturnParam
- {
- get { return hasReturnParam; }
- }
- Delegate mCallback;
- public Delegate Callback
- {
- get { return mCallback; }
- }
- string mAssetPath;
- public string AssetPath
- {
- get { return mAssetPath; }
- }
- string[] mAssetName;
- public string[] AssetName
- {
- get { return mAssetName; }
- }
- long mLoadingSeqId = 0;
- public long LoadingSeqId
- {
- get { return mLoadingSeqId; }
- }
- public LoadAssetsTask(long seqId, string assetPath,string[] assetName, Delegate callback, bool returnParam_)
- {
- mLoadingSeqId = seqId;
- mAssetPath = assetPath;
- mAssetName = assetName;
- mCallback = callback;
- hasReturnParam = returnParam_;
- }
- public void Invoke<T>(T goes)
- {
- if (hasReturnParam)
- {
- Callback.DynamicInvoke(goes, mLoadingSeqId, mAssetPath, mAssetName);
- }
- else
- {
- Callback.DynamicInvoke(goes);
- }
- }
- }
- public class LoadTask
- {
- string mBundleName;
- public string BundleName
- {
- get { return mBundleName; }
- }
- List<LoadAssetsTask> mAssetsTask = new List<LoadAssetsTask>();
- public List<LoadAssetsTask> AssetsTask
- {
- get { return mAssetsTask; }
- }
- public int AssetsTaskCnt
- {
- get { return mAssetsTask.Count; }
- }
- Type mDelegateType;
- public Type DelegateType
- {
- get { return mDelegateType; }
- }
- ELoadType mLoadType;
- public ELoadType LoadType
- {
- get { return mLoadType; }
- }
- float mLoadStartTime;
- public float LoadStartTime
- {
- get { return mLoadStartTime; }
- set
- {
- mLoadStartTime = value;
- }
- }
- private AssetBundle mBundle = null;
- public AssetBundle Bundle
- {
- get { return mBundle; }
- set { mBundle = value; }
- }
- private bool isDone = false;
- public bool IsDone
- {
- get { return isDone; }
- set { isDone = value; }
- }
- //依赖的ab包是否加载完成
- private bool isDependencyDone = true;
- public bool IsDependencyDone
- {
- get { return isDependencyDone; }
- set { isDependencyDone = value; }
- }
- //需要加载ab包是否有依赖包
- private bool isDependency = false;
- public bool IsDependency
- {
- get { return isDependency; }
- set { isDependency = value; }
- }
- public LoadTask(string bundleName)
- {
- mBundleName = bundleName;
- // mBundleName = bundleName.ToLower();
- // if (!mBundleName.Contains(".unity3d"))
- // {
- // mBundleName = mBundleName + ".unity3d";
- // }
- mLoadType = ELoadType.AssetBundle;
- //DebugHelper.LogError("bundleName:" + bundleName);
- }
- public LoadTask(long seqId, string bundleName,string assetPath, string[] assetName, Delegate callback, bool callbackWithParam, Type type, ELoadType loadType = ELoadType.OTHER)
- {
- mBundleName = bundleName;
- // mBundleName = bundleName.ToLower();
- // if (!mBundleName.Contains(".unity3d"))
- // {
- // mBundleName = mBundleName + ".unity3d";
- // }
- mAssetsTask.Add(new LoadAssetsTask(seqId, assetPath, assetName, callback, callbackWithParam));
- mDelegateType = type;
- mLoadType = loadType;
- //DebugHelper.LogError("bundleName:" + bundleName);
- }
- public void ChangeTask(long seqId, string bundleName, string assetPath, string[] assetName, Delegate callback, bool callbackWithParam, Type type, ELoadType loadType = ELoadType.OTHER)
- {
- if (mLoadType == ELoadType.AssetBundle) return;
- mAssetsTask.Add(new LoadAssetsTask(seqId, assetPath, assetName, callback, callbackWithParam));
- mDelegateType = type;
- mLoadType = loadType;
- }
- public LoadAssetsTask FindTask(long seqId)
- {
- for (int idx = 0; idx < mAssetsTask.Count; idx++)
- {
- LoadAssetsTask task = mAssetsTask[idx];
- if (task.LoadingSeqId == seqId)
- {
- return task;
- }
- }
- return null;
- }
- public void RemoveTask(long seqId)
- {
- LoadAssetsTask task = FindTask(seqId);
- if (task != null)
- {
- mAssetsTask.Remove(task);
- }
- }
- public bool IsExist(long seqId)
- {
- for (int idx = 0; idx < mAssetsTask.Count; idx++)
- {
- LoadAssetsTask task = mAssetsTask[idx];
- if (task.LoadingSeqId == seqId)
- {
- return true;
- }
- }
- return false;
- }
- }
- public class LoadAssetbundleTask
- {
- private LoadTask mLoader = null;
- private AssetBundleCreateRequest mAsync = null;
- private bool mbIsDone = false;
- private bool mbNotified = false;
- public LoadTask Loader
- {
- get { return mLoader; }
- }
- public bool IsDone
- {
- get { return mbIsDone; }
- }
- public LoadAssetbundleTask(LoadTask info)
- {
- mLoader = info;
- }
- public void Update()
- {
- if (mAsync == null && mLoader.IsDependencyDone)
- {
- mAsync = AssetsMgr.Instance.CreatePackageLoader(mLoader.BundleName);
- if (mAsync == null && !mbNotified)
- {
- Ending(null);
- mbNotified = true;
- }
- else if (mAsync != null && mAsync.isDone)
- {
- if (!mbNotified)
- {
- Ending(null);
- mbNotified = true;
- }
- }
- }
- else if (mAsync != null && mAsync.isDone)
- {
- if (!mbNotified)
- {
- Ending(mAsync.assetBundle);
- mbNotified = true;
- }
- }
- }
- public void Dispose()
- {
- mLoader = null;
- }
- void Ending(AssetBundle bundle)
- {
- mLoader.Bundle = bundle;
- mbIsDone = true;
- AssetsMgr.Instance.NotifyAssetbundleLoaded(mLoader, this);
- }
- }
- public class AssetsMgr : SingletonMono<AssetsMgr>
- {
- private List<string> mResidentAssetBundleList = new List<string>();
- private Dictionary<string, string> mAssetsMappingDict = new Dictionary<string, string>();
- private Dictionary<string, Bundle> mBundlesLoaded = new Dictionary<string, Bundle>();
- private Dictionary<string, LoadTask> mBundlesLoading = new Dictionary<string, LoadTask>();
- private Dictionary<string, LoadTask> mCurLoadingBundleDic = new Dictionary<string, LoadTask>();
- private List<LoadTask> mLoadTasks = new List<LoadTask>();
- private Queue<LoadTask> mLoadFinshedTask = new Queue<LoadTask>();
- private List<string> expired = new List<string>();
- private List<LoadAssetbundleTask> mAssetbundleLoadTasks = new List<LoadAssetbundleTask>();
- private Dictionary<string, LanguageAssetBundleName> abNameInfo = new Dictionary<string, LanguageAssetBundleName>(1024);
- private static readonly int GCRepeatRate = 7;//主城重复清理gc时间间隔.
- private static readonly int GCReleaseRate = 2;//切换场景gc时间间隔.
- private static readonly int MaxLoadingCoroutineCount = 10;
- private int mLoadingCoroutineCount = 0;
- private AssetBundleManifest assetBundleManifest = null;
-
- private const string c_ResVersionCodeKey = "resversioncode";
- private VersionCode m_ResVersionCode = VersionCode.zeroVersionCode;
- private string resLanguage = "";
- public VersionCode resVersionCode
- {
- get { return m_ResVersionCode; }
- }
- public string GetReslanguage()
- {
-
- string languagekey = "language";
- if (string.IsNullOrEmpty(resLanguage))
- {
- if (abNameInfo.ContainsKey(languagekey))
- {
- if (abNameInfo[languagekey].BaseName == "auto")
- {
- SetLocalizedLanguage();
- }
- else
- {
- resLanguage = abNameInfo[languagekey].BaseName;
- }
-
- }
- else
- {
- resLanguage = "base";
- }
- }
-
- return resLanguage;
- }
- public void SetLocalizedLanguage()
- {
- switch (Application.systemLanguage)
- {
- case SystemLanguage.Chinese:
- case SystemLanguage.ChineseSimplified:
- case SystemLanguage.ChineseTraditional:
- {
- resLanguage = "base";
- }
- break;
- case SystemLanguage.Afrikaans:
-
- case SystemLanguage.Arabic:
-
- case SystemLanguage.Basque:
-
- case SystemLanguage.Belarusian:
-
- case SystemLanguage.Bulgarian:
-
- case SystemLanguage.Catalan:
-
-
- case SystemLanguage.Czech:
-
- case SystemLanguage.Danish:
-
- case SystemLanguage.Dutch:
-
- case SystemLanguage.English:
-
- case SystemLanguage.Estonian:
-
- case SystemLanguage.Faroese:
-
- case SystemLanguage.Finnish:
-
- case SystemLanguage.French:
-
- case SystemLanguage.German:
-
- case SystemLanguage.Greek:
-
- case SystemLanguage.Hebrew:
-
-
- case SystemLanguage.Icelandic:
-
- case SystemLanguage.Indonesian:
-
- case SystemLanguage.Italian:
-
- case SystemLanguage.Japanese:
-
- case SystemLanguage.Korean:
-
- case SystemLanguage.Latvian:
-
- case SystemLanguage.Lithuanian:
-
- case SystemLanguage.Norwegian:
-
- case SystemLanguage.Polish:
-
- case SystemLanguage.Portuguese:
-
- case SystemLanguage.Romanian:
-
- case SystemLanguage.Russian:
-
- case SystemLanguage.SerboCroatian:
-
- case SystemLanguage.Slovak:
-
- case SystemLanguage.Slovenian:
-
- case SystemLanguage.Spanish:
-
- case SystemLanguage.Swedish:
-
- case SystemLanguage.Thai:
-
- case SystemLanguage.Turkish:
-
- case SystemLanguage.Ukrainian:
-
- case SystemLanguage.Vietnamese:
-
-
-
- case SystemLanguage.Unknown:
-
- case SystemLanguage.Hungarian:
-
- default:
- {
- resLanguage = "en_";
- }
- break;
- }
- }
- public string GetlanguageAbName_EN(string abname)
- {
- string ret = "";
-
- if (abNameInfo.ContainsKey(abname))
- {
- ret = abNameInfo[abname].En;
- }
-
- return ret;
- }
- public override void InitMgr()
- {
- base.InitMgr();
-
- #if UNITY_EDITOR
- if (Constants.AssetbundleMode)
- {
- if (null == assetBundleManifest)
- {
- GetAssetBundleManifest("assetbundle", ref assetBundleManifest);
- }
- //StartCoroutine(GetAssetsMapping());
- GetAssetsMappingSync();
- }
- #else
- if (null == assetBundleManifest)
- {
- GetAssetBundleManifest("assetbundle", ref assetBundleManifest);
- //StartCoroutine(GetAssetsMapping());
- GetAssetsMappingSync();
- }
- #endif
- }
- public void InitAbNameCfg(Action action = null)
- {
- DownloadMgr.Instance.ReadDataFromFile(LanguageAssetBundleName.FileName_S(),data =>
- {
-
- if (data != null)
- {
- CsvReader csvReader = new CsvReader(LanguageAssetBundleName.FileName_S(), data);
- LanguageAssetBundleName.OnCsvLoad(csvReader);
- LanguageAssetBundleName.Foreach(it =>
- {
- abNameInfo.Add(it.BaseName, it);
- //Debug.Log(it.BaseName);
- });
- LanguageAssetBundleName.Clear();
- }
- action?.Invoke();
- });
- }
- private string GetAssetsMappingName()
- {
- #if UNITY_IOS
- Debug.Log("============afi============");
- return "{0}afi.bytes";
- #else
- return "{0}assetsmapping.bytes";
- #endif
- }
- private void GetAssetsMappingSync()
- {
- string path = string.Format(GetAssetsMappingName(), FileSystem.LocalDocumentPath);
- if (!FileSystem.Exists(path))
- {
- path = string.Format(GetAssetsMappingName(), FileSystem.LocalPackagePath);
- }
- if (!path.Contains("file://"))
- {
- path = "file://" + path;
- }
- try
- {
- WWW www = new WWW(path);
- while (!www.isDone) { }
- if (string.IsNullOrEmpty(www.error))
- {
- string data = www.text;
- string[] ContentLines = www.text.Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries);
- for (int idx = 0; idx < ContentLines.Length; idx++)
- {
- string content = ContentLines[idx];
- string[] temp = content.Split(',');
- mAssetsMappingDict.Add(temp[0].ToLower(), temp[1]);
- }
- if (mAssetsMappingDict.ContainsKey(c_ResVersionCodeKey))
- {
- m_ResVersionCode = mAssetsMappingDict[c_ResVersionCodeKey];
- mAssetsMappingDict.Remove(c_ResVersionCodeKey);
- }
- AssetsObscureUtil.InitAssetsObscureConfig(ref mAssetsMappingDict);
- }
- else
- {
- DebugHelper.LogError("Load AssetsMapping Fail:" + www.error + " filePath:" + path);
- }
- }
- catch (Exception e)
- {
- DebugHelper.LogError("Load AssetsMapping Fail:" + e.ToString() + " filePath:" + path);
- }
- }
- public void InitDependenciesAsync(Action<bool> completeCB)
- {
- #if UNITY_EDITOR
- if (!Constants.AssetbundleMode)
- {
- if (completeCB != null) completeCB(true);
- return;
- }
- #endif
- StartCoroutine(AsyncInitDependencies(completeCB));
- }
- private IEnumerator AsyncInitDependencies(Action<bool> completeCB)
- {
- string path = null;
- if (null == assetBundleManifest)
- {
- path = string.Format(GetAssetsMappingName(), FileSystem.LocalDocumentPath);
- if (!FileSystem.Exists(path))
- {
- path = string.Format(GetAssetsMappingName(), FileSystem.LocalPackagePath);
- }
- if (!path.Contains("file://"))
- {
- path = "file://" + path;
- }
- WWW www = new WWW(path);
- yield return www;
- if (string.IsNullOrEmpty(www.error))
- {
- byte[] bytes = www.bytes;
- byte value;
- int length = bytes.Length;
- for (int i = 0, iMax = Mathf.FloorToInt(length * 0.5f); i < iMax; i += 2)
- {
- value = bytes[i];
- bytes[i] = bytes[length - i - 1];
- bytes[length - i - 1] = value;
- }
- UTF8Encoding encoding = new UTF8Encoding(false);
- string data = encoding.GetString(bytes);
- string[] ContentLines = data.Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries);
- for (int idx = 0; idx < ContentLines.Length; idx++)
- {
- string content = ContentLines[idx];
- string[] temp = content.Split(',');
- mAssetsMappingDict.Add(temp[0].ToLower(), temp[1]);
- }
- if (mAssetsMappingDict.ContainsKey(c_ResVersionCodeKey))
- {
- m_ResVersionCode = mAssetsMappingDict[c_ResVersionCodeKey];
- mAssetsMappingDict.Remove(c_ResVersionCodeKey);
- }
- AssetsObscureUtil.InitAssetsObscureConfig(ref mAssetsMappingDict);
- }
- else
- {
- DebugHelper.LogError("Load AssetsMapping Fail:" + www.error + " filePath:" + path);
- }
- string assetbundleName = AssetsObscureUtil.GetABFileName("assetbundle");
- ulong offset = AssetsObscureUtil.GetABOffset(assetbundleName);
- path = string.Format("{0}{1}", FileSystem.LocalDocumentPath, assetbundleName);
- if (!FileSystem.Exists(path))
- {
- path = string.Format("{0}{1}", FileSystem.LocalPackagePath, assetbundleName);
- }
- var assetBundleCreateRequest = AssetBundle.LoadFromFileAsync(path, 0, offset);
- yield return assetBundleCreateRequest;
- var assetBundleRequest = assetBundleCreateRequest.assetBundle.LoadAssetAsync("AssetBundleManifest");
- yield return assetBundleRequest;
- assetBundleManifest = (AssetBundleManifest)assetBundleRequest.asset;
- if (completeCB != null) completeCB(true);
- }
- }
- public void InitResidentAssetBundleList(Action<bool> completeCB)
- {
- #if UNITY_EDITOR
- if (!Constants.AssetbundleMode)
- {
- if (completeCB != null) completeCB(true);
- return;
- }
- #endif
- StartCoroutine(AsyncInitResidentAssetBundleList(completeCB));
- }
- private IEnumerator AsyncInitResidentAssetBundleList(Action<bool> completeCB)
- {
- string shaderName = AssetsObscureUtil.GetABFileName("shader.unity3d");
- ulong offset = AssetsObscureUtil.GetABOffset(shaderName);
- mResidentAssetBundleList.Clear();
- mResidentAssetBundleList.Add(shaderName);
- string path = string.Format("{0}{1}", FileSystem.LocalDocumentPath, shaderName);
- if (!FileSystem.Exists(path))
- {
- path = string.Format("{0}{1}", FileSystem.LocalPackagePath, shaderName);
- }
- AssetBundleCreateRequest shaderABCreateRequest = AssetBundle.LoadFromFileAsync(path, 0, offset);
- yield return shaderABCreateRequest;
- AssetBundle shaderAB = shaderABCreateRequest.assetBundle;
- if (shaderAB != null)
- {
- Bundle bundle = new Bundle(shaderAB, shaderName);
- mBundlesLoaded.Add(shaderName, bundle);
- }
- Shader.WarmupAllShaders();
- if (completeCB != null) completeCB(true);
- }
- public void AddResidentAsset(string assetName)
- {
- mResidentAssetBundleList.Add(assetName);
- }
- private string GetABName(string assetName, Type type)
- {
- string abName = null;
- if (!FileUtils.HasExtension(assetName))
- {
- assetName += GetFileTypeExtention(type);
- }
- mAssetsMappingDict.TryGetValue(assetName.ToLower(), out abName);
- return abName;
- }
- private string GetFileTypeExtention(Type type)
- {
- string ext = "";
- if (type.Equals(typeof(List<GameObject>)) || type.Equals(typeof(GameObject)))
- {
- ext = ".prefab";
- }
- else if (type.Equals(typeof(List<TextAsset>)))
- {
- ext = ".bytes";
- }
- else if (type.Equals(typeof(List<AudioClip>)) || type.Equals(typeof(AudioClip)))
- {
- ext = ".ogg";
- }else if(type.Equals(typeof(List<VideoClip>)) || type.Equals(typeof(VideoClip)))
- {
- ext = ".mp4";
- }
- else if (type.Equals(typeof(List<Texture2D>)) || type.Equals(typeof(Texture2D)))
- {
- ext = ".png";
- }
- else if (type.Equals(typeof(List<PlayableAsset>)) || type.Equals(typeof(PlayableAsset)))
- {
- ext = ".playable";
- }else if(type.Equals(typeof(List<Material>)) || type.Equals(typeof(Material)))
- {
- ext = ".mat";
- }else if(type.Equals(typeof(List<Sprite>)) || type.Equals(typeof(Sprite)))
- {
- ext = ".png";
- }
- else if(type.Equals(typeof(List<RuntimeAnimatorController>)) || type.Equals(typeof(RuntimeAnimatorController)))
- {
- ext = ".controller";
- }
- return ext;
- }
- protected override void Dispose()
- {
- if (mBundlesLoaded != null)
- {
- foreach (var item in mBundlesLoaded)
- {
- if (item.Value != null)
- item.Value.Unload();
- }
- mBundlesLoaded.Clear();
- }
- mBundlesLoading = null;
- mBundlesLoaded = null;
- if (mLoadTasks != null)
- mLoadTasks.Clear();
- if (expired != null)
- expired.Clear();
- StopAllCoroutines();
- base.Dispose();
- }
- void GetAssetBundleManifest(string fileName, ref AssetBundleManifest maniFest)
- {
- if (null == assetBundleManifest)
- {
- string path = string.Format("{0}{1}", FileSystem.LocalDocumentPath, fileName);
- //Debug.Log(path);
- AssetBundle ab = null;
- if (FileSystem.Exists(path))
- {
- ab = AssetBundle.LoadFromFile(path);
- }
- else
- {
- path = string.Format("{0}{1}", FileSystem.LocalPackagePath, fileName);
- ab = AssetBundle.LoadFromFile(path);
- }
- //DebugHelper.Log(path);
- if (null != ab)
- maniFest = (AssetBundleManifest)ab.LoadAsset("AssetBundleManifest");
- }
- }
- IEnumerator GetAssetsMapping()
- {
- string path = string.Format(GetAssetsMappingName(), FileSystem.LocalDocumentPath);
- if (!FileSystem.Exists(path))
- {
- path = string.Format(GetAssetsMappingName(), FileSystem.LocalPackagePath);
- }
- if(!path.Contains("file://"))
- {
- path = "file://" + path;
- }
-
- WWW www = new WWW(path);
- yield return www;
- if (string.IsNullOrEmpty(www.error))
- {
- //DebugHelper.LogError("GetAssetsMapping-------------");
- string[] ContentLines = www.text.Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries);
- //Debug.LogError(www.text);
- for (int idx = 0; idx < ContentLines.Length; idx++)
- {
- string content = ContentLines[idx];
- string[] temp = content.Split(',');
- mAssetsMappingDict.Add(temp[0].ToLower(), temp[1]);
- }
- }
- else
- {
- DebugHelper.LogError("Load AssetsMapping Fail:" + www.error+" filePath:"+ path);
- }
- }
- public IEnumerator LoadSubSceneLocalAssetData(string levelName)
- {
- AsyncOperation ao = SceneManager.LoadSceneAsync(levelName, LoadSceneMode.Additive);
- yield return ao;
- if (!ao.isDone)
- {
- DebugHelper.LogError("Load Scene " + levelName + " Failed");
- }
- ao = null;
- }
- public IEnumerator LoadSubSceneFromAssetBundle(string levelName)
- {
- if (!mBundlesLoaded.ContainsKey(levelName))
- {
- AssetBundleCreateRequest abRequest = null;
- string sceneABName = AssetsObscureUtil.GetABFileName(levelName.ToLower() + ".unity3d");
- ulong offset = AssetsObscureUtil.GetABOffset(sceneABName);
- //加载场景依赖包
- string[] deps = assetBundleManifest.GetAllDependencies(sceneABName);
- if (deps.Length > 0)
- {
- for (int idx = 0; idx < deps.Length; idx++)
- {
- string depABName = deps[idx];
- if (mBundlesLoaded.ContainsKey(depABName)) continue;
- if (mCurLoadingBundleDic.ContainsKey(depABName))
- {
- continue;
- }
- string path = string.Format("{0}{1}", FileSystem.LocalDocumentPath, depABName);
- ulong depOffset = AssetsObscureUtil.GetABOffset(depABName);
- if (FileSystem.Exists(path))
- {
- abRequest = AssetBundle.LoadFromFileAsync(path, 0, depOffset);
- }
- else
- {
- path = string.Format("{0}{1}", FileSystem.LocalPackagePath, depABName);
- abRequest = AssetBundle.LoadFromFileAsync(path, 0, depOffset);
- }
- syncReqDict.Add(depABName, abRequest);
- mCurLoadingBundleDic.Add(depABName, new LoadTask(depABName));
- }
- foreach (var p in syncReqDict)
- {
- AssetBundleCreateRequest req = p.Value;
- yield return req;
- Bundle depBundle = new Bundle(req.assetBundle, p.Key);
- mBundlesLoaded.Add(p.Key, depBundle);
- mCurLoadingBundleDic.Remove(p.Key);
- }
- syncReqDict.Clear();
- }
- //加载场景ab
- string sceneABPath = FileSystem.LocalDocumentPath + sceneABName;
- if (FileSystem.Exists(sceneABPath))
- {
- abRequest = AssetBundle.LoadFromFileAsync(sceneABPath, 0, offset);
- }
- else
- {
- sceneABPath = FileSystem.LocalPackagePath + sceneABName;
- abRequest = AssetBundle.LoadFromFileAsync(sceneABPath, 0, offset);
- }
- yield return abRequest;
- Bundle bundle = new Bundle(abRequest.assetBundle, levelName);
- mBundlesLoaded.Add(levelName, bundle);
- }
- else
- {
- DebugHelper.Log("[LoadSceneAssetbundle].mBundlesLoaded.ContainsKey {0}", levelName);
- mBundlesLoaded[levelName].LastUsedTime = Time.realtimeSinceStartup;
- }
- yield return 1;
- AsyncOperation ao = SceneManager.LoadSceneAsync(levelName, LoadSceneMode.Additive);
- yield return ao;
- ao = null;
- }
- public IEnumerator LoadSceneLocalAssetData(string levelName)
- {
- AsyncOperation ao = SceneManager.LoadSceneAsync(levelName, LoadSceneMode.Single);
- yield return ao;
- if (!ao.isDone)
- {
- DebugHelper.LogError("Load Scene " + levelName + " Failed");
- }
- ao = null;
- }
- Dictionary<string, AssetBundleCreateRequest> syncReqDict = new Dictionary<string, AssetBundleCreateRequest>();
- public IEnumerator LoadSceneAssetbundle(string levelName)
- {
- if (!mBundlesLoaded.ContainsKey(levelName))
- {
- AssetBundleCreateRequest abRequest = null;
- string sceneABName = AssetsObscureUtil.GetABFileName(levelName.ToLower() + ".unity3d");
- ulong offset = AssetsObscureUtil.GetABOffset(sceneABName);
- //加载场景依赖包
- string[] deps = assetBundleManifest.GetAllDependencies(sceneABName);
- if (deps.Length > 0)
- {
- for (int idx = 0; idx < deps.Length; idx++)
- {
- string depABName = deps[idx];
- if (mBundlesLoaded.ContainsKey(depABName)) continue;
- if (mCurLoadingBundleDic.ContainsKey(depABName))
- {
- continue;
- }
- string path = FileSystem.LocalDocumentPath + depABName;
- ulong depOffset = AssetsObscureUtil.GetABOffset(depABName);
- if (FileSystem.Exists(path))
- {
- abRequest = AssetBundle.LoadFromFileAsync(path, 0, depOffset);
- }
- else
- {
- path = FileSystem.LocalPackagePath + depABName;
- abRequest = AssetBundle.LoadFromFileAsync(path, 0, depOffset);
- }
- syncReqDict.Add(depABName, abRequest);
- mCurLoadingBundleDic.Add(depABName, new LoadTask(depABName));
- }
- foreach (var p in syncReqDict)
- {
- AssetBundleCreateRequest req = p.Value;
- yield return req;
- Bundle depBundle = new Bundle(req.assetBundle, p.Key);
- mBundlesLoaded.Add(p.Key, depBundle);
- mCurLoadingBundleDic.Remove(p.Key);
- }
- syncReqDict.Clear();
- }
- //加载场景ab
- string sceneABPath = FileSystem.LocalDocumentPath + sceneABName;
- if (FileSystem.Exists(sceneABPath))
- {
- abRequest = AssetBundle.LoadFromFileAsync(sceneABPath, 0, offset);
- }
- else
- {
- sceneABPath = FileSystem.LocalPackagePath + sceneABName;
- abRequest = AssetBundle.LoadFromFileAsync(sceneABPath, 0, offset);
- }
- yield return abRequest;
- Bundle bundle = new Bundle(abRequest.assetBundle, levelName);
- mBundlesLoaded.Add(levelName, bundle);
- }
- else
- {
- DebugHelper.Log("[LoadSceneAssetbundle].mBundlesLoaded.ContainsKey {0}", levelName);
- mBundlesLoaded[levelName].LastUsedTime = Time.realtimeSinceStartup;
- }
- yield return 1;
- AsyncOperation ao = SceneManager.LoadSceneAsync(levelName, LoadSceneMode.Single);
- yield return ao;
- ao = null;
- }
- public Shader FindShader(string shaderName, string shaderPath)
- {
- string shaderABName = AssetsObscureUtil.GetABFileName("shader.unity3d");
- #if UNITY_EDITOR
- if (!Constants.AssetbundleMode) //editor mode LocalModeOrAssetbundleMode; Local;
- {
- return Shader.Find(shaderName);
- }
- else //TestMode with local assetBundle mode;
- {
- if (!mBundlesLoaded.ContainsKey(shaderABName))
- return null;
- AssetBundle bundle = mBundlesLoaded[shaderABName].Asset;
- if(bundle!=null)
- {
- Shader shader = bundle.LoadAsset<Shader>(shaderPath + ".shader");
- return shader;
- }
- return null;
- }
- #else
- if (!mBundlesLoaded.ContainsKey(shaderABName))
- return null;
- AssetBundle bundle = mBundlesLoaded[shaderABName].Asset;
- if(bundle!=null)
- {
- Shader shader = bundle.LoadAsset<Shader>(shaderPath + ".shader");
- return shader;
- }
- return null;
- #endif
- }
- public GameObject GetAssetFromResource(string assetName)
- {
- GameObject asset = Resources.Load<GameObject>(assetName);
- return asset;
- }
- public T GetAssetFromResources<T>(string assetName) where T : UnityEngine.Object
- {
- T asset = Resources.Load<T>(assetName);
- return asset;
- }
- public int GetAsset<T>(AssetCallbackWithParams<T> callback, ELoadType type, long seqId, string pathName, params string[] assetName)
- {
- //Debug.Log($"pathName = [{pathName}] assetName = [{assetName}]");
- #if UNITY_EDITOR
- if (!Application.isPlaying)//editor mode Not Playing;
- {
- StartCoroutine(LoadFromLocalAssetData<T>(callback, seqId, pathName, assetName));
- return 1;
- }
- else if (!Constants.AssetbundleMode) //editor mode LocalModeOrAssetbundleMode; Local;
- {
- StartCoroutine(LoadFromLocalAssetData<T>(callback, seqId, pathName, assetName));
- return 1;
- }
- else //TestMode with local assetBundle mode;
- {
- return LoadFromAssetbundle<T>(callback, type, seqId, pathName, assetName);
- }
- #else
- return LoadFromAssetbundle<T>(callback, type, seqId, pathName, assetName);
- #endif
- }
- public void CancelLoadAsset(long seqId)
- {
- foreach (var p in mBundlesLoading)
- {
- LoadTask task = p.Value;
- if (task != null && task.IsExist(seqId))
- {
- task.RemoveTask(seqId);
- if (task.AssetsTaskCnt == 0)
- {
- mBundlesLoading.Remove(task.BundleName);
- mLoadTasks.Remove(task);
- }
- return;
- }
- }
- }
- IEnumerator LoadFromLocalAssetData<T>(AssetCallbackWithParams<T> callback, long seqId, string pathName, params string[] assetName)
- {
- #if UNITY_EDITOR
- if (typeof(T).Equals(typeof(AssetBundle)))
- {
- DebugHelper.LogError("LoadFromLocalAssetData 不能加载类型是AssetBundle的资源");
- yield break;
- }
- if (typeof(T).Equals(typeof(List<GameObject>)))
- {
- List<GameObject> gos = new List<GameObject>();
- if (assetName.Length <= 0)
- {
- List<string> files = FileSystem.getAllFilesPath(pathName);
- for (int i = 0; i < files.Count; ++i)
- {
- if (files[i] != "")
- {
- GameObject g = UnityEditor.AssetDatabase.LoadAssetAtPath<GameObject>(files[i]);
- gos.Add(g);
- }
- }
- }
- else
- {
- string path = "";
- for (int i = 0; i < assetName.Length; ++i)
- {
- if (!string.IsNullOrEmpty(assetName[i]))
- {
- if (!string.IsNullOrEmpty(pathName))
- {
- path = string.Format("{0}/{1}.prefab", pathName, assetName[i]);
- }
- else
- {
- path = string.Format("{0}.prefab", assetName[i]);
- }
- GameObject g = UnityEditor.AssetDatabase.LoadAssetAtPath<GameObject>(path);
- gos.Add(g);
- }
- }
- }
- if(Application.isPlaying)
- yield return new WaitForEndOfFrame();
- callback.DynamicInvoke(gos, seqId, pathName, assetName);
- }
- else if (typeof(T).Equals(typeof(List<Texture2D>)))
- {
- List<Texture2D> gos = new List<Texture2D>();
- string path = "";
- for (int i = 0; i < assetName.Length; ++i)
- {
- if (!string.IsNullOrEmpty(assetName[i]))
- {
- if(!string.IsNullOrEmpty(pathName))
- {
- path = string.Format("{0}/{1}.png", pathName, assetName[i]);
- }
- else
- {
- path = string.Format("{0}.png", assetName[i]);
- }
-
- Texture2D g = UnityEditor.AssetDatabase.LoadAssetAtPath<Texture2D>(path);
- gos.Add(g);
- }
- }
- if (Application.isPlaying)
- yield return new WaitForEndOfFrame();
- callback.DynamicInvoke(gos, seqId, pathName, assetName);
- }
- else if (typeof(T).Equals(typeof(List<Sprite>)))
- {
- List<Sprite> gos = new List<Sprite>();
- string path = "";
- for (int i = 0; i < assetName.Length; ++i)
- {
- if (!string.IsNullOrEmpty(assetName[i]))
- {
- if (!string.IsNullOrEmpty(pathName))
- {
- path = string.Format("{0}/{1}.png", pathName, assetName[i]);
- }
- else
- {
- path = string.Format("{0}.png", assetName[i]);
- }
- Sprite sp = UnityEditor.AssetDatabase.LoadAssetAtPath<Sprite>(path);
- gos.Add(sp);
- }
- }
- if (Application.isPlaying)
- yield return new WaitForEndOfFrame();
- callback.DynamicInvoke(gos, seqId, pathName, assetName);
- }
- else if (typeof(T).Equals(typeof(List<TextAsset>)))
- {
- List<TextAsset> gos = new List<TextAsset>();
- if (assetName.Length <= 0)
- {
- List<string> files = FileSystem.getAllFilesPath(pathName);
- for (int i = 0; i < files.Count; ++i)
- {
- if (files[i] != "")
- {
- TextAsset g = UnityEditor.AssetDatabase.LoadAssetAtPath<TextAsset>(files[i]);
- gos.Add(g);
- }
- }
- }
- else
- {
- if (assetName[0] != "")
- {
- string path = "";
- for (int i = 0; i < assetName.Length; ++i)
- {
- if (assetName[i] != "")
- {
- if(!string.IsNullOrEmpty(pathName))
- path = string.Format("{0}/{1}", pathName, assetName[i]);
- else
- path = string.Format("{0}", assetName[i]);
- TextAsset g = UnityEditor.AssetDatabase.LoadAssetAtPath<TextAsset>(path);
- if (g != null)
- gos.Add(g);
- }
- }
- }
- }
- if (Application.isPlaying)
- yield return new WaitForEndOfFrame();
- callback.DynamicInvoke(gos, seqId, pathName, assetName);
- }
- else if (typeof(T).Equals(typeof(List<PlayableAsset>)))
- {
- List<PlayableAsset> gos = new List<PlayableAsset>();
- string path = "";
- if (assetName.Length > 0)
- {
- for (int i = 0; i < assetName.Length; ++i)
- {
- if (assetName[i] != "")
- {
- if(!string.IsNullOrEmpty(pathName))
- path = string.Format("{0}/{1}.playable", pathName, assetName[i]);
- else
- path = string.Format("{0}.playable", assetName[i]);
- PlayableAsset g = UnityEditor.AssetDatabase.LoadAssetAtPath<PlayableAsset>(path);
- gos.Add(g);
- }
- }
- }
- else
- {
- string[] paths = Directory.GetFiles(pathName);
- foreach (string subPath in Directory.GetFiles(pathName))
- {
- path = subPath.Replace('\\', '/');
- string ext = Path.GetExtension(path);
- if ((ext != ".meta") && (ext != ".unity"))
- {
- PlayableAsset g = UnityEditor.AssetDatabase.LoadAssetAtPath<PlayableAsset>(path);
- gos.Add(g);
- }
- }
- }
- if (Application.isPlaying)
- yield return new WaitForEndOfFrame();
- callback.DynamicInvoke(gos, seqId, pathName, assetName);
- }
- else if (typeof(T).Equals(typeof(List<RuntimeAnimatorController>)))
- {
- if (assetName == null || assetName.Length == 0)
- {
- DebugHelper.LogError("error assetName == null ");
- callback.DynamicInvoke(null, seqId, pathName, assetName);
- yield break;
- }
- List<RuntimeAnimatorController> racs = new List<RuntimeAnimatorController>();
- string path = "";
- for (int i = 0; i < assetName.Length; ++i)
- {
- if (!string.IsNullOrEmpty(assetName[i]))
- {
- if (!string.IsNullOrEmpty(pathName))
- {
- path = string.Format("{0}/{1}.controller", pathName, assetName[i]);
- }
- else
- {
- path = string.Format("{0}.controller", assetName[i]);
- }
-
- RuntimeAnimatorController rac = UnityEditor.AssetDatabase.LoadAssetAtPath<RuntimeAnimatorController>(path);
- racs.Add(rac);
- }
- }
- if (Application.isPlaying)
- yield return new WaitForEndOfFrame();
- callback.DynamicInvoke(racs, seqId, pathName, assetName);
- }
- else if (typeof(T).Equals(typeof(List<AudioClip>)))
- {
- List<AudioClip> gos = new List<AudioClip>();
- for (int i = 0; i < assetName.Length; ++i)
- {
- if (!string.IsNullOrEmpty(assetName[i]))
- {
- string path = string.Format("{0}.ogg", pathName);
- if (!path.Contains(assetName[i]))
- {
- if (!string.IsNullOrEmpty(pathName))
- path = string.Format("{0}/{1}.ogg", pathName, assetName[i]);
- else
- path = string.Format("{0}.ogg", assetName[i]);
- }
- AudioClip ac = UnityEditor.AssetDatabase.LoadAssetAtPath<AudioClip>(path);
- gos.Add(ac);
- }
- }
- if (Application.isPlaying)
- yield return new WaitForEndOfFrame();
- callback.DynamicInvoke(gos, seqId, pathName, assetName);
- }
- else if (typeof(T).IsSubclassOf(typeof(ScriptableObject)))
- {
- string path = pathName;
- if (!path.Contains(assetName[0])) {
- if(!string.IsNullOrEmpty(pathName))
- path = string.Format("{0}/{1}", pathName, assetName[0]);
- else
- path = string.Format("{0}", assetName[0]);
- }
- ScriptableObject so = UnityEditor.AssetDatabase.LoadAssetAtPath<ScriptableObject>(path);
- if (Application.isPlaying)
- yield return new WaitForEndOfFrame();
- callback.DynamicInvoke(so, pathName, assetName);
- }
- else if (typeof(T).Equals(typeof(GameObject)))//访问单个资源
- {
- if (assetName.Length > 0 && !string.IsNullOrEmpty(assetName[0]))
- {
- string path = string.Format("{0}.prefab", pathName);
- if (!File.Exists(path)) {
- if(!string.IsNullOrEmpty(pathName))
- path = string.Format("{0}/{1}.prefab", pathName, assetName[0]);
- else
- path = string.Format("{0}.prefab", assetName[0]);
- }
- GameObject g = UnityEditor.AssetDatabase.LoadAssetAtPath<GameObject>(path);
- if (Application.isPlaying)
- yield return new WaitForEndOfFrame();
- callback.DynamicInvoke(g, seqId, pathName, assetName);
- }
- }
- else if (typeof(T).Equals(typeof(AudioClip)))//访问单个资源
- {
- if (assetName.Length > 0 && !string.IsNullOrEmpty(assetName[0]))
- {
- string path = string.Format("{0}.ogg", pathName);
- if (!path.Contains(assetName[0])) {
- if(!string.IsNullOrEmpty(pathName))
- path = string.Format("{0}/{1}.ogg", pathName, assetName[0]);
- else
- path = string.Format("{0}.ogg", assetName[0]);
- }
- AudioClip ac = UnityEditor.AssetDatabase.LoadAssetAtPath<AudioClip>(path);
- if (Application.isPlaying)
- yield return new WaitForEndOfFrame();
- callback.DynamicInvoke(ac, seqId, pathName, assetName);
- }
- }
- else if (typeof(T).Equals(typeof(VideoClip)))//访问单个资源
- {
- if (assetName.Length > 0 && !string.IsNullOrEmpty(assetName[0]))
- {
- string path = string.Format("{0}.mp4", pathName);
- if (!path.Contains(assetName[0])) {
- if(!string.IsNullOrEmpty(pathName))
- path = string.Format("{0}/{1}.mp4", pathName, assetName[0]);
- else
- path = string.Format("{0}.mp4", assetName[0]);
- }
- VideoClip vc = UnityEditor.AssetDatabase.LoadAssetAtPath<VideoClip>(path);
- if (Application.isPlaying)
- yield return new WaitForEndOfFrame();
- callback.DynamicInvoke(vc, seqId, pathName, assetName);
- }
- }
- else if (typeof(T).Equals(typeof(Texture2D)))//访问单个资源
- {
- string path = string.Format("{0}.png", pathName);
- if (!pathName.Contains(assetName[0])) {
- if(!string.IsNullOrEmpty(pathName))
- path = string.Format("{0}/{1}.png", pathName, assetName[0]);
- else
- path = string.Format("{0}.png", assetName[0]);
- }
- Texture2D ac = UnityEditor.AssetDatabase.LoadAssetAtPath<Texture2D>(path);
- if (Application.isPlaying)
- yield return new WaitForEndOfFrame();
- callback.DynamicInvoke(ac, seqId, pathName, assetName);
- }
- else if (typeof(T).Equals(typeof(Sprite)))//访问单个资源
- {
- string path = string.Format("{0}.png", pathName);
- if (!pathName.Contains(assetName[0])) {
- if(!string.IsNullOrEmpty(pathName))
- path = string.Format("{0}/{1}.png", pathName, assetName[0]);
- else
- path = string.Format("{0}.png", assetName[0]);
- }
- Sprite sp = UnityEditor.AssetDatabase.LoadAssetAtPath<Sprite>(path);
- if (Application.isPlaying)
- yield return new WaitForEndOfFrame();
- callback.DynamicInvoke(sp, seqId, pathName, assetName);
- }
- else if (typeof(T).Equals(typeof(Material)))//访问单个资源
- {
- string path = string.Format("{0}.mat", pathName);
- if (!pathName.Contains(assetName[0])) {
- if(!string.IsNullOrEmpty(pathName))
- path = string.Format("{0}/{1}.mat", pathName, assetName[0]);
- else
- path = string.Format("{0}.mat", assetName[0]);
- }
- Material mat = UnityEditor.AssetDatabase.LoadAssetAtPath<Material>(path);
- if (Application.isPlaying)
- yield return new WaitForEndOfFrame();
- callback.DynamicInvoke(mat, seqId, pathName, assetName);
- }
- else if (typeof(T).Equals(typeof(RuntimeAnimatorController)))//访问单个资源
- {
- string path = string.Format("{0}.controller", pathName);
- if (!pathName.Contains(assetName[0])) {
- if(!string.IsNullOrEmpty(pathName))
- path = string.Format("{0}/{1}.controller", pathName, assetName[0]);
- else
- path = string.Format("{0}.controller", assetName[0]);
- }
- RuntimeAnimatorController rac = UnityEditor.AssetDatabase.LoadAssetAtPath<RuntimeAnimatorController>(path);
- if (Application.isPlaying)
- yield return new WaitForEndOfFrame();
- callback.DynamicInvoke(rac, seqId, pathName, assetName);
- }
- else
- {
- //DebugHelper.LogError("LoadFromLocalAssetData type is Error: "+ pathName);
- }
- #else
- yield break;
- #endif
- }
- public T LoadAssetSync<T>(string pathName, string assetName) where T : UnityEngine.Object
- {
- T asset = null;
- #if UNITY_EDITOR
- if (!Constants.AssetbundleMode)
- {
- if (!string.IsNullOrEmpty(assetName))
- {
- string path;
- if (FileUtils.HasExtension(assetName))
- {
- path = string.Format("{0}/{1}", pathName, assetName);
- }
- else
- {
- string ext = GetFileTypeExtention(typeof(T));
- path = string.Format("{0}/{1}{2}", pathName, assetName, ext);
- }
- asset = UnityEditor.AssetDatabase.LoadAssetAtPath<T>(path);
- }
- return asset;
- }
- #endif
- if (!string.IsNullOrEmpty(assetName))
- {
- string abName = GetABName(pathName + "/" + assetName, typeof(T));
-
- ulong offset = AssetsObscureUtil.GetABOffset(abName);
- if (!string.IsNullOrEmpty(abName))
- {
- string abPath = string.Format("{0}{1} ", FileSystem.LocalDocumentPath, abName);
- if (!FileSystem.Exists(abPath))
- {
- abPath = string.Format("{0}{1}", FileSystem.LocalPackagePath, abName);
- }
- AssetBundle ab = null;
- if (mBundlesLoaded.ContainsKey(abName))
- {
- Bundle bundle = mBundlesLoaded[abName];
- ab = bundle.Asset;
- }
- else
- {
- string[] deps = assetBundleManifest.GetAllDependencies(abName);
- if (deps != null)
- {
- for (int i = 0; i < deps.Length; ++i)
- {
- string depabName = deps[i];
- if (mBundlesLoaded.ContainsKey(depabName))
- continue;
- string depabPath = string.Format("{0}{1} ", FileSystem.LocalDocumentPath, depabName);
- ulong depOffset = AssetsObscureUtil.GetABOffset(depabName);
- if (!FileSystem.Exists(depabPath))
- {
- depabPath = string.Format("{0}{1}", FileSystem.LocalPackagePath, depabName);
- }
- AssetBundle depab = AssetBundle.LoadFromFile(depabPath, 0, depOffset);
- Bundle depabBundle = new Bundle(depab, depabName);
- mBundlesLoaded.Add(depabName, depabBundle);
- }
- }
- ab = AssetBundle.LoadFromFile(abPath, 0, offset);
- Bundle abBundle = new Bundle(ab, abName);
- mBundlesLoaded.Add(abName, abBundle);
- }
- if (!FileUtils.HasExtension(assetName))
- {
- assetName += GetFileTypeExtention(typeof(T));
- }
- if (!string.IsNullOrEmpty(pathName))
- assetName = pathName + "/" + assetName;
- asset = ab.LoadAsset<T>(assetName);
- }
- else
- {
- DebugHelper.LogError(assetName+" 资源没有放入ab包");
- }
- }
- return asset;
- }
- public Object[] LoadABSync(string pathName, params string[] assetName)
- {
- Object[] objs = null;
- #if UNITY_EDITOR
- if (!Constants.AssetbundleMode)
- {
- objs = new Object[assetName.Length];
- for (int i = 0; i < assetName.Length; ++i)
- {
- if (!string.IsNullOrEmpty(assetName[i]))
- {
- string path = string.Format("{0}/{1}.prefab", pathName, assetName[i]);
- Object g = UnityEditor.AssetDatabase.LoadAssetAtPath<Object>(path);
- objs[i] = g;
- }
- }
- return objs;
- }
- #endif
- string abName = pathName.Replace("Assets/Content/", "");
- abName = abName.Replace("/", "");
- abName = abName.ToLower() + ".unity3d";
- abName = AssetsObscureUtil.GetABFileName(abName);
- ulong offset = AssetsObscureUtil.GetABOffset(abName);
-
- string abPath = string.Format("{0}{1} ", FileSystem.LocalDocumentPath, abName);
-
- if (!FileSystem.Exists(abPath))
- {
- abPath = string.Format("{0}{1}", FileSystem.LocalPackagePath, abName);
- }
- AssetBundle ab = null;
- if (mBundlesLoaded.ContainsKey(abName))
- {
- Bundle bundle = mBundlesLoaded[abName];
- ab = bundle.Asset;
- }
- else
- {
- string[] deps = assetBundleManifest.GetAllDependencies(abName);
- if (deps != null)
- {
- for (int i = 0; i < deps.Length; ++i)
- {
- string depabName = deps[i];
- if (mBundlesLoaded.ContainsKey(depabName))
- continue;
- string depabPath = string.Format("{0}{1} ", FileSystem.LocalDocumentPath, depabName);
- ulong depOffset = AssetsObscureUtil.GetABOffset(depabName);
- if (!FileSystem.Exists(depabPath))
- {
- depabPath = string.Format("{0}{1}", FileSystem.LocalPackagePath, depabName);
- }
- AssetBundle depab = AssetBundle.LoadFromFile(depabPath, 0, depOffset);
- Bundle depabBundle = new Bundle(depab, depabName);
- mBundlesLoaded.Add(depabName, depabBundle);
- }
- }
- ab = AssetBundle.LoadFromFile(abPath, 0, offset);
- Bundle abBundle = new Bundle(ab, abName);
- mBundlesLoaded.Add(abName, abBundle);
- }
-
- if (assetName == null || assetName.Length == 0)
- {
- objs = ab.LoadAllAssets();
- }
- else
- {
- objs = new Object[assetName.Length];
- for (int i = 0; i < assetName.Length; i++)
- {
- objs[i] = ab.LoadAsset(assetName[i]);
- }
- }
- return objs;
- }
- Dictionary<string, List<string>> tempDic = new Dictionary<string, List<string>>();
- int LoadFromAssetbundle<T>(AssetCallbackWithParams<T> callback, ELoadType loadType, long seqId, string pathName, params string[] assetName)
- {
- string abName = null;
- if (assetName == null || assetName.Length == 0)
- {
- abName = pathName.Replace("Assets/Content/", "");
- abName = abName.Replace("/", "").ToLower();
- if (!abName.Contains(".unity3d"))
- {
- abName = abName + ".unity3d";
- }
- abName = AssetsObscureUtil.GetABFileName(abName);
- AddLoadTask<T>(seqId, abName,pathName,callback, loadType, assetName);
- return 1;
- }
- else
- {
- tempDic.Clear();
- for (int idx = 0; idx < assetName.Length; idx++)
- {
- string fullPath = assetName[idx];
- if(!string.IsNullOrEmpty(pathName))
- {
- fullPath = pathName + "/" + assetName[idx];
- }
- string tempAB = GetABName(fullPath, typeof(T));
- if(!string.IsNullOrEmpty(tempAB))
- {
- List<string> assetList = null;
- if (!tempDic.TryGetValue(tempAB,out assetList))
- {
- assetList = new List<string>();
- tempDic.Add(tempAB, assetList);
- }
- assetList.Add(assetName[idx]);
- }
- else
- {
- DebugHelper.LogError(string.Format("{0} 没有打入ab包中", fullPath));
- }
- }
- if(tempDic.Count > 0)
- {
- foreach (var p in tempDic)
- {
- AddLoadTask<T>(seqId, p.Key, pathName, callback, loadType, p.Value.ToArray());
- }
- }
- return tempDic.Count;
- }
- }
- void AddLoadTask<T>(long seqId, string abName,string pathName, AssetCallbackWithParams<T> callback, ELoadType loadType, params string[] assetName)
- {
- LoadTask task = new LoadTask(seqId, abName, pathName, assetName, callback as Delegate, true, typeof(T), loadType);
- if (!mBundlesLoaded.ContainsKey(task.BundleName))
- {
- if(mCurLoadingBundleDic.ContainsKey(task.BundleName))
- {
- LoadTask task1 = mCurLoadingBundleDic[task.BundleName];
- task1.ChangeTask(seqId, abName, pathName, assetName, callback as Delegate, true, typeof(T), loadType);
- }
- else
- {
- if (mBundlesLoading.ContainsKey(task.BundleName))
- {
- mBundlesLoading[task.BundleName].AssetsTask.AddRange(task.AssetsTask);
- return;
- }
- else
- {
- if (mCurLoadingBundleDic.ContainsKey(task.BundleName))
- {
- DebugHelper.LogError("mCurLoadingBundleDic 包函数了:" + task.BundleName);
- }
- mBundlesLoading.Add(task.BundleName, task);
- }
- mLoadTasks.Add(task);
- }
- }
- else
- {
- if (mBundlesLoaded.ContainsKey(task.BundleName))
- {
- mBundlesLoaded[task.BundleName].Priority = 0;
- }
- string[] deps = assetBundleManifest.GetAllDependencies(task.BundleName);
- if (deps.Length > 0)
- {
- string depName = string.Empty;
- for (int i = 0; i < deps.Length; ++i)
- {
- depName = deps[i];
- if (mBundlesLoaded.ContainsKey(depName))
- {
- mBundlesLoaded[depName].Priority = 0;
- }
- }
- }
- mLoadFinshedTask.Enqueue(task);
- }
- }
- void Update()
- {
- while (mLoadFinshedTask.Count > 0)
- {
- LoadTask task = mLoadFinshedTask.Dequeue();
- if (mBundlesLoaded.ContainsKey(task.BundleName))
- {
- AsyncLoad(task);
- }
- }
- while (mLoadingCoroutineCount < MaxLoadingCoroutineCount && mLoadTasks.Count > 0)
- {
- LoadTask task = mLoadTasks[0];
- task.LoadStartTime = Time.realtimeSinceStartup;
- LoadAssetTask(task);
- mLoadTasks.RemoveAt(0);
- }
- for (int i = 0; i < mAssetbundleLoadTasks.Count; ++i)
- {
- mAssetbundleLoadTasks[i].Update();
- }
- }
- #region inner_methods
- public AssetBundleCreateRequest CreatePackageLoader(string bundleName)
- {
- AssetBundleCreateRequest abRequest = null;
- try
- {
- string path = string.Format("{0}{1}", FileSystem.LocalDocumentPath, bundleName);
- ulong offset = AssetsObscureUtil.GetABOffset(bundleName);
- if (FileSystem.Exists(path))
- {
- abRequest = AssetBundle.LoadFromFileAsync(path, 0, offset);
- }
- else
- {
- path = string.Format("{0}{1}", FileSystem.LocalPackagePath, bundleName);
- abRequest = AssetBundle.LoadFromFileAsync(path, 0, offset);
- }
- }
- catch (Exception e)
- {
- DebugHelper.LogError("Load AB: " + e.ToString());
- return null;
- }
- return abRequest;
- }
- List<string> temp = new List<string>();
- public void NotifyAssetbundleLoaded(LoadTask task, LoadAssetbundleTask abTask)
- {
- //DebugHelper.LogError("[bhy] loadingAb Finish: " + task.BundleName + " IsDependencyDone:"+task.IsDependency);
- #if PROFILE
- UnityEngine.Profiling.Profiler.BeginSample("Loaded" + task.BundleName);
- #endif
- mAssetbundleLoadTasks.Remove(abTask);
- if (mCurLoadingBundleDic.ContainsKey(task.BundleName))
- {
- mCurLoadingBundleDic.Remove(task.BundleName);
- }
- mBundlesLoaded.Add(task.BundleName, new Bundle(task.Bundle, task.BundleName));
- for (int i = 0; i < mAssetbundleLoadTasks.Count; ++i)
- {
- if (!mAssetbundleLoadTasks[i].Loader.IsDependencyDone)
- {
- CheckDependencyOnAssetbundleLoaded(mAssetbundleLoadTasks[i].Loader);
- }
- }
- if (task.LoadType != ELoadType.AssetBundle && task.IsDependencyDone)
- {
- LoadAssetTaskFinish(task);
- }else if(task.LoadType == ELoadType.AssetBundle && task.IsDependencyDone)
- {
- if(mBundlesLoading.ContainsKey(task.BundleName))
- {
- LoadTask loadingTask = mBundlesLoading[task.BundleName];
- if(loadingTask.IsDependencyDone)
- {
- loadingTask.Bundle = task.Bundle;
- LoadAssetTaskFinish(loadingTask);
- }
- }
- }
- temp.Clear();
- foreach (var p in mBundlesLoading)
- {
- if (p.Value.IsDependency)
- {
- if (CheckDependencyPackageInfo(p.Value))
- {
- temp.Add(p.Key);
- }
- }
- }
- for (int idx = 0; idx < temp.Count; idx++)
- {
- mBundlesLoading.Remove(temp[idx]);
- }
- #if PROFILE
- UnityEngine.Profiling.Profiler.EndSample();
- #endif
- }
- void LoadAssetTask(LoadTask task)
- {
- mLoadingCoroutineCount++;
- if (CheckDependencyPackageInfo(task))
- {
- mBundlesLoading.Remove(task.BundleName);
- }
- }
- void LoadAssetTaskFinish(LoadTask task)
- {
- mLoadingCoroutineCount--;
- mLoadFinshedTask.Enqueue(task);
- mBundlesLoading.Remove(task.BundleName);
- }
- bool CheckDependencyPackageInfo(LoadTask task)
- {
- string bundleName = task.BundleName;
- string[] deps = assetBundleManifest.GetAllDependencies(bundleName);
- if (deps == null || deps.Length == 0)
- {
- task.IsDependency = false;
- task.IsDependencyDone = true;
- }
- else
- {
- task.IsDependency = true;
- task.IsDependencyDone = true;
- for (int i = 0; i < deps.Length; ++i)
- {
- string depPackage = deps[i];
- if (mBundlesLoaded.ContainsKey(depPackage))
- continue;
- task.IsDependencyDone = false;
- NotifyLoadAssetbundle(depPackage);
- }
- }
- if (task.IsDependencyDone)
- {
- if (mBundlesLoaded.ContainsKey(task.BundleName))
- {
- mLoadingCoroutineCount--;
- mLoadFinshedTask.Enqueue(task);
- return true;
- }
- else
- {
- NotifyLoadAssetbundle(task.BundleName, task);
- }
- }
- return false;
- }
- void NotifyLoadAssetbundle(string bundleName, LoadTask task = null)
- {
- if (mBundlesLoaded.ContainsKey(bundleName) || mCurLoadingBundleDic.ContainsKey(bundleName))
- {
- return;
- }
- LoadTask t = task;
- if (t == null)
- {
- t = new LoadTask(bundleName);
- }
- mCurLoadingBundleDic.Add(bundleName, t);
- mAssetbundleLoadTasks.Add(new LoadAssetbundleTask(t));
- }
- void CheckDependencyOnAssetbundleLoaded(LoadTask task)
- {
- string bundleName = task.BundleName;
- string[] deps = assetBundleManifest.GetAllDependencies(bundleName);
- if (deps == null || deps.Length == 0)
- {
- task.IsDependency = false;
- task.IsDependencyDone = true;
- }
- else
- {
- task.IsDependencyDone = true;
- for (int i = 0; i < deps.Length; ++i)
- {
- string depPackage = deps[i];
- if (mBundlesLoaded.ContainsKey(depPackage))
- continue;
- task.IsDependencyDone = false;
- NotifyLoadAssetbundle(depPackage);
- }
- }
- }
- void AsyncLoad(LoadTask task)
- {
- Bundle bundle = mBundlesLoaded[task.BundleName];
- if (bundle == null)
- {
- DebugHelper.LogWarning("[AssetsMgr].DoCallBack Bundle not exists for name [{0}]", task.BundleName);
- return;
- }
- try
- {
- if (task.DelegateType.Equals(typeof(List<GameObject>)))
- {
- for (int j = 0; j < task.AssetsTask.Count; ++j)
- {
- LoadAssetsTask lat = task.AssetsTask[j];
- StartCoroutine(AsyncMultiAssetFromAB<GameObject>(task.BundleName, bundle.Asset, lat));
- }
- }
- else if (task.DelegateType.Equals(typeof(List<TextAsset>)))
- {
- for (int j = 0; j < task.AssetsTask.Count; j++)
- {
- LoadAssetsTask lat = task.AssetsTask[j];
- StartCoroutine(AsyncMultiAssetFromAB<TextAsset>(task.BundleName, bundle.Asset, lat));
- }
- }
- else if (task.DelegateType.Equals(typeof(List<AudioClip>)))
- {
- for (int j = 0; j < task.AssetsTask.Count; j++)
- {
- LoadAssetsTask lat = task.AssetsTask[j];
- StartCoroutine(AsyncMultiAssetFromAB<AudioClip>(task.BundleName, bundle.Asset, lat));
- }
- }
- else if (task.DelegateType.Equals(typeof(List<Texture2D>)))
- {
- for (int j = 0; j < task.AssetsTask.Count; j++)
- {
- LoadAssetsTask lat = task.AssetsTask[j];
- StartCoroutine(AsyncMultiAssetFromAB<Texture2D>(task.BundleName, bundle.Asset, lat));
- }
- }
- else if (task.DelegateType.Equals(typeof(List<Sprite>)))
- {
- for (int j = 0; j < task.AssetsTask.Count; j++)
- {
- LoadAssetsTask lat = task.AssetsTask[j];
- StartCoroutine(AsyncMultiAssetFromAB<Sprite>(task.BundleName, bundle.Asset, lat));
- }
- }
- else if (task.DelegateType.Equals(typeof(List<PlayableAsset>)))
- {
- for (int j = 0; j < task.AssetsTask.Count; j++)
- {
- LoadAssetsTask lat = task.AssetsTask[j];
- StartCoroutine(AsyncMultiAssetFromAB<PlayableAsset>(task.BundleName, bundle.Asset, lat));
- }
- }
- else if(task.DelegateType.Equals(typeof(List<RuntimeAnimatorController>)))
- {
- for (int j = 0; j < task.AssetsTask.Count; j++)
- {
- LoadAssetsTask lat = task.AssetsTask[j];
- StartCoroutine(AsyncMultiAssetFromAB<RuntimeAnimatorController>(task.BundleName, bundle.Asset, lat));
- }
- }
- else if (task.DelegateType.Equals(typeof(Texture2D)))
- {
- for (int j = 0; j < task.AssetsTask.Count; j++)
- {
- LoadAssetsTask lat = task.AssetsTask[j];
- StartCoroutine(AsyncSingleAssetFromAB<Texture2D>(task.BundleName, bundle.Asset, lat));
- }
- }
- else if (task.DelegateType.Equals(typeof(GameObject)))
- {
- for (int j = 0; j < task.AssetsTask.Count; j++)
- {
- LoadAssetsTask lat = task.AssetsTask[j];
- StartCoroutine(AsyncSingleAssetFromAB<GameObject>(task.BundleName, bundle.Asset, lat));
- }
- }
- else if (task.DelegateType.Equals(typeof(AudioClip)))
- {
- for (int j = 0; j < task.AssetsTask.Count; j++)
- {
- LoadAssetsTask lat = task.AssetsTask[j];
- StartCoroutine(AsyncSingleAssetFromAB<AudioClip>(task.BundleName, bundle.Asset, lat));
- }
- }
- else if (task.DelegateType.Equals(typeof(PlayableAsset)))
- {
- for (int j = 0; j < task.AssetsTask.Count; j++)
- {
- LoadAssetsTask lat = task.AssetsTask[j];
- StartCoroutine(AsyncSingleAssetFromAB<PlayableAsset>(task.BundleName, bundle.Asset, lat));
- }
- }
- else if (task.DelegateType.Equals(typeof(Material)))
- {
- for (int j = 0; j < task.AssetsTask.Count; j++)
- {
- LoadAssetsTask lat = task.AssetsTask[j];
- StartCoroutine(AsyncSingleAssetFromAB<Material>(task.BundleName, bundle.Asset, lat));
- }
- }else if(task.DelegateType.Equals(typeof(Sprite)))
- {
- for (int j = 0; j < task.AssetsTask.Count; j++)
- {
- LoadAssetsTask lat = task.AssetsTask[j];
- StartCoroutine(AsyncSingleAssetFromAB<Sprite>(task.BundleName, bundle.Asset, lat));
- }
- }
- else if(task.DelegateType.Equals(typeof(RuntimeAnimatorController)))
- {
- for (int j = 0; j < task.AssetsTask.Count; j++)
- {
- LoadAssetsTask lat = task.AssetsTask[j];
- StartCoroutine(AsyncSingleAssetFromAB<RuntimeAnimatorController>(task.BundleName, bundle.Asset, lat));
- }
- }
- else
- {
- DebugHelper.LogError("[DoCallBack].cant support type {0}", task.DelegateType);
- }
- }
- catch (Exception e)
- {
- DebugHelper.LogException(e);
- }
- finally
- {
- }
- }
- IEnumerator AsyncMultiAssetFromAB<T>(string assetBunleName, AssetBundle bundle, LoadAssetsTask assetsTask) where T : UnityEngine.Object
- {
- if (bundle == null)
- yield break;
- List<T> gos = new List<T>();
- if (assetsTask.AssetName.Length > 0)
- {
- HashSet<string> dic = new HashSet<string>();
- for (int idx = 0; idx < assetsTask.AssetName.Length; idx++)
- {
- string assetName = assetsTask.AssetName[idx].Trim();
- if (string.IsNullOrEmpty(assetName)) continue;
- if (!FileUtils.HasExtension(assetName))
- {
- assetName += GetFileTypeExtention(typeof(T));
- }
- if (dic.Contains(assetName)) continue;
- string assetFilePath = assetName;
- if (!string.IsNullOrEmpty(assetsTask.AssetPath))
- assetFilePath = assetsTask.AssetPath + "/" + assetName;
- AssetBundleRequest req = bundle.LoadAssetAsync<T>(assetFilePath);
- dic.Add(assetName);
- yield return req;
- T g = req.asset as T;
- if (g == null)
- {
- DebugHelper.LogError("AsyncMultiAssetFromAB has null object: " + assetName);
- }
- gos.Add(g);
- }
- }
- else
- {
- AssetBundleRequest req = bundle.LoadAllAssetsAsync<T>();
- yield return req;
- var allAssets = req.allAssets;
- for (int idx = 0, idxMax = allAssets.Length; idx < idxMax; idx++)
- {
- gos.Add(allAssets[idx] as T);
- }
- }
- assetsTask.Invoke(gos);
- }
- IEnumerator AsyncSingleAssetFromAB<T>(string assetBunleName, AssetBundle bundle, LoadAssetsTask assetsTask) where T : UnityEngine.Object
- {
- if (bundle == null)
- yield break;
- if (assetsTask.AssetName.Length > 0 && !string.IsNullOrEmpty(assetsTask.AssetName[0]))
- {
- string name = "";
- if(!string.IsNullOrEmpty(assetsTask.AssetPath))
- name = assetsTask.AssetPath + "/" + assetsTask.AssetName[0] + GetFileTypeExtention(typeof(T));
- else
- name = assetsTask.AssetName[0] + GetFileTypeExtention(typeof(T));
- AssetBundleRequest req = bundle.LoadAssetAsync<T>(name);
- yield return req;
- T g = req.asset as T;
- if (g == null)
- {
- DebugHelper.LogError("AsyncMultiAssetFromAB has null object: " + name);
- }
- assetsTask.Invoke(g);
- }
- }
- #endregion
- }
|