static void ZipAndCopy(string outPath, string name) { string outP = GetOutPath(CreateAssetBundle.AssetPath); string resP = Path.Combine(outP, name + CreateAssetBundle.ResInfoName); string info = File.ReadAllText(Path.Combine(outP, name + CreateAssetBundle.ResInfoName)); ResourceInfo itemInfo = JsonUtility.FromJson <ResourceInfo> (info); BundleNames.Clear(); for (int i = 0; i < itemInfo.ResList.Count; i++) { if (itemInfo.ResList [i].IsAsset) { BundleNames.Add(itemInfo.ResList [i].Name); string filePath = Path.Combine(outP, itemInfo.ResList[i].Name); long size = FileTools.GetFileSize(filePath); itemInfo.ResLength += size; } } CreateAssetBundle.SaveResInfoFile(FileTools.CombinePath(outP, name + CreateAssetBundle.ResInfoName), itemInfo); BundleNames.Add(name + CreateAssetBundle.ResInfoName); string zipPath = Path.Combine(outPath, name + ".zip"); ZipUtils.CreateZipFile(zipPath, outP, BundleNames); }
void OnWizardCreate() { string strTarget = System.Enum.GetName(typeof(BuildTarget), Target); if (strTarget == null || strTarget == "") { CreateWizard(); return; } try { List <string> filelist = null; if (IgnorePrefab != null && IgnorePrefab.Length != 0) { filelist = new List <string>(); foreach (string str in IgnorePrefab) { filelist.Add(str); } } if (!CreateAssetBundle.PackageAllPrefab(Target, filelist, PrefabDirectory)) { CreateWizard(); return; } } catch (System.Exception exp) { Debug.Log(exp.Message); CreateWizard(); return; } }
public static bool PackageAssetBundle(BuildTarget buildTarget) { Caching.ClearCache(); string[] dirs = new string[] { SAAppConfig.DataDir,//数据表 //SAAppConfig.TextureDir,//图片 //SAAppConfig.MaterialDir,//材质 //SAAppConfig.PrefabFontAtlasDir,//字体 SAAppConfig.ParticleDir, //粒子 SAAppConfig.SoundDir, //音效 SAAppConfig.PrefabAtlasDir, //图集 SAAppConfig.ModelDir, //模型预置 //SAAppConfig.FBXDir,//动作文件 SAAppConfig.PrefabUIDir, //UI预置 SAAppConfig.LuaByteDir //Lua }; string[] extNames = new string[] { "*.*",//数据表 //"*.png;*.jpg",//图片 //"*.mat",//材质 //"*.*",//字体 "*.prefab", //粒子 "*.prefab", //音效 "*.prefab", //图集 "*.prefab;", //模型预置 //"*.prefab",//"*.FBX;*.fbx",//fbx动作文件 "*.prefab", //UI预置 "*.bytes" }; //Lua return(CreateAssetBundle.Execute(buildTarget, BuildAssetBundleOptions.DeterministicAssetBundle | BuildAssetBundleOptions.ChunkBasedCompression, "", dirs, extNames)); }
public static bool PackageShader(BuildTarget buildTarget) { Caching.ClearCache(); string[] dirs = new string[] { //SAAppConfig.ShaderDir,//Shader SAAppConfig.MaterialDir//Shader }; string[] extNames = new string[] { "*.mat" };//, "*.prefab" return(CreateAssetBundle.Execute(buildTarget, BuildAssetBundleOptions.DeterministicAssetBundle | BuildAssetBundleOptions.UncompressedAssetBundle, "s", dirs, extNames, true, "shader.sa")); }
static void ExecuteCreateResource() { //删除所有动作组件 VisualAutuPack.DelAnimationComponent(); //一键所有prefab散包 VisualAutuPack.Execute(BuildTarget.iPhone); //一键所有动作 VisualAutuPack.ExecuteAnim(BuildTarget.iPhone); //资源加密 CreateAssetBundle.ExecuteEncryption(BuildTarget.iPhone); //MD5 生成OK CreateMD5List.ExecuteMd5(BuildTarget.iPhone, projectName); EditorUtility.DisplayDialog("", "MD5 生成OK", "OK"); }
private void OnGUI() { GUILayout.BeginHorizontal(); m_md5Path = EditorGUILayout.TextField("Standard Package MD5 File: ", m_md5Path, GUILayout.Width(500), GUILayout.Height(20)); if (GUILayout.Button("Select MD5 File", GUILayout.Width(150), GUILayout.Height(30))) { m_openFileName = new OpenFileName(); m_openFileName.structSize = Marshal.SizeOf(m_openFileName); m_openFileName.filter = "MD5 File(*.bytes)\0*.bytes"; m_openFileName.file = new string(new char[256]); m_openFileName.maxFile = m_openFileName.file.Length; m_openFileName.fileTitle = new string(new char[64]); m_openFileName.maxFileTitle = m_openFileName.fileTitle.Length; m_openFileName.initialDir = (Application.dataPath + "/Resources").Replace("/", "\\"); m_openFileName.title = "Select MD5 Dialog"; m_openFileName.flags = 0x00080000 | 0x00001000 | 0x00000800 | 0x00000008; if (LocalDialog.GetSaveFileName(m_openFileName)) { Debug.Log(m_openFileName.file); m_md5Path = m_openFileName.file; } } GUILayout.EndHorizontal(); GUILayout.Space(30); GUILayout.BeginHorizontal(); m_hotCount = EditorGUILayout.TextField("Update Version: ", m_hotCount, GUILayout.Width(350), GUILayout.Height(20)); GUILayout.EndHorizontal(); GUILayout.Space(10); GUILayout.BeginHorizontal(); { EditorGUILayout.LabelField("Update Description: ", GUILayout.Width(147)); m_description = EditorGUILayout.TextArea(m_description, GUILayout.Height(50)); } GUILayout.EndHorizontal(); GUILayout.Space(10); GUILayout.BeginHorizontal(); if (GUILayout.Button("START PACKING", GUILayout.Width(150), GUILayout.Height(50))) { if (!string.IsNullOrEmpty(m_md5Path) && m_md5Path.EndsWith(".bytes")) { //BundleEditor.Build(); CreateAssetBundle.ReadMd5Com(m_md5Path, m_hotCount, m_description); } } GUILayout.EndHorizontal(); }
public static void PublishAndroid(PublishType t) { //OpenDebugMode(); if (t == PublishType.My) { PackageEditor.ToMy(); } else if (t == PublishType.Park) { PackageEditor.ToPack(); } CopyResToAsset(); CreateAssetBundle.CreateAsset(); ExportAndroid(t); CopyAssetToRes(); //CloseDebugMode(); EditorUtility.DisplayDialog("提示", "导出完成!", "确定"); }
void OnGUI() { if (GUI.Button(new Rect(40f, 20f, 200f, 50f), "创建assetbundle散包")) { CreateAssetBundle.Execute(buildTarget); EditorUtility.DisplayDialog("", "创建assetbundle散包", "OK"); } if (GUI.Button(new Rect(40f, 90f, 200f, 50f), "创建assetbundle整包")) { string filename = EditorUtility.SaveFilePanel("", AssetBundleController.GetPlatformPath(buildTarget), "输入bundle名称,点击保存", "assetbundle"); CreateAssetBundle.ExecuteAll(filename, buildTarget); EditorUtility.DisplayDialog("", filename, "OK"); } if (GUI.Button(new Rect(300f, 20f, 200f, 50f), "一键所有prefab散包")) { VisualAutuPack.Execute(buildTarget); //CreateAssetBundle.Execute(buildTarget); //EditorUtility.DisplayDialog("", "创建assetbundle散包", "OK"); } if (GUI.Button(new Rect(300f, 90f, 200f, 50f), "删除动作组件")) { bool isOk = EditorUtility.DisplayDialog("删除动作组件", "警告:不可逆过程,需要通过svn才能还原!确定要删除所有动作组件吗", "确定", "取消"); if (isOk) { VisualAutuPack.DelAnimationComponent(); } } if (GUI.Button(new Rect(300f, 160f, 200f, 50f), "一键所有动作组件bundle")) { VisualAutuPack.ExecuteAnim(buildTarget); } if (GUI.Button(new Rect(40f, 160f, 200f, 50f), "资源加密")) { CreateAssetBundle.ExecuteEncryption(buildTarget); } if (GUI.Button(new Rect(40f, 230f, 200f, 50f), "生成 MD5")) { CreateMD5List.Execute(buildTarget); EditorUtility.DisplayDialog("", "MD5 生成OK", "OK"); } }
static void CreateAsset(string rootName, string name, int appV, int codeV, int resV) { PublishEditor.MoveResToModuleAsset(name); BundleNames.Clear(); ResourceInfo resInfo = new ResourceInfo(); resInfo.AppVersion = appV; resInfo.CodeVersion = codeV; resInfo.ResVersion = resV; resInfo.ResList = new List <ResourceItemInfo> (); ResourceItemInfo item = new ResourceItemInfo(); item.Path = name; item.Name = name; item.IsResident = false; GetResItemInfo(resInfo, item.Path, false, BundleNames); item.ResNames = new List <string> (); resInfo.ResList.Add(item); item.IsAsset = AssetHeplerEditor.SetAssetBundleName("Assets/" + rootName + "/" + name, item.Name, item.ResNames); string outP = GetOutPath(CreateAssetBundle.AssetPath); //FileTools.ClearDirectory (outP); FileTools.CreateDirectory(outP); BuildPipeline.BuildAssetBundles(outP, BuildAssetBundleOptions.UncompressedAssetBundle | BuildAssetBundleOptions.ForceRebuildAssetBundle, EditorUserBuildSettings.activeBuildTarget); CreateAssetBundle.SetDependencies(resInfo, outP); CreateAssetBundle.SaveResInfoFile(FileTools.CombinePath(outP, name + CreateAssetBundle.ResInfoName), resInfo); CreateAssetBundle.ClearAssetName(rootName, resInfo); //CopyToSteaming(rootName, name); PublishEditor.MoveModuleAssetToRes(name); AssetDatabase.Refresh(); //EditorUtility.DisplayDialog("提示", "打包AssetBundle完成!", "确定"); }
//Createボタンが押された private void OnWizardCreate() { string[] modelNames = new string[targets.Length]; string[] modelOwners = new string[targets.Length]; string[] modelVers = new string[targets.Length]; for (int i = 0; i < targets.Length; i++) { //ModelDescriptionを引っ張る var modelDescription = targets[i].GetComponent <ModelDescription>(); modelNames[i] = ""; modelOwners[i] = ""; modelVers[i] = ""; if (modelDescription != null) { modelNames[i] = modelDescription.modelName; modelOwners[i] = modelDescription.modelOwner; modelVers[i] = modelDescription.modelVersion; } } CreateAssetBundle.Create(targets, buildtargetplatforms, encrypt, modelNames, modelOwners, modelVers); }
/// <summary> /// 创建一个prefab /// </summary> /// <param name="obj"></param> /// <param name="createLuafile"></param> /// <param name="alert"></param> public static void CreatePrefab(GameObject obj, bool createLuafile, bool alert = true) { // prefab部分 UITools.SetGameObjectLayer(obj.transform, LayerMask.NameToLayer("UI")); Transform parent = obj.transform.parent; Dictionary <Transform, Transform> dic = new Dictionary <Transform, Transform>(); Dictionary <Transform, int> dicindex = new Dictionary <Transform, int>(); Transform[] tfs = obj.transform.GetComponentsInChildren <Transform>(true); foreach (Transform tf in tfs) // 去除#np的节点 { if (tf.name.IndexOf(Constants.LUA_SUFFIX) >= 0) { dic.Add(tf, tf.parent); dicindex.Add(tf, tf.GetSiblingIndex()); tf.SetParent(parent, true); } } Scene scene = UnityEditor.SceneManagement.EditorSceneManager.GetActiveScene(); string path = scene.path; if (!path.Contains(Application.dataPath)) { path = path.Replace("Assets/UINew/", "/UINew/"); path = Application.dataPath + path; } string ext = System.IO.Path.GetExtension(path); string filename = System.IO.Path.GetFileNameWithoutExtension(path); path = path.Replace(ext, ".prefab").Replace("Assets/UINew/scene", "Assets/UINew/prefab"); string folder = System.IO.Path.GetDirectoryName(path); string assetpath = UnityEditor.FileUtil.GetProjectRelativePath(path); string respath = assetpath.Replace(".prefab", "").Replace("Assets/UINew/prefab/", ""); if (!System.IO.Directory.Exists(folder)) { System.IO.Directory.CreateDirectory(folder); } // lua部分 LuaBehaviour lb = obj.GetComponent <LuaBehaviour>(); if (lb != null) { createLuafile = true; } if (createLuafile) { if (lb == null || string.IsNullOrEmpty(lb.luaFile)) { if (!UILuaEditor.CreateUIFile(obj, filename, respath)) { return; } } else { if (filename == System.IO.Path.GetFileNameWithoutExtension(lb.luaFile)) { UILuaEditor.ModificationLuaFile(obj, filename, respath, alert); } else { UnityEditor.EditorUtility.DisplayDialog("生成失败", "lua 文件名不匹配!", "OK"); return; } } } // 生成prefab if (System.IO.File.Exists(path)) { GameObject tar = AssetDatabase.LoadAssetAtPath <GameObject>(assetpath); PrefabUtility.ReplacePrefab(obj, tar, ReplacePrefabOptions.ReplaceNameBased); } else { PrefabUtility.CreatePrefab(assetpath, obj); } string bundlename = assetpath.Replace(".prefab", ".unity3d").Replace("Assets/UINew/prefab", "prefab"); CreateAssetBundle.SetAssetName(assetpath, bundlename, false); foreach (KeyValuePair <Transform, Transform> kv in dic) // 还原#np的节点 { kv.Key.SetParent(kv.Value, true); kv.Key.SetSiblingIndex(dicindex[kv.Key]); } dic.Clear(); dic = null; dicindex.Clear(); dicindex = null; EditorSceneManager.SaveScene(SceneManager.GetActiveScene()); }
public static void CreateSceneAndroid() { buildTarget = UnityEditor.BuildTarget.Android; CreateAssetBundle.ExecuteScene(buildTarget); EditorUtility.DisplayDialog("", "CreateSceneAndroid (1) Completed", "OK"); }
public static void CreateSceneWin() { buildTarget = UnityEditor.BuildTarget.StandaloneWindows; CreateAssetBundle.ExecuteScene(buildTarget); EditorUtility.DisplayDialog("", "CreateSceneWin (1) Completed", "OK"); }
public static void ExecuteWebPlayer() { CreateAssetBundle.Execute(UnityEditor.BuildTarget.WebPlayer); EditorUtility.DisplayDialog("AssetbundleEditor", "Assetbundle package completed!", "OK"); }
public static void ExecuteMac() { CreateAssetBundle.Execute(UnityEditor.BuildTarget.StandaloneOSXIntel64); EditorUtility.DisplayDialog("AssetbundleEditor", "Assetbundle package completed!", "OK"); }