using System; using System.Collections.Generic; using System.IO; using System.Reflection; using UnityEditor; using UnityEngine; using UnityEngine.XR; using UnityEditor.PackageManager; using UnityEditor.PackageManager.Requests; using System.Threading; using System.Collections; using static UnityEditor.PlayerSettings; public class Test { [MenuItem("GHZ/GHZGlassSDK/Test")] public static void test() { string type = "DreamGlass"; ListRequest request = Client.List(true); while (!request.IsCompleted) { System.Threading.Thread.Sleep(500); // 等待PackageManager请求完成 } System.Threading.Thread.Sleep(1000); if (type == "DreamGlass") { try { if (!Directory.Exists("Assets/Plugins/Android/")) { Directory.CreateDirectory("Assets/Plugins"); Directory.CreateDirectory("Assets/Plugins/Android"); } } catch { } try { if (File.Exists("Assets/Plugins/Android/AndroidManifest.xml.OLD")) { FileUtil.DeleteFileOrDirectory("Assets/Plugins/Android/AndroidManifest.xml.OLD"); } } catch { } try { if (File.Exists("Assets/Plugins/Android/AndroidManifest.xml")) { FileUtil.CopyFileOrDirectory("Assets/Plugins/Android/AndroidManifest.xml", "Assets/Plugins/Android/AndroidManifest.xml.OLD"); FileUtil.DeleteFileOrDirectory("Assets/Plugins/Android/AndroidManifest.xml"); } } catch { } } else { try { if (File.Exists("Assets/Plugins/Android/AndroidManifest.xml.OLD")) { if (File.Exists("Assets/Plugins/Android/AndroidManifest.xml")) { FileUtil.DeleteFileOrDirectory("Assets/Plugins/Android/AndroidManifest.xml"); } FileUtil.CopyFileOrDirectory("Assets/Plugins/Android/AndroidManifest.xml.OLD", "Assets/Plugins/Android/AndroidManifest.xml"); FileUtil.DeleteFileOrDirectory("Assets/Plugins/Android/AndroidManifest.xml.OLD"); } } catch { } } if (request.Status == StatusCode.Success) { Debug.Log("开始所搜是否有测试案例:"); foreach (UnityEditor.PackageManager.PackageInfo package in request.Result) { if (package.name == "jh.xr.engine" || package.name == "com.ximmerse.xr" || package.name == "com.ghz.xr") // 替换为你的Package名称 { string packagePath = package.assetPath + "/Samples~";//"Packages/com.ghz.avideoplayer"; // 替换为你的Package路径 string destinationPath = "Assets/GHZSDK/" + package.name; // 替换为你想要放置Samples的目标路径 // FileUtil.CopyFileOrDirectory(packagePath, destinationPath); if (type == "DreamGlass") { Debug.Log("找到测试案例 进行复制:"); packagePath = package.assetPath + "/Samples~/ShadowCreator/Plugins/Android/AndroidManifest.xml";//"Packages/com.ghz.avideoplayer"; // 替换为你的Package路径 destinationPath = "Assets/Plugins/Android/AndroidManifest.xml"; // 替换为你想要放置Samples的目标路径 FileUtil.CopyFileOrDirectory(packagePath, destinationPath); } Debug.Log("找到测试案例 全部复制完成:"+ type+" "+ type == " DreamGlass"); AssetDatabase.Refresh(); } } } else { Debug.LogError("Failed to list installed packages: " + request.Error.message); } // 模拟等待2秒 // 在这里执行异步操作完成后的逻辑 } }