public void SaveConfig(string strFilePath) { using (StreamWriter sw = new StreamWriter(strFilePath, false, CommonFunc.GetCharsetEncoding())) { foreach (KeyValuePair <string, SortedDictionary <int, List <DependencyAsset> >[]> curSection in m_ConfigData) { string strContent = "[" + curSection.Key + "]"; sw.WriteLine(strContent); StringBuilder sb = new StringBuilder(); sb.Append("\t"); for (AssetBundleType s = AssetBundleType.Texture; s < AssetBundleType.Max; ++s) { SortedDictionary <int, List <DependencyAsset> > textureData = GetSubData(curSection.Value, s); if (textureData.Count > 0) { sb.Append(s + ":"); foreach (KeyValuePair <int, List <DependencyAsset> > kvp in textureData) { foreach (DependencyAsset dasset in kvp.Value) { sb.Append(kvp.Key + "=" + dasset.AssetName); sb.Append(","); } } sb.Append(";"); } } sw.WriteLine(sb.ToString()); } sw.Close(); } }
public void AddConfig(string sectionName, AssetBundleType subType, string assetName, int assetIndex) { SortedDictionary <int, List <DependencyAsset> >[] sectionData = GetSection(sectionName); if (sectionData != null) { SortedDictionary <int, List <DependencyAsset> > subData = GetSubData(sectionData, subType); if (subData != null) { DependencyAsset dasset = new DependencyAsset(); dasset.AssetName = assetName; dasset.AssetType = subType; dasset.Depth = assetIndex; if (subData.ContainsKey(assetIndex)) { subData[assetIndex].Add(dasset); } else { subData.Add(assetIndex, new List <DependencyAsset>() { dasset }); } } } }
public SortedDictionary <int, List <DependencyAsset> > GetConfig(string sectionName) { SortedDictionary <int, List <DependencyAsset> > map = new SortedDictionary <int, List <DependencyAsset> >(); for (AssetBundleType arType = AssetBundleType.Texture; arType < AssetBundleType.Max; ++arType) { SortedDictionary <int, List <DependencyAsset> > subMap = GetConfig(sectionName, arType); if (subMap != null) { foreach (int assetIndex in subMap.Keys) { List <DependencyAsset> list = subMap[assetIndex]; if (map.ContainsKey(assetIndex)) { map[assetIndex].AddRange(list); } else { map.Add(assetIndex, list); } } } } return(map); }
public void Read(BinaryReader reader) { fullName = reader.ReadString(); shortName = reader.ReadString(); size = reader.ReadInt32(); hash = reader.ReadString(); type = ( AssetBundleType)reader.ReadInt32(); int assetsCount = reader.ReadInt32(); assets = new List <AssetInfo>(); for (int i = 0; i < assetsCount; ++i) { AssetInfo assetInfo = new AssetInfo(); assetInfo.fullName = reader.ReadString(); assetInfo.aliasName = reader.ReadString(); assets.Add(assetInfo); } int dependencyCount = reader.ReadInt32(); List <string> dependencyNames = new List <string>(); for (int i = 0; i < dependencyCount; ++i) { dependencyNames.Add(reader.ReadString()); } dependencies = dependencyNames.ToArray(); }
/// <summary> /// 获取文件类型 /// </summary> public static AssetBundleType GetAssetType(string assetPath) { AssetBundleType arType = AssetBundleType.Max; if (IsImageFile(assetPath)) { arType = AssetBundleType.Texture; } else if (IsSoundFile(assetPath)) { arType = AssetBundleType.Sound; } else if (IsPrefabFile(assetPath)) { arType = AssetBundleType.Pre; } else if (IsFBXFile(assetPath)) { arType = AssetBundleType.Model; } else if (IsScriptFile(assetPath)) { arType = AssetBundleType.Script; } else if (IsScriptDLLFile(assetPath)) { arType = AssetBundleType.ScriptDLL; } else if (IsMatFile(assetPath)) { arType = AssetBundleType.Material; } else if (IsAnimationFile(assetPath)) { arType = AssetBundleType.Animation; } else if (IsShaderFile(assetPath)) { arType = AssetBundleType.Shd; } else if (IsSceneFile(assetPath)) { arType = AssetBundleType.Scene; } else if (IsMetaFile(assetPath)) { //Ignore this type file } else if (IsAssetFile(assetPath)) { arType = AssetBundleType.Asset; } else { Debug.LogError("UnKnown asset Type, assetPath=" + assetPath); } return(arType); }
public static Sprite LoadIconAsset(AssetBundleType assetBundleType, int iconFileDataID) { if (iconFileDataID == 894556) { string locale = Main.instance.GetLocale(); if (locale != "enUS") { return(Resources.Load <Sprite>("MiscIcons/LocalizedIcons/" + locale + "/XP_Icon")); } } if (iconFileDataID == 1380306) { return(Resources.Load <Sprite>("MissionMechanicEffects/MechanicIcon-Curse-Shadow")); } if (iconFileDataID == 1383683) { return(Resources.Load <Sprite>("MissionMechanicEffects/MechanicIcon-Disorienting-Shadow")); } if (iconFileDataID == 1383682) { return(Resources.Load <Sprite>("MissionMechanicEffects/MechanicIcon-Lethal-Shadow")); } if (iconFileDataID == 1390116) { return(Resources.Load <Sprite>("MissionMechanicEffects/MechanicIcon-Powerful-Shadow")); } if (iconFileDataID == 1383681) { return(Resources.Load <Sprite>("MissionMechanicEffects/MechanicIcon-Slowing-Shadow")); } int mobileAtlasMemberOverride = GeneralHelpers.GetMobileAtlasMemberOverride(iconFileDataID); if (mobileAtlasMemberOverride > 0) { return(TextureAtlas.instance.GetAtlasSprite(mobileAtlasMemberOverride)); } AssetBundle assetBundle = null; string text = string.Empty; if (assetBundleType == AssetBundleType.Icons) { text = "Assets/BundleAssets/Icons/"; assetBundle = AssetBundleManager.Icons; } if (assetBundleType == AssetBundleType.PortraitIcons) { text = "Assets/BundleAssets/PortraitIcons/"; assetBundle = AssetBundleManager.portraitIcons; } string text2 = text + iconFileDataID + ".tga"; Sprite sprite = assetBundle.LoadAsset <Sprite>(text2); if (sprite == null) { text2 = text + iconFileDataID + ".png"; sprite = assetBundle.LoadAsset <Sprite>(text2); } return(sprite); }
public static Sprite LoadIconAsset(AssetBundleType assetBundleType, int iconFileDataID) { if (iconFileDataID == 894556) { string locale = Main.instance.GetLocale(); return(Resources.Load <Sprite>(string.Concat("MiscIcons/LocalizedIcons/", locale, "/XP_Icon"))); } if (iconFileDataID == 1380306) { return(Resources.Load <Sprite>("MissionMechanicEffects/MechanicIcon-Curse-Shadow")); } if (iconFileDataID == 1383683) { return(Resources.Load <Sprite>("MissionMechanicEffects/MechanicIcon-Disorienting-Shadow")); } if (iconFileDataID == 1383682) { return(Resources.Load <Sprite>("MissionMechanicEffects/MechanicIcon-Lethal-Shadow")); } if (iconFileDataID == 1390116) { return(Resources.Load <Sprite>("MissionMechanicEffects/MechanicIcon-Powerful-Shadow")); } if (iconFileDataID == 1383681) { return(Resources.Load <Sprite>("MissionMechanicEffects/MechanicIcon-Slowing-Shadow")); } int mobileAtlasMemberOverride = GeneralHelpers.GetMobileAtlasMemberOverride(iconFileDataID); if (mobileAtlasMemberOverride > 0) { return(TextureAtlas.instance.GetAtlasSprite(mobileAtlasMemberOverride)); } AssetBundle icons = null; string empty = string.Empty; if (assetBundleType == AssetBundleType.Icons) { empty = "Assets/BundleAssets/Icons/"; icons = AssetBundleManager.Icons; } if (assetBundleType == AssetBundleType.PortraitIcons) { empty = "Assets/BundleAssets/PortraitIcons/"; icons = AssetBundleManager.PortraitIcons; } string str = string.Concat(empty, iconFileDataID, ".tga"); Sprite sprite = icons.LoadAsset <Sprite>(str); if (sprite == null) { str = string.Concat(empty, iconFileDataID, ".png"); sprite = icons.LoadAsset <Sprite>(str); } return(sprite); }
/// <summary> /// 修复文件后缀 /// </summary> /// <param name="iFilePath">文件路径</param> /// <param name="iAssetType">Asset类型</param> /// <exception cref="ArgumentOutOfRangeException"></exception> /// <returns>修复后的文件路径(带文件后缀)</returns> public static string FixedFileSunffix(string iFilePath, AssetBundleType iAssetType) { var lastIndex1 = iFilePath.LastIndexOf("/", StringComparison.Ordinal); var lastIndex2 = iFilePath.LastIndexOf(".", StringComparison.Ordinal); if (lastIndex1 < lastIndex2) { return(iFilePath); } switch (iAssetType) { case AssetBundleType.Prefab: iFilePath += FileSunffixPrefab; break; case AssetBundleType.Audio: iFilePath += FileSunffixAudioWav; break; case AssetBundleType.Mat: iFilePath += FileSunffixMat; break; case AssetBundleType.SpriteTexture: iFilePath += FileSunffixTexturePng; break; case AssetBundleType.SpriteAtlas: iFilePath += FileSunffixSpriteatlas; break; case AssetBundleType.Asset: iFilePath += FileSunffixAsset; break; case AssetBundleType.Txt: iFilePath += FileSunffixTxt; break; case AssetBundleType.Json: iFilePath += FileSunffixJson; break; case AssetBundleType.Scene: iFilePath += FileSunffixScene; break; case AssetBundleType.None: break; default: throw new ArgumentOutOfRangeException("iAssetType", actualValue: iAssetType, message: null); } return(iFilePath); }
AssetBundleType GetSubType(string curline) { for (AssetBundleType s = AssetBundleType.Texture; s < AssetBundleType.Max; ++s) { if (curline.StartsWith(s.ToString())) { return(s); } } return(AssetBundleType.Max); }
public UniGameResourcesPackage(XmlNode node) : base() { packageName = node.Attribute("name"); packageId = UniGameResources.PackageNameToIdPackage(packageName); packagePath = node.Attribute("path"); packageLocalVersion = 0; packageRealVersion = Convert.ToInt32(node.Attribute("version")); packageLocalSize = 0; packageRealSize = Convert.ToInt64(node.Attribute("size")); existType = (ResourcesPackageExistType)Convert.ToInt32(node.Attribute("existtype")); assetBundleType = (AssetBundleType)Convert.ToInt32(node.Attribute("type")); inventoryFileName = node.Attribute("inventoryFileName"); }
public static void InitUIWndLoader(string assetDir, string assetWWWDir, string inAssetDir, string inAssetWWWDir, string netAssetDir) { for (AssetBundleType arType = AssetBundleType.Texture; arType < AssetBundleType.Max; ++arType) { AssetLoader textureLoader = new AssetLoader(); textureLoader.InitLoader( "UIWndLoader_" + arType.ToString(), assetWWWDir + arType + "/", assetDir + arType + "/", inAssetWWWDir + arType + "/", inAssetDir + arType + "/", netAssetDir + arType + "/", "." + arType.ToString().ToLower()); uiwndloader.m_AssetLoaderMap.Add(arType, textureLoader); } }
void ReleaseWndAsset(string wndName, AssetBundleConfig config) { for (AssetBundleType arType = AssetBundleType.Texture; arType < AssetBundleType.Max; ++arType) { SortedDictionary <int, List <DependencyAsset> > textureData = config.GetConfig(wndName, arType); if (textureData != null) { if (m_AssetLoaderMap.ContainsKey(arType)) { foreach (List <DependencyAsset> list in textureData.Values) { foreach (DependencyAsset dasset in list) { m_AssetLoaderMap[arType].ReleaseAsset(dasset.AssetName, null, true); } } } } } }
SortedDictionary <int, List <DependencyAsset> >[] GetSection(string sectionName) { SortedDictionary <int, List <DependencyAsset> >[] sectionData = null; if (m_ConfigData.ContainsKey(sectionName)) { sectionData = m_ConfigData[sectionName]; } else { sectionData = new SortedDictionary <int, List <DependencyAsset> > [(int)AssetBundleType.Max]; for (AssetBundleType s = AssetBundleType.Texture; s < AssetBundleType.Max; ++s) { sectionData[(int)s] = new SortedDictionary <int, List <DependencyAsset> >(); } m_ConfigData.Add(sectionName, sectionData); } return(sectionData); }
/// <summary> /// 获取指定资源 /// </summary> static void BuildAssetList(string dirPath, List <string> fileList, AssetBundleType assetType) { string[] fileArr = Directory.GetFiles(dirPath); foreach (string filePath in fileArr) { if (BuildAssetBundle.GetAssetType(filePath) == assetType) { fileList.Add(filePath); } } string[] dirArr = Directory.GetDirectories(dirPath); foreach (string dir in dirArr) { if (!dir.Contains("/.")) { BuildAssetList(dir, fileList, assetType); } } }
void CancelBundle() { bundleName = ""; mainAssetName = ""; relatedAssetName = ""; materialShader = null; if (backupDirectRelatedAsset == null) { bundleType = AssetBundleType.None; return; } MeshRenderer renderer = GetComponent <MeshRenderer>(); Image image = GetComponent <Image>(); switch (bundleType) { case AssetBundleType.MaterialTexturePair: if (renderer != null) { renderer.sharedMaterial = backupDirectRelatedAsset as Material; } break; case AssetBundleType.UISprite: if (image != null) { image.sprite = backupDirectRelatedAsset as Sprite; } break; default: break; } backupDirectRelatedAsset = null; bundleType = AssetBundleType.None; }
/// <summary> /// 获取指定资源 /// </summary> static void BuildAssetList(string dirPath, List <string> fileList, AssetBundleType assetType, string filterAsset) { string[] filters = filterAsset.Split(';'); string[] fileArr = Directory.GetFiles(dirPath); foreach (string filePath in fileArr) { if (BuildAssetBundle.GetAssetType(filePath) == assetType) { if (string.IsNullOrEmpty(filterAsset)) { fileList.Add(filePath); } else { foreach (string filter in filters) { if (filePath.Contains(filter)) { fileList.Add(filePath); break; } } } } } string[] dirArr = Directory.GetDirectories(dirPath); foreach (string dir in dirArr) { if (!dir.Contains("/.")) { BuildAssetList(dir, fileList, assetType, filterAsset); } } }
static void ProcEnchantEffect_File(string filePath, string dirPath, string destParentPath, List <string> shdList) { GameObject effectPrefab = AssetDatabase.LoadMainAssetAtPath(dirPath) as GameObject; if (effectPrefab == null) { Debug.Log(dirPath); return; } string bundleName = effectPrefab.name; List <GameObject> particallist = new List <GameObject>(); Dictionary <string, DependencyAsset> allAssetBundleMap = new Dictionary <string, DependencyAsset>(); //记录所有已经打包的Asset GameObject rendererClone = (GameObject)PrefabUtility.InstantiatePrefab(effectPrefab); for (int i = rendererClone.transform.childCount - 1; i >= 0; --i) { Transform childTran = rendererClone.transform.GetChild(i); if (childTran.name.Contains("Bip01")) { FindParticalFromBonse(particallist, childTran); break; } } Object rendererPrefab = null; string effectAssetPath = string.Empty; if (bundleName.Contains("group")) { rendererPrefab = GenerateResource.ReplacePrefab(rendererClone, rendererClone.name); } else { GameObject effectRoot = new GameObject(); effectRoot.name = bundleName; foreach (GameObject p in particallist) { GameObject gParent = new GameObject(GetTransfromPathName(p.transform.parent)); gParent.transform.position = p.transform.parent.position; gParent.transform.rotation = p.transform.parent.rotation; gParent.transform.localScale = Vector3.one; p.transform.parent = gParent.transform; gParent.transform.parent = effectRoot.transform; } rendererPrefab = GenerateResource.ReplacePrefab(effectRoot, effectRoot.name); } effectAssetPath = AssetDatabase.GetAssetPath(rendererPrefab); AssetDatabase.Refresh(); //刷新 AssetDatabase.SaveAssets(); //保存 AssetBundleConfig modeConfig = new AssetBundleConfig(); Dictionary <string, List <DependencyAsset> > allAssetRefs = BuildAssetBundle.GetAssetDependencieRefs((new List <string>() { effectAssetPath }).ToArray()); string dirName = bundleName; //打包依赖资源 foreach (string modePath in allAssetRefs.Keys) { string modeName = BuildAssetBundle.GetAssetName(modePath); List <DependencyAsset> depList = allAssetRefs[modePath]; for (int i = 0; i < depList.Count; ++i) { List <Object> includeList = new List <Object>(); DependencyAsset dasset = depList[i]; AssetBundleType arType = dasset.AssetType; string assetName = dasset.AssetName; string assetFullName = dasset.AssetName + "." + dasset.AssetSuffix; string assetPath = dasset.AssetPath; string bundleParentPath = destParentPath + arType + "/"; string bundlePath = bundleParentPath + assetName + "." + arType.ToString().ToLower(); if (modePath.Equals(assetPath)) { //重新改变路径 bundleParentPath = destParentPath + assetName + "/"; bundlePath = bundleParentPath + assetName + ".enceff"; } else { //忽略原始FBX或者Prefab文件,也忽略了最终需要生成的FBX或Prefab if (arType == AssetBundleType.Pre) { continue; } if (arType == AssetBundleType.Shd && shdList.Contains(assetFullName)) { continue; } modeConfig.AddConfig(modeName, arType, assetName, i); } if (!allAssetBundleMap.ContainsKey(assetName)) { if (!Directory.Exists(bundleParentPath)) { Directory.CreateDirectory(bundleParentPath); } if (modePath.Equals(assetPath)) { BuildPipeline.PushAssetDependencies(); } if (arType == AssetBundleType.Shd) { BuildShaderExtend.GenerateShaderExtend(assetPath, dasset.IsLeaf); } else { if (!BuildAssetBundle.IsLegalAsset(assetName)) { string errorTips = string.Format("Generate enchant effect warning, asset name is not all lower,FileName is {0},AssetName is {1}", dirName, assetPath); Debug.LogError(errorTips); EditorUtility.DisplayDialog("Error", errorTips + "Please try again!", "OK"); return; } Object obj = AssetDatabase.LoadAssetAtPath(assetPath, typeof(Object)); includeList.Add(obj); BuildAssetBundle.Build(obj, includeList.ToArray(), bundlePath, dasset.IsLeaf); if (modePath.Equals(assetPath)) { BuildPipeline.PopAssetDependencies(); } allAssetBundleMap.Add(assetName, dasset); } } else { DependencyAsset usedAsset = allAssetBundleMap[assetName]; if (usedAsset.AssetType != arType) { Debug.LogError("Build EnchantEffect error, same asset name has been found.AssetName=" + assetPath + "," + usedAsset.AssetPath); } } } } if (!Directory.Exists(destParentPath + dirName)) { Directory.CreateDirectory(destParentPath + dirName); } string configDirPath = destParentPath + dirName + "/" + bundleName + ".txt"; modeConfig.SaveConfig(configDirPath); //删除临时资源 AssetDatabase.DeleteAsset(effectAssetPath); GameObject.DestroyImmediate(rendererClone); }
/// <summary> /// Build bundle for this gameobject texture or material /// </summary> /// <returns></returns> void BuildBundle() { MeshRenderer renderer = GetComponent <MeshRenderer>(); Image image = GetComponent <Image>(); //prepare direct related asset if (renderer != null) { bundleType = AssetBundleType.MaterialTexturePair; backupDirectRelatedAsset = renderer.sharedMaterial; renderer.sharedMaterial = Resources.Load <Material>("DefaultMaterial"); } else if (image != null && image.sprite != null) { bundleType = AssetBundleType.UISprite; backupDirectRelatedAsset = image.sprite; image.sprite = null; } else { bundleType = AssetBundleType.None; return; } relatedAssetName = backupDirectRelatedAsset.name; //Get main asset name Object mainAsset = null; switch (bundleType) { case AssetBundleType.MaterialTexturePair: mainAsset = (backupDirectRelatedAsset as Material).mainTexture; break; case AssetBundleType.UISprite: mainAsset = backupDirectRelatedAsset; break; default: break; } if (mainAsset == null) { return; } var bundleDescriptor = SearchBundleDescriptor(mainAsset); mainAssetName = mainAsset.name; //Has been marked as bundle before if (bundleDescriptor != null) { bundleName = bundleDescriptor.bundleName; if (bundleType == AssetBundleType.MaterialTexturePair) { materialShader = (bundleDescriptor.relatedAssets[0] as Material).shader; } bundleDescriptor.relatedAssets.Add(backupDirectRelatedAsset); return; } else { // Create the array of bundle build details. List <string> assetNames = new List <string>(); switch (bundleType) { case AssetBundleType.MaterialTexturePair: bundleName = "materialtexturepair-" + mainAssetName + "-" + bundleBuildIndex.ToString(); assetNames.Add(AssetDatabase.GetAssetPath(backupDirectRelatedAsset)); materialShader = (backupDirectRelatedAsset as Material).shader; break; case AssetBundleType.UISprite: bundleName = "uisprite-" + mainAssetName + "-" + bundleBuildIndex.ToString(); assetNames.Add(AssetDatabase.GetAssetPath(backupDirectRelatedAsset)); break; default: break; } bundleDescriptor = new BundleDescriptor(); bundleDescriptor.bundleName = bundleName; bundleDescriptor.mainAsset = mainAsset; bundleDescriptor.relatedAssets.Add(backupDirectRelatedAsset); bundleDescriptors.Add(bundleDescriptor); bundleBuildIndex++; } }
/// <summary> /// 解析数据; /// </summary> private void ParseConfig(StreamReader sr) { string strLine = null; char[] trimEnd = { ' ', '\r', '\n', '\t' }; SortedDictionary <int, List <DependencyAsset> >[] sectionData = null; SortedDictionary <int, List <DependencyAsset> > subData = null; while ((strLine = sr.ReadLine()) != null) { strLine = strLine.Trim(trimEnd); if (IsSection(ref strLine)) { sectionData = GetSection(strLine); } else { string[] contentArr = strLine.Split(';'); if (contentArr == null) { continue; } int contentLength = contentArr.Length; for (int i = 0; i < contentLength; ++i) { string content = contentArr[i]; if (string.IsNullOrEmpty(content)) { //去除空字符串 continue; } //解析Texture:1=t_texture_1 string[] allAssetArr = content.Split(':'); if (allAssetArr == null || allAssetArr.Length != 2) { //长度必须为2 continue; } AssetBundleType assetType = GetSubType(allAssetArr[0]); subData = GetSubData(sectionData, assetType); if (subData == null) { continue; } //解析1=t_texture_3,2=t_texture_2_a string[] assetArr = allAssetArr[1].Split(','); if (assetArr == null) { continue; } int assetLength = assetArr.Length; for (int j = 0; j < assetLength; ++j) { string asset = assetArr[j]; if (string.IsNullOrEmpty(asset)) { continue; } string[] itemArr = asset.Split('='); if (itemArr == null || itemArr.Length != 2) { Debug.LogError("Load assetBundle error," + content); continue; } int assetIndex = 0; bool indexFlag = int.TryParse(itemArr[0].Trim(trimEnd), out assetIndex); string assetName = itemArr[1].Trim(trimEnd);; if (!indexFlag) { Debug.LogWarning("Load uiconfig filed warning, Invailde asset index," + assetName); } DependencyAsset dasset = new DependencyAsset(); dasset.AssetName = assetName; dasset.AssetType = assetType; dasset.Depth = assetIndex; if (subData.ContainsKey(assetIndex)) { subData[assetIndex].Add(dasset); } else { subData.Add(assetIndex, new List <DependencyAsset>() { dasset }); } } } } } }
SortedDictionary <int, List <DependencyAsset> > GetSubData(SortedDictionary <int, List <DependencyAsset> >[] sectionData, AssetBundleType subType) { if (sectionData != null) { if (subType >= 0 && (int)subType < sectionData.Length) { return(sectionData[(int)subType]); } } return(null); }
public static void ProcUIScene(List <string> specialList, List <string> uiScenePrefabList, List <string> prefabList) { AssetBundleConfig uiConfig = new AssetBundleConfig(); //UI配置文件 AssetBundleConfig prefabConfig = new AssetBundleConfig(); //动态Prefab配置文件 Dictionary <string, AssetBundleType> allAssetBundleMap = new Dictionary <string, AssetBundleType>(); //记录所有打包的Asset List <string> comAssetList = new List <string>(); //记录所有公共资源 List <string> ignoreBundleList = new List <string>(); //需要删除的资源 #if PACKAGE_BASIC //添加小包过滤操作 Dictionary <string, string> extendAssetMap = new Dictionary <string, string>(); List <string> basicAssetList = new List <string>(); #endif //开始打包资源 BuildPipeline.PushAssetDependencies(); //打包部分指定Shader List <string> shdList = BuildShader.BuildAllShader("all"); //打包Special Texture foreach (string texturePath in specialList) { string sTemp = texturePath.Replace('\\', '/'); int startIndex = sTemp.LastIndexOf('/') + 1; int endIndex = sTemp.LastIndexOf('.') - 1; string textureName = sTemp.Substring(startIndex, endIndex - startIndex + 1); if (!allAssetBundleMap.ContainsKey(textureName)) { string parentPath = GetParentPath(texturePath); if (!Directory.Exists(parentPath)) { Directory.CreateDirectory(parentPath); } if (!BuildAssetBundle.IsLegalAsset(textureName)) { Debug.LogError("Build ui error, asset name is not all lower," + texturePath); EditorUtility.DisplayDialog("Error", "Build ui error, asset name is not all lower,Please try again!" + texturePath, "OK"); return; } Texture2D tex2D = AssetDatabase.LoadAssetAtPath(texturePath, typeof(Texture2D)) as Texture2D; string path = parentPath + textureName + "." + AssetBundleType.Texture.ToString().ToLower(); BuildAssetBundle.Build(tex2D, null, path, true); allAssetBundleMap.Add(textureName, AssetBundleType.Texture); } } //获取依赖关系 Dictionary <string, List <DependencyAsset> > prefabAssetRefMap = BuildAssetBundle.GetAssetDependencieRefs(prefabList.ToArray()); //获取动态Prefab依赖关系 Dictionary <string, List <DependencyAsset> > uiAssetRefMap = BuildAssetBundle.GetAssetDependencieRefs(uiScenePrefabList.ToArray()); //获取UI依赖关系 Dictionary <string, List <DependencyAsset> > allAssetRefMap = new Dictionary <string, List <DependencyAsset> >(uiAssetRefMap); if (prefabAssetRefMap != null && prefabAssetRefMap.Count > 0) { foreach (string prefabPath in prefabAssetRefMap.Keys) { if (!allAssetRefMap.ContainsKey(prefabPath)) { allAssetRefMap.Add(prefabPath, prefabAssetRefMap[prefabPath]); } } } //排序 List <string> allAssetRefKeyList = null; if (allAssetRefMap != null && allAssetRefMap.Count > 0) { allAssetRefKeyList = new List <string>(allAssetRefMap.Keys); allAssetRefKeyList.Sort(new UICompare()); } //获取所有脚本 if (allAssetRefKeyList != null && allAssetRefKeyList.Count > 0) { foreach (string uiscenePath in allAssetRefKeyList) { List <DependencyAsset> val = allAssetRefMap[uiscenePath]; foreach (DependencyAsset dasset in val) { string sceneDepPath = dasset.AssetPath; AssetBundleType assetType = dasset.AssetType; if (assetType == AssetBundleType.Script) { if (!comAssetList.Contains(sceneDepPath)) { comAssetList.Add(sceneDepPath); } } else if (assetType == AssetBundleType.ScriptDLL) { string dllPath = AssetBundlePath.DLLPrefabAssetDir + dasset.AssetName + ".prefab"; if (File.Exists(dllPath)) { if (!comAssetList.Contains(dllPath)) { comAssetList.Add(dllPath); } } else { Debug.LogError("Build UI failed. Can not find dll file prefab, path=" + dllPath); } } } } } //打包公共资源 if (comAssetList != null && comAssetList.Count > 0) { //创建界面目录 string comParentPath = AssetBundlePath.UIAssetRootPath + AssetBundleType.Scene + "/"; //场景目录 if (!Directory.Exists(comParentPath)) { Directory.CreateDirectory(comParentPath); } List <Object> comObjectList = new List <Object>(); for (int i = 0; i < comAssetList.Count; ++i) { comObjectList.Add(AssetDatabase.LoadAssetAtPath(comAssetList[i], typeof(Object))); } BuildAssetBundle.Build(null, comObjectList.ToArray(), comParentPath + "ui_common" + "." + AssetBundleType.Scene.ToString().ToLower(), true); comObjectList.Clear(); } //打包其他资源 if (allAssetRefKeyList != null && allAssetRefKeyList.Count > 0) { foreach (string rootAssetPath in allAssetRefKeyList) { AssetBundleConfig bundleConfig = null; string rootAssetName = BuildAssetBundle.GetAssetName(rootAssetPath); AssetBundleType rootAssetType = BuildAssetBundle.GetAssetType(rootAssetPath); //确定配置文件 if (uiScenePrefabList.Contains(rootAssetPath)) { bundleConfig = uiConfig; } else if (prefabList.Contains(rootAssetPath)) { bundleConfig = prefabConfig; } else { Debug.LogError("Build ui error, can not find current assetType," + rootAssetType + "," + rootAssetPath); } List <DependencyAsset> depList = allAssetRefMap[rootAssetPath]; for (int i = 0; i < depList.Count; ++i) { DependencyAsset dasset = depList[i]; AssetBundleType arType = dasset.AssetType; string assetName = dasset.AssetName; string assetFullName = dasset.AssetName + "." + dasset.AssetSuffix; string assetPath = dasset.AssetPath; string bundleParentPath = AssetBundlePath.UIAssetRootPath + arType + "/"; string bundlePath = bundleParentPath + assetName + "." + arType.ToString().ToLower(); bool popDependence = false; if (arType == AssetBundleType.Max) { Debug.LogError("BuildUI error, unSupport assetBundle," + rootAssetPath); } if (IgnoreAssetList.Contains(assetFullName)) { if (!ignoreBundleList.Contains(bundlePath)) { ignoreBundleList.Add(bundlePath); } } else { if (rootAssetName.Equals(assetName)) { popDependence = true; } else if (dasset.IsLeaf || assetPath.Replace('\\', '/').Contains(AssetBundlePath.ArtUIDir)) { if (arType == AssetBundleType.Script || arType == AssetBundleType.ScriptDLL) { continue; } else if (arType == AssetBundleType.Shd && shdList.Contains(assetFullName)) { //忽略已经打包的Shader,此操作为了兼容旧版本 continue; } } else { continue; } bundleConfig.AddConfig(rootAssetName, arType, assetName, i); } if (!allAssetBundleMap.ContainsKey(assetName)) { if (!BuildAssetBundle.IsLegalAsset(assetName)) { Debug.LogError("Build ui error, asset name is not all lower," + assetPath); EditorUtility.DisplayDialog("Error", "Build ui error, asset name is not all lower,Please try again!" + assetPath, "OK"); return; } BuildBundle(assetPath, bundleParentPath, bundlePath, dasset.IsLeaf, popDependence); allAssetBundleMap.Add(assetName, arType); #if PACKAGE_BASIC //记录扩展包资源 if (IsExtendPackageScene(rootAssetPath) && !extendAssetMap.ContainsKey(assetPath)) { if (specialList.Contains(assetPath)) { //Check it again. Debug.LogError("Special texture dictionary has same texture,TexturePath=" + assetPath + ".UIScenePath=" + rootAssetPath); } else { extendAssetMap.Add(assetPath, bundlePath); } } //记录小包资源 if (IsBasicPackageScene(rootAssetPath) && !basicAssetList.Contains(assetPath)) { basicAssetList.Add(assetPath); } #endif } else { AssetBundleType usedType = allAssetBundleMap[assetName]; if (usedType != arType) { Debug.LogError("Build UI error, same asset name has been found.AssetName=" + assetName + "." + arType + "," + assetName + "." + usedType + ".UIPath=" + rootAssetPath); } } } } } //保存UI界面配置文件 if (uiScenePrefabList != null && uiScenePrefabList.Count > 0) { string uisceneParentPath = AssetBundlePath.UIAssetRootPath + AssetBundleType.Scene + "/"; //场景目录 if (!Directory.Exists(uisceneParentPath)) { Directory.CreateDirectory(uisceneParentPath); } uiConfig.SaveConfig(uisceneParentPath + "uiconfig.txt"); } else { Debug.Log("Build UI tips:no scene found."); } //保存Prefab配置文件 if (prefabList != null && prefabList.Count > 0) { string prefabconfigParentPath = AssetBundlePath.UIAssetRootPath + AssetBundleType.Scene + "/"; if (!Directory.Exists(prefabconfigParentPath)) { Directory.CreateDirectory(prefabconfigParentPath); } prefabConfig.SaveConfig(prefabconfigParentPath + "uiprefabconfig.txt"); } else { Debug.Log("Build UI tips:no dynamic prefab found."); } //删除忽略的资源 foreach (string delPath in ignoreBundleList) { if (!string.IsNullOrEmpty(delPath)) { File.Delete(delPath); } } #if PACKAGE_BASIC //过滤小包中用到的资源 foreach (string basicAssetPath in basicAssetList) { if (extendAssetMap.ContainsKey(basicAssetPath)) { extendAssetMap.Remove(basicAssetPath); } } //删除扩展包资源 foreach (string path in extendAssetMap.Values) { if (string.IsNullOrEmpty(path)) { Debug.LogError("Build basic package error, can not delete unuse texture"); } else { File.Delete(path); } } #endif //结束打包资源 BuildPipeline.PopAssetDependencies(); AssetDatabase.Refresh(); }
void OnWizardCreate() { bundleType = pBundleType; OnMICreateAssetbundleClicked(); }
public SortedDictionary <int, List <DependencyAsset> > GetConfig(string sectionName, AssetBundleType subType) { if (m_ConfigData.ContainsKey(sectionName)) { SortedDictionary <int, List <DependencyAsset> >[] sectionData = m_ConfigData[sectionName]; if (sectionData != null) { return(GetSubData(sectionData, subType)); } } return(null); }