Explorar o código

编辑器拓展APP语言切换

lvjincheng %!s(int64=3) %!d(string=hai) anos
pai
achega
b52edfd5e4

+ 12 - 7
Assets/BowArrow/Scripts/CommonConfig.cs

@@ -1,3 +1,4 @@
+using System;
 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
@@ -5,8 +6,14 @@ using UnityEngine;
 /**通用配置(2021/12/18新增) */
 public class CommonConfig
 {
-    //App初始语言设置
-    public static readonly int AppLanguage = 1;
+    public static readonly string[] AppNames = {"青凤鸾", "HOUYI"};
+    public static readonly int[] AppLanguages = {0, 1};
+    public static readonly int[] ServerIndexes = {0, 1};
+    //根据产品名决定默认语言
+    public static int AppLanguage 
+    {
+        get => AppLanguages[Array.IndexOf(AppNames, Application.productName)];
+    }
     public static bool ReleaseVersion2 = true;
     /*
         特定版本功能
@@ -49,10 +56,8 @@ public class CommonConfig
     public static string businessServerWsURL;
     //游戏对战服务器
     public static string gamePKServerWsURL;
-    public static int serverIndex {
-        get {
-            if (AppLanguage == 0) return 0;
-            else return 1;
-        }
+    public static int serverIndex
+    {
+        get => ServerIndexes[Array.IndexOf(AppNames, Application.productName)];
     }
 }

+ 37 - 0
Assets/BowArrow/Scripts/Editor/MenuChangeAppLanguage.cs

@@ -0,0 +1,37 @@
+using UnityEditor;
+
+//在编辑菜单中增加功能-APP语言版本切换
+public class MenuChangeAppLanguage
+{
+    static void RefreshMenuChecked()
+    {
+        Menu.SetChecked("APP语言版本切换/中文", CommonConfig.AppLanguage == 0);
+        Menu.SetChecked("APP语言版本切换/英文", CommonConfig.AppLanguage == 1);
+    }
+
+    [MenuItem("APP语言版本切换/中文")]
+    static void ToCN() 
+    {
+        PlayerSettings.productName = CommonConfig.AppNames[0];
+    }
+
+    [MenuItem("APP语言版本切换/中文", true)]
+    static bool ToCN_Check() 
+    {
+        RefreshMenuChecked();
+        return true;
+    }
+
+    [MenuItem("APP语言版本切换/英文")]
+    static void ToEN() 
+    {
+        PlayerSettings.productName = CommonConfig.AppNames[1];
+    }
+
+    [MenuItem("APP语言版本切换/英文", true)]
+    static bool ToEN_Check() 
+    {
+        RefreshMenuChecked();
+        return true;
+    }
+}

+ 11 - 0
Assets/BowArrow/Scripts/Editor/MenuChangeAppLanguage.cs.meta

@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: 18d25b09d6396f34c953775f3e0d6abf
+MonoImporter:
+  externalObjects: {}
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 1 - 1
ProjectSettings/ProjectSettings.asset

@@ -13,7 +13,7 @@ PlayerSettings:
   useOnDemandResources: 0
   accelerometerFrequency: 60
   companyName: JssF
-  productName: HOUYI
+  productName: "\u9752\u51E4\u9E3E"
   defaultCursor: {fileID: 0}
   cursorHotspot: {x: 0, y: 0}
   m_SplashScreenBackgroundColor: {r: 0.13725491, g: 0.12156863, b: 0.1254902, a: 1}