You've already forked Commercialization.topon
升级sdk至 2.1.1
This commit is contained in:
@@ -16,7 +16,7 @@ namespace AnyThink.Scripts.IntegrationManager.Editor
|
||||
|
||||
public class ATConfig
|
||||
{
|
||||
public static string PLUGIN_VERSION = "2.1.0";
|
||||
public static string PLUGIN_VERSION = "2.1.1";
|
||||
public static bool isDebug = false;
|
||||
|
||||
public static int OS_ANDROID = 1;
|
||||
@@ -45,8 +45,8 @@ public static bool isDebug = false;
|
||||
//network json文件名
|
||||
public static string network_data_file_name = "network_data.json";
|
||||
//插件设置的数据
|
||||
private static string plugin_setting_data_path = $"{RootPath}/Resources/json/" + PLUGIN_VERSION;
|
||||
private static string plugin_setting_data_file_name = "plugin_setting_data.json";
|
||||
public static string plugin_setting_data_path = $"{RootPath}/Resources/json/" + PLUGIN_VERSION;
|
||||
public static string plugin_setting_data_file_name = "plugin_setting_data.json";
|
||||
|
||||
private static string _rootPath;
|
||||
|
||||
@@ -175,6 +175,7 @@ public static bool isDebug = false;
|
||||
//Android
|
||||
if (!string.IsNullOrEmpty(android_version)) {
|
||||
var networkPath = getAndroidNetworkPath(network);
|
||||
Directory.CreateDirectory(networkPath);
|
||||
ATLog.log("saveInstalledNetworkVersion() >>> android networkPath: " + networkPath + " exist: " + Directory.Exists(networkPath));
|
||||
if (Directory.Exists(networkPath)) {
|
||||
string fullPath = Path.Combine(networkPath, networkDataFileName);
|
||||
@@ -192,7 +193,8 @@ public static bool isDebug = false;
|
||||
var ios_version = installedVersions.Ios;
|
||||
if (!string.IsNullOrEmpty(ios_version)) {
|
||||
var networkPath = getIosNetworkPath(network);
|
||||
ATLog.log("saveInstalledNetworkVersion() >>> ios networkPath: " + networkPath);
|
||||
Directory.CreateDirectory(networkPath);
|
||||
ATLog.log("saveInstalledNetworkVersion() >>> ios networkPath: " + networkPath);
|
||||
if (Directory.Exists(networkPath)) {
|
||||
string fullPath = Path.Combine(networkPath, networkDataFileName);
|
||||
var networkData = new NetworkLocalData();
|
||||
@@ -332,7 +334,12 @@ public static bool isDebug = false;
|
||||
|
||||
public static bool enableAndroidX() {
|
||||
var pluginSettingData = getPluginSettingData();
|
||||
return pluginSettingData.getCountrySettingData().enableAndroidX;
|
||||
return pluginSettingData.getCountrySettingData().androidXSetting == 1;
|
||||
}
|
||||
|
||||
public static bool isDefaultAndroidX() {
|
||||
var pluginSettingData = getPluginSettingData();
|
||||
return pluginSettingData.getCountrySettingData().androidXSetting == 0;
|
||||
}
|
||||
|
||||
//获取默认选中的地区
|
||||
|
||||
@@ -297,7 +297,7 @@ namespace AnyThink.Scripts.IntegrationManager.Editor
|
||||
network.CurrentVersions = versions;
|
||||
|
||||
// await Task.Delay(1000);
|
||||
Thread.Sleep(1000);
|
||||
// Thread.Sleep(1000);
|
||||
//下面的逻辑会延迟一秒后执行,确保unitypackage先解压到本地
|
||||
ATConfig.saveInstalledNetworkVersion(network, os);
|
||||
ATLog.log("UpdateCurrentVersions() >>> AndroidVersion: " + versions.Android);
|
||||
@@ -339,25 +339,24 @@ namespace AnyThink.Scripts.IntegrationManager.Editor
|
||||
}
|
||||
|
||||
//获取AndroidX开关状态
|
||||
public bool enableAndroidX(PluginData pluginData) {
|
||||
public int getAndroidXSetting(PluginData pluginData) {
|
||||
if (pluginData == null) {
|
||||
return false;
|
||||
return 0;
|
||||
}
|
||||
var pluginSettingData = pluginData.pluginSettingData;
|
||||
if (pluginSettingData == null) {
|
||||
return false;
|
||||
return 0;
|
||||
}
|
||||
CountrySettingData countrySettingData = pluginSettingData.getCountrySettingData();
|
||||
|
||||
return countrySettingData.enableAndroidX;
|
||||
return countrySettingData.androidXSetting;
|
||||
}
|
||||
|
||||
//设置并保存AndroidX开关状态
|
||||
public void saveAndroidXSetting(PluginData pluginData, bool enable) {
|
||||
ATLog.log("saveAndroidXSetting() >>> enable: " + enable);
|
||||
public void saveAndroidXSetting(PluginData pluginData, int androidXSetting) {
|
||||
ATLog.log("saveAndroidXSetting() >>> androidXSetting: " + androidXSetting);
|
||||
var pluginSettingData = pluginData.pluginSettingData;
|
||||
CountrySettingData countrySettingData = pluginSettingData.getCountrySettingData();
|
||||
countrySettingData.enableAndroidX = enable;
|
||||
countrySettingData.androidXSetting = androidXSetting;
|
||||
|
||||
ATConfig.savePluginSettingData(pluginSettingData);
|
||||
}
|
||||
|
||||
@@ -126,6 +126,8 @@ namespace AnyThink.Scripts.IntegrationManager.Editor
|
||||
warningIcon.LoadImage(warningIconData);
|
||||
|
||||
loadPluginData();
|
||||
//热更新
|
||||
ATIntegrationHotFix.Instance.loadHotFixData();
|
||||
}
|
||||
|
||||
//这个方法在插件启动时会调用,然后脚本重新加载时也会重新调用,所以加载数据放在Awake中
|
||||
@@ -359,27 +361,30 @@ namespace AnyThink.Scripts.IntegrationManager.Editor
|
||||
|
||||
private void DrawAndroidXUI()
|
||||
{
|
||||
if (!ATConfig.isSelectedChina()) {
|
||||
return;
|
||||
}
|
||||
|
||||
bool isChina = ATConfig.isSelectedChina();
|
||||
// if (!ATConfig.isSelectedChina()) {
|
||||
// return;
|
||||
// }
|
||||
EditorGUILayout.LabelField("AndroidX (Only for Android)", titleLabelStyle);
|
||||
GUILayout.Space(4);
|
||||
using (new EditorGUILayout.HorizontalScope("box"))
|
||||
{
|
||||
GUILayout.Space(5);
|
||||
|
||||
bool enableAndroidX = ATIntegrationManager.Instance.enableAndroidX(pluginData);
|
||||
string[] options = new string[] { "Disable", "Enable" };
|
||||
int androidXSetting = ATIntegrationManager.Instance.getAndroidXSetting(pluginData);
|
||||
string[] options = new string[] { "Default", "Enable", "Disable" };
|
||||
if (!isChina) {
|
||||
options = new string[] { "Default", "Enable" };
|
||||
}
|
||||
// 创建Dropdown组件
|
||||
int lastDropdownIndex = enableAndroidX ? 1 : 0;
|
||||
int lastDropdownIndex = androidXSetting;
|
||||
int curDropdownIndex = EditorGUILayout.Popup("Enable AndroidX:", lastDropdownIndex, options);
|
||||
|
||||
//变化才设置
|
||||
if (curDropdownIndex != lastDropdownIndex)
|
||||
{
|
||||
ATLog.log("DrawAndroidXUI() >>> curDropdownIndex: " + curDropdownIndex + " lastDropdownIndex: " + lastDropdownIndex);
|
||||
ATIntegrationManager.Instance.saveAndroidXSetting(pluginData, curDropdownIndex == 1);
|
||||
ATIntegrationManager.Instance.saveAndroidXSetting(pluginData, curDropdownIndex);
|
||||
}
|
||||
GUILayout.Space(5);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,164 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Xml.Linq;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Networking;
|
||||
using UnityEditor.PackageManager.Requests;
|
||||
using UnityEditor.PackageManager;
|
||||
using System.Threading.Tasks;
|
||||
using System.Threading;
|
||||
|
||||
namespace AnyThink.Scripts.IntegrationManager.Editor
|
||||
{
|
||||
public class ATIntegrationHotFix {
|
||||
public static ATIntegrationHotFix Instance = new ATIntegrationHotFix();
|
||||
|
||||
private ATIntegrationHotFix()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private static string plugin_hot_fix_data_file_name = "plugin_hot_fix_data.json";
|
||||
|
||||
public void loadHotFixData()
|
||||
{
|
||||
var downloadUrl = ATNetInfo.getHotfixPluginDownloadUrl(ATConfig.PLUGIN_VERSION);
|
||||
ATLog.log("loadHotFixData() >>> downloadUrl: " + downloadUrl);
|
||||
ATEditorCoroutine.startCoroutine(loadHotFixDataWithIEnumerator(downloadUrl));
|
||||
}
|
||||
|
||||
private IEnumerator loadHotFixDataWithIEnumerator(string url) {
|
||||
var hotFixDataRequest = UnityWebRequest.Get(url);
|
||||
var webRequest = hotFixDataRequest.SendWebRequest();
|
||||
while (!webRequest.isDone)
|
||||
{
|
||||
yield return new WaitForSeconds(0.1f);
|
||||
}
|
||||
|
||||
#if UNITY_2020_1_OR_NEWER
|
||||
if (hotFixDataRequest.result != UnityWebRequest.Result.Success)
|
||||
#elif UNITY_2017_2_OR_NEWER
|
||||
if (hotFixDataRequest.isNetworkError || hotFixDataRequest.isHttpError)
|
||||
#else
|
||||
if (hotFixDataRequest.isError)
|
||||
#endif
|
||||
{
|
||||
// Debug.Log("loadPluginData failed.");
|
||||
// callback(null);
|
||||
ATLog.log("load hotfix data failed.");
|
||||
}
|
||||
else
|
||||
{
|
||||
//解析热修复的数据
|
||||
try {
|
||||
string hotFixData = hotFixDataRequest.downloadHandler.text;
|
||||
var hotFixDataObj = JsonUtility.FromJson<HotfixPluginData>(hotFixData);
|
||||
ATLog.log("loadHotFixDataWithIEnumerator() >>> hotFixData: " + hotFixData);
|
||||
//判断status是否需要进行热更新
|
||||
if (hotFixDataObj.status != 1) {
|
||||
ATLog.log("loadHotFixDataWithIEnumerator() >>> 热更新被禁止");
|
||||
} else {
|
||||
var localHotFixDataObj = getHotfixPluginData();
|
||||
if (localHotFixDataObj == null) {
|
||||
//本地未曾下载过热更新
|
||||
ATLog.log("loadHotFixDataWithIEnumerator() >>> 本地未曾下载过热更新");
|
||||
ATEditorCoroutine.startCoroutine(loadHotFixPlugin(hotFixDataObj));
|
||||
} else {
|
||||
var compareVersionResult = ATDataUtil.CompareVersions(localHotFixDataObj.hot_fix_version, hotFixDataObj.hot_fix_version);
|
||||
ATLog.log("loadHotFixDataWithIEnumerator() >>> compareVersionResult: " + compareVersionResult);
|
||||
//本地版本比远端版本低,则需要更新
|
||||
if (compareVersionResult == VersionComparisonResult.Lesser) {
|
||||
ATEditorCoroutine.startCoroutine(loadHotFixPlugin(hotFixDataObj));
|
||||
} else {
|
||||
//不需要热更新
|
||||
saveHotfixData(hotFixData);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch(Exception e) {
|
||||
ATLog.logError("parseNetworksJson() >>> failed: " + e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private IEnumerator loadHotFixPlugin(HotfixPluginData hotFixDataObj) {
|
||||
var path = Path.Combine(Application.temporaryCachePath, hotFixDataObj.file_name);
|
||||
ATLog.log("downloadPluginWithEnumerator() >>> path: " + path);
|
||||
#if UNITY_2017_2_OR_NEWER
|
||||
var downloadHandler = new DownloadHandlerFile(path);
|
||||
#else
|
||||
var downloadHandler = new ATDownloadHandler(path);
|
||||
#endif
|
||||
var downloadUrl = hotFixDataObj.download_url;
|
||||
UnityWebRequest downloadPluginRequest = new UnityWebRequest(downloadUrl)
|
||||
{ method = UnityWebRequest.kHttpVerbGET,
|
||||
downloadHandler = downloadHandler
|
||||
};
|
||||
|
||||
#if UNITY_2017_2_OR_NEWER
|
||||
var operation = downloadPluginRequest.SendWebRequest();
|
||||
#else
|
||||
var operation = downloadPluginRequest.Send();
|
||||
#endif
|
||||
while (!operation.isDone)
|
||||
{
|
||||
yield return new WaitForSeconds(0.1f); // Just wait till downloadPluginRequest is completed. Our coroutine is pretty rudimentary.
|
||||
if (operation.progress != 1 && operation.isDone)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#if UNITY_2020_1_OR_NEWER
|
||||
if (downloadPluginRequest.result != UnityWebRequest.Result.Success)
|
||||
#elif UNITY_2017_2_OR_NEWER
|
||||
if (downloadPluginRequest.isNetworkError || downloadPluginRequest.isHttpError)
|
||||
#else
|
||||
if (downloadPluginRequest.isError)
|
||||
#endif
|
||||
{
|
||||
ATLog.log(downloadPluginRequest.error);
|
||||
}
|
||||
else
|
||||
{
|
||||
AssetDatabase.ImportPackage(path, false);
|
||||
AssetDatabase.Refresh();
|
||||
|
||||
string hotFixData = JsonUtility.ToJson(hotFixDataObj);
|
||||
saveHotfixData(hotFixData);
|
||||
}
|
||||
downloadPluginRequest.Dispose();
|
||||
downloadPluginRequest = null;
|
||||
}
|
||||
|
||||
|
||||
private void saveHotfixData(string hotfixPluginData) {
|
||||
var directoryPath = ATConfig.plugin_setting_data_path;
|
||||
// 确保目标文件夹存在
|
||||
if (!Directory.Exists(directoryPath))
|
||||
{
|
||||
// 如果目录不存在,则创建它
|
||||
Directory.CreateDirectory(directoryPath);
|
||||
}
|
||||
string fullPath = Path.Combine(directoryPath, plugin_hot_fix_data_file_name);
|
||||
ATLog.log("saveHotfixData() >>> fullPath: " + fullPath + " hotfixPluginData: " + hotfixPluginData);
|
||||
File.WriteAllText(fullPath, hotfixPluginData);
|
||||
}
|
||||
|
||||
private HotfixPluginData getHotfixPluginData() {
|
||||
string fullPath = Path.Combine(ATConfig.plugin_setting_data_path, plugin_hot_fix_data_file_name);
|
||||
if (!File.Exists(fullPath)) {
|
||||
return null;
|
||||
}
|
||||
string json = File.ReadAllText(fullPath);
|
||||
if(json == "") {
|
||||
return null;
|
||||
}
|
||||
return JsonUtility.FromJson<HotfixPluginData>(json);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bad9077d375594a889ee0fbf3bf84b2a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,8 +1,6 @@
|
||||
//菜单栏
|
||||
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
// using DownloadManager;
|
||||
|
||||
namespace AnyThink.Scripts.IntegrationManager.Editor
|
||||
@@ -12,28 +10,29 @@ namespace AnyThink.Scripts.IntegrationManager.Editor
|
||||
#if AnyThinkSDKEditor
|
||||
/**
|
||||
* The special characters at the end represent a shortcut for this action.
|
||||
*
|
||||
*
|
||||
* % - ctrl on Windows, cmd on macOS
|
||||
* # - shift
|
||||
* & - alt
|
||||
*
|
||||
*
|
||||
* So, (shift + cmd/ctrl + t) will launch the integration manager
|
||||
*/
|
||||
[MenuItem ("AnyThink/SDK Manager %#t")]
|
||||
private static void IntegrationManager ()
|
||||
[MenuItem("AnyThink/SDK Manager %#t")]
|
||||
private static void IntegrationManager()
|
||||
{
|
||||
ATIntegrationManagerWindow.ShowManager ();
|
||||
|
||||
ATIntegrationManagerWindow.ShowManager();
|
||||
}
|
||||
|
||||
[MenuItem ("AnyThink/Documentation")]
|
||||
public static void Documentation ()
|
||||
[MenuItem("AnyThink/Documentation")]
|
||||
public static void Documentation()
|
||||
{
|
||||
// if (ATConfig.isSelectedChina()) {
|
||||
// Application.OpenURL("https://newdocs.toponad.com/docs/lgfbO4");
|
||||
// } else {
|
||||
// Application.OpenURL("https://docs.toponad.com/#/en-us/unity/unity_doc/unity_access_doc_new?id=_3-integration");
|
||||
// }
|
||||
Application.OpenURL ("https://newdocs.toponad.com/docs/lgfbO4");
|
||||
Application.OpenURL("https://newdocs.toponad.com/docs/lgfbO4");
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -29,6 +29,11 @@ namespace AnyThink.Scripts.IntegrationManager.Editor
|
||||
{
|
||||
return "https://topon-sdk-release.oss-cn-hangzhou.aliyuncs.com/Unity_Release/plugin/" + pluginVersion + "/" + getPluginFileName(pluginVersion);
|
||||
}
|
||||
|
||||
public static string getHotfixPluginDownloadUrl(string pluginVersion)
|
||||
{
|
||||
return "https://topon-sdk-release.oss-cn-hangzhou.aliyuncs.com/Unity_Release/plugin/" + pluginVersion + "/hotfix/hotfix_config.json";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -171,7 +171,7 @@ namespace AnyThink.Scripts.IntegrationManager.Editor
|
||||
|
||||
public string ios_version; //当前已安装的iOS sdk的版本号
|
||||
|
||||
public bool enableAndroidX = false; //当前的AndroidX设置
|
||||
public int androidXSetting = 0; //当前的AndroidX设置,0=default; 1=修改为AndroidX;2=修改为非AndroidX
|
||||
|
||||
public int country;
|
||||
|
||||
@@ -180,9 +180,6 @@ namespace AnyThink.Scripts.IntegrationManager.Editor
|
||||
|
||||
public CountrySettingData(int country) {
|
||||
this.country = country;
|
||||
if (country == ATConfig.NONCHINA_COUNTRY) {
|
||||
this.enableAndroidX = true;
|
||||
}
|
||||
}
|
||||
|
||||
public string getAdmobAppId(int os) {
|
||||
@@ -210,4 +207,14 @@ namespace AnyThink.Scripts.IntegrationManager.Editor
|
||||
public int country;
|
||||
public string path;
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public class HotfixPluginData
|
||||
{
|
||||
public string plugin_version;
|
||||
public string hot_fix_version;
|
||||
public string download_url;
|
||||
public int status;
|
||||
public string file_name;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user