Test.cs 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Reflection;
  5. using UnityEditor;
  6. using UnityEngine;
  7. using UnityEngine.XR;
  8. using UnityEditor.PackageManager;
  9. using UnityEditor.PackageManager.Requests;
  10. using System.Threading;
  11. using System.Collections;
  12. using static UnityEditor.PlayerSettings;
  13. public class Test
  14. {
  15. [MenuItem("GHZ/GHZGlassSDK/Test")]
  16. public static void test()
  17. {
  18. string type = "DreamGlass";
  19. ListRequest request = Client.List(true);
  20. while (!request.IsCompleted)
  21. {
  22. System.Threading.Thread.Sleep(500);
  23. // 等待PackageManager请求完成
  24. }
  25. System.Threading.Thread.Sleep(1000);
  26. if (type == "DreamGlass")
  27. {
  28. try
  29. {
  30. if (!Directory.Exists("Assets/Plugins/Android/"))
  31. {
  32. Directory.CreateDirectory("Assets/Plugins");
  33. Directory.CreateDirectory("Assets/Plugins/Android");
  34. }
  35. }
  36. catch
  37. {
  38. }
  39. try
  40. {
  41. if (File.Exists("Assets/Plugins/Android/AndroidManifest.xml.OLD"))
  42. {
  43. FileUtil.DeleteFileOrDirectory("Assets/Plugins/Android/AndroidManifest.xml.OLD");
  44. }
  45. }
  46. catch
  47. {
  48. }
  49. try
  50. {
  51. if (File.Exists("Assets/Plugins/Android/AndroidManifest.xml"))
  52. {
  53. FileUtil.CopyFileOrDirectory("Assets/Plugins/Android/AndroidManifest.xml", "Assets/Plugins/Android/AndroidManifest.xml.OLD");
  54. FileUtil.DeleteFileOrDirectory("Assets/Plugins/Android/AndroidManifest.xml");
  55. }
  56. }
  57. catch
  58. {
  59. }
  60. }
  61. else
  62. {
  63. try
  64. {
  65. if (File.Exists("Assets/Plugins/Android/AndroidManifest.xml.OLD"))
  66. {
  67. if (File.Exists("Assets/Plugins/Android/AndroidManifest.xml"))
  68. {
  69. FileUtil.DeleteFileOrDirectory("Assets/Plugins/Android/AndroidManifest.xml");
  70. }
  71. FileUtil.CopyFileOrDirectory("Assets/Plugins/Android/AndroidManifest.xml.OLD", "Assets/Plugins/Android/AndroidManifest.xml");
  72. FileUtil.DeleteFileOrDirectory("Assets/Plugins/Android/AndroidManifest.xml.OLD");
  73. }
  74. }
  75. catch
  76. {
  77. }
  78. }
  79. if (request.Status == StatusCode.Success)
  80. {
  81. Debug.Log("开始所搜是否有测试案例:");
  82. foreach (UnityEditor.PackageManager.PackageInfo package in request.Result)
  83. {
  84. if (package.name == "jh.xr.engine" || package.name == "com.ximmerse.xr" || package.name == "com.ghz.xr") // 替换为你的Package名称
  85. {
  86. string packagePath = package.assetPath + "/Samples~";//"Packages/com.ghz.avideoplayer"; // 替换为你的Package路径
  87. string destinationPath = "Assets/GHZSDK/" + package.name; // 替换为你想要放置Samples的目标路径
  88. // FileUtil.CopyFileOrDirectory(packagePath, destinationPath);
  89. if (type == "DreamGlass")
  90. {
  91. Debug.Log("找到测试案例 进行复制:");
  92. packagePath = package.assetPath + "/Samples~/ShadowCreator/Plugins/Android/AndroidManifest.xml";//"Packages/com.ghz.avideoplayer"; // 替换为你的Package路径
  93. destinationPath = "Assets/Plugins/Android/AndroidManifest.xml"; // 替换为你想要放置Samples的目标路径
  94. FileUtil.CopyFileOrDirectory(packagePath, destinationPath);
  95. }
  96. Debug.Log("找到测试案例 全部复制完成:"+ type+" "+ type == " DreamGlass");
  97. AssetDatabase.Refresh();
  98. }
  99. }
  100. }
  101. else
  102. {
  103. Debug.LogError("Failed to list installed packages: " + request.Error.message);
  104. }
  105. // 模拟等待2秒
  106. // 在这里执行异步操作完成后的逻辑
  107. }
  108. }