GxrGradleVerify.cs 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. //==========================================================
  2. //
  3. // Copyright (c) Guangzhou Shixiang Technology Co.,Ltd.
  4. // All rights reserved.
  5. //
  6. //==========================================================
  7. using System.IO;
  8. using UnityEditor;
  9. namespace GxrSdk.Editor
  10. {
  11. /// <summary>
  12. /// gradle文件校验
  13. /// 根据Unity版本使用对应的gradle文件
  14. /// </summary>
  15. [InitializeOnLoad]
  16. public class GxrGradleVerify
  17. {
  18. /// <summary>
  19. /// 本地存放不同版本的Gradle文件的路径
  20. /// </summary>
  21. private static readonly string GradleFolder = "Assets/Plugins/Android/gradle/";
  22. /// <summary>
  23. /// launcherTemplate.gradle默认路径
  24. /// </summary>
  25. private static readonly string DestLauncherTemplateGradle = "Assets/Plugins/Android/launcherTemplate.gradle";
  26. /// <summary>
  27. /// mainTemplate.gradle默认路径
  28. /// </summary>
  29. private static readonly string DestMainTemplateGradle = "Assets/Plugins/Android/mainTemplate.gradle";
  30. static GxrGradleVerify()
  31. {
  32. EditorApplication.update += Update;
  33. }
  34. private static void Update()
  35. {
  36. EditorApplication.update -= Update;
  37. string launcherTemplateGradle = null;
  38. string mainTemplateGradle = null;
  39. #if UNITY_2022_1_OR_NEWER
  40. launcherTemplateGradle = GradleFolder + "Unity2022/launcherTemplate.gradle";
  41. #elif UNITY_2021_1_OR_NEWER
  42. launcherTemplateGradle = GradleFolder + "Unity2021/launcherTemplate.gradle";
  43. #elif UNITY_2020_1_OR_NEWER
  44. launcherTemplateGradle = GradleFolder + "Unity2020/launcherTemplate.gradle";
  45. #elif UNITY_2019_1_OR_NEWER
  46. launcherTemplateGradle = GradleFolder + "Unity2019/launcherTemplate.gradle";
  47. mainTemplateGradle = GradleFolder + "Unity2019/mainTemplate.gradle";
  48. #endif
  49. if (File.Exists(launcherTemplateGradle))
  50. {
  51. File.Copy(launcherTemplateGradle, DestLauncherTemplateGradle, true);
  52. }
  53. if (File.Exists(mainTemplateGradle))
  54. {
  55. File.Copy(mainTemplateGradle, DestMainTemplateGradle, true);
  56. }
  57. }
  58. }
  59. }