private static ABPInfo GetABPInfo() { var tt = typeof(AssetBundleSettingHelper); var abp = new ABPInfo(tt.Name, ".cs"); var filesDir = SearchFolders(Application.dataPath, abp.NameWithExt); if (filesDir.Count <= 0) { //没有找到本文件路径,把Application.dataPath目录放进去吧 filesDir.Add(Application.dataPath); } else if (filesDir.Count > 1) { //找到多个同名文件,这个需要打个日志 foreach (var f in filesDir) { Debug.LogError("same file ? " + f + abp.NameWithExt); } } var abpInfo = new ABPInfo(AssetBundleSettingHelper.ABSHName, AssetBundleSettingHelper.ABSHExtName); foreach (var f in filesDir) { abpInfo.SetPath(f); var fi = new FileInfo(Path.Combine(f, abpInfo.NameWithExt)); if (fi.Exists) { return(abpInfo); } } return(abpInfo); }
private ABPInfo GetStreamingAssetABPIByVersion(string versionName, string name, string extName) { string path = Path.Combine(GetStreamingAssetsPath(), versionName); ABPInfo abpi = new ABPInfo(name, extName, path: path); return(abpi); }
private ABPInfo GetPersistentDataABPIByVersion(string versionName, string name, string extName) { string path = Path.Combine(GetPersistentDataPath(), versionName); ABPInfo abpi = new ABPInfo(name, extName, path: path); return(abpi); }
/// <summary> /// 把制定打包的AB文件移动到streamingAssets文件夹中适当的位置,要先清空文件夹后移动 /// </summary> /// <param name="bt">BuildTarget的类型,一般都是打目标版本的类型</param> public static void MoveAssetBundleToStreamingAssets(BuildTarget bt) { RuntimePlatform runtimePlatform = AssetBundleSettingHelperEditor.BuildTargetToRuntimePlatform(bt); string versionName = GetABSH().RuntimePlatformToSimplifyName(runtimePlatform); //string streamingAssetsPath = AssetBundleHelper.GetStreamingAssetsPath(); //清理三个文件夹 ABPInfo[] deleteABPIs = new ABPInfo[3]; deleteABPIs[0] = GetABSH().GetStreamingAssetABPath(ABSH.RuntimePlatformToSimplifyName(RuntimePlatform.WindowsEditor)); deleteABPIs[1] = GetABSH().GetStreamingAssetABPath(ABSH.RuntimePlatformToSimplifyName(RuntimePlatform.OSXEditor)); deleteABPIs[2] = GetABSH().GetStreamingAssetABPath(ABSH.RuntimePlatformToSimplifyName(RuntimePlatform.Android)); foreach (var abpiTmp in deleteABPIs) { if (Directory.Exists(abpiTmp.Dir_Relative)) { Directory.Delete(abpiTmp.Dir_Relative, true); } } var abpiTar = GetABSH().GetStreamingAssetABPath(versionName); Directory.CreateDirectory(abpiTar.Dir_Relative); var abpi = GetABSH().GetAssetBundleOutputPath(versionName); CopyFolder(abpi.Dir_Relative, abpiTar.Dir_Relative); AssetDatabase.Refresh(); }
public static void SaveABSH(AssetBundleSettingHelper absh, ABPInfo abpi) { EditorUtility.SetDirty(absh); AssetDatabase.SaveAssets(); // EditorApplication // Application // Editor. //absh.SetDirty(); }
public static ABPInfo GetABOutputABPIByVersion(this AssetBundleSettingHelper absh, string versionName, string name, string extName = "") { if (extName.Equals("")) { extName = absh.AssetBundelExtName; } string path = Path.Combine(absh.ABOutputPath, versionName); ABPInfo abpi = new ABPInfo(name, extName, relativePath: path); return(abpi); }
private void PushResToNeedLoad_Real(string path, Action <UnityEngine.Object> callback, bool bInstantiate) { //path = Path.Combine(Ins.ABSettingHelper.NeedBuildABPath, path).ToLower(); path = path.ToLower(); //Debug.Log(path); //lock(NeedLoadQueue) // { // NeedLoadQueue.Enqueue(new KeyValuePair<string, KeyValuePair<bool, Action<UnityEngine.Object>>>(path, new KeyValuePair<bool, Action<UnityEngine.Object>>(bInstantiate, callback))); // } ABPInfo abpi = ABSettingHelper.GetCurPlatformABPath(path); NeedLoadQueue.Enqueue(new Tuple <ABPInfo, bool, Action <UnityEngine.Object> >(abpi, bInstantiate, callback)); BeginLoadRes(); }
private void UpdateFile(ABPInfo abpi, byte[] bytes, AssetBundleSettingHelper ABSettingHelper) { if (!Directory.Exists(abpi.Dir_Full)) { Directory.CreateDirectory(abpi.Dir_Full); } if (File.Exists(abpi.FullName)) { File.Delete(abpi.FullName); } FileStream fsDes = File.Create(abpi.FullName); fsDes.Write(bytes, 0, bytes.Length); fsDes.Flush(); fsDes.Close(); }
public static AssetBundleSettingHelper GetABSH(out ABPInfo abpInfo) { AssetBundleSettingHelper absh = null; abpInfo = GetABPInfo(); var fi = new FileInfo(abpInfo.FullName); if (fi.Exists) { absh = AssetDatabase.LoadAssetAtPath <AssetBundleSettingHelper>(abpInfo.FullName_RelativePath); if (absh == null) { Debug.LogError("Not found :" + abpInfo.FullName + " then create"); } else { return(absh); } } absh = ScriptableObject.CreateInstance <AssetBundleSettingHelper>(); CreateABSH(absh, abpInfo); return(absh); }
private static void CreateFile(ABPInfo abpi, byte[] bytes) { if (!Directory.Exists(abpi.Dir_Full)) { Directory.CreateDirectory(abpi.Dir_Full); } if (File.Exists(abpi.FullName)) { AssetBundleHelper.TestLog("File.Delete(name);" + abpi.FullName); File.Delete(abpi.FullName); } try { FileStream fsDes = File.Create(abpi.FullName); fsDes.Write(bytes, 0, bytes.Length); fsDes.Flush(); fsDes.Close(); AssetBundleHelper.TestLog("File.CreateFile(name);" + abpi.FullName); } catch (Exception e) { AssetBundleHelper.TestLog("CreateFile:" + e); } }
/// <summary> /// 这里获得是分析结果输出位置 /// </summary> /// <returns></returns> public ABPInfo GetDataAnalysisXmlABPI() { ABPInfo abpi = new ABPInfo(xmlDataAnalysisName, xmlExtName, relativePath: Path.Combine(xmlABAnalysisDir, xmlDataAnalysisDir)); return(abpi); }
/// <summary> /// 这个获得的路径位置是分析结果xml在打成AB前应该存在的位置,也就是要打包的目录下 /// </summary> /// <returns></returns> public ABPInfo GetDataAnalysisXmlMoveTargetABPI() { ABPInfo abpi = new ABPInfo(xmlDataAnalysisName, xmlExtName, relativePath: NeedBuildABPath); return(abpi); }
public ABPInfo GetABUses_OutdateABPI() { ABPInfo abpi = new ABPInfo("", xmlExtName, relativePath: Path.Combine(xmlABAnalysisDir, xmlABUses_OutdateDir)); return(abpi); }
public ABPInfo GetABUsesABPI() { ABPInfo abpi = new ABPInfo(xmlABUsesDir + "_" + DateTime.Now.ToString("yyyy-MM-dd_HH_mm_ss"), xmlExtName, relativePath: Path.Combine(xmlABAnalysisDir, xmlABUsesDir)); return(abpi); }
public static void CreateABSH(AssetBundleSettingHelper absh, ABPInfo abpi) { AssetDatabase.CreateAsset(absh, abpi.FullName_RelativePath); }
private T LoadResource_Sync_Real <T>(string assetName) where T : UnityEngine.Object { if (ABSettingHelper.UseAssetBundle) { if (manifest == null) { throw new NullReferenceException("manifest == null"); } var abpi = ABSettingHelper.GetCurPlatformABPath(assetName); string[] dps = manifest.GetAllDependencies(abpi.DependencyName); for (int i = 0; i < dps.Length; i++) { ABPInfo abpiTT = ABSettingHelper.GetCurPlatformABPath(dps[i]); { if (!AssetBundleDic.ContainsKey(abpiTT.URI)) { var ab = AssetBundle.LoadFromFile(abpiTT.FullName); if (ab != null) { AssetBundleDic.Add(abpiTT.URI, ab, -1); } else { Debug.LogError("Not Found File:" + abpiTT.FullName); } } } } if (!AssetBundleDic.ContainsKey(abpi.URI)) { var ab = AssetBundle.LoadFromFile(abpi.FullName); if (ab != null) { AssetBundleDic.Add(abpi.URI, ab, -1); } else { Debug.LogError("Not Found File:" + abpi.FullName); } } if (!AssetBundleDic.ContainsKey(abpi.URI, false)) { Debug.LogError("!AssetBundleDic.ContainsKey(name) :" + abpi.URI); return(null); } var obj = AssetBundleDic.GetAssetBundle(abpi.URI).LoadAsset <T>(abpi.AssetName); return(obj); } else { #if UNITY_EDITOR var obj = UnityEditor.AssetDatabase.LoadAssetAtPath <T>(assetName); if (obj == null) { Debug.LogError("Asset not load:" + assetName); } return(obj); #else throw new Exception("What!!!!!!!!!!!! look here!!!!!!!!"); #endif } //return null; }
/// <summary> /// 会被打成assetbundle所有资源的加载都通过这里实现,没有同步加载方式,只有异步 /// 没有resources.load在加载方式,编辑器中可根据设置使用AssetDatabase加载(虽然这时是可以同步加载,但是保证一致性,还是要表现成异步) /// </summary> /// <param name="loadResourceName">要加载的资源的名字</param> /// <param name="callback">资源加载成功后的回调</param> /// <returns></returns> private IEnumerator LoadResourceAsyn() { ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //这里可能没有修改正确,启用异步加载前请检查并检验代码 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// if (!Ins.ABSettingHelper.IsAsynLoadRes) { yield break; } //string streamingAssetsPath = (AssetBundleSettingHelper.PathToPlatformFormat(AssetBundleSettingHelper.GetStreamingAssetsPath())); //string platformBundlePath = (AssetBundleSettingHelper.Combine(streamingAssetsPath, ABSettingHelper.GetPlatformPathName())); //var abpi = ABSettingHelper.GetCurPlatformBundlePath(); while (CurNeedPreloadAB.Count > 0 || NeedLoadQueue.Count > 0) { //先加载需要加载的资源,没有的时候再加载预加载资源 while (NeedLoadQueue.Count > 0) { List <WWW> listWWWs = new List <WWW>(); Dictionary <string, string> listDPs = new Dictionary <string, string>(); var needLoad = NeedLoadQueue.Dequeue(); var loadResourceABPI = needLoad.t1; var bInstantiate = needLoad.t2; var callback = needLoad.t3; UnityEngine.Object newObj = null; if (ABSettingHelper.UseAssetBundle) { listDPs.Clear(); listWWWs.Clear(); //通过bundle加载 //ABPInfo abpiTmp = ABSettingHelper.GetCurPlatformABPath(loadResourceName); //如果这个时候还为空直接终止 if (manifest == null) { throw new NullReferenceException("manifest == null"); //yield break; } { string[] dps = manifest.GetAllDependencies(loadResourceABPI.DependencyName); //AssetBundle[] abs = new AssetBundle[dps.Length]; for (int i = 0; i < dps.Length; i++) { ABPInfo abpiTT = ABSettingHelper.GetCurPlatformABPath(dps[i]); { if (!AssetBundleDic.ContainsKey(abpiTT.URI)) { listWWWs.Add(new WWW(abpiTT.URI)); } listDPs.Add(abpiTT.URI, dps[i]); } } { if (!AssetBundleDic.ContainsKey(loadResourceABPI.URI)) { listWWWs.Add(new WWW(loadResourceABPI.URI)); } } while (true && listWWWs.Count > 0) { yield return(null); for (int i = 0; i < listWWWs.Count;) { var www = listWWWs[i]; if (www.error != null) { listWWWs.RemoveAt(i); string info = "www.error != null :" + www.url + " " + www.error; www.Dispose(); throw new NullReferenceException(info); //Debug.Assert(false, "wwwtar.error != null :" + www.url +" "+ www.error); } else if (www.isDone) { listWWWs.RemoveAt(i); var bundleTar = www.assetBundle; string key = www.url; int size = www.size; www.Dispose(); if (bundleTar != null) { AssetBundleDic.Add(key, bundleTar, size); } else { //Debug.Assert(false, "bundleTar == null :" + www.url); throw new NullReferenceException("bundleTar == null :" + key); } } else { i++; } } } if (!AssetBundleDic.ContainsKey(loadResourceABPI.URI, false)) { //Debug.LogError("!AssetBundleDic.ContainsKey(name) :" + name); throw new NullReferenceException("!AssetBundleDic.ContainsKey(loadResourceABPI.URI) :" + loadResourceABPI.URI); } { var obj = AssetBundleDic.GetAssetBundle(loadResourceABPI.URI).LoadAsset(loadResourceABPI.AssetName); if (obj != null) { if (bInstantiate) { newObj = Instantiate(obj) as UnityEngine.Object; } else { newObj = obj; } } else { // while (true) // { // Debug.LogError("name:"+ name+ " loadResourceName" + loadResourceName); // yield return new WaitForSeconds(5.0f) ; // } throw new NullReferenceException("obj == null "); //Debug.Assert(false, "obj == null "); } AssetBundleDic.UnloadABUseAnalysis(listDPs, loadResourceABPI.URI); } } } else { #if UNITY_EDITOR yield return(null); var obj = UnityEditor.AssetDatabase.LoadAssetAtPath <UnityEngine.Object>(loadResourceABPI.AssetName); if (obj != null) { if (bInstantiate) { newObj = Instantiate(obj) as UnityEngine.Object; } else { newObj = obj; } } else { throw new NullReferenceException("obj == null here " + loadResourceABPI.AssetName); //Debug.Assert(false, "obj == null here "); } Debug.Log("AssetDataBase.load:" + loadResourceABPI.AssetName); #endif } if (newObj != null) { callback(newObj); } else { //Debug.Assert(false, "newObj == null "); throw new NullReferenceException("newObj == null "); } } if (CurNeedPreloadAB.Count > 0) { yield return(null); var fAB = CurNeedPreloadAB[0]; ABPInfo abpiTmp_Preload = ABSettingHelper.GetCurPlatformABPath(fAB); { if (!AssetBundleDic.ContainsKey(abpiTmp_Preload.Dir_Full)) { using (WWW www = new WWW(abpiTmp_Preload.URI)) { if (www == null) { // while (true) // { // Debug.LogError("www == null " + namePreload); // Thread.Sleep(3000); // } Debug.LogError(Thread.CurrentContext.ContextID + ":www == null" + abpiTmp_Preload.Dir_Full + ":" + Time.realtimeSinceStartup); } //else //{ //Debug.LogError(Thread.CurrentContext.ContextID+":"+www.url + "----------" + www.assetBundle + " isDone:" + www.isDone + " error:" + www.error + " :" + Time.realtimeSinceStartup); //} while (!www.isDone && (www.error == null || www.error.Equals(""))) { yield return(null); } if (www.error != null) { string info = "www.error != null :" + www.url + " " + www.error; //www.Dispose(); throw new NullReferenceException(info); } else if (www.isDone) { //try { AssetBundle bundleTar = null; //try //{ bundleTar = www.assetBundle; //} //catch //{ // Debug.LogError(www.url + "**1111*" + www + " :" + Time.realtimeSinceStartup); //} string key = www.url; if (bundleTar != null) { AssetBundleDic.Add(key, bundleTar, www.size); } else { Debug.LogError(Thread.CurrentContext.ContextID + ":" + www.url + "**2222*" + www.assetBundle + " isDone:" + www.isDone + " error:" + www.error + " :" + Time.realtimeSinceStartup); // while (true) // { // Debug.LogError(Thread.CurrentContext.ContextID + ":" + "bundleTar != null " + namePreload); // yield return new WaitForSeconds(5.0f); // } throw new NullReferenceException(Thread.CurrentContext.ContextID + ":" + "bundleTar == null :" + key); } //www.Dispose(); } //catch { } } } } } CurNeedPreloadAB.RemoveAt(0); } //AssetBundleRecord.msgTmp.Clear(); } LoadResCor = null; bLoadingRes = false; Debug.Log(Thread.CurrentContext.ContextID + ":Load End" + " :" + Time.realtimeSinceStartup); }