Пример #1
0
 static int WriteValue(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 3);
         IniUtil obj  = (IniUtil)ToLua.CheckObject(L, 1, typeof(IniUtil));
         string  arg0 = ToLua.CheckString(L, 2);
         object  arg1 = ToLua.ToVarObject(L, 3);
         obj.WriteValue(arg0, arg1);
         return(0);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
Пример #2
0
    /// <summary>
    /// 打包
    /// </summary>
    public static void BuildAssets(BuildTarget target)
    {
        // StreamingAssets 目录
        string streamingAssetsPath       = Application.dataPath + "/StreamingAssets/";
        string StreamingAssetsPathUpload = Application.dataPath + "/../StreamingAssetsUpload/";

        // 没有StreamingAssets就创建
        if (!Directory.Exists(streamingAssetsPath))
        {
            Directory.CreateDirectory(streamingAssetsPath);
        }
        if (!Directory.Exists(StreamingAssetsPathUpload))
        {
            Directory.CreateDirectory(StreamingAssetsPathUpload);
        }

        // 清空StreamingAssets目录
        clearDirectory(streamingAssetsPath);
        clearDirectory(StreamingAssetsPathUpload);

        //if ( Const.ResourceMode == "assetbundle" )
        //{
        BuildPipeline.BuildAssetBundles(StreamingAssetsPathUpload, BuildAssetBundleOptions.ChunkBasedCompression, target);
        //}
        //else
        //    UnityEngine.Debug.Log( "Const.ResourceMode = " + Const.ResourceMode );

        FileInfo fi = new FileInfo(StreamingAssetsPathUpload + "StreamingAssetsUpload");

        fi.MoveTo(StreamingAssetsPathUpload + "StreamingAssets");

        fi = new FileInfo(StreamingAssetsPathUpload + "StreamingAssetsUpload.manifest");
        fi.MoveTo(StreamingAssetsPathUpload + "StreamingAssets.manifest");

        // -------------------------------------- 资源版本文件部分 -------------------------------------------
        // 修改app配置的版本号,每次打包+1
        IniUtil resverIni = new IniUtil();

        resverIni.OpenFromTXT(Application.dataPath + "/../Config/resver.txt");
        int new_resource_version = Convert.ToInt32(resverIni.ReadValue("RESOURCE_VERSION", "0")) + 1;

        resverIni.WriteValue("RESOURCE_VERSION", new_resource_version);
        File.Copy(Application.dataPath + "/../Config/resver.txt", StreamingAssetsPathUpload + "resver.txt", true);

        // -------------------------------------- 配置文件部分 -------------------------------------------
        // 配置文件在StreamingAssets文件夹中的路径
        string targetTxtPath = StreamingAssetsPathUpload + "/Data/";

        if (Directory.Exists(targetTxtPath))
        {
            Directory.Delete(targetTxtPath, true);
        }
        Directory.CreateDirectory(targetTxtPath);

        paths.Clear();
        files.Clear();

        // 配置文件源路径
        string sourceTxtPath = Application.dataPath + "/Resources/PackAssets/Data/";

        // 递归遍历所有文件文件夹
        Recursive(sourceTxtPath);

        // 遍历所有文件并复制
        foreach (string f in files)
        {
            if (f.EndsWith(".meta") || f.EndsWith(".DS_Store"))
            {
                continue;
            }
            string newfile = f.Replace(sourceTxtPath, "");
            if (newfile.Equals("user.txt"))
            {
                continue;
            }
            string newpath = targetTxtPath + newfile;
            string path    = Path.GetDirectoryName(newpath);
            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }
            File.Copy(f, newpath, true);
        }

        // -------------------------------------- lua脚本部分 -------------------------------------------
        // lua脚本在StreamingAssets文件夹中的路径
        string luaPath = StreamingAssetsPathUpload + "Lua/";

        if (Directory.Exists(luaPath))
        {
            Directory.Delete(luaPath, true);
        }
        Directory.CreateDirectory(luaPath);

        paths.Clear();
        files.Clear();

        // lua脚本源路径
        string luaDataPath = Application.dataPath + "/Lua/";

        // 递归遍历所有文件文件夹
        Recursive(luaDataPath);

        // 遍历所有文件并复制
        foreach (string f in files)
        {
            if (!f.EndsWith(".lua"))
            {
                continue;
            }
            string newfile = f.Replace(luaDataPath, "");
            string newpath = luaPath + newfile;
            string path    = Path.GetDirectoryName(newpath);
            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }
            File.Copy(f, newpath, true);
//            if ( target == BuildTarget.StandaloneWindows || target == BuildTarget.StandaloneOSXUniversal )
//                File.Copy( f, newpath, true );
//            else
//#if UNITY_STANDALONE_WIN
//                Execute( Application.dataPath + "/../../Public/ghlua.exe", f + " " + newpath, 0 );
//#else
//			Execute(Application.dataPath+"/../../Public/ghlua", f + " " + newpath, 0);
//#endif

            //Execute(Application.dataPath+"/../../Public/luajit/luajit.exe", " -b " + f + " " + newpath, 0);
            //Execute(Application.dataPath + "/../../Public/luac/Luac.exe", " -o " + newpath + " " + f, 0);
        }

        // -------------------------------------- 所有文件列表部分 -------------------------------------------
        // 文件列表
        string newFilePath = StreamingAssetsPathUpload + "files.txt";

        if (target == BuildTarget.Android)
        {
            newFilePath = StreamingAssetsPathUpload + "android_files.txt";
        }
        else if (target == BuildTarget.iOS)
        {
            newFilePath = StreamingAssetsPathUpload + "ios_files.txt";
        }
        else if (target == BuildTarget.StandaloneWindows)
        {
            newFilePath = StreamingAssetsPathUpload + "windows_files.txt";
        }
        else if (target == BuildTarget.StandaloneOSXUniversal)
        {
            newFilePath = StreamingAssetsPathUpload + "osx_files.txt";
        }

        // 如果文件存在删除文件
        if (File.Exists(newFilePath))
        {
            File.Delete(newFilePath);
        }

        paths.Clear();
        files.Clear();

        // 递归遍历所有文件文件夹
        Recursive(StreamingAssetsPathUpload);

        // 创建文件列表
        FileStream   fs = new FileStream(newFilePath, FileMode.CreateNew);
        StreamWriter sw = new StreamWriter(fs);

        for (int i = 0; i < files.Count; i++)
        {
            string file = files[i];
            string ext  = Path.GetExtension(file);
            if (ext.Equals(".meta") || ext.Equals(".manifest") || ext.Equals(".DS_Store"))
            {
                continue;
            }

            // md5 值
            string md5 = Utils.md5file(file);
            // 文件大小
            FileInfo fileInfo = new FileInfo(file);
            long     size     = fileInfo.Length;
            // 文件相对路径
            string value = file.Replace(StreamingAssetsPathUpload, string.Empty);
            sw.WriteLine(value + "|" + md5 + "|" + size);
        }
        sw.Close();
        fs.Close();

        // ------------------------------------------------------------------------------------------------------------------------------------------------------------
        // -------------------------------------- 完毕以后,把StreamingAssetsUpload里的文件拷贝到StreamingAssets,刨去需要过滤的 -------------------------------------------
        if (target == BuildTarget.Android || target == BuildTarget.StandaloneWindows)
        {
            foreach (string f in files)
            {
                //string filename = Path.GetFileName( f );
                //if ( filename.Equals( "android_files.txt" )  )
                //    continue;

                //if ( filename.Equals( "ui_background" ) )
                //    continue;
                //if ( filename.Equals( "ui_background.manifest" ) )
                //    continue;

                //if ( filename.Equals( "ui_building" ) )
                //    continue;
                //if ( filename.Equals( "ui_building.manifest" ) )
                //    continue;

                //if ( filename.Equals( "ui_dialog" ) )
                //    continue;
                //if ( filename.Equals( "ui_dialog.manifest" ) )
                //    continue;

                //if ( filename.Equals( "ui_film" ) )
                //    continue;
                //if ( filename.Equals( "ui_film.manifest" ) )
                //    continue;

                //if ( filename.Equals( "ui_pre" ) )
                //    continue;
                //if ( filename.Equals( "ui_pre.manifest" ) )
                //    continue;

                //if ( filename.Equals( "tiled2unity" ) )
                //    continue;
                //if ( filename.Equals( "tiled2unity.manifest" ) )
                //    continue;

                //if ( filename.Equals( "mapthumb" ) )
                //    continue;
                //if ( filename.Equals( "mapthumb.manifest" ) )
                //    continue;

                //if ( filename.Equals( "mapcity" ) )
                //    continue;
                //if ( filename.Equals( "mapcity.manifest" ) )
                //    continue;

                //if ( filename.Equals( "building" ) )
                //    continue;
                //if ( filename.Equals( "building.manifest" ) )
                //    continue;

                //if ( filename.Equals( "char_1" ) )
                //    continue;
                //if ( filename.Equals( "char_1.manifest" ) )
                //    continue;

                //if ( filename.Equals( "city_0" ) )
                //    continue;
                //if ( filename.Equals( "city_0.manifest" ) )
                //    continue;

                //if ( filename.Equals( "effect_0" ) )
                //    continue;
                //if ( filename.Equals( "effect_0.manifest" ) )
                //    continue;

                //if ( filename.Equals( "effect_2" ) )
                //    continue;
                //if ( filename.Equals( "effect_2.manifest" ) )
                //    continue;

                string newfile = f.Replace("../StreamingAssetsUpload", "StreamingAssets");
                string path    = Path.GetDirectoryName(newfile);
                if (!Directory.Exists(path))
                {
                    Directory.CreateDirectory(path);
                }
                File.Copy(f, newfile, true);
            }
        }
        else if (target == BuildTarget.iOS)
        {
            foreach (string f in files)
            {
                string filename = Path.GetFileName(f);
                if (filename.Equals("ios_files.txt"))
                {
                    continue;
                }

                string newfile = f.Replace("../StreamingAssetsUpload", "StreamingAssets");
                string path    = Path.GetDirectoryName(newfile);
                if (!Directory.Exists(path))
                {
                    Directory.CreateDirectory(path);
                }
                File.Copy(f, newfile, true);
            }
        }

        newFilePath = newFilePath.Replace("../StreamingAssetsUpload", "StreamingAssets");
        // 如果文件存在删除文件
        if (File.Exists(newFilePath))
        {
            File.Delete(newFilePath);
        }

        paths.Clear();
        files.Clear();

        // 递归遍历所有文件文件夹
        Recursive(streamingAssetsPath);

        // 从新创建文件列表
        fs = new FileStream(newFilePath, FileMode.CreateNew);
        sw = new StreamWriter(fs);
        for (int i = 0; i < files.Count; i++)
        {
            string file = files[i];
            string ext  = Path.GetExtension(file);
            if (ext.Equals(".meta") || ext.Equals(".manifest") || ext.Equals(".DS_Store"))
            {
                continue;
            }
            // md5 值
            string md5 = Utils.md5file(file);
            // 文件大小
            FileInfo fileInfo = new FileInfo(file);
            long     size     = fileInfo.Length;
            // 文件相对路径
            string value = file.Replace(streamingAssetsPath, string.Empty);
            sw.WriteLine(value + "|" + md5 + "|" + size);
        }
        sw.Close();
        fs.Close();

        AssetDatabase.Refresh();
        //ZipProxy.compless(resPath, "z.zip");
    }
Пример #3
0
    // 根据选择语言进行初始化
    public static int init()
    {
        destroy();

        countryCodeTable  = new Dictionary <string, string[]>();
        countryIdTable    = new Dictionary <int, string[]>();
        languageCodeTable = new Dictionary <string, string[]>();
        languageIdTable   = new Dictionary <int, string[]>();

        // 读取国家信息
        TableUtil _countryTxt = new TableUtil();

        if (_countryTxt.OpenFromData("localization_country.txt") == false)
        {
            return(-1);
        }
        for (int row = 0; row < _countryTxt.GetRecordsNum(); row++)
        {
            string countryCode   = _countryTxt.GetValue(row, 0);       //  国家英文代码(国际标准)
            string CountryID     = _countryTxt.GetValue(row, 1);       //  国家数字代码(国际标准)
            string CountryNameID = _countryTxt.GetValue(row, 2);       //  国家名称ID
            string CountryFlag   = _countryTxt.GetValue(row, 3);       //  国旗资源名
            string CountryMoney  = _countryTxt.GetValue(row, 4);       //  货币简称

            // 英文编码作key
            if (countryCodeTable.ContainsKey(countryCode) == false)
            {
                string[] ls = new string[4];
                ls[0] = CountryID;
                ls[1] = CountryNameID;
                ls[2] = CountryFlag;
                ls[3] = CountryMoney;
                countryCodeTable.Add(countryCode, ls);
            }
            // 数字编码作key
            if (countryIdTable.ContainsKey(Convert.ToInt32(CountryID)) == false)
            {
                string[] ls = new string[4];
                ls[0] = countryCode;
                ls[1] = CountryNameID;
                ls[2] = CountryFlag;
                ls[3] = CountryMoney;
                countryIdTable.Add(Convert.ToInt32(CountryID), ls);
            }
        }

        // 读取语言信息
        TableUtil _languageTxt = new TableUtil();

        if (_languageTxt.OpenFromData("localization_language.txt") == false)
        {
            return(-2);
        }
        for (int row = 0; row < _languageTxt.GetRecordsNum(); row++)
        {
            string LanguageCode      = _languageTxt.GetValue(row, 0);       //  语言英文代码(国际标准)
            string LanguageCustomID  = _languageTxt.GetValue(row, 1);       //  语言自定义ID(无标准,暂时跟u3d里定义的语言ID走)
            string LanguageNameID    = _languageTxt.GetValue(row, 2);       //  语言名称ID
            string LanguageDirectory = _languageTxt.GetValue(row, 3);       //  语言存在目录
            string TranslationCode   = _languageTxt.GetValue(row, 4);       //  翻译Code

            // 英文编码作key
            if (languageCodeTable.ContainsKey(LanguageCode) == false)
            {
                string[] ls = new string[4];
                ls[0] = LanguageCustomID;
                ls[1] = LanguageNameID;
                ls[2] = LanguageDirectory;
                ls[3] = TranslationCode;
                languageCodeTable.Add(LanguageCode, ls);
            }
            // 数字编码作key
            if (languageIdTable.ContainsKey(Convert.ToInt32(LanguageCustomID)) == false)
            {
                string[] ls = new string[4];
                ls[0] = LanguageCode;
                ls[1] = LanguageNameID;
                ls[2] = LanguageDirectory;
                ls[3] = TranslationCode;
                languageIdTable.Add(Convert.ToInt32(LanguageCustomID), ls);
            }
        }

        // 用户本地配置文件里获取玩家已经选择的国家语言
        IniUtil userIni = new IniUtil();

        userIni.OpenFromTXT(PathUtil.ConfigPath() + "user.txt");

        // 读取使用语言
        currentLanguage = userIni.ReadValue("LANGUAGE", "").ToString();
        if (currentLanguage == "")
        {
            // 没有存档的,使用设备当前的
            currentLanguage = DeviceHelper.getLanguage();
            userIni.WriteValue("LANGUAGE", currentLanguage);
        }

        // 读取使用国家
        currentCountry = userIni.ReadValue("COUNTRY", "").ToString();
        if (currentCountry == "")
        {
            // 没有存档的,使用设备当前的
            currentCountry = DeviceHelper.getCountry();
            userIni.WriteValue("COUNTRY", currentCountry);
        }

        // 先去语言信息里找一下,语言-地区的目录(如zh-cn),没有则直接使用语言(如zh,ru,en等),还是没有则使用英文的
        string localizeDir = languageDirectory(currentLanguage + "-" + currentCountry);

        if (localizeDir == "")
        {
            localizeDir = languageDirectory(currentLanguage);
            if (localizeDir == "")
            {
                localizeDir = languageDirectory("en");
                if (localizeDir == "")
                {
                    return(-3);
                }
            }
        }
        localizeDir = localizeDir + "/";

        // 读取基础文字表
        TableUtil _localizetxt = new TableUtil();

        localize = new Dictionary <int, string>();
        if (_localizetxt.OpenFromData(localizeDir + "localize.txt") == false)
        {
            // 没有对应的语言文件夹,用英语的
            localizeDir = languageDirectory("en") + "/";
            if (_localizetxt.OpenFromData(localizeDir + "localize.txt") == false)
            {
                return(-4);
            }
        }

        for (int row = 0; row < _localizetxt.GetRecordsNum(); row++)
        {
            int    key  = Convert.ToInt32(_localizetxt.GetValue(row, 0));
            string text = _localizetxt.GetValue(row, 1);
            text = text.Replace("\\n", "\n");
            localize.Add(key, text);
        }

        // 读取道具文字表
        TableUtil _localizeItemTxt = new TableUtil();

        localize_item = new Dictionary <int, string>();
        if (_localizeItemTxt.OpenFromData(localizeDir + "localize_item.txt") == false)
        {
            // 没有对应的语言文件夹,用英语的
            localizeDir = languageDirectory("en") + "/";
            if (_localizeItemTxt.OpenFromData(localizeDir + "localize_item.txt") == false)
            {
                return(-5);
            }
        }

        for (int row = 0; row < _localizeItemTxt.GetRecordsNum(); row++)
        {
            int    key  = Convert.ToInt32(_localizeItemTxt.GetValue(row, 0));
            string text = _localizeItemTxt.GetValue(row, 1);
            text = text.Replace("\\n", "\n");
            localize_item.Add(key, text);
        }

        // 读取任务文字表
        TableUtil _localizeQuestTxt = new TableUtil();

        localize_quest = new Dictionary <int, string>();
        if (_localizeQuestTxt.OpenFromData(localizeDir + "localize_quest.txt") == false)
        {
            // 没有对应的语言文件夹,用英语的
            localizeDir = languageDirectory("en") + "/";
            if (_localizeQuestTxt.OpenFromData(localizeDir + "localize_quest.txt") == false)
            {
                return(-6);
            }
        }

        for (int row = 0; row < _localizeQuestTxt.GetRecordsNum(); row++)
        {
            int    key  = Convert.ToInt32(_localizeQuestTxt.GetValue(row, 0));
            string text = _localizeQuestTxt.GetValue(row, 1);
            text = text.Replace("\\n", "\n");
            localize_quest.Add(key, text);
        }

        // 容错处理,所有找不到的文字使用英文
        localizeDir = languageDirectory("en") + "/";

        // 读取基础文字表
        TableUtil localizetxt_en_us = new TableUtil();

        localize_en_us = new Dictionary <int, string>();
        localizetxt_en_us.OpenFromData(localizeDir + "localize.txt");
        for (int row = 0; row < localizetxt_en_us.GetRecordsNum(); row++)
        {
            int    key  = Convert.ToInt32(localizetxt_en_us.GetValue(row, 0));
            string text = localizetxt_en_us.GetValue(row, 1);
            text = text.Replace("\\n", "\n");
            localize_en_us.Add(key, text);
        }

        // 读取道具文字表
        TableUtil localizeitemtxt_en_us = new TableUtil();

        localize_item_en_us = new Dictionary <int, string>();
        localizeitemtxt_en_us.OpenFromData(localizeDir + "localize_item.txt");
        for (int row = 0; row < localizeitemtxt_en_us.GetRecordsNum(); row++)
        {
            int    key  = Convert.ToInt32(localizeitemtxt_en_us.GetValue(row, 0));
            string text = localizeitemtxt_en_us.GetValue(row, 1);
            text = text.Replace("\\n", "\n");
            localize_item_en_us.Add(key, text);
        }

        // 读取任务文字表
        TableUtil localizequesttxt_en_us = new TableUtil();

        localize_quest_en_us = new Dictionary <int, string>();
        localizequesttxt_en_us.OpenFromData(localizeDir + "localize_quest.txt");
        for (int row = 0; row < localizequesttxt_en_us.GetRecordsNum(); row++)
        {
            int    key  = Convert.ToInt32(localizequesttxt_en_us.GetValue(row, 0));
            string text = localizequesttxt_en_us.GetValue(row, 1);
            text = text.Replace("\\n", "\n");
            localize_quest_en_us.Add(key, text);
        }

        bInited = true;
        return(0);
    }