修复ios问题
This commit is contained in:
parent
4345a9c326
commit
fb67d4b324
26
Assets/Editor/iOSFixDuplicateShellScript.cs
Normal file
26
Assets/Editor/iOSFixDuplicateShellScript.cs
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
#if UNITY_IOS
|
||||||
|
using UnityEditor;
|
||||||
|
using UnityEditor.Callbacks;
|
||||||
|
using System.IO;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
|
|
||||||
|
public class iOSFixDuplicateShellScript
|
||||||
|
{
|
||||||
|
[PostProcessBuild]
|
||||||
|
public static void OnPostProcessBuild(BuildTarget target, string pathToBuiltProject)
|
||||||
|
{
|
||||||
|
if (target != BuildTarget.iOS) return;
|
||||||
|
|
||||||
|
string projPath = Path.Combine(pathToBuiltProject, "Unity-iPhone.xcodeproj/project.pbxproj");
|
||||||
|
if (!File.Exists(projPath)) return;
|
||||||
|
|
||||||
|
string content = File.ReadAllText(projPath);
|
||||||
|
|
||||||
|
// 匹配 GameAssembly target 的 buildPhases 中连续两个相同的 ShellScript
|
||||||
|
string pattern = @"(\t+([A-F0-9]+) /\* ShellScript \*/,)\n\t+\2 /\* ShellScript \*,/";
|
||||||
|
content = Regex.Replace(content, pattern, "$1");
|
||||||
|
|
||||||
|
File.WriteAllText(projPath, content);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
11
Assets/Editor/iOSFixDuplicateShellScript.cs.meta
Normal file
11
Assets/Editor/iOSFixDuplicateShellScript.cs.meta
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 7deade7af8d5c428e8c773a0c818f45c
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@ -853,7 +853,7 @@ Camera:
|
|||||||
m_GameObject: {fileID: 963194225}
|
m_GameObject: {fileID: 963194225}
|
||||||
m_Enabled: 1
|
m_Enabled: 1
|
||||||
serializedVersion: 2
|
serializedVersion: 2
|
||||||
m_ClearFlags: 4
|
m_ClearFlags: 2
|
||||||
m_BackGroundColor: {r: 0.19215687, g: 0.3019608, b: 0.4745098, a: 0}
|
m_BackGroundColor: {r: 0.19215687, g: 0.3019608, b: 0.4745098, a: 0}
|
||||||
m_projectionMatrixMode: 1
|
m_projectionMatrixMode: 1
|
||||||
m_GateFitMode: 2
|
m_GateFitMode: 2
|
||||||
|
|||||||
@ -307,15 +307,27 @@ namespace Kill.UI.Pages
|
|||||||
// 异步解析二维码以避免卡顿
|
// 异步解析二维码以避免卡顿
|
||||||
if (useAsyncScan)
|
if (useAsyncScan)
|
||||||
{
|
{
|
||||||
|
// 在主线程提取像素数据(Unity API 必须在主线程调用)
|
||||||
|
Color32[] pixels = previewTexture.GetPixels32();
|
||||||
|
int texWidth = previewTexture.width;
|
||||||
|
int texHeight = previewTexture.height;
|
||||||
|
byte[] rgbBytes = new byte[pixels.Length * 3];
|
||||||
|
for (int i = 0; i < pixels.Length; i++)
|
||||||
|
{
|
||||||
|
rgbBytes[i * 3] = pixels[i].r;
|
||||||
|
rgbBytes[i * 3 + 1] = pixels[i].g;
|
||||||
|
rgbBytes[i * 3 + 2] = pixels[i].b;
|
||||||
|
}
|
||||||
|
|
||||||
string result = null;
|
string result = null;
|
||||||
bool scanComplete = false;
|
bool scanComplete = false;
|
||||||
|
|
||||||
// 在后台线程执行解码
|
// 在后台线程执行 ZXing 解码(纯计算,不涉及 Unity API)
|
||||||
System.Threading.ThreadPool.QueueUserWorkItem(_ =>
|
System.Threading.ThreadPool.QueueUserWorkItem(_ =>
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
result = DecodeQRCode(previewTexture);
|
result = DecodeQRCodeFromBytes(rgbBytes, texWidth, texHeight);
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
@ -478,6 +490,27 @@ namespace Kill.UI.Pages
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 从原始字节数据解析二维码(不依赖 Unity API,可在后台线程调用)
|
||||||
|
/// </summary>
|
||||||
|
private string DecodeQRCodeFromBytes(byte[] rgbBytes, int width, int height)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var luminanceSource = new ZXing.RGBLuminanceSource(rgbBytes, width, height);
|
||||||
|
string result = TryDecodeWithBinarizer(luminanceSource);
|
||||||
|
if (!string.IsNullOrEmpty(result))
|
||||||
|
return result;
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Debug.LogError($"二维码解析失败: {ex.Message}");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -8,9 +8,6 @@ EditorBuildSettings:
|
|||||||
- enabled: 1
|
- enabled: 1
|
||||||
path: Assets/Scenes/MainScene.unity
|
path: Assets/Scenes/MainScene.unity
|
||||||
guid: c850ee8c3b14cc8459e7e186857cf567
|
guid: c850ee8c3b14cc8459e7e186857cf567
|
||||||
- enabled: 0
|
|
||||||
path: Assets/Scenes/BlueToothTest.unity
|
|
||||||
guid: 225b59975b598b74cb6fa7cbd7119dbe
|
|
||||||
m_configObjects:
|
m_configObjects:
|
||||||
com.unity.adaptiveperformance.loader_settings: {fileID: 11400000, guid: 0488490a53b3eb2409be4727abdf829a,
|
com.unity.adaptiveperformance.loader_settings: {fileID: 11400000, guid: 0488490a53b3eb2409be4727abdf829a,
|
||||||
type: 2}
|
type: 2}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user