示例#1
0
        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);
            }
        }
示例#2
0
        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);
            }
        }