public static void DoExport() { var files = AssetDatabase.GetAllAssetPaths().Where(p => p.StartsWith("Assets/Lua/proto") && (p.EndsWith(".proto") || p.EndsWith(".pb")) ).ToArray(); //copy EditorUtils.CheckstreamingAssetsPath(); string OutLuaProtobufPath = GetLuaProtobufResourcesPath(); AssetDatabase.DeleteAsset(OutLuaProtobufPath); GetLuaProtobufResourcesPath(); var dests = new string[files.Length]; System.Text.StringBuilder sb = new System.Text.StringBuilder(); for (int i = 0; i < files.Length; i++) { string xfile = System.IO.Path.GetFileName(files[i]);//.Remove(0, rootPath.Length + 1); string file = files[i].Replace("\\", "/"); string dest = OutLuaProtobufPath + "/" + CUtils.GetRightFileName(xfile).Replace(".", "+"); string destName = dest + ".bytes"; dests[i] = destName; Debug.LogFormat("Copy({0},{1})", file, destName); System.IO.File.Copy(file, destName, true); sb.AppendFormat("\r\n {0} ({1}) ", file, destName); } string tmpPath = EditorUtils.GetAssetTmpPath(); EditorUtils.CheckDirectory(tmpPath); string outPath = Path.Combine(tmpPath, "lua_protobuf_export_log.txt"); Debug.Log("write to path=" + outPath); using (StreamWriter sr = new StreamWriter(outPath, false)) { sr.Write(sb.ToString()); } EditorUtility.ClearProgressBar(); AssetDatabase.Refresh(); //addressables var setting = AASEditorUtility.LoadAASSetting(); var groupSchama = AASEditorUtility.DefaltGroupSchema[0]; var group = AASEditorUtility.FindGroup(LUA_PROTO_GROUP_NAME, groupSchama);//setting.FindGroup(LUA_GROUP_NAME); foreach (var str in dests) { var guid = AssetDatabase.AssetPathToGUID(str); //获得GUID var entry = setting.CreateOrMoveEntry(guid, group); //通过GUID创建entry entry.SetAddress(System.IO.Path.GetFileNameWithoutExtension(str)); entry.SetLabel("lua_protobuf", true); } }
public static void DoExportLua(string rootPath) { EditorUtils.CheckstreamingAssetsPath(); string OutLuaBytesPath = GetLuaBytesResourcesPath(); AssetDatabase.DeleteAsset(OutLuaBytesPath); GetLuaBytesResourcesPath(); System.Text.StringBuilder sb = new System.Text.StringBuilder(); var files = Directory.GetFiles(rootPath, "*.lua", SearchOption.AllDirectories); var dests = new string[files.Length]; for (int i = 0; i < files.Length; i++) { string xfile = files[i].Remove(0, rootPath.Length + 1); xfile = "lua_" + xfile.Replace("\\", "+").Replace("/", "+"); string file = files[i].Replace("\\", "/"); string dest = OutLuaBytesPath + "/" + CUtils.GetRightFileName(xfile); string destName = dest.Substring(0, dest.Length - 3) + "bytes"; dests[i] = destName; System.IO.File.Copy(file, destName, true); sb.AppendFormat("\r\n {0} ({1}) ", file, destName); } string tmpPath = EditorUtils.GetAssetTmpPath(); EditorUtils.CheckDirectory(tmpPath); string outPath = Path.Combine(tmpPath, "lua_export_log.txt"); Debug.Log("write to path=" + outPath); using (StreamWriter sr = new StreamWriter(outPath, false)) { sr.Write(sb.ToString()); } EditorUtility.ClearProgressBar(); AssetDatabase.Refresh(); //addressables var setting = AASEditorUtility.LoadAASSetting(); var groupSchama = AASEditorUtility.DefaltGroupSchema[0]; var group = AASEditorUtility.FindGroup(LUA_GROUP_NAME, groupSchama); //setting.FindGroup(LUA_GROUP_NAME); AASEditorUtility.ClearGroup(LUA_GROUP_NAME); //清空 foreach (var str in dests) { var guid = AssetDatabase.AssetPathToGUID(str); //获得GUID var entry = setting.CreateOrMoveEntry(guid, group); //通过GUID创建entry entry.SetAddress(System.IO.Path.GetFileNameWithoutExtension(str)); entry.SetLabel("lua_script", true); } }
public static void ExportLanguage() { var files = AssetDatabase.GetAllAssetPaths().Where(p => p.StartsWith("Assets/Config/Lan") && p.EndsWith(".csv") ).ToArray(); // EditorUtils.CheckstreamingAssetsPath(); EditorUtils.CheckDirectory("Assets/LuaBytes/lan_bundle"); var dests = new List <string>(); foreach (string abPath in files) { string name = CUtils.GetAssetName(abPath); string abName = CUtils.GetRightFileName(name + Common.CHECK_ASSETBUNDLE_SUFFIX); Hugula.BytesAsset bytes = (Hugula.BytesAsset)ScriptableObject.CreateInstance(typeof(Hugula.BytesAsset)); bytes.bytes = File.ReadAllBytes(abPath); string bytesPath = string.Format("Assets/LuaBytes/lan_bundle/{0}.asset", name); dests.Add(bytesPath); AssetDatabase.CreateAsset(bytes, bytesPath); // BuildScript.BuildABs(new string[] { bytesPath }, null, abName, SplitPackage.DefaultBuildAssetBundleOptions); // Debug.Log(name + " " + abName + " export"); } AssetDatabase.Refresh(); var setting = AASEditorUtility.LoadAASSetting(); var group = AASEditorUtility.FindGroup(LAN_GROUP_NAME, AASEditorUtility.DefaltGroupSchema[0]); //setting.FindGroup(LUA_GROUP_NAME); AASEditorUtility.ClearGroup(LAN_GROUP_NAME); //清空 foreach (var str in dests) { var guid = AssetDatabase.AssetPathToGUID(str); //获得GUID var entry = setting.CreateOrMoveEntry(guid, group); //通过GUID创建entry entry.SetAddress(System.IO.Path.GetFileNameWithoutExtension(str)); entry.SetLabel("lan_csv", true); } }
public static void CreateAudioClipAsset() { var selection = Selection.objects; string path = string.Empty; StringBuilder sb = new StringBuilder(); foreach (Object s in selection) { if (s is DefaultAsset && (path = AssetDatabase.GetAssetPath(s)) != null && Directory.Exists(path)) { var ragName = s.name.ToLower() + "_audio.asset"; var tagName = s.name.ToLower() + "_atlas"; string res_path = Path.Combine(path, ragName); sb.Append("Crate audioclip asset :"); sb.Append(ragName); sb.Append("\r\n"); var allchildren = EditorUtils.getAllChildFiles(path, @"\.meta$|\.manifest$|\.DS_Store$|\.u$", null, false); List <int> names = new List <int>(); List <AudioClip> audioClips = new List <AudioClip>(); for (int i = 0; i < allchildren.Count; i++) { var itemPath = allchildren[i]; var ti = AssetImporter.GetAtPath(itemPath); var aclip = AssetDatabase.LoadAssetAtPath <AudioClip>(itemPath); if (aclip) { audioClips.Add(aclip); names.Add(LuaHelper.StringToHash(aclip.name)); if (ti != null) { ti.assetBundleName = tagName + Common.CHECK_ASSETBUNDLE_SUFFIX; } } EditorUtility.DisplayProgressBar("Processing...", "生成中... (" + (i + 1) + " / " + allchildren.Count + ")", (i + 1) / allchildren.Count); } EditorUtility.ClearProgressBar(); //生成或者替换资源 var audioAsset = AssetDatabase.LoadAssetAtPath <AudioClipAsset>(res_path); if (audioAsset == null) { audioAsset = AudioClipAsset.CreateInstance <AudioClipAsset>(); AssetDatabase.CreateAsset(audioAsset, res_path); } audioAsset.audioClips = audioClips.ToArray(); audioAsset.audioNames = names.ToArray(); EditorUtility.SetDirty(audioAsset); var groupAssets = new List <string>(); groupAssets.Add(res_path); var atlasGroup = AASEditorUtility.FindGroup(AudioClipAsset.DEFALUT_SOUND_ASSET_NAME, AASEditorUtility.DefaltGroupSchema[0]); AASEditorUtility.SetGroupAddress(AASEditorUtility.LoadAASSetting(), atlasGroup, groupAssets); sb.AppendFormat("build {0} success count = {1} ", ragName, names.Count); AssetDatabase.SaveAssets(); } } sb.AppendLine("\r\nall completed"); Debug.Log(sb.ToString()); }
public static void CreateAtlasAsset() { var selection = Selection.objects; string path = string.Empty; StringBuilder sb = new StringBuilder(); string tagName = string.Empty; foreach (Object s in selection) { if (s is DefaultAsset && (path = AssetDatabase.GetAssetPath(s)) != null && Directory.Exists(path)) { var ragName = s.name.ToLower() + "_atlas.spriteatlas"; string atlas_path = Path.Combine(path, ragName); tagName = s.name.ToLower() + "_atlas"; sb.Append("Crate atlas Asset :"); sb.Append(ragName); sb.Append("\r\n"); var allchildren = EditorUtils.getAllChildFiles(path, @"\.meta$|\.manifest$|\.DS_Store$|\.u$", null, false); int count = 0; List <int> names = new List <int>(); List <Sprite> allSprites = new List <Sprite>(); foreach (var f in allchildren) { count++; TextureImporter ti = AssetImporter.GetAtPath(f) as TextureImporter; if (ti != null) { if (ti.textureType != TextureImporterType.Sprite) { ti.textureType = TextureImporterType.Sprite; } Object[] objs = AssetDatabase.LoadAllAssetRepresentationsAtPath(f); foreach (var item in objs) { if (item is Sprite) { sb.AppendLine(item.name); names.Add(UnityEngine.Animator.StringToHash(item.name)); allSprites.Add((Sprite)item); } } // ti.spritePackingTag = tagName; // ti.assetBundleName = tagName + Common.CHECK_ASSETBUNDLE_SUFFIX; EditorUtility.DisplayProgressBar("Processing...", "生成中... (" + count + " / " + allchildren.Count + ")", count / allchildren.Count); } else { Debug.LogWarningFormat("{0} is not Texture ", f); } } EditorUtility.ClearProgressBar(); //生成或者替换资源 var atlas = AssetDatabase.LoadAssetAtPath <SpriteAtlas>(atlas_path); if (atlas == null) { atlas = new SpriteAtlas(); AssetDatabase.CreateAsset(atlas, atlas_path); SpriteAtlasPackingSettings packSet = new SpriteAtlasPackingSettings() { blockOffset = 1, enableRotation = false, enableTightPacking = false, padding = 2, }; atlas.SetPackingSettings(packSet); SpriteAtlasTextureSettings textureSet = new SpriteAtlasTextureSettings() { readable = false, generateMipMaps = false, sRGB = false, filterMode = FilterMode.Bilinear, }; atlas.SetTextureSettings(textureSet); } SpriteAtlasExtensions.Add(atlas, allSprites.ToArray()); EditorUtility.SetDirty(atlas); var groupAssets = new List <string>(); groupAssets.Add(atlas_path); var atlasGroup = AASEditorUtility.FindGroup(tagName, AASEditorUtility.DefaltGroupSchema[0]); AASEditorUtility.SetGroupAddress(AASEditorUtility.LoadAASSetting(), atlasGroup, groupAssets); sb.AppendFormat("build {0} success count = {1} ", ragName, names.Count); AssetDatabase.SaveAssets(); } } sb.AppendLine("\r\nall completed"); Debug.Log(sb.ToString()); EditorUtils.WriteToTmpFile(tagName + ".txt", sb.ToString()); }
public static void GenerateAllAtlasMapping() { StringBuilder sb = new StringBuilder(); List <int> allSprites = new List <int>(); List <string> atlasNames = new List <string>(); var files = AssetDatabase.GetAllAssetPaths().Where(p => p.EndsWith(".spriteatlas") ).ToArray(); for (int i = 0; i < files.Length; i++) { var o = AssetDatabase.LoadAssetAtPath <UnityEngine.U2D.SpriteAtlas>(files[i]); var ti = AssetImporter.GetAtPath(files[i]); var key = System.IO.Path.GetFileNameWithoutExtension(files[i]); if (o != null) { // var assetBundleName = ti.assetBundleName; EditorUtility.DisplayProgressBar("Processing...", "生成中... (" + i + " / " + files.Length + ")", (float)i / (float)files.Length); var sps = new UnityEngine.Sprite[o.spriteCount]; int len = o.GetSprites(sps); for (int j = 0; j < len; j++) { string name = sps[j].name.Replace("(Clone)", ""); int id = UnityEngine.Animator.StringToHash(name); allSprites.Add(id); atlasNames.Add(key); sb.AppendFormat("{0}({1}) {2}\r\n", name, id, key); } } } EditorUtility.ClearProgressBar(); string mapping_root_name = Hugula.Atlas.AtlasManager.ATLAS_MAPPING_ROOT_NAME; string atlas_path = Path.Combine(AtlasConfig.ATLAS_MAPPING_ROOT, mapping_root_name + ".asset"); //生成或者替换资源 var atlas = AssetDatabase.LoadAssetAtPath <MappingAsset>(atlas_path); if (atlas == null) { atlas = MappingAsset.CreateInstance <MappingAsset>(); AssetDatabase.CreateAsset(atlas, atlas_path); } atlas.names = allSprites.ToArray(); atlas.keys = atlasNames.ToArray(); EditorUtility.SetDirty(atlas); //aas var groupAssets = new List <string>(); groupAssets.Add(atlas_path); var atlasGroup = AASEditorUtility.FindGroup(mapping_root_name, AASEditorUtility.DefaltGroupSchema[0]); AASEditorUtility.SetGroupAddress(AASEditorUtility.LoadAASSetting(), atlasGroup, groupAssets); AssetDatabase.SaveAssets(); Debug.LogFormat(" save {0} count = {1} ", atlas_path, atlasNames.Count); EditorUtils.WriteToTmpFile(mapping_root_name + ".txt", sb.ToString()); }