Beispiel #1
0
        public static AppNameConfigData Load()
        {
            if (!Directory.Exists(mConfigSavedDir))
            {
                Directory.CreateDirectory(mConfigSavedDir);
            }

            if (!File.Exists(mConfigSavedDir + mConfigSavedFileName))
            {
                var fileStream = File.Create(mConfigSavedDir + mConfigSavedFileName);
                fileStream.Close();
            }

            AssetDatabase.Refresh();

            var retConfigData = new AppNameConfigData();

            var localizeConfig = SerializeHelper.LoadJson <LocalizeConfig> (mConfigSavedDir + mConfigSavedFileName);

            if (localizeConfig == null || localizeConfig.LanguageDatas == null || localizeConfig.LanguageDatas.Length == 0)
            {
                retConfigData.SupportedLanguageItems.Add(new LanguageData(4, Application.productName));
            }
            else
            {
                retConfigData.SupportedLanguageItems.AddRange(localizeConfig.LanguageDatas);
            }

            return(retConfigData);
        }
        static void Open()
        {
            AppNameEditorWindow appNameEditorWindow = (AppNameEditorWindow)EditorWindow.GetWindow(typeof(AppNameEditorWindow), true);

            appNameEditorWindow.titleContent  = new  GUIContent("App Name Config");
            appNameEditorWindow.CurConfigData = AppNameConfigData.Load();
            appNameEditorWindow.Show();
        }
        public static AppNameConfigData Load()
        {
            var    retConfigData = new AppNameConfigData();
            string keyPrefix     = COUNTRY_PREFIX + Application.productName + Application.companyName;

            for (int i = 0; i < LanguageDef.Length; i++)
            {
                string appName = EditorPrefs.GetString(keyPrefix + LanguageDef[i], "");
                if (!string.IsNullOrEmpty(appName))
                {
                    retConfigData.SupportedLanguageItems.Add(new LanguageData(i, appName));
                }
            }

            return(retConfigData);
        }
        public static void Generate(AppNameConfigData curConfigData)
        {
            string androidResPath = Application.dataPath + "/Plugins/Android/res";

            if (!Directory.Exists(androidResPath))
            {
                Directory.CreateDirectory(androidResPath);
            }

            CreateLanguageResFiles("", Application.productName);

            // 全部先填写默认的名字
            foreach (string languageDef in curConfigData.LanguageDefAndroid)
            {
                string valueDirPath = Application.dataPath + "/Plugins/Android/res/values-" + languageDef;
                if (Directory.Exists(valueDirPath))
                {
                    CreateLanguageResFiles(languageDef, Application.productName);
                }
            }

            // 单独语言的名字
            Dictionary <string, string> languageDict = new Dictionary <string, string> ();

            foreach (var languageData in curConfigData.SupportedLanguageItems)
            {
                languageDict.Add(curConfigData.LanguageDefAndroid [languageData.Index], languageData.AppName);
            }

            foreach (KeyValuePair <string, string> languagePair in languageDict)
            {
                CreateLanguageResFiles(languagePair.Key, languagePair.Value);
            }

            AssetDatabase.Refresh();
        }
Beispiel #5
0
        public static void OnPostProcessBuild(BuildTarget target, string pathToBuiltProject)
        {
            if (target != BuildTarget.iOS)
            {
                Debug.LogWarning("Target is not iPhone. XCodePostProcess will not run");
                return;
            }


            #region 写入Plist
            Debug.Log("Run mine ----------------------------------------------------------------- ");
            string plistPath = pathToBuiltProject + "/Info.Plist";
            Dictionary <string, object> dict = (Dictionary <string, object>)PlistCS.Plist.readPlist(plistPath);

            dict["LSHasLocalizedDisplayName"] = true;
            PlistCS.Plist.writeXml(dict, plistPath);
            #endregion

            var    permissionConfig  = PermissionDesEditorWindow.Load();
            string strPermissionName = "";
            if (null == permissionConfig || string.IsNullOrEmpty(permissionConfig.SelectedStamp))
            {
            }
            else
            {
                strPermissionName = permissionConfig.SelectedStamp;
            }

            Debug.Log(strPermissionName);

            if (strPermissionName.EndsWith(","))
            {
                strPermissionName = strPermissionName.Remove(strPermissionName.Length - 1);
            }
            Debug.Log(strPermissionName);

            string[]   strPermissionIndexes = strPermissionName.Split(',');
            List <int> permissionList       = new List <int> ();

            for (int i = 0; i < strPermissionIndexes.Length; i++)
            {
                if (!string.IsNullOrEmpty(strPermissionIndexes [i]))
                {
                    permissionList.Add(int.Parse(strPermissionIndexes [i]));
                }
            }
            int[] permissionIndexes = permissionList.ToArray();

            #region 生成资源文件

            // Create a new project object from build target
            XCProject project = new XCProject(pathToBuiltProject);

            var variantGroup         = project.variantGroups;
            var rootGroup            = project.rootGroup;
            var buildFiles           = project.buildFiles;
            var resourcesBuildPhases = project.resourcesBuildPhases;

            var variant = new PBXVariantGroup("InfoPlist.strings", null, "GROUP");
            // mark variants
            variantGroup.Add(variant);
            // add variant to project
            rootGroup.AddChild(variant);

            // add variant in build process

            var appNameConfigData = AppNameConfigData.Load();

            Dictionary <string, string> language = new Dictionary <string, string> ();
            foreach (var languageData in appNameConfigData.SupportedLanguageItems)
            {
                language.Add(appNameConfigData.LanguageDefiOS [languageData.Index], languageData.AppName);
            }
            // English  en    french fr

            foreach (KeyValuePair <string, string> entry in language)
            {
                string folder = project.projectRootPath + "/" + entry.Key + ".lproj";
                if (!Directory.Exists(folder))
                {
                    Directory.CreateDirectory(folder);
                }
                string filePath = folder + "/InfoPlist.strings";
                string content  = "\"CFBundleDisplayName\" = \"" + entry.Value + "\";\n";

                List <PermissionDescription> permissionDescriptions = GetLanguagePermissionDescriptions(entry.Key, permissionIndexes);

                foreach (PermissionDescription permissionDescription in permissionDescriptions)
                {
                    content += "\"" + permissionDescription.PermissionName + "\" = \"" + permissionDescription.Description + "\";\n";
                }

                File.WriteAllText(filePath, content);

                var    result   = project.AddFile(filePath, (PBXGroup)variant, "SOURCE_ROOT", true, false);
                string firstKey = "";

                foreach (KeyValuePair <string, object> resultEntry in result)
                {
                    firstKey = resultEntry.Key;
                    break;
                }
                PBXFileReference fileReference = (PBXFileReference)result[firstKey];
                fileReference.Remove("name");
                fileReference.Add("name", entry.Key);

                PBXBuildFile buildFile = new PBXBuildFile(fileReference);
                buildFiles.Add(buildFile);
            }

            project.Save();
            #endregion
        }