//==========================================================
//
// Copyright (c) Guangzhou Shixiang Technology Co.,Ltd.
// All rights reserved.
//
//==========================================================
using System.IO;
using UnityEditor;
namespace GxrSdk.Editor
{
///
/// gradle文件校验
/// 根据Unity版本使用对应的gradle文件
///
[InitializeOnLoad]
public class GxrGradleVerify
{
///
/// 本地存放不同版本的Gradle文件的路径
///
private static readonly string GradleFolder = "Assets/Plugins/Android/gradle/";
///
/// launcherTemplate.gradle默认路径
///
private static readonly string DestLauncherTemplateGradle = "Assets/Plugins/Android/launcherTemplate.gradle";
///
/// mainTemplate.gradle默认路径
///
private static readonly string DestMainTemplateGradle = "Assets/Plugins/Android/mainTemplate.gradle";
static GxrGradleVerify()
{
EditorApplication.update += Update;
}
private static void Update()
{
EditorApplication.update -= Update;
string launcherTemplateGradle = null;
string mainTemplateGradle = null;
#if UNITY_2022_1_OR_NEWER
launcherTemplateGradle = GradleFolder + "Unity2022/launcherTemplate.gradle";
#elif UNITY_2021_1_OR_NEWER
launcherTemplateGradle = GradleFolder + "Unity2021/launcherTemplate.gradle";
#elif UNITY_2020_1_OR_NEWER
launcherTemplateGradle = GradleFolder + "Unity2020/launcherTemplate.gradle";
#elif UNITY_2019_1_OR_NEWER
launcherTemplateGradle = GradleFolder + "Unity2019/launcherTemplate.gradle";
mainTemplateGradle = GradleFolder + "Unity2019/mainTemplate.gradle";
#endif
if (File.Exists(launcherTemplateGradle))
{
File.Copy(launcherTemplateGradle, DestLauncherTemplateGradle, true);
}
if (File.Exists(mainTemplateGradle))
{
File.Copy(mainTemplateGradle, DestMainTemplateGradle, true);
}
}
}
}