public void compareAssetBundleInfo(string oldfilename, string newContent) { AssetBundleInfoData old = new AssetBundleInfoData(); if(!old.ReadAssetBundleInfoFile (oldfilename)) { Debug.LogWarning( "recreate empty assetinfo.txt" ); recreatEmptyAssetinfo(oldfilename); old.ReadAssetBundleInfoFile (oldfilename); } ReadAssetBundleInfo(newContent); foreach(KeyValuePair<string, AssetBundleInfo> pair in AssetBundleInfos){ pair.Value.isNew = IsNewBundle(pair.Key, old); } }
public int GetDLAllCount(AssetBundleInfoData abid, out int size) { int num = 0; size = 0; foreach (AssetBundleInfo assetBundleInfo in abid.assetBundleInfoList) { uint crc = assetBundleInfo.crc; uint recordCRC = this.GetRecordCRC(abid.abPath, assetBundleInfo.abName); int recordVersion = this.GetRecordVersion(abid.abPath, assetBundleInfo.abName); if (!(this.level != string.Empty) || !(this.level != assetBundleInfo.level.Trim())) { if (recordVersion == -1) { num++; size += int.Parse(assetBundleInfo.size); } else if (recordCRC != crc) { num++; size += int.Parse(assetBundleInfo.size); } else { string url = string.Concat(new object[] { this.GetAssetBundleRootPath(), abid.abPath, assetBundleInfo.abName, ".unity3d?", AssetDataMng.assetVersion }); Hash128 hash = new Hash128(0u, 0u, 0u, (uint)recordVersion); if (!Caching.IsVersionCached(url, hash)) { num++; size += int.Parse(assetBundleInfo.size); } else { Caching.MarkAsUsed(url, hash); } } } } return num; }
private void OnReceivedAssetBundleData(string responseText, string errorText, WWWHelper.TimeOut isTimeOut) { if (!string.IsNullOrEmpty(errorText) || isTimeOut == WWWHelper.TimeOut.YES) { this.www_err_bk = errorText; } else { try { AssetBundleInfoData item = JsonMapper.ToObject <AssetBundleInfoData>(responseText); this.abidList.Add(item); } catch (JsonException ex) { this.www_err_bk = ex.ToString(); } } }
public static void BuildAssetBundles(BuildTarget platform, string infoPath, string objectPath, bool forceBuildAll, AssetBundleInfoData newData, AssetBundleInfoData oldData ) { newData.ClearData(); oldData.ClearData(); //read Asset bundle info file oldData.ReadAssetBundleInfoFile( infoPath ); //gathering all build objects GetbuildObjects(objectPath, newData); //update assetbundle version AssetBundleInfoData.AssetBundleInfo[] AssetBundleInfoForBuild = null; if(forceBuildAll) AssetBundleInfoForBuild = newData.UpdateAll(oldData); else AssetBundleInfoForBuild = newData.UpdateVersion(oldData); //for each updated data, build assetbundle foreach( AssetBundleInfoData.AssetBundleInfo info in AssetBundleInfoForBuild ){ List<Object> objects = new List<Object>(); foreach(string s in info.objs){ objects.Add(newData.AssetObjectInfos[s].obj); } BuildPipeline.BuildAssetBundle(objects[0], objects.ToArray(), infoPath + "/" + info.Name + ".unity3d", BuildAssetBundleOptions.CollectDependencies | BuildAssetBundleOptions.CompleteAssets, platform); } //remember the old Assetbundles foreach(KeyValuePair<string, AssetBundleInfoData.AssetBundleInfo> pair in oldData.AssetBundleInfos){ if(!newData.AssetBundleInfos.ContainsKey(pair.Key)){ newData.AssetBundleInfos.Add(pair.Key, pair.Value); foreach(string s in pair.Value.objs){ if(!newData.AssetObjectInfos.ContainsKey(s)){ newData.AssetObjectInfos.Add( s, oldData.AssetObjectInfos[s] ); } } } } //write info file newData.WriteAssetBundleInfo(infoPath); AssetDatabase.SaveAssets(); AssetDatabase.Refresh(); }
public void DownLoad_AllAssetBundleData(string name, AssetBundleInfoData abid, Action<int> actAllEnd) { if (this.DLAllList.ContainsKey(name)) { global::Debug.LogError("===================================== AssetBundleMng:DownLoad_AllAssetBundleData = " + name + "既にあります!"); } else { AB_DownLoad_ALLInfo ab_DownLoad_ALLInfo = new AB_DownLoad_ALLInfo(); ab_DownLoad_ALLInfo.ABM_Instance = this; ab_DownLoad_ALLInfo.abid = abid; ab_DownLoad_ALLInfo.actEndCallBackAll = actAllEnd; ab_DownLoad_ALLInfo.execFCT = 0; ab_DownLoad_ALLInfo.progressFCT = 0; ab_DownLoad_ALLInfo.progressAll = 0f; ab_DownLoad_ALLInfo.dlFCT = this.GetDLAllCount(abid); ab_DownLoad_ALLInfo.dlFCT_COMP = 0; ab_DownLoad_ALLInfo.bIsAllEnd = false; ab_DownLoad_ALLInfo.cur_abdlI = this.DownLoad_OneAssetBundleData(ab_DownLoad_ALLInfo.abid.name, ab_DownLoad_ALLInfo.abid.ver, ab_DownLoad_ALLInfo.abid.abPath, ab_DownLoad_ALLInfo.abid.assetBundleInfoList[ab_DownLoad_ALLInfo.execFCT++], new Action<AssetBundle, AB_DownLoadInfo>(ab_DownLoad_ALLInfo.EndCallBackOne), false); this.DLAllList.Add(name, ab_DownLoad_ALLInfo); } }
public override void OnInspectorGUI() { base.OnInspectorGUI(); AssetBundleBuilder myTarget = (AssetBundleBuilder)target; bool rdyForBuild = true; bool bOk = false; if (GUILayout.Button("select resource path")) { string tempPath = EditorUtility.OpenFolderPanel("select an resource folder", "./", "*.*"); int idx = tempPath.LastIndexOf("Assets"); if(idx < 0) Debug.LogError("please select a folder in unity project"); else myTarget.ResourcePath = tempPath.Substring(idx+6, tempPath.Length-idx-6) + "/"; } if (GUILayout.Button("Generate Packs")) { myTarget.GeneratePacks(); } GUI.color = ( bOk = (!System.String.IsNullOrEmpty(myTarget.FromPath)) )? Color.green : Color.red; rdyForBuild = rdyForBuild && bOk; if (GUILayout.Button("select folder to build from")) { string tempPath = EditorUtility.OpenFolderPanel("select an asset folder", "./", "*.*"); int idx = tempPath.LastIndexOf("Assets"); if(idx < 0) Debug.LogError("please select a folder in unity project"); else myTarget.FromPath = tempPath.Substring(idx, tempPath.Length-idx) + "/"; } GUI.color = ( bOk = (!System.String.IsNullOrEmpty(myTarget.BuiltPath)) )? Color.green : Color.red; rdyForBuild = rdyForBuild && bOk; if (GUILayout.Button("select folder for desination")) { string tempPath = EditorUtility.OpenFolderPanel("select an asset folder", "./", "*.*"); int idx = tempPath.LastIndexOf("Assets"); if(idx < 0) Debug.LogError("please select a folder in unity project"); else myTarget.BuiltPath = tempPath.Substring(idx, tempPath.Length-idx) + "/"; } GUI.color = rdyForBuild ? Color.green : Color.red; if (GUILayout.Button("Build Asset Bundle")) { buildByPlatform(false); } GUI.color = rdyForBuild ? Color.green : Color.red; if (GUILayout.Button("Force Build All")) { buildByPlatform(true); } if(GUILayout.Button("View AssetBundleInfo") && myTarget.assetBundleInfo != null) { AssetBundleInfoData data = new AssetBundleInfoData(); myTarget.AssetBundleInfos = new List<AssetBundleInfoData.AssetBundleInfo>(); myTarget.AssetObjectInfos = new List<AssetBundleInfoData.AssetObjectInfo>(); data.ReadAssetBundleInfo( myTarget.assetBundleInfo.text ); foreach( KeyValuePair< string, AssetBundleInfoData.AssetBundleInfo > pair in data.AssetBundleInfos) { myTarget.AssetBundleInfos.Add( pair.Value ); } foreach( KeyValuePair< string, AssetBundleInfoData.AssetObjectInfo > pair in data.AssetObjectInfos) { myTarget.AssetObjectInfos.Add( pair.Value ); } myTarget.version = data.version; } }
public static void AddBuildObject(string ObjectName, string PackName, Object obj, AssetBundleInfoData data) { data.AddAssetObjectInfo(ObjectName, PackName, obj); }
public static void GetbuildObjects(string Frompath, AssetBundleInfoData data) { string[] paths = Directory.GetFiles(Frompath, "*.prefab"); //add Object info foreach( string s in paths ){ int idx = s.LastIndexOf("Assets"); GameObject pref = AssetDatabase.LoadAssetAtPath(s.Substring(idx, s.Length-idx), typeof(Object)) as GameObject; AssetBundlePack pack = pref.GetComponent<AssetBundlePack>(); if(pack != null){ foreach(Object obj in pack.objects){ AddBuildObject( obj.name, pack.name, obj, data ); } } else{ AddBuildObject( pref.name, pref.name, pref, data ); } } }
public bool LoadObjectASync(AssetBundleInfoData abid, string resourceName, Action<UnityEngine.Object> actEnd) { AssetBundleMng.<LoadObjectASync>c__AnonStorey7 <LoadObjectASync>c__AnonStorey = new AssetBundleMng.<LoadObjectASync>c__AnonStorey7();
public int GetDLAllCount(AssetBundleInfoData abid) { int num = 0; return this.GetDLAllCount(abid, out num); }
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; }
bool IsNewBundle(string bundleName, AssetBundleInfoData old) { if(!old.AssetBundleInfos.ContainsKey(bundleName)){ //Debug.LogError("NewAssetBundle: " + bundleName); return true; } else if(!AssetBundleInfos.ContainsKey(bundleName)) return false; else if(old.AssetBundleInfos[bundleName].version < AssetBundleInfos[bundleName].version){ //Debug.LogError("UpdateAssetBundle: " + bundleName + " ver " + AssetBundleVersionBefore[bundleName].ToString() + "--->" +AssetBundleInfos[bundleName].version); return true; } return false; }
public AssetBundleInfo[] UpdateVersion(AssetBundleInfoData prevData) { List<AssetBundleInfo> UpdatedAssetbundle = new List<AssetBundleInfo>(); foreach(KeyValuePair<string, AssetBundleInfo> pair in AssetBundleInfos){ if(prevData.AssetBundleInfos.ContainsKey(pair.Key)){ AssetBundleInfo info2 = prevData.AssetBundleInfos[pair.Key]; if(!AssetBundleInfo.checkEqual(this, pair.Value, prevData, info2)){ pair.Value.version = info2.version + 1; UpdatedAssetbundle.Add(pair.Value); } else pair.Value.version = info2.version; } else UpdatedAssetbundle.Add(pair.Value); } foreach(KeyValuePair<string, AssetObjectInfo> pair in AssetObjectInfos){ if(prevData.AssetObjectInfos.ContainsKey(pair.Key)){ AssetObjectInfo info2 = prevData.AssetObjectInfos[pair.Key]; if(pair.Value != info2){ pair.Value.version = info2.version +1; } else pair.Value.version = info2.version; } } if(UpdatedAssetbundle.Count > 0) version = prevData.version + 1; return UpdatedAssetbundle.ToArray(); }
public AssetBundleInfo[] UpdateAll(AssetBundleInfoData prevData) { foreach(KeyValuePair<string, AssetBundleInfo> pair in AssetBundleInfos){ if(prevData.AssetBundleInfos.ContainsKey(pair.Key)){ pair.Value.version = prevData.AssetBundleInfos[pair.Key].version + 1; } } foreach(KeyValuePair<string, AssetObjectInfo> pair in AssetObjectInfos){ if(prevData.AssetObjectInfos.ContainsKey(pair.Key)){ pair.Value.version = prevData.AssetObjectInfos[pair.Key].version + 1; } } version = prevData.version + 1; return AssetBundleInfos.Values.ToArray(); }