static void ProcAtlas_Files(List <string> fileList) { Dictionary <string, Object> atlasMap = new Dictionary <string, Object>(); string[] atlasArr = fileList.ToArray(); foreach (string atlasPath in atlasArr) { if (!atlasMap.ContainsKey(atlasPath)) { atlasMap.Add(atlasPath, AssetDatabase.LoadAssetAtPath(atlasPath, typeof(UIAtlas))); } } foreach (KeyValuePair <string, Object> atlkvp in atlasMap) { if (!BuildAssetBundle.IsLegalAsset(atlkvp.Value.name)) { Debug.LogError("Generate atlas error, asset name is not all lower," + atlkvp.Key); EditorUtility.DisplayDialog("Error", "Generate atlas error, asset name is not all lower, Please try again!" + atlkvp.Key, "OK"); return; } string path = UIAtlasAssetbundlePath + atlkvp.Value.name + ".atl"; BuildPipeline.PushAssetDependencies(); BuildAssetBundle.Build(atlkvp.Value, null, path, true); BuildPipeline.PopAssetDependencies(); } }
public static List <string> BuildAllShader(string name) { List <string> allShdName = new List <string>(); string[] strShader = Directory.GetFiles(AssetBundlePath.ShaderSrcDir, "*.shader", SearchOption.AllDirectories); List <Object> listShaderO = new List <Object>(); foreach (string s in strShader) { string sTemp = s.Replace('\\', '/'); string shdName = sTemp.Substring(sTemp.LastIndexOf('/') + 1); if (!allShdName.Contains(shdName)) { allShdName.Add(shdName); } listShaderO.Add(AssetDatabase.LoadAssetAtPath(s, typeof(Shader))); } Object[] allShader = listShaderO.ToArray(); string path = AssetBundlePath.ShaderAssetbundlePath + name + ".shd"; BuildAssetBundle.Build(null, allShader, path, true); return(allShdName); }
public static void GenerateShaderExtend(string shaderPath, bool isLeaf) { if (!Directory.Exists(AssetBundlePath.ShaderExtendAssetbundlePath)) { Directory.CreateDirectory(AssetBundlePath.ShaderExtendAssetbundlePath); } List <Object> listShaderO = new List <Object>(); listShaderO.Add(AssetDatabase.LoadAssetAtPath(shaderPath, typeof(Shader))); string sTemp = shaderPath.Replace('\\', '/'); string shdName = sTemp.Substring(sTemp.LastIndexOf('/') + 1); shdName = shdName.Replace(".shader", ".shd"); if (!BuildAssetBundle.IsLegalAsset(shdName)) { Debug.LogError("Build shader extend error, asset name is not all lower," + shaderPath); EditorUtility.DisplayDialog("Error", "Build shader extend error, asset name is not all lower, Please try again!" + shaderPath, "OK"); return; } Object[] allShader = listShaderO.ToArray(); string path = AssetBundlePath.ShaderExtendAssetbundlePath + shdName; BuildAssetBundle.Build(null, allShader, path, isLeaf); }
/*[@MenuItem("版本发布/版本发布")] * static void Apply() * { * EditorWindow.GetWindow(typeof(BuildVersionWnd)); * }*/ //[@MenuItem("版本发布/制作AB包")] public static void BuildVersionTest() { //xlua 生成 //CSObjectWrapEditor.Generator.GenAll(); BuildAssetBundle.Build(); EditorUtility.DisplayDialog("提示", "AB包生产完毕", "确定"); }
/// <summary> /// 打包手持、翅膀、尾巴、左右手持、肩膀 /// </summary> /// <param name="characterFBX">模型</param> /// <param name="bundleParentPath">生成文件父路径</param> static void ProcMaterials_FileForWingHip(GameObject characterFBX, string bundleParentPath) { string bundleName = characterFBX.name; if (bundleName.StartsWith("wing_") || bundleName.StartsWith("hip_") || bundleName.StartsWith("lefthand_") || bundleName.StartsWith("righthand_") || bundleName.StartsWith("shoulders_") || bundleName.StartsWith("leftear_") || bundleName.StartsWith("rightear_")) { GameObject rendererClone = (GameObject)PrefabUtility.InstantiatePrefab(characterFBX); string desPath = bundleParentPath + bundleName + ".clh"; if (File.Exists(desPath)) { File.Delete(desPath); } List <Object> includeList = new List <Object>(); Object rendererPrefab = GenerateResource.ReplacePrefab(rendererClone, rendererClone.name); includeList.Add(rendererPrefab); if (!Directory.Exists(bundleParentPath)) { Directory.CreateDirectory(bundleParentPath); } BuildAssetBundle.Build(null, includeList.ToArray(), desPath); AssetDatabase.DeleteAsset(AssetDatabase.GetAssetPath(rendererPrefab)); } }
static void ExportNoMeshSocksMaterial(Material mat) { bool needBuild = true; string matPath = AssetDatabase.GetAssetPath(mat); string matName = mat.name; if (IsIOS()) { //在IOS环境下,假如不是ios资源,查找到存在ios mat资源,则不编译该文件 if (!IsIOSFile(matPath)) { string matIOSPath = GetExtendPath(matPath, "_ios"); if (File.Exists(matIOSPath)) { needBuild = false; } } else { matName = CheckIOSMat(mat.name); } } else { //非ios环境下,假如它是ios mat文件 ,则不编译该文件 if (IsIOSFile(matPath)) { needBuild = false; } } if (needBuild) { GameObject o = new GameObject(matName); SkinnedMeshRenderer smr = o.AddComponent <SkinnedMeshRenderer>(); smr.sharedMaterial = mat; Object rendererPrefab = GenerateResource.ReplacePrefab(o, o.name); string desPath = MaterialsAssetbundlePath + rendererPrefab.name + ".clh"; if (File.Exists(desPath)) { File.Delete(desPath); } BuildPipeline.PushAssetDependencies(); BuildAssetBundle.Build(null, new Object[] { rendererPrefab }, desPath); BuildPipeline.PopAssetDependencies(); Debug.Log("Saved " + rendererPrefab.name); AssetDatabase.DeleteAsset(AssetDatabase.GetAssetPath(rendererPrefab)); } }
public static void OneKey() { //构建配置表 //XmlBuilder.BuildeXml(); //更新资源 BuildAssetBundle.UpdateAllAssetBundleName(); //构建资源 BuildAssetBundle.Build(); //生成MD5 EditorUtil.MD5(Application.dataPath + "/StreamingAssets/"); //生成资源配置版本号 EditorUtil.ModifyConfig("res_version", EditorUtil.Version()); //复制到对应的发布资源目标 EditorUtil.CopyDir(Application.dataPath + "/StreamingAssets/", EditorUtil.resources_path + EditorUtil.Platform + "/StreamingAssets/"); Debug.Log("一键发布成功"); }
public static void BuildAllShader(string name) { string[] strShader = Directory.GetFiles(ShaderSrcDir, "*.shader", SearchOption.AllDirectories); List <Object> listShaderO = new List <Object>(); foreach (string s in strShader) { listShaderO.Add(AssetDatabase.LoadAssetAtPath(s, typeof(Shader))); } Object[] allShader = listShaderO.ToArray(); string path = ShaderAssetbundlePath + name + ".shd"; BuildPipeline.PushAssetDependencies(); BuildAssetBundle.Build(null, allShader, path, true); }
/// <summary> /// 打包所有贴图 /// </summary> /// <param name="srcPath">源路径</param> /// <param name="destParentPath">生成文件父路径</param> static void ProcTextures(string srcPath, string destParentPath) { List <string> textureList = new List <string>(); BuildAssetBundle.GetFiles(srcPath, "*.tga", ref textureList); if (!Directory.Exists(destParentPath + AssetBundleType.Texture.ToString())) { Directory.CreateDirectory(destParentPath + AssetBundleType.Texture.ToString()); } foreach (string s in textureList) { Object obj = AssetDatabase.LoadAssetAtPath(s, typeof(Object)); string bundlePath = destParentPath + AssetBundleType.Texture.ToString() + "/" + BuildAssetBundle.GetAssetName(s) + "." + AssetBundleType.Texture.ToString().ToLower(); BuildAssetBundle.Build(obj, null, bundlePath, true); } }
private static void ProcAnimations_File(string filePath) { Object[] objArr = AssetDatabase.LoadAllAssetRepresentationsAtPath(filePath); if (objArr == null || objArr.Length == 0) { return; } GameObject characterFBX = (GameObject)AssetDatabase.LoadMainAssetAtPath(filePath); string bundleName = characterFBX.name.ToUpper(); GameObject.Destroy(characterFBX); //Delete old asset; string[] bundleArr = Directory.GetFiles(AniAssetbundlePath, bundleName + ".assetbundle"); foreach (string bundlePath in bundleArr) { File.Delete(bundlePath); } string tempAnimationAssetPath = "Assets/TempAnimation.asset"; foreach (Object obj in objArr) { AnimationClip aniClip = obj as AnimationClip; if (aniClip != null) { AnimationClip newClip = RemoveScaleCurve(aniClip); if (newClip != null) { AssetDatabase.CreateAsset(newClip, tempAnimationAssetPath); string path = AniAssetbundlePath + bundleName + ".assetbundle"; Object clipAsset = AssetDatabase.LoadAssetAtPath(tempAnimationAssetPath, typeof(AnimationClip)); BuildAssetBundle.Build(clipAsset, null, path); Debug.Log("Saved " + bundleName + " animation"); AssetDatabase.DeleteAsset(tempAnimationAssetPath); } } } }
static void ProcSpecialEffectAssetBundle(string strPrefabPath) { Object saveObject = (Object)AssetDatabase.LoadMainAssetAtPath(strPrefabPath); if (saveObject != null) { if (!BuildAssetBundle.IsLegalAsset(saveObject.name)) { Debug.LogError("Generate special effect error, asset name is not all lower," + strPrefabPath); EditorUtility.DisplayDialog("Error", "Generate special effect error, asset name is not all lower,Please try again!" + strPrefabPath, "OK"); return; } string path = EffectAssetbundlePath + saveObject.name + ".pre"; BuildPipeline.PushAssetDependencies(); BuildAssetBundle.Build(saveObject, null, path, true); BuildPipeline.PopAssetDependencies(); } }
static void ProcBones_File(string filePath) { Object o = AssetDatabase.LoadMainAssetAtPath(filePath); if (o is GameObject) { GameObject characterFBX = (GameObject)o; string bundleName = characterFBX.name; Debug.Log("******* Creating Bones assetbundles for: " + bundleName + " *******"); //remove bones; GameObject rendererClone = (GameObject)PrefabUtility.InstantiatePrefab(characterFBX); Animator at = rendererClone.GetComponent <Animator>(); if (at != null) { Object.DestroyImmediate(at); } Object rendererPrefab = GenerateResource.ReplacePrefab(rendererClone, rendererClone.name); string bundleParentPath = BonesAssetbundlePath; if (!Directory.Exists(bundleParentPath)) { Directory.CreateDirectory(bundleParentPath); } if (!BuildAssetBundle.IsLegalAsset(bundleName)) { Debug.LogError("Generate bone error, asset name is not all lower," + filePath); EditorUtility.DisplayDialog("Error", "Generate bone error, asset name is not all lower,Please try again!" + filePath, "OK"); return; } BuildAssetBundle.Build(rendererPrefab, null, bundleParentPath + bundleName + ".res"); Debug.Log("Saved Bones to '" + bundleParentPath + bundleName + ".res"); AssetDatabase.DeleteAsset(AssetDatabase.GetAssetPath(rendererPrefab)); GameObject.DestroyImmediate(rendererClone); } }
static void ProcMaterials_FileForWingHip(GameObject characterFBX) { if (!IsNeedBone(characterFBX.name)) { GameObject rendererClone = (GameObject)PrefabUtility.InstantiatePrefab(characterFBX); string desPath = MaterialsAssetbundlePath + characterFBX.name + ".clh"; if (File.Exists(desPath)) { File.Delete(desPath); } List <Object> includeList = new List <Object>(); Object rendererPrefab = GenerateResource.ReplacePrefab(rendererClone, rendererClone.name); includeList.Add(rendererPrefab); BuildPipeline.PushAssetDependencies(); BuildAssetBundle.Build(null, includeList.ToArray(), desPath); BuildPipeline.PopAssetDependencies(); AssetDatabase.DeleteAsset(AssetDatabase.GetAssetPath(rendererPrefab)); } }
/// <summary> /// 打包流光特效 /// </summary> static void ProcLightMaterial() { if (!Directory.Exists(AssetBundlePath.EnchantLightMaterialBundlePath)) { Directory.CreateDirectory(AssetBundlePath.EnchantLightMaterialBundlePath); } string lightMatDir = AssetBundlePath.EnchantLightMaterialAssetPath; string[] filetga = Directory.GetFiles(lightMatDir, "*.mat"); string path = AssetBundlePath.EnchantLightMaterialBundlePath + "light.material"; List <Object> assetlist = new List <Object>(); foreach (string f in filetga) { Object o = AssetDatabase.LoadMainAssetAtPath(f); assetlist.Add(o); } BuildAssetBundle.Build(null, assetlist.ToArray(), path, true); assetlist.Clear(); }
/// <summary> /// 打包资源 /// </summary> /// <param name="assetPath">源路径</param> /// <param name="bundleParentPath">目标父路径</param> /// <param name="bundlePath">目标路径</param> /// <param name="isLeaf">是否是叶子节点</param> /// <param name="needPopDepencance"></param> static void BuildBundle(string assetPath, string bundleParentPath, string bundlePath, bool isLeaf, bool popDependence) { if (!Directory.Exists(bundleParentPath)) { Directory.CreateDirectory(bundleParentPath); } if (popDependence) { BuildPipeline.PushAssetDependencies(); } Object obj = AssetDatabase.LoadAssetAtPath(assetPath, typeof(Object)); BuildAssetBundle.Build(obj, null, bundlePath, isLeaf); if (popDependence) { BuildPipeline.PopAssetDependencies(); } obj = null; }
private static void ProcDynamicPrefab(List <string> prefabList) { string bundleParentPath = AssetBundlePath.PrefabAssetRootPath + "/"; for (int i = 0; i < prefabList.Count; ++i) { BuildPipeline.PushAssetDependencies(); Object o = AssetDatabase.LoadAssetAtPath(prefabList[i], typeof(Object)); if (!BuildAssetBundle.IsLegalAsset(o.name)) { Debug.LogError("Build dynamic prefab error, asset name is not all lower," + prefabList[i]); EditorUtility.DisplayDialog("Error", "Build dynamic prefab error, asset name is not all lower,Please try again!" + prefabList[i], "OK"); return; } string bundlePath = bundleParentPath + o.name + ".pre"; BuildAssetBundle.Build(o, null, bundlePath, true); BuildPipeline.PopAssetDependencies(); } }
static void BuilderDefualtTexture() { string skinpath = MaterialsAssetbundlePath + "Skin/"; if (!Directory.Exists(skinpath)) { Directory.CreateDirectory(skinpath); } string[] filetga = Directory.GetFiles(MaterialsSrcDir + "Skin", "*.mat"); string path = skinpath + "default.skn"; List <Object> assetlist = new List <Object>(); foreach (string f in filetga) { //FileInfo i= new FileInfo(f); Object o = AssetDatabase.LoadMainAssetAtPath(f); assetlist.Add(o); } BuildAssetBundle.Build(null, assetlist.ToArray(), path, true); assetlist.Clear(); }
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(); }
public static void BuildRes() { BuildAssetBundle.Build(); }
static void ProcMaterials_File(Object o, List <string> matList) { if (o is GameObject) { GameObject characterFBX = (GameObject)o; string bundleName = characterFBX.name; Debug.Log("******* Creating Material assetbundles for: " + bundleName + " *******"); #if false string desPath = MaterialsAssetbundlePath + bundleName + ".clh"; if (File.Exists(desPath)) { File.Delete(desPath); } BuildPipeline.PushAssetDependencies(); BuildPipeline.BuildAssetBundle(characterFBX, null, desPath, BuildAssetBundleOptions.CollectDependencies | BuildAssetBundleOptions.UncompressedAssetBundle | BuildAssetBundleOptions.DeterministicAssetBundle, EditorUserBuildSettings.activeBuildTarget); BuildPipeline.PopAssetDependencies(); #else if (!IsNeedBone(bundleName)) { ProcMaterials_FileForWingHip(characterFBX); return; } //remove bones; GameObject rendererClone = (GameObject)PrefabUtility.InstantiatePrefab(characterFBX); //GameObject Bonese = null; //获取骨骼下的所有特效 List <GameObject> particallist = new List <GameObject>(); 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; } } for (int i = rendererClone.transform.childCount - 1; i >= 0; --i) { List <Object> includeList = new List <Object>(); List <string> holderList = new List <string>(); Transform childTran = rendererClone.transform.GetChild(i); if (childTran.name.Contains("Bip01")) { //FindParticalFromBonse( particallist ,childTran); continue; } else { childTran.parent = null; } string desPath = MaterialsAssetbundlePath + childTran.name + ".clh"; if (File.Exists(desPath)) { File.Delete(desPath); } // we don't need to Save bones and animations . Any // As we can not edit assets we instantiate // the fbx and remove what we dont need. As only assets can be // added to assetbundles we save the result as a prefab and delete // it as soon as the assetbundle is created. GameObject partClone = childTran.gameObject; foreach (SkinnedMeshRenderer smr in partClone.GetComponentsInChildren <SkinnedMeshRenderer>(true)) { //Replace Mat for IOS if (IsIOS()) { string matPath = string.Empty; string matIOSPath = string.Empty; List <Material> matList1 = new List <Material>(); foreach (Material mat in smr.sharedMaterials) { matPath = AssetDatabase.GetAssetPath(mat); matIOSPath = GetExtendPath(matPath, "_ios"); if (File.Exists(matIOSPath)) { Material newMat = AssetDatabase.LoadAssetAtPath(FixToUnityPath(matIOSPath), typeof(Material)) as Material; if (newMat != null) { matList1.Add(newMat); } } else { matList1.Add(mat); } } smr.sharedMaterials = matList1.ToArray(); } //判断蒙皮的骨骼是否是共用骨骼 if (IsCommonBone(smr)) { //Bonesname List <string> boneNames = new List <string>(); foreach (Transform t in smr.bones) { boneNames.Add(GetTransfromPathName(t)); } StringHolder holder = ScriptableObject.CreateInstance <StringHolder>(); holder.content = boneNames.ToArray(); string holderPath = "Assets/" + smr.name + "bonenames.prefab"; AssetDatabase.CreateAsset(holder, holderPath); includeList.Add(AssetDatabase.LoadAssetAtPath(holderPath, typeof(StringHolder))); holderList.Add(holderPath); foreach (Material mat in smr.sharedMaterials) { if (mat != null && mat.name.Contains("socks_") && !matList.Contains(mat.name)) { matList.Add(mat.name); } } } else { smr.gameObject.name = smr.gameObject.name + "_nobone"; } } if (particallist.Count != 0) { foreach (GameObject p in particallist) { if (p.name.Contains(partClone.name)) { 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 = partClone.transform; } } foreach (Transform t in partClone.transform) { if (t.childCount > 0) { particallist.Remove(t.GetChild(0).gameObject); } } } Object rendererPrefab = GenerateResource.ReplacePrefab(partClone, partClone.name); includeList.Add(rendererPrefab); BuildPipeline.PushAssetDependencies(); BuildAssetBundle.Build(null, includeList.ToArray(), desPath); BuildPipeline.PopAssetDependencies(); Debug.Log("Saved " + rendererPrefab.name); AssetDatabase.DeleteAsset(AssetDatabase.GetAssetPath(rendererPrefab)); foreach (string s in holderList) { AssetDatabase.DeleteAsset(s); } } GameObject.DestroyImmediate(rendererClone); #endif } }
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); }
static void ProcUIScene(List <string> specialList, List <string> uisceneList) { UIConfig uiConfig = new UIConfig(); Dictionary <string, Object> textureMap = new Dictionary <string, Object>(); Dictionary <string, Object> soundMap = new Dictionary <string, Object>(); string TextureNomallPath = ""; #if PACKAGE_BASIC //添加小包过滤操作 Dictionary <string, string> deleteTextureMap = new Dictionary <string, string>(); Dictionary <string, string> deleteSoundMap = new Dictionary <string, string>(); List <string> notDelTextureList = new List <string>(); List <string> notDelSoundList = new List <string>(); #endif string[] textureArr = specialList.ToArray(); foreach (string texturePath in textureArr) { if (!textureMap.ContainsKey(texturePath)) { textureMap.Add(texturePath, AssetDatabase.LoadAssetAtPath(texturePath, typeof(Texture2D))); } } foreach (string uiscenePath in uisceneList) { string sectionName = uiscenePath.Substring(uiscenePath.LastIndexOf('/') + 1); sectionName = sectionName.Replace(".unity", ""); string[] sceneDepArr = AssetDatabase.GetDependencies(new string[1] { uiscenePath }); foreach (string sceneDepPath in sceneDepArr) { if (IsImageFile(sceneDepPath)) { if (!textureMap.ContainsKey(sceneDepPath)) { textureMap.Add(sceneDepPath, AssetDatabase.LoadAssetAtPath(sceneDepPath, typeof(Texture2D))); } #if PACKAGE_BASIC //添加小包过滤操作 if (uiscenePath.Contains(UIWndSrcDir) && !deleteTextureMap.ContainsKey(sceneDepPath)) { if (specialList.Contains(sceneDepPath)) { //Check it again. Debug.LogError("Special texture dictionary has same texture,TexturePath=" + sceneDepPath + ".UIScenePath=" + uiscenePath); } else { deleteTextureMap.Add(sceneDepPath, null); } } if (uiscenePath.Contains(UIWndBasicSrcDir) && !notDelTextureList.Contains(sceneDepPath)) { notDelTextureList.Add(sceneDepPath); } #endif if (textureMap[sceneDepPath].name != "Nomall") { uiConfig.AddConfig(sectionName, UISubSection.UI_Texture, textureMap[sceneDepPath].name); } } else if (IsSoundFile(sceneDepPath)) { if (!soundMap.ContainsKey(sceneDepPath)) { soundMap.Add(sceneDepPath, AssetDatabase.LoadAssetAtPath(sceneDepPath, typeof(AudioClip))); } #if PACKAGE_BASIC //添加小包过滤操作 if (uiscenePath.Contains(UIWndSrcDir) && !deleteSoundMap.ContainsKey(sceneDepPath)) { deleteSoundMap.Add(sceneDepPath, null); } if (uiscenePath.Contains(UIWndBasicSrcDir) && !notDelSoundList.Contains(sceneDepPath)) { notDelSoundList.Add(sceneDepPath); } #endif uiConfig.AddConfig(sectionName, UISubSection.UI_Sound, soundMap[sceneDepPath].name); } } } #if PACKAGE_BASIC //过滤小包中用到的资源 foreach (string notPath in notDelTextureList) { if (deleteTextureMap.ContainsKey(notPath)) { deleteTextureMap.Remove(notPath); } } foreach (string notPath in notDelSoundList) { if (deleteSoundMap.ContainsKey(notPath)) { deleteSoundMap.Remove(notPath); } } #endif BuildPipeline.PushAssetDependencies(); foreach (KeyValuePair <string, Object> texturekvp in textureMap) { string path = UITextureAssetbundlePath + texturekvp.Value.name + ".uit"; if (texturekvp.Value.name == "Nomall") { TextureNomallPath = path; } #if PACKAGE_BASIC //添加小包过滤操作 if (deleteTextureMap.ContainsKey(texturekvp.Key)) { deleteTextureMap[texturekvp.Key] = path; } #endif BuildAssetBundle.Build(texturekvp.Value, null, path, true); } foreach (KeyValuePair <string, Object> soundkvp in soundMap) { string path = UISoundAssetbundlePath + soundkvp.Value.name + ".auc"; #if PACKAGE_BASIC //添加小包过滤操作 if (deleteSoundMap.ContainsKey(soundkvp.Key)) { deleteSoundMap[soundkvp.Key] = path; } #endif BuildAssetBundle.Build(soundkvp.Value, null, path, true); } string storePath = UIWndAssetbundlePath + "UI.unity"; BuildPipeline.BuildStreamedSceneAssetBundle(uisceneList.ToArray(), storePath, EditorUserBuildSettings.activeBuildTarget); BuildPipeline.PopAssetDependencies(); uiConfig.SaveConfig(UIWndAssetbundlePath + "UIConfig.txt"); if (!string.IsNullOrEmpty(TextureNomallPath)) { File.Delete(TextureNomallPath); } #if PACKAGE_BASIC //添加小包过滤操作 foreach (string path in deleteTextureMap.Values) { if (string.IsNullOrEmpty(path)) { Debug.LogError("Build basic package error, can not delete unuse texture"); } else { File.Delete(path); } } foreach (string path in deleteSoundMap.Values) { if (string.IsNullOrEmpty(path)) { Debug.LogError("Build basic package error, can not delete unuse sound"); } else { File.Delete(path); } } #endif }
static void ProcUIScene(List <string> specialList, string uiscenePath) { Dictionary <string, Object> textureMap = new Dictionary <string, Object>(); Dictionary <string, Object> soundMap = new Dictionary <string, Object>(); string TextureNomallPath = ""; string[] textureArr = specialList.ToArray(); foreach (string texturePath in textureArr) { if (!textureMap.ContainsKey(texturePath)) { textureMap.Add(texturePath, AssetDatabase.LoadAssetAtPath(texturePath, typeof(Texture2D))); } } string uisceneName = uiscenePath.Substring(uiscenePath.LastIndexOf('/') + 1); string sectionName = uisceneName.Replace(".unity", ""); string configPath = UIWndAssetbundlePath + "UIConfig.txt"; UIConfig uiConfig = new UIConfig(); uiConfig.LoadConfig(configPath, configPath); uiConfig.ClearSection(sectionName); string[] sceneDepArr = AssetDatabase.GetDependencies(new string[1] { uiscenePath }); foreach (string sceneDepPath in sceneDepArr) { if (IsImageFile(sceneDepPath)) { if (!textureMap.ContainsKey(sceneDepPath)) { textureMap.Add(sceneDepPath, AssetDatabase.LoadAssetAtPath(sceneDepPath, typeof(Texture2D))); } if (textureMap[sceneDepPath].name != "Nomall") { uiConfig.AddConfig(sectionName, UISubSection.UI_Texture, textureMap[sceneDepPath].name); } } else if (IsSoundFile(sceneDepPath)) { if (!soundMap.ContainsKey(sceneDepPath)) { soundMap.Add(sceneDepPath, AssetDatabase.LoadAssetAtPath(sceneDepPath, typeof(AudioClip))); } uiConfig.AddConfig(sectionName, UISubSection.UI_Sound, soundMap[sceneDepPath].name); } } BuildPipeline.PushAssetDependencies(); foreach (KeyValuePair <string, Object> texturekvp in textureMap) { string path = UITextureAssetbundlePath + texturekvp.Value.name + ".uit"; if (texturekvp.Value.name == "Nomall") { TextureNomallPath = path; } BuildAssetBundle.Build(texturekvp.Value, null, path, true); } foreach (KeyValuePair <string, Object> soundkvp in soundMap) { string path = UISoundAssetbundlePath + soundkvp.Value.name + ".auc"; BuildAssetBundle.Build(soundkvp.Value, null, path, true); } string storePath = UIWndAssetbundlePath + uisceneName; BuildPipeline.PushAssetDependencies(); BuildPipeline.BuildStreamedSceneAssetBundle(new string[] { uiscenePath }, storePath, EditorUserBuildSettings.activeBuildTarget); BuildPipeline.PopAssetDependencies(); BuildPipeline.PopAssetDependencies(); uiConfig.SaveConfig(configPath); if (!string.IsNullOrEmpty(TextureNomallPath)) { File.Delete(TextureNomallPath); } }