123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125 |
- 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秒
- // 在这里执行异步操作完成后的逻辑
- }
- }
|