diff --git a/Assets/Editor/iOSFixDuplicateShellScript.cs b/Assets/Editor/iOSFixDuplicateShellScript.cs new file mode 100644 index 0000000..470c63c --- /dev/null +++ b/Assets/Editor/iOSFixDuplicateShellScript.cs @@ -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 diff --git a/Assets/Editor/iOSFixDuplicateShellScript.cs.meta b/Assets/Editor/iOSFixDuplicateShellScript.cs.meta new file mode 100644 index 0000000..91c0ef2 --- /dev/null +++ b/Assets/Editor/iOSFixDuplicateShellScript.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 7deade7af8d5c428e8c773a0c818f45c +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scenes/MainScene.unity b/Assets/Scenes/MainScene.unity index d48244a..4906776 100644 --- a/Assets/Scenes/MainScene.unity +++ b/Assets/Scenes/MainScene.unity @@ -853,7 +853,7 @@ Camera: m_GameObject: {fileID: 963194225} m_Enabled: 1 serializedVersion: 2 - m_ClearFlags: 4 + m_ClearFlags: 2 m_BackGroundColor: {r: 0.19215687, g: 0.3019608, b: 0.4745098, a: 0} m_projectionMatrixMode: 1 m_GateFitMode: 2 diff --git a/Assets/Scripts/UI/Pages/ConnectDevice/ScanQRcode.cs b/Assets/Scripts/UI/Pages/ConnectDevice/ScanQRcode.cs index b8bf1a0..eece869 100644 --- a/Assets/Scripts/UI/Pages/ConnectDevice/ScanQRcode.cs +++ b/Assets/Scripts/UI/Pages/ConnectDevice/ScanQRcode.cs @@ -307,15 +307,27 @@ namespace Kill.UI.Pages // 异步解析二维码以避免卡顿 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; bool scanComplete = false; - // 在后台线程执行解码 + // 在后台线程执行 ZXing 解码(纯计算,不涉及 Unity API) System.Threading.ThreadPool.QueueUserWorkItem(_ => { try { - result = DecodeQRCode(previewTexture); + result = DecodeQRCodeFromBytes(rgbBytes, texWidth, texHeight); } catch (Exception e) { @@ -478,6 +490,27 @@ namespace Kill.UI.Pages return null; } } + + /// + /// 从原始字节数据解析二维码(不依赖 Unity API,可在后台线程调用) + /// + 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; + } + } diff --git a/ProjectSettings/EditorBuildSettings.asset b/ProjectSettings/EditorBuildSettings.asset index 38d9967..1758819 100644 --- a/ProjectSettings/EditorBuildSettings.asset +++ b/ProjectSettings/EditorBuildSettings.asset @@ -8,9 +8,6 @@ EditorBuildSettings: - enabled: 1 path: Assets/Scenes/MainScene.unity guid: c850ee8c3b14cc8459e7e186857cf567 - - enabled: 0 - path: Assets/Scenes/BlueToothTest.unity - guid: 225b59975b598b74cb6fa7cbd7119dbe m_configObjects: com.unity.adaptiveperformance.loader_settings: {fileID: 11400000, guid: 0488490a53b3eb2409be4727abdf829a, type: 2}