// sample unity recommended code: IEnumerator DownloadNoCache(AssetBundleInfo info) { // Download the file from the URL. It will not be saved in the Cache string path; if (useLocal) path = localPath+info.bundleName+".unity3d"; else path = urlPath+info.bundleName+".unity3d"; using (WWW www = new WWW(path)) { yield return www; if (www.error != null) throw new Exception("WWW download had an error:" + www.error); AssetBundle bundle = www.assetBundle; if (info.assetName == "") Instantiate(bundle.mainAsset); else Instantiate(bundle.Load(info.assetName)); // Unload the AssetBundles compressed contents to conserve memory bundle.Unload(false); } }
public void Load(AssetBundleInfo info){ // for now, just start loading this immediately // later we will queue later stage requests if (info.bundleName == "") return; loading.Add (info); if (useCache) StartCoroutine(DownloadAndCache(info)); else StartCoroutine(DownloadNoCache(info)); // once the bundle is instantiated, it needs to link itself up, load animations, assign scripts, etc... // best to let the bundle main asset contain the appropriate scripts to perform those operations }
/// <summary> /// 停止播放音乐 /// </summary> public void StopMusic() { if (null == this.m_curMusicAudioSource) { Debug.LogError("null == AudioSource"); } else { this.m_curMusicAudioSource.Stop(); this.m_curMusicAudioSource.clip = null; if (null != this.m_assetRequestMusic) { this.m_assetRequestMusic.Release(); this.m_assetRequestMusic = null; this.m_strCurMusicFile = string.Empty; } } }
/// <summary> /// 同步加载AssetBundle及其依赖 /// </summary> /// <param name="abName"></param> /// <returns></returns> public AssetBundleInfo LoadAssetBundle(string abName) { AssetBundleInfo assetBundleInfo = GetAssetBundleInfo(abName); if (assetBundleInfo != null) { List <AssetBundleInfo> depends = assetBundleInfo.GetDependAssetBundeInfos(); if (depends != null) { for (int i = 0, count = depends.Count; i < count; ++i) { depends[i].LoadAssetBundle(); } } assetBundleInfo.LoadAssetBundle(); } return(assetBundleInfo); }
private IEnumerator _DoLoadScene(XManifest.Scene info) { AssetBundleInfo bundleInfo = GetAssetBundleInfo(info.bundle); if (!bundleInfo.isDone) { yield return(CoroutineHelper.Run(_LoadAssetBundleAsync(bundleInfo))); } if (bundleInfo.isDone) { bundleInfo.IncRef(Time.time); yield return(SceneManager.LoadSceneAsync(info.name)); bundleInfo.DecRef(); } }
public static void SetAssetBundleInfo(GameObject _gameObject) { string user = Environment.UserName; DateTime thisDay = DateTime.Now; string makeTime = thisDay.ToString("G"); AssetBundleInfo info = _gameObject.GetComponent <AssetBundleInfo> (); if (info == null) { info = _gameObject.AddComponent <AssetBundleInfo> (); } info.lastAuthor = user; info.makeTime = makeTime; info.verID = 100; }
public override void LoadAssetBundleAsync(AssetBundleInfo bundleInfo, Action <float> onProgress, Action <AssetBundle> onComplete, Action <AssetsException> onError) { if (bundleInfo.IsEmbedBundle) { StartCoroutine(LoadEmbedAssetBundleCoroutine(bundleInfo.bundleName, onProgress, onComplete, onError)); } else if (bundleInfo.IsRemoteBundle) { StartCoroutine(LoadRemoteAssetBundleCoroutine(bundleInfo.BundleUrl, onProgress, onComplete, onError)); } else { throw new Exception("Unknown bundle loading method"); } }
IEnumerator LoadAsyncImpl <T>(string abName, string assetName, System.Action <T> finishLoad) where T : UnityEngine.Object { #if UNITY_EDITOR if (!bundleLoadMode)//编辑器下的非Bundle加载模式 { string[] assetPaths = AssetDatabase.GetAssetPathsFromAssetBundleAndAssetName(abName, assetName); T target = null; if (assetPaths.Length > 0) { target = AssetDatabase.LoadAssetAtPath <T>(assetPaths[0]); } yield return(null); if (finishLoad != null) { finishLoad(target); } yield break; } #endif yield return(StartCoroutine(LoadAssetBundle(abName))); AssetBundleInfo abInfo = null; if (assetBundleInfoDic.TryGetValue(abName, out abInfo)) { AssetBundleRequest abRequest = abInfo.ab.LoadAssetAsync(assetName); while (!abRequest.isDone) { yield return(null); } //内存标记2 LoadAsset T res = abRequest.asset as T; finishLoad(res); abInfo.UseAsset(assetName, abRequest.asset); } else { GLog.Error(abName + " is not find~"); } }
protected void initAssetConfig(byte[] fileBuffer, int fileSize) { byte[] tempStringBuffer = mBytesPool.newBytes(256); mAssetBundleInfoList.Clear(); mAssetToBundleInfo.Clear(); Serializer serializer = new Serializer(fileBuffer, fileSize); serializer.read(out int assetBundleCount); for (int i = 0; i < assetBundleCount; ++i) { // AssetBundle名字 serializer.readString(tempStringBuffer, tempStringBuffer.Length); string bundleName = getFileNameNoSuffix(bytesToString(tempStringBuffer)); if (!mAssetBundleInfoList.TryGetValue(bundleName, out AssetBundleInfo bundleInfo)) { bundleInfo = new AssetBundleInfo(bundleName); mAssetBundleInfoList.Add(bundleName, bundleInfo); } // AssetBundle包含的所有Asset的名字 serializer.read(out int assetCount); for (int k = 0; k < assetCount; ++k) { serializer.readString(tempStringBuffer, tempStringBuffer.Length); string assetName = bytesToString(tempStringBuffer); bundleInfo.addAssetName(assetName); mAssetToBundleInfo.Add(assetName, bundleInfo.getAssetInfo(assetName)); } // AssetBundle的所有依赖项 serializer.read(out int depCount); for (int j = 0; j < depCount; ++j) { serializer.readString(tempStringBuffer, tempStringBuffer.Length); bundleInfo.addParent(getFileNameNoSuffix(bytesToString(tempStringBuffer))); } } mBytesPool.destroyBytes(tempStringBuffer); // 配置清单解析完毕后,为每个AssetBundleInfo查找对应的依赖项 foreach (var info in mAssetBundleInfoList) { info.Value.findAllDependence(); } mInited = true; log("AssetBundle初始化完成, AssetBundle count : " + mAssetBundleInfoList.Count, LOG_LEVEL.FORCE); }
private IEnumerator InitLoadStreamFolderABConfig() { string url = AssetBundlePath.Instance.StreamingAssetPathUrl + "/" + AssetBundlePath.AssetDependentFileBundleName; WWW www = new WWW(url); yield return(www); if (www.isDone) { if (!string.IsNullOrEmpty(www.error)) { DebugSystem.LogError("www Load Error:" + www.error); www.Dispose(); yield break; } } AssetBundle mConfigBundle = www.assetBundle; AssetBundleManifest mAllBundleMainifest = mConfigBundle.LoadAsset <AssetBundleManifest>("AssetBundleManifest"); if (mAllBundleMainifest == null) { DebugSystem.LogError("Mainifest is Null"); www.Dispose(); yield break; } string[] mAssetNames = mAllBundleMainifest.GetAllAssetBundles(); if (mAssetNames != null) { foreach (var v in mAssetNames) { string bundleName = v; string[] bundleDependentList = mAllBundleMainifest.GetAllDependencies(v); Hash128 mHash = mAllBundleMainifest.GetAssetBundleHash(v); AssetBundleInfo mABInfo = new AssetBundleInfo(bundleName, mHash, bundleDependentList); mStreamFolderABInfoList.Add(mABInfo); } } else { DebugSystem.Log("初始化资源依赖文件: Null"); } mConfigBundle.Unload(false); www.Dispose(); }
/// <summary> /// 返回需要更新或下载的ab /// </summary> public IList <AssetBundleInfo> FindUpdatableRes(string[] abs) { var lst = new List <AssetBundleInfo>(); foreach (var ab in abs) { AssetBundleInfo remoteItem = null; AssetBundleInfo localItem = null; if (remoteResConfig.ContainsKey(ab)) { remoteItem = remoteResConfig[ab]; } if (localResConfig.ContainsKey(ab)) { localItem = localResConfig[ab]; } //本地远端都没有,忽略文件 if (localItem == null && remoteItem == null) { com.QH.QPGame.GameUtils.Logger.UI.Log("not found neither local nor remote"); continue; } //本地远端都有,比较版本 if (localItem != null && remoteItem != null) { if (IsValidABFile(localItem, remoteItem, true)) { com.QH.QPGame.GameUtils.Logger.UI.Log("invalid ab version. local:" + localItem + " remote:" + remoteItem); continue; } lst.Add(remoteItem); } else { lst.Add(remoteItem); } } return(lst); }
/// <summary> /// 异步载入素材协程 /// </summary> IEnumerator OnLoadAsset <T>(string abName) where T : UnityEngine.Object { AssetBundleInfo bundleInfo = GetLoadedAssetBundle(abName); if (bundleInfo == null) { yield return(StartCoroutine(OnLoadAssetBundle(abName, typeof(T)))); bundleInfo = GetLoadedAssetBundle(abName); if (bundleInfo == null) { m_LoadRequests.Remove(abName); Debug.LogError("OnLoadAsset--->>>" + abName); yield break; } } List <LoadAssetRequest> list = null; if (!m_LoadRequests.TryGetValue(abName, out list)) { m_LoadRequests.Remove(abName); yield break; } for (int i = 0; i < list.Count; i++) { string assetNames = list[i].assetNames; AssetBundleRequest request = bundleInfo.m_AssetBundle.LoadAssetAsync(assetNames, list[i].assetType); yield return(request); if (list[i].sharpFunc != null) { list[i].sharpFunc(request.asset); list[i].sharpFunc = null; } if (list[i].luaFunc != null) { list[i].luaFunc.Call(request.asset); list[i].luaFunc.Dispose(); list[i].luaFunc = null; } bundleInfo.m_ReferencedCount++; } m_LoadRequests.Remove(abName); }
private IEnumerator DoLoadAssetBundle(string abName, Type type) { string url = mBaseDownloadingURL + abName; WWW download = null; if (type == typeof(AssetBundleManifest)) { download = new WWW(url); } else { string[] dependencies = mAssetBundleManifest.GetAllDependencies(abName); if (dependencies.Length > 0) { mDependencies.Add(abName, dependencies); for (int i = 0; i < dependencies.Length; ++i) { string depName = dependencies[i]; AssetBundleInfo bundleInfo = null; if (mLoadedAssetBundles.TryGetValue(depName, out bundleInfo)) { ++bundleInfo.mReferencedCount; } else if (!mLoadRequests.ContainsKey(depName)) { yield return(StartCoroutine(DoLoadAssetBundle(depName, type))); } } } download = WWW.LoadFromCacheOrDownload(url, mAssetBundleManifest.GetAssetBundleHash(abName), 0); } yield return(download); AssetBundle assetObj = download.assetBundle; if (assetObj != null) { mLoadedAssetBundles.Add(abName, new AssetBundleInfo(assetObj)); } }
/// <summary> /// 释放AssetBundle /// </summary> static public void UnloadAssetBundle(string assetBundleName) { AssetBundleInfo bundle = GetLoadedAssetBundle(assetBundleName); if (bundle == null) { return; } if (--bundle.m_ReferencedCount <= 0) { if (m_LoadRequests.ContainsKey(assetBundleName)) { return; } bundle.m_AssetBundle.Unload(false); m_LoadedAssetBundles.Remove(assetBundleName); } }
private bool IsRedirectTable(AssetBundleInfo assetBundleInfo, out ExcelData excelData) { try { excelData = ManualLoadAsset <ExcelData>(assetBundleInfo); } catch { excelData = null; } if (excelData != null && IsRedirectTable(excelData)) { return(true); } excelData = null; return(false); }
/// <summary> /// 卸载不用的 /// </summary> public void UnloadUnusedBundle(bool force = false) { if (_isCurrentLoading == false || force) { List <string> keys = new List <string>(_loadedAssetBundle.Keys); bool hasUnusedBundle = false; //一次最多卸载的个数,防止卸载过多太卡 int unloadLimit = 20; int unloadCount = 0; do { hasUnusedBundle = false; for (int i = 0; i < keys.Count && !_isCurrentLoading && unloadCount < unloadLimit; i++) { if (_isCurrentLoading && !force) { break; } string key = keys[i]; AssetBundleInfo abi = _loadedAssetBundle[key]; if (abi.isUnused) { hasUnusedBundle = true; unloadCount++; this.RemoveBundleInfo(abi); i--; keys.Remove(key); } } } while (hasUnusedBundle && !_isCurrentLoading && unloadCount < unloadLimit); #if UNITY_EDITOR if (unloadCount > 0) { Debug.Log("===>> Unload Count: " + unloadCount); Resources.UnloadUnusedAssets(); } #endif } }
/// <summary> /// 破棄 /// </summary> public override void Unload() { //アセットバンドルへの参照を解除 if (this.info != null) { var item = ReferencedAssetBundle.Get(this.info.assetBundleName); item.Unload(this); foreach (var dependency in this.info.dependencies) { item = ReferencedAssetBundle.Get(dependency); item.Unload(this); } this.info = null; } base.Unload(); }
public virtual void Dispose() { UnloadBundle(); var e = deps.GetEnumerator(); while (e.MoveNext()) { AssetBundleInfo dep = e.Current; dep.depChildren.Remove(this.bundleName); dep.Release(); } deps.Clear(); references.Clear(); if (onUnloaded != null) { onUnloaded(this); } }
// Returns true if more Update calls are required. public override bool Update() { if (m_Request != null) { return(false); } AssetBundleInfo bundle = ResourceManager.GetLoadedAssetBundle(m_AssetBundleName, out m_DownloadingError); if (bundle != null) { m_Request = bundle.m_AssetBundle.LoadAssetAsync(m_AssetName, m_Type); return(false); } else { return(true); } }
protected override void OnRelease(PlayerActor player) { player.CameraControl.EventCameraLocator.set_runtimeAnimatorController((RuntimeAnimatorController)null); // ISSUE: cast to a reference type // ISSUE: explicit reference operation (^ (CinemachineBlendDefinition&)ref player.CameraControl.CinemachineBrain.m_DefaultBlend).m_Style = (__Null)this._prevStyle; player.CameraControl.Mode = CameraMode.Normal; player.ChaControl.visibleAll = true; if (Object.op_Inequality((Object)this._agent, (Object)null)) { AssetBundleInfo outInfo = (AssetBundleInfo)null; this._agent.ChangeAnimator(Singleton <Resources> .Instance.Animation.GetCharaAnimator(0, ref outInfo)); if (!this._registeredBefore) { this._agent.RefreshWalkStatus(Singleton <Manager.Map> .Instance.PointAgent.Waypoints); Singleton <Manager.Map> .Instance.InitSearchActorTargets(this._agent); player.PlayerController.CommandArea.AddCommandableObject((ICommandable)this._agent); using (IEnumerator <KeyValuePair <int, AgentActor> > enumerator = Singleton <Manager.Map> .Instance.AgentTable.GetEnumerator()) { while (enumerator.MoveNext()) { KeyValuePair <int, AgentActor> current = enumerator.Current; if (!Object.op_Equality((Object)current.Value, (Object)this._agent)) { current.Value.AddActor((Actor)this._agent); } } } } this._agent.ClearItems(); this._agent.ClearParticles(); this._agent.ActivateNavMeshAgent(); this._agent.EnableBehavior(); this._agent.ChangeBehavior(Desire.ActionType.Normal); } Singleton <Manager.Input> .Instance.ReserveState(Manager.Input.ValidType.Action); Singleton <Manager.Input> .Instance.SetupState(); player.SetScheduledInteractionState(true); player.ReleaseInteraction(); }
static public void MarkLocalAssetBundle(BuildTarget target) { Debug.Log("執行操作:Mark Local AssetBundle"); string reslistPath = string.Format( "{0}/assetbundles/{1}/reslist.json", Application.streamingAssetsPath, GetAssetBundlesPlatformFolder(target) ); if (!File.Exists(reslistPath)) { Debug.LogWarningFormat("沒有在StreamPath/assetbundles/{0}下找到reslist.json", GetAssetBundlesPlatformFolder(target)); return; } string rawInfo = File.ReadAllText(reslistPath); if (string.IsNullOrEmpty(rawInfo)) { Debug.LogWarning("reslist.json是空文件"); return; } int confVer = 0; Dictionary <string, AssetBundleInfo> infoDict = AssetBundleManager.ParseReslist(rawInfo, false, out confVer); Dictionary <string, AssetBundleInfo> newDict = new Dictionary <string, AssetBundleInfo>(); foreach (var pair in infoDict) { string path = string.Format("{0}/assetbundles/{1}/{2}", Application.streamingAssetsPath, GetAssetBundlesPlatformFolder(target), pair.Key); AssetBundleInfo newInfo = pair.Value; newInfo.Packaged = File.Exists(path); newDict.Add(newInfo.Path, newInfo); } FileInfo fInfo = new FileInfo(reslistPath); SaveReslist(fInfo, newDict, confVer); Debug.Log("操作完成"); }
/// <summary> /// 添加引用到AssetBundle /// </summary> /// <param name="assetBundleInfo"></param> public void AddAssetBundleRef(AssetBundleInfo assetBundleInfo) { if (assetBundleInfo == null) { return; } if (isScene == true) { GameObject sceneObj = new GameObject(name); assetBundleInfo.AddAssetRef(sceneObj); } else { if (_asset != null) { assetBundleInfo.AddAssetRef(_asset); } } }
public AssetBundleInfo LoadSingleAssetBundle(string assetPath) { string assetBundleName = GetAssetBundleNameByAssetMaps(assetPath); AssetBundleInfo abInfo = null; if (_asset_bundles.TryGetValue(assetBundleName, out abInfo)) { if (abInfo.IsLoader) { return(abInfo); } abInfo.LoadFromFile(); _is_current_loader.Add(abInfo); } return(abInfo); }
private void LoadAllAssets <T>(AssetBundleInfo bundleInfo, Action <T[]> resolve, Action <Exception> reject) where T : UnityEngine.Object { AssetBundleLoader.LoadAssetBundle(bundleInfo.url, bundleInfo.version) .Then(bundle => { T[] result = bundle.LoadAllAssets <T>(); for (int i = 0; i < result.Length; i++) { AddAssetToCache(bundleInfo.bundleId, result[i].name, result[i]); } resolve(result); }) .Catch(exception => { reject(exception); }); }
private string GetAssetBundleText(AssetBundleInfo abInfo) { if (null == abInfo) { return(string.Empty); } else { TextAsset asset = abInfo.Require(null) as TextAsset; if (null != asset && !string.IsNullOrEmpty(asset.text)) { return(asset.text); } else { return(string.Empty); } } }
//携程用记录依赖 private void OnRecordModule(AssetBundleInfo abInfo, string moduleName) { if (RecordModule(abInfo, moduleName)) { string[] dependencies = abInfo.dependencies; if (dependencies == null) { return; } for (int i = 0; i < dependencies.Length; i++) { AssetBundleInfo depAbInfo = null; if (_bundleDic.TryGetValue(dependencies[i], out depAbInfo)) { OnRecordModule(depAbInfo, moduleName); } } } }
IEnumerator OnLoadAssetBundle(string abName, Type type) { string url = m_BaseDownloadingURL + abName; url = "file:///c:/luaframework/" + abName; WWW download = null; if (type == typeof(AssetBundleManifest)) { download = new WWW(url); } else { string[] dependencies = m_AssetBundleManifest.GetAllDependencies(abName); if (dependencies.Length > 0) { m_Dependencies.Add(abName, dependencies); for (int i = 0; i < dependencies.Length; i++) { string depName = dependencies[i]; AssetBundleInfo bundleInfo = null; if (m_LoadedAssetBundles.TryGetValue(depName, out bundleInfo)) { bundleInfo.m_ReferencedCount++; } else if (!m_LoadRequests.ContainsKey(depName)) { yield return(StartCoroutine(OnLoadAssetBundle(depName, type))); } } } download = WWW.LoadFromCacheOrDownload(url, m_AssetBundleManifest.GetAssetBundleHash(abName), 0); } yield return(download); AssetBundle assetObj = download.assetBundle; if (assetObj != null) { m_LoadedAssetBundles.Add(abName, new AssetBundleInfo(assetObj)); } }
/// 载入AssetBundle public AssetBundle LoadAB(string abName, string modlue) { if (GameMain.Inst.ResourceMode == 0) { return(null); } abName = abName.ToLower(); AssetBundleInfo abInfo = null; if (!_bundleDic.TryGetValue(abName, out abInfo)) { abInfo = new AssetBundleInfo(); _bundleDic.Add(abName, abInfo); AssetBundle ab_tmp; if (IsEncrypt(abName)) { ab_tmp = AssetBundle.LoadFromFile(CommonUtils.GetABPath(abName.GetHashCode().ToString()), 0, 18); } else { ab_tmp = AssetBundle.LoadFromFile(CommonUtils.GetABPath(abName.GetHashCode().ToString())); } if (ab_tmp == null) { Debug.LogErrorFormat("<ResMgr> 加载{0}失败!", abName); return(null); } abInfo.ab = ab_tmp; abInfo.ab.name = abName; //手动赋值,打包自动生成的根AB包的Name为空 } //记录使用者 if (RecordModule(abInfo, modlue)) { LoadDependencies(modlue, abName);//加载该ab包的依赖包 } return(abInfo.ab); }
AssetBundleInfo IBundleServices.GetAssetBundleInfo(string bundleName) { if (_variantCollector != null) { bundleName = _variantCollector.RemapVariantName(_patchManifest, bundleName); } if (_patchManifest.Elements.TryGetValue(bundleName, out PatchElement element)) { string localPath = AssetPathHelper.MakeStreamingLoadPath(element.MD5); AssetBundleInfo bundleInfo = new AssetBundleInfo(bundleName, localPath, string.Empty, element.Version, element.IsEncrypted); return(bundleInfo); } else { MotionLog.Warning($"Not found element in patch manifest : {bundleName}"); AssetBundleInfo bundleInfo = new AssetBundleInfo(bundleName, string.Empty); return(bundleInfo); } }
void InternalLoadAssetBundleAsync( AssetBundleInfo abInfo, AssetBundleLoaderRequest request) { abInfo.AsynLoadFromFile(request, (mainAB) => { _is_current_loader.Add(abInfo); List <string> dependencys = _dependency.GetDependency(mainAB.GetAssetBundleName()); for (int i = 0; i < dependencys.Count; i++) { AssetBundleLoaderRequest deRequest = AssetBundleLoaderRequest.New(dependencys[i]); LoadAssetBundleAsync(deRequest); deRequest.OnCompleted = (ab) => { ab.AddReferenceCount(); }; } }); }
static void export() { AssetBundleInfo abi = new AssetBundleInfo(); var abs = AssetDatabase.GetAllAssetBundleNames(); for (int i = 0; i < abs.Length; i++) { var files = AssetDatabase.GetAssetPathsFromAssetBundle(abs[i]); abi.AssetBundles[abs[i]] = files; foreach (var f in files) { Debug.Log(abs[i] + ":" + f); } } var writer = new YamlDotNet.Serialization.Serializer(); string str = writer.Serialize(abi); Debug.Log(str); File.WriteAllText(getconfpath(), str); }
void UnloadAssetBundleInternal(string abName, bool isThorough) { AssetBundleInfo bundle = GetLoadedAssetBundle(abName); if (bundle == null) { return; } if (--bundle.m_ReferencedCount <= 0) { if (m_LoadRequests.ContainsKey(abName)) { return; //如果当前AB处于Async Loading过程中,卸载会崩溃,只减去引用计数即可 } bundle.m_AssetBundle.Unload(isThorough); m_LoadedAssetBundles.Remove(abName); Util.Log(abName + " has been unloaded successfully"); } }
public static bool checkEqual( AssetBundleInfoData data1, AssetBundleInfo info1, AssetBundleInfoData data2, AssetBundleInfo info2 ) { if(info1.objs.Count != info2.objs.Count) return false; foreach( string name in info1.objs ){ if(info2.objs.Contains(name)){ if(data1.GetMD5(name) != data2.GetMD5(name) ) return false; } else return false; } return true; }
public void LinkFrom(ScriptedObjectInfo info){ // initialize members from deserialized info gameObject.name = info.unityObjectName; moveToParentOnDrop = info.moveToParentOnDrop; // set this in each prefab, but false so constructed ones dont dropTargetName = info.dropTargetName; // don't process the scripts in this method register = info.register; // instead, derive this from any contained scripts who listen to status messages prettyname = info.prettyname; // this was on the OI class, we shouldnt need it here XMLName = info.XMLName; XMLDirectory = info.XMLDirectory; assetBundleInfo = info.assetBundleInfo; voiceList = info.voiceList; voiceLists = info.voiceLists; vitalsBehaviors = info.vitalsBehaviors; scanRecords = info.scanRecords; }
public void InitFrom(ScriptedObjectInfo info){ // we should probably destroy any existing hierarchy here, calling OnDestroy() on our children; // initialize members from deserialized info gameObject.name = info.unityObjectName; moveToParentOnDrop = info.moveToParentOnDrop; // set this in each prefab, but false so constructed ones dont dropTargetName = info.dropTargetName; // make children from all the scriptInfos, and init each one from it's info, which will build the Actions scripts = new InteractionScript[info.scripts.Length]; for (int i = 0; i<info.scripts.Length; i++){ GameObject go = new GameObject(info.scripts[i].unityObjectName); go.transform.parent = this.transform; scripts[i] = go.AddComponent("InteractionScript") as InteractionScript; scripts[i].InitFrom(info.scripts[i]); } if (info.startupScriptName != null && info.startupScriptName != ""){ for (int i = 0; i<scripts.Length; i++){ if (scripts[i].name == info.startupScriptName){ startupScript = scripts[i]; break; } } } register = info.register; // instead, derive this from any contained scripts who listen to status messages prettyname = info.prettyname; // this was on the OI class, we shouldnt need it here XMLName = info.XMLName; XMLDirectory = info.XMLDirectory; assetBundleInfo = info.assetBundleInfo; voiceList = info.voiceList; voiceLists = info.voiceLists; vitalsBehaviors = info.vitalsBehaviors; scanRecords = info.scanRecords; }
string _GetAssetBundlePath(AssetBundleInfo abi) { string assetBundlePath = Path.Combine(LPetUtil.GetAppStoragePath(), abi.guid); if (!Directory.Exists(assetBundlePath)) { Directory.CreateDirectory(assetBundlePath); } return assetBundlePath; }
public void InitFrom(LinkableContentInfo info){ assetBundleInfo = info.assetBundleInfo; voiceLists = info.voiceLists; vitalsBehaviors = info.vitalsBehaviors; assessmentListXMLs = info.assessmentListXMLs; }
string _GetAssetBundleFullPath(AssetBundleInfo abi) { return Path.Combine(_GetAssetBundlePath(abi), _GetAssetBundleName(abi)); }
/// <summary> /// 根据资源配置XML构造资源依赖信息。 /// </summary> /// <param name="se">XML数据</param> /// <param name="parentFolder"></param> /// <returns></returns> private AssetBundleInfo GetAssetBundleInfo(SecurityElement se, string parentFolder) { var path = string.Concat(parentFolder, (se.Children[0] as SecurityElement).Text);//.Replace("\\", "/");// if (m_allRecources.ContainsKey(path)) { //LoggerHelper.Warning("Same resource: " + path); return m_allRecources[path]; } else { var ab = new AssetBundleInfo(); ab.Path = path; for (int i = 1; i < se.Children.Count; i++) { var child = se.Children[i] as SecurityElement; ab.SubResource.Add(GetAssetBundleInfo(child, parentFolder)); } m_allRecources.Add(path, ab); return ab; } }
/// <summary> /// 获取所有需要加载的资源文件信息。 /// </summary> /// <param name="info"></param> /// <returns></returns> private HashSet<string> GetAllFile(AssetBundleInfo info) { HashSet<string> list = new HashSet<string>(); if (info.Asset == null) { foreach (var item in info.SubResource) { var subRes = GetAllFile(item); foreach (var set in subRes) { if (!list.Add(set)) LoggerHelper.Debug("exist 1: " + set); } } if (!list.Add(info.Path)) LoggerHelper.Debug("exist 2: " + info.Path); } return list; }
//run Time usage public bool ReadAssetBundleInfo(string fileText) { ClearData(); try { string[] block = fileText.Split(new string[]{"<<Version>>", "<<AssetInfo>>", "<<PackInfo>>"}, System.StringSplitOptions.RemoveEmptyEntries ); version = System.Convert.ToInt32( block[0] ); if(block.Length > 1) { string[] dataSet = block[1].Split('#'); foreach(string s in dataSet){ string[] values = s.Split(','); AssetBundleInfo info = new AssetBundleInfo(); info.Name = values[0]; info.version = System.Convert.ToInt32( values[1] ); AssetBundleInfos.Add(info.Name, info); //Debug.LogError("assetbundle :" + info.Name + " " + info.version.ToString()); } } if(block.Length > 2) { string[] dataSet = block[2].Split('#'); foreach(string s in dataSet){ string[] values = s.Split(','); AssetObjectInfo info = new AssetObjectInfo(); info.Name = values[0]; string packNames = values[1]; foreach(string pks in packNames.Split('+')){ info.PackName.Add(pks); } info.version = System.Convert.ToInt32( values[2] ); info.MD5 = values[3]; AssetObjectInfos.Add(info.Name, info); foreach(string packname in info.PackName){ AssetBundleInfos[packname].objs.Add(info.Name); } } } } catch(System.Exception e) { Debug.LogError( "local assetinfo format error" ); return false; } return true; }
IEnumerator DownloadAndCache (AssetBundleInfo info){ // Wait for the Caching system to be ready while (!Caching.ready) yield return null; int version = 0; // Load the AssetBundle file from Cache if it exists with the same version or download and store it in the cache string path; if (useLocal) path = localPath+info.bundleName+".unity3d"; else path = urlPath+info.bundleName+".unity3d"; using(WWW www = WWW.LoadFromCacheOrDownload (path, version)){ yield return www; if (www.error != null) throw new Exception("WWW download had an error:" + www.error); AssetBundle bundle = www.assetBundle; if (info.assetName == "") Instantiate(bundle.mainAsset); else Instantiate(bundle.Load(info.assetName)); // Unload the AssetBundles compressed contents to conserve memory bundle.Unload(false); } }
public void AddAssetObjectInfo(string ObjectName, string PackName, Object obj) { AssetBundleInfoData.AssetObjectInfo info = null; if(AssetObjectInfos.ContainsKey(ObjectName)) info = AssetObjectInfos[ObjectName]; else info = new AssetObjectInfo(); info.Name = ObjectName; info.PackName.Add(PackName); info.obj = obj; info.MD5 = GetMD5HashFromFile( AssetDatabase.GetAssetPath(obj) ); if(AssetObjectInfos.ContainsKey(ObjectName)){ if(AssetObjectInfos[ObjectName].obj != obj){ Debug.LogError( "Adding different object with the same name " + info.Name + " to Assetbundle builder, please try different name. "); return; } } else AssetObjectInfos.Add(ObjectName, info); if(System.String.IsNullOrEmpty(PackName)){ AssetBundleInfo Ainfo = new AssetBundleInfo(); Ainfo.Name = info.Name; Ainfo.objs.Add(info.Name); AssetBundleInfos.Add(Ainfo.Name, Ainfo); } else{ if(AssetBundleInfos.ContainsKey(PackName)){ AssetBundleInfos[PackName].objs.Add(ObjectName); } else{ AssetBundleInfo Ainfo = new AssetBundleInfo(); Ainfo.Name = PackName; Ainfo.objs.Add(info.Name); AssetBundleInfos.Add(Ainfo.Name, Ainfo); } } }
void _AssignAssetBundleInfo(AssetBundleInfo abi, string jsonKey, object jsonValue) { if (jsonKey == "guid") { abi.guid = jsonValue.ToString(); } else if (jsonKey == "name") { abi.name = jsonValue.ToString(); } else if (jsonKey == "server_url") { abi.server_url = jsonValue.ToString(); } else if (jsonKey == "asset_version") { abi.asset_version = (float) Convert.ToDouble(jsonValue); } else if (jsonKey == "support_gameversion") { abi.support_gameversion = (float) Convert.ToDouble(jsonValue); } }
string _GetAssetBundleName(AssetBundleInfo abi) { return (abi.name + "_" + abi.asset_version.ToString()); }
void _GetAssetBundleInfoFromJson(JsonReader reader) { AssetBundleInfo abi = null; while (reader.Read()) { if (reader.Token == JsonToken.ArrayStart) { _assetBundlesList = new List<KeyValuePair<string, AssetBundleInfo>>(); } else if (reader.Token == JsonToken.ArrayEnd) { break; } else if (reader.Token == JsonToken.ObjectStart) { abi = new AssetBundleInfo(); } else if (reader.Token == JsonToken.ObjectEnd) { if (_assetBundlesList != null) { _assetBundlesList.Add(new KeyValuePair<string, AssetBundleInfo>(abi.guid, abi)); } else { LPetUtil.DebugLogf("AssetBundle List is null. Json Data is wrong!!!"); } } else if (reader.Token == JsonToken.PropertyName) { string jsonKey = reader.Value.ToString(); reader.Read(); _AssignAssetBundleInfo(abi, jsonKey, reader.Value); } } _DebugPrintAssetBundlesList("Initialized Assets"); }