fix:添加中控所需脚本,调整打包文件

This commit is contained in:
bzx
2025-10-11 14:57:01 +08:00
parent 6cfdd9283b
commit 05e60cff41
5 changed files with 57 additions and 8 deletions

View File

@@ -0,0 +1,40 @@
#if UNITY_EDITOR
using UnityEditor;
using UnityEditor.Build;
using UnityEditor.Build.Reporting;
using UnityEngine;
using System.IO;
using System.Text.RegularExpressions;
public class BuildPostProcessor : IPreprocessBuildWithReport
{
public int callbackOrder => 0;
public void OnPreprocessBuild(BuildReport report)
{
if (report.summary.platform == BuildTarget.Android)
{
UpdateAndroidManifest();
}
}
private void UpdateAndroidManifest()
{
string manifestPath = Path.Combine(Application.dataPath, "Plugins/Android/AndroidManifest.xml");
if (File.Exists(manifestPath))
{
string manifestContent = File.ReadAllText(manifestPath);
string packageName = PlayerSettings.applicationIdentifier;
// 使用正则表达式匹配并替换 android:path 的值
string updatedContent = Regex.Replace(manifestContent,
@"android:path=""[^""]*""",
$"android:path=\"/{packageName}\"");
File.WriteAllText(manifestPath, updatedContent);
Debug.Log($"Updated AndroidManifest.xml with package name: {packageName}");
}
}
}
#endif

View File

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