killapp/Assets/Editor/iOSFixDuplicateShellScript.cs
yuqucheng 82c997068d feat: 更新iOS构建脚本、Firebase依赖及图标资源
- 优化 iOS 重复 Shell 脚本修复逻辑
- 添加 Firebase Analytics 依赖
- 重命名图标资源为 Icon-iPhone 标准格式
2026-07-06 15:42:29 +08:00

82 lines
2.4 KiB
C#

#if UNITY_IOS
using UnityEditor;
using UnityEditor.Callbacks;
using System.IO;
using System.Text.RegularExpressions;
using UnityEngine;
public class iOSFixDuplicateShellScript
{
[PostProcessBuild(999)]
public static void OnPostProcessBuild(BuildTarget target, string pathToBuiltProject)
{
if (target != BuildTarget.iOS) return;
FixDuplicateShellScript(pathToBuiltProject);
FixPodfile(pathToBuiltProject);
}
private static void FixDuplicateShellScript(string pathToBuiltProject)
{
string projPath = Path.Combine(pathToBuiltProject, "Unity-iPhone.xcodeproj/project.pbxproj");
if (!File.Exists(projPath))
{
Debug.LogWarning("[FixDupShellScript] pbxproj not found: " + projPath);
return;
}
string content = File.ReadAllText(projPath);
string pattern = @"(\t+([A-F0-9]+) /\* ShellScript \*/,)\r?\n\t+\2 /\* ShellScript \*,/";
string newContent = Regex.Replace(content, pattern, "$1");
if (newContent != content)
{
File.WriteAllText(projPath, newContent);
Debug.Log("[FixDupShellScript] Removed duplicate ShellScript from GameAssembly target");
}
else
{
Debug.Log("[FixDupShellScript] No duplicate ShellScript found");
}
}
private static void FixPodfile(string pathToBuiltProject)
{
string podfilePath = Path.Combine(pathToBuiltProject, "Podfile");
if (!File.Exists(podfilePath))
{
Debug.LogWarning("[FixPodfile] Podfile not found");
return;
}
string content = File.ReadAllText(podfilePath);
bool modified = false;
// 移除不需要的 Firebase/Analytics
if (content.Contains("Firebase/Analytics"))
{
content = Regex.Replace(content, @"\s*pod\s+'Firebase/Analytics'[^\n]*\n?", "\n");
modified = true;
}
// 将 12.4.0 统一为 12.14.0
if (content.Contains("12.4.0"))
{
content = content.Replace("12.4.0", "12.14.0");
modified = true;
}
if (modified)
{
File.WriteAllText(podfilePath, content);
Debug.Log("[FixPodfile] Cleaned up Podfile");
}
else
{
Debug.Log("[FixPodfile] Podfile already clean");
}
}
}
#endif