static void ProcEnchantEffect_Dir(string dirPath, List <string> shdList) { Dictionary <string, string> assetMap = new Dictionary <string, string>(); //获取所有模型 List <string> prefabList = new List <string>(); BuildAssetBundle.GetFiles(dirPath, "*.prefab", ref prefabList); foreach (string s in prefabList) { string sTemp = s.Replace('\\', '/'); if (!sTemp.Contains(AssetBundlePath.EnchantEffectAssetPath)) { continue; } string assetName = BuildAssetBundle.GetAssetName(s); if (assetMap.ContainsKey(assetName)) { assetMap.Remove(assetName); } assetMap.Add(assetName, s); } //打包所有模型 foreach (string assetName in assetMap.Keys) { string pathTemp = assetMap[assetName].Replace('\\', '/'); string parentPath = pathTemp.Substring(0, pathTemp.LastIndexOf('/') + 1); ProcEnchantEffect_File(parentPath, pathTemp, AssetBundlePath.EnchantEffectBundlePath, shdList); } }
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); }
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(); } }
/*[@MenuItem("版本发布/版本发布")] * static void Apply() * { * EditorWindow.GetWindow(typeof(BuildVersionWnd)); * }*/ //[@MenuItem("版本发布/制作AB包")] public static void BuildVersionTest() { //xlua 生成 //CSObjectWrapEditor.Generator.GenAll(); BuildAssetBundle.Build(); EditorUtility.DisplayDialog("提示", "AB包生产完毕", "确定"); }
static void ProceStage_Dir(string filePath) { string parentPath = GetStagePath(filePath); if (!Directory.Exists(parentPath)) { Directory.CreateDirectory(parentPath); } filePath = filePath.Replace('\\', '/'); string stageName = filePath.Substring(filePath.LastIndexOf('/') + 1); stageName = stageName.Replace(".unity", ".scene"); if (!BuildAssetBundle.IsLegalAsset(stageName)) { Debug.LogError("Generate stage warning, asset name is not all lower," + filePath); EditorUtility.DisplayDialog("Error", "Generate stage warning, asset name is not all lower,Please try again!" + filePath, "OK"); return; } BuildPipeline.PushAssetDependencies(); BuildPipeline.BuildStreamedSceneAssetBundle(new string[] { filePath }, parentPath + stageName, EditorUserBuildSettings.activeBuildTarget); BuildPipeline.PopAssetDependencies(); }
static void CopyToTarget(BuildAssetBundle window, string target_path) { List <string> bundles = new List <string>(); //bundles = GetAssetbundles(window.bundle_crc_name, window.export_path); CopyDir(window.assetbundles_path, target_path + "/assetbundles", bundles); //lua string csharp_script_path = Path.Combine(window.dest_path, "csharp_script").Replace("\\", "/"); bundles.Add(csharp_script_path); CopyDir(window.export_path, Path.Combine(target_path, "Assets"), bundles); //csharp_script //File.Copy(csharp_script_path, Path.Combine(target_path, "csharp_script"), true); List <string> empty = new List <string>(); //Dest CopyDir(window.dest_path, Path.Combine(target_path, "Dest"), empty); //StreamingAssets/Data CopyDir(Path.Combine(Application.streamingAssetsPath, "Data"), Path.Combine(target_path, "Assets\\Data"), empty); //StreamingAssets/Textures CopyDir(Path.Combine(Application.streamingAssetsPath, "Textures"), Path.Combine(target_path, "Assets\\Textures"), empty); }
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); }
/// <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)); } }
void GetAllUIScene() { string uiscene = PlayerPrefs.GetString(UIScenePrefs); string[] uisceneArray = uiscene.Split('|'); for (int i = 0; i < uisceneArray.Length; ++i) { if (!string.IsNullOrEmpty(uisceneArray[i])) { m_MarkedUIList.Add(uisceneArray[i]); } } List <string> uisceneList = BuildAssetBundle.GetAllUIPrefab(); for (int i = 0; i < uisceneList.Count; ++i) { AssetItem item = new AssetItem(); item.IsChecked = HasMarkedUI(uisceneList[i]); item.AssetName = uisceneList[i]; m_listEnum.Add(item); } m_ChooseUI = PlayerPrefs.GetInt(UIPrefs) == 1 ? true : false; m_ChooseTexture = PlayerPrefs.GetInt(TexturePrefs) == 1 ? true : false; }
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 OneKeyBuild(string target_path, BuildTarget platform, bool lua_debug, bool assetbundle, bool clean, bool build_lua, bool export_data, bool csharp_script, bool set_bundlename) { Debug.Log("BuildTarget-" + platform.ToString() + "\n" + "target_path-" + target_path); BuildAssetBundle window = EditorWindow.GetWindow <BuildAssetBundle>(); window.InitPath(); window.SwitchPlatform(platform); //create dest path. CreateFolder(window.dest_path); if (assetbundle) { if (clean) //clear assetbundle path { FileUtil.DeleteFileOrDirectory(window.assetbundles_path); CreateFolder(window.assetbundles_path); } //0.export dependency. if (csharp_script) { window.BuildCSharpScript(); } //1.build Assetbundle. window.BuildAssetBundles(set_bundlename); } //2.compile lua code if (build_lua) { FileUtil.DeleteFileOrDirectory(window.export_path); CreateFolder(window.export_path); window.BuildLua(lua_debug); } //3. if (export_data) { window.PakAll(); } //4.copy asset to target_path //assetbundles CopyToTarget(window, target_path); }
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); }
private static Dictionary <string, string> GetUIPrefabList() { List <string> prefabList = new List <string>(); BuildAssetList(AssetBundlePath.UIPrefabAssetDir, prefabList, AssetBundleType.Pre); Dictionary <string, string> dic = new Dictionary <string, string>(); foreach (var v in prefabList) { string fileName = BuildAssetBundle.GetAssetName(v); dic[fileName] = v; } return(dic); }
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("一键发布成功"); }
/// <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); } } } }
private void LoadAssetScene() { if (isLoadScene) { return; } isLoadScene = true; sceneAssetList.Clear(); List <string> scenePathList = BuildAssetBundle.GetBuildSettingsScenes(); for (int i = 0; i < scenePathList.Count; ++i) { SceneAsset sceneAsset = AssetDatabase.LoadAssetAtPath <SceneAsset>(scenePathList[i]); sceneAssetList.Add(sceneAsset); } }
/// <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); } } }
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(); } }
private static List <string> FixedUIPrefabList(List <string> sceneList) { List <string> list = new List <string>(); Dictionary <string, string> dic = GetUIPrefabList(); foreach (var v in sceneList) { string fileName = BuildAssetBundle.GetAssetName(v); if (dic.ContainsKey(fileName)) { list.Add(dic[fileName]); } else { Debug.LogError("UIPrefab File is no Exist,filename is : " + v); } } return(list); }
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); } }
/// <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(); }
public static void Build(string externalResourcesPath) { var exportPath = GetExportPath(); if (string.IsNullOrEmpty(exportPath)) { return; } if (Directory.Exists(exportPath)) { Directory.Delete(exportPath, true); } EditorApplication.LockReloadAssemblies(); #if ENABLE_CRIWARE CriAssetGenerator.Generate(exportPath, externalResourcesPath); #endif // CriAssetGeneratorでCriのManifestファイルを生成後に実行. var assetBundleManifest = BuildAssetBundle.BuildAllAssetBundles(exportPath); // ビルド成果物の情報をAssetInfoManifestに書き込み. AssetInfoManifestGenerator.SetAssetFileInfo(exportPath, externalResourcesPath, assetBundleManifest); // 再度AssetInfoManifestだけビルドを実行. BuildAssetBundle.BuildAssetInfoManifest(exportPath, externalResourcesPath); // 不要ファイル削除. BuildAssetBundle.DeleteUnUseFiles(exportPath); // AssetBundleファイルをパッケージ化. BuildAssetBundle.BuildPackage(exportPath); EditorApplication.UnlockReloadAssemblies(); UnityConsole.Event(ExternalResources.ConsoleEventName, ExternalResources.ConsoleEventColor, "Build ExternalResource Complete."); }
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)); } }
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(); } }
/// <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; }
/// <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); } } }
public static void BuildGame() { string[] levels = GetPublishType() == "Development" ? GetDevelopmentBuildLevels() : GetProductBuildLevels(); string[] platformList = GetExternalArg("PlatformList").Split('#'); var buildTarget = GetBuildTarget(); for (int i = 0, count = platformList.Length; i < count; i++) { var platformName = platformList[i]; BuildAssetBundle.MakePlatformConfig(platformName); SetBundleVersion(platformName, buildTarget); switch (buildTarget) { case BuildTarget.Android: BuildGameAndroid(levels, platformName); break; case BuildTarget.iOS: BuildGameIOS(levels); return; } } }
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 UpdateAllAssetBundleName() { BuildAssetBundle.UpdateAllAssetBundleName(); }