|
|
@@ -1,4 +1,8 @@
|
|
|
+using System.Collections.Generic;
|
|
|
+using System.IO;
|
|
|
+using System.Text.RegularExpressions;
|
|
|
using UnityEditor;
|
|
|
+using UnityEditor.Build;
|
|
|
using UnityEngine;
|
|
|
|
|
|
public class MenuChangeAppLanguage
|
|
|
@@ -65,7 +69,8 @@ public class MenuChangeAppLanguage
|
|
|
};
|
|
|
|
|
|
PlayerSettings.SetApplicationIdentifier(BuildTargetGroup.iOS, bundleId);
|
|
|
- PlayerSettings.iOS.targetDevice = device == DeviceType.iPhone ? iOSTargetDevice.iPhoneOnly : iOSTargetDevice.iPadOnly;
|
|
|
+ //现在iphone模式需要上传ipad
|
|
|
+ PlayerSettings.iOS.targetDevice = device == DeviceType.iPhone ? iOSTargetDevice.iPhoneAndiPad : iOSTargetDevice.iPadOnly;
|
|
|
PlayerSettings.iOS.appleDeveloperTeamID = "WR7WD35237";
|
|
|
PlayerSettings.iOS.appleEnableAutomaticSigning = true;
|
|
|
#endif
|
|
|
@@ -123,5 +128,201 @@ public class MenuChangeAppLanguage
|
|
|
for (int i = 0; i < icons.Length; i++) icons[i] = texture;
|
|
|
PlayerSettings.SetIconsForTargetGroup(BuildTargetGroup.Unknown, icons);
|
|
|
AssetDatabase.SaveAssets();
|
|
|
+
|
|
|
+#if UNITY_IOS
|
|
|
+ if (device == DeviceType.iPhone)
|
|
|
+ ApplyAllIosIcons(langId);
|
|
|
+ else
|
|
|
+ ClearIosIcons();
|
|
|
+#endif
|
|
|
+ }
|
|
|
+
|
|
|
+ private static readonly string iconPathCN = "Assets/BowArrow/Textures/Common/AppIconsCN"; // iOS中文图标文件夹
|
|
|
+ private static readonly string iconPathEN = "Assets/BowArrow/Textures/Common/AppIconsEN"; // iOS英文图标文件夹
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 批量导入 iOS 所有图标
|
|
|
+ /// </summary>
|
|
|
+ public static void ApplyAllIosIcons(int langId)
|
|
|
+ {
|
|
|
+ string iconPath = langId == 1 ? iconPathEN : iconPathCN;
|
|
|
+
|
|
|
+ // ✅ 收集文件
|
|
|
+ string[] files = Directory.GetFiles(iconPath, "*.png", SearchOption.AllDirectories);
|
|
|
+ if (files.Length == 0)
|
|
|
+ {
|
|
|
+ Debug.LogError($"未找到图标文件: {iconPath}");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // ✅ 解析像素尺寸
|
|
|
+ Dictionary<int, Texture2D> pixelMap = new();
|
|
|
+ foreach (string file in files)
|
|
|
+ {
|
|
|
+ Texture2D tex = AssetDatabase.LoadAssetAtPath<Texture2D>(file);
|
|
|
+ if (tex == null) continue;
|
|
|
+
|
|
|
+ if (TryParseIconPixel(file, out int pixels))
|
|
|
+ {
|
|
|
+ pixelMap[pixels] = tex;
|
|
|
+ Debug.Log($"识别图标: {Path.GetFileName(file)} → {pixels}px");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+#if UNITY_2022_1_OR_NEWER
|
|
|
+ var target = NamedBuildTarget.iOS;
|
|
|
+ var iconKinds = PlayerSettings.GetSupportedIconKinds(target);
|
|
|
+
|
|
|
+ foreach (var kind in iconKinds)
|
|
|
+ {
|
|
|
+ var icons = PlayerSettings.GetPlatformIcons(target, kind);
|
|
|
+
|
|
|
+ // ✅ 清空旧图标
|
|
|
+ for (int i = 0; i < icons.Length; i++)
|
|
|
+ icons[i].SetTexture(null);
|
|
|
+
|
|
|
+ for (int i = 0; i < icons.Length; i++)
|
|
|
+ {
|
|
|
+ int size = Mathf.RoundToInt(icons[i].width);
|
|
|
+ if (pixelMap.TryGetValue(size, out var tex))
|
|
|
+ {
|
|
|
+ icons[i].SetTexture(tex);
|
|
|
+ Debug.Log($"✅ [2022+] 设置 {kind} 图标 {size}px");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ PlayerSettings.SetPlatformIcons(target, kind, icons);
|
|
|
+ }
|
|
|
+#else
|
|
|
+ var group = BuildTargetGroup.iOS;
|
|
|
+ var iconKinds = PlayerSettings.GetSupportedIconKindsForPlatform(group);
|
|
|
+
|
|
|
+ foreach (var kind in iconKinds)
|
|
|
+ {
|
|
|
+ var icons = PlayerSettings.GetPlatformIcons(group, kind);
|
|
|
+
|
|
|
+ // ✅ 清空旧图标
|
|
|
+ for (int i = 0; i < icons.Length; i++)
|
|
|
+ icons[i].SetTexture(null);
|
|
|
+
|
|
|
+ for (int i = 0; i < icons.Length; i++)
|
|
|
+ {
|
|
|
+ int size = Mathf.RoundToInt(icons[i].width);
|
|
|
+ if (pixelMap.TryGetValue(size, out var tex))
|
|
|
+ {
|
|
|
+ icons[i].SetTexture(tex);
|
|
|
+ Debug.Log($"✅ [2021] 设置 {kind} 图标 {size}px");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ PlayerSettings.SetPlatformIcons(group, kind, icons);
|
|
|
+ }
|
|
|
+#endif
|
|
|
+
|
|
|
+ AssetDatabase.SaveAssets();
|
|
|
+ Debug.Log("🎯 iOS App Icons 全部导入完成!");
|
|
|
+ }
|
|
|
+ public static void ClearIosIcons()
|
|
|
+ {
|
|
|
+#if UNITY_2022_1_OR_NEWER
|
|
|
+ var target = NamedBuildTarget.iOS;
|
|
|
+ var iconKinds = PlayerSettings.GetSupportedIconKinds(target);
|
|
|
+
|
|
|
+ foreach (var kind in iconKinds)
|
|
|
+ {
|
|
|
+ var icons = PlayerSettings.GetPlatformIcons(target, kind);
|
|
|
+
|
|
|
+ // ✅ 清空旧图标
|
|
|
+ for (int i = 0; i < icons.Length; i++)
|
|
|
+ icons[i].SetTexture(null);
|
|
|
+
|
|
|
+ PlayerSettings.SetPlatformIcons(target, kind, icons);
|
|
|
+ }
|
|
|
+#else
|
|
|
+ var group = BuildTargetGroup.iOS;
|
|
|
+ var iconKinds = PlayerSettings.GetSupportedIconKindsForPlatform(group);
|
|
|
+
|
|
|
+ foreach (var kind in iconKinds)
|
|
|
+ {
|
|
|
+ var icons = PlayerSettings.GetPlatformIcons(group, kind);
|
|
|
+
|
|
|
+ // ✅ 清空旧图标
|
|
|
+ for (int i = 0; i < icons.Length; i++)
|
|
|
+ icons[i].SetTexture(null);
|
|
|
+
|
|
|
+ PlayerSettings.SetPlatformIcons(group, kind, icons);
|
|
|
+ }
|
|
|
+#endif
|
|
|
+
|
|
|
+ AssetDatabase.SaveAssets();
|
|
|
+ Debug.Log("🎯 iOS App Icons 全部清空!");
|
|
|
+ }
|
|
|
+ /// <summary>
|
|
|
+ /// 支持多种命名方式的像素解析
|
|
|
+ /// </summary>
|
|
|
+ private static bool TryParseIconPixel(string file, out int pixels)
|
|
|
+ {
|
|
|
+ pixels = 0;
|
|
|
+ string name = Path.GetFileNameWithoutExtension(file);
|
|
|
+
|
|
|
+ // ① 匹配 iPhoneApp_60pt@3x → 180px
|
|
|
+ Match m = Regex.Match(name, @"(\d+(?:\.\d+)?)pt@(\d+)x");
|
|
|
+ if (m.Success)
|
|
|
+ {
|
|
|
+ float pt = float.Parse(m.Groups[1].Value);
|
|
|
+ int scale = int.Parse(m.Groups[2].Value);
|
|
|
+ pixels = Mathf.RoundToInt(pt * scale);
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ // ② 匹配 store_1024pt 或 icon_60pt(无倍数,pt=px)
|
|
|
+ m = Regex.Match(name, @"(\d+)pt");
|
|
|
+ if (m.Success)
|
|
|
+ {
|
|
|
+ pixels = int.Parse(m.Groups[1].Value);
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ // ③ 匹配直接像素命名 icon_180x180
|
|
|
+ m = Regex.Match(name, @"(\d+)x\d+");
|
|
|
+ if (m.Success)
|
|
|
+ {
|
|
|
+ pixels = int.Parse(m.Groups[1].Value);
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ // ④ 特殊情况:AppStore_1024.png
|
|
|
+ m = Regex.Match(name, @"1024");
|
|
|
+ if (m.Success)
|
|
|
+ {
|
|
|
+ pixels = 1024;
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ return false;
|
|
|
}
|
|
|
+ /// <summary>
|
|
|
+ /// 从文件名中提取像素尺寸,如 "iPhoneApp_60pt@3x" → 180px
|
|
|
+ /// </summary>
|
|
|
+ //private static bool TryParseIconPixel(string file, out int pixels)
|
|
|
+ //{
|
|
|
+ // pixels = 0;
|
|
|
+ // string name = Path.GetFileNameWithoutExtension(file);
|
|
|
+ // Match m = Regex.Match(name, @"(\d+(?:\.\d+)?)pt@(\d+)x");
|
|
|
+ // if (m.Success)
|
|
|
+ // {
|
|
|
+ // float pt = float.Parse(m.Groups[1].Value);
|
|
|
+ // int scale = int.Parse(m.Groups[2].Value);
|
|
|
+ // pixels = Mathf.RoundToInt(pt * scale);
|
|
|
+ // return true;
|
|
|
+ // }
|
|
|
+
|
|
|
+ // // 匹配直接像素命名: Icon_120x120.png
|
|
|
+ // m = Regex.Match(name, @"(\d+)x\d+");
|
|
|
+ // if (m.Success)
|
|
|
+ // {
|
|
|
+ // pixels = int.Parse(m.Groups[1].Value);
|
|
|
+ // return true;
|
|
|
+ // }
|
|
|
+
|
|
|
+ // return false;
|
|
|
+ //}
|
|
|
}
|