mirror of
https://github.com/XCharts-Team/XCharts.git
synced 2026-05-19 15:00:08 +00:00
优化版本更新检测
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
|
||||
# 更新日志
|
||||
|
||||
* (2020.05.24) 优化版本更新检测
|
||||
* (2020.05.22) 发布`v1.5.0`版本
|
||||
* (2020.05.21) 增加`圆角柱图`支持渐变
|
||||
* (2020.05.21) 增加`Background`背景组件
|
||||
|
||||
@@ -112,15 +112,19 @@ namespace XCharts
|
||||
|
||||
private void CheckWarning()
|
||||
{
|
||||
if (GUILayout.Button("Check Update "))
|
||||
{
|
||||
CheckVersionEditor.ShowWindow();
|
||||
}
|
||||
if (m_CheckWarning)
|
||||
{
|
||||
EditorGUILayout.BeginHorizontal();
|
||||
if (GUILayout.Button("Check warning"))
|
||||
if (GUILayout.Button("Check Warning"))
|
||||
{
|
||||
m_CheckWarning = true;
|
||||
m_Target.CheckWarning();
|
||||
}
|
||||
if (GUILayout.Button("Hide warning"))
|
||||
if (GUILayout.Button("Hide Warning"))
|
||||
{
|
||||
m_CheckWarning = false;
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ namespace XCharts
|
||||
private static CheckVersionEditor window;
|
||||
|
||||
[MenuItem("Component/XCharts/Check For Update")]
|
||||
private static void ShowWindow()
|
||||
public static void ShowWindow()
|
||||
{
|
||||
window = GetWindow<CheckVersionEditor>();
|
||||
window.titleContent = new GUIContent("XCharts Check For Update");
|
||||
@@ -25,6 +25,11 @@ namespace XCharts
|
||||
XChartsMgr.Instance.CheckVersion();
|
||||
}
|
||||
|
||||
void OnInspectorUpdate()
|
||||
{
|
||||
Repaint();
|
||||
}
|
||||
|
||||
private void OnGUI()
|
||||
{
|
||||
var mgr = XChartsMgr.Instance;
|
||||
@@ -32,27 +37,38 @@ namespace XCharts
|
||||
GUILayout.Label("当前版本:" + mgr.nowVersion);
|
||||
if (mgr.needUpdate && !mgr.isCheck)
|
||||
{
|
||||
GUILayout.BeginHorizontal();
|
||||
GUILayout.Label("最新版本:" + mgr.newVersion);
|
||||
GUILayout.Label("");
|
||||
if (mgr.isCheck) GUILayout.Label("检测中...");
|
||||
else if (mgr.isNetworkError) GUILayout.Label("检测失败:" + mgr.networkError);
|
||||
else GUILayout.Label("有更新!");
|
||||
if (GUILayout.Button("去Github主页"))
|
||||
else
|
||||
{
|
||||
Application.OpenURL("https://github.com/monitor1394/unity-ugui-XCharts");
|
||||
GUILayout.Label("有更新!");
|
||||
}
|
||||
GUILayout.EndHorizontal();
|
||||
|
||||
GUILayout.Label("");
|
||||
if (!string.IsNullOrEmpty(mgr.desc))
|
||||
{
|
||||
GUILayout.Label(mgr.desc);
|
||||
GUILayout.Label("");
|
||||
}
|
||||
|
||||
scrollPos = GUILayout.BeginScrollView(scrollPos);
|
||||
GUILayout.TextArea(mgr.changeLog);
|
||||
GUILayout.EndScrollView();
|
||||
if (GUILayout.Button("去Github主页"))
|
||||
{
|
||||
Application.OpenURL("https://github.com/monitor1394/unity-ugui-XCharts");
|
||||
}
|
||||
if (GUILayout.Button("点Star支持"))
|
||||
{
|
||||
Application.OpenURL("https://github.com/monitor1394/unity-ugui-XCharts/stargazers");
|
||||
}
|
||||
if (GUILayout.Button("问题反馈"))
|
||||
{
|
||||
Application.OpenURL("https://github.com/monitor1394/unity-ugui-XCharts/issues");
|
||||
}
|
||||
if (!string.IsNullOrEmpty(mgr.changeLog))
|
||||
{
|
||||
scrollPos = GUILayout.BeginScrollView(scrollPos);
|
||||
GUILayout.TextArea(mgr.changeLog);
|
||||
GUILayout.EndScrollView();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -69,11 +85,18 @@ namespace XCharts
|
||||
if (!string.IsNullOrEmpty(mgr.desc))
|
||||
{
|
||||
GUILayout.Label(mgr.desc);
|
||||
GUILayout.Label("");
|
||||
}
|
||||
if (GUILayout.Button("去Github主页"))
|
||||
{
|
||||
Application.OpenURL(mgr.homepage);
|
||||
Application.OpenURL("https://github.com/monitor1394/unity-ugui-XCharts");
|
||||
}
|
||||
if (GUILayout.Button("点Star支持"))
|
||||
{
|
||||
Application.OpenURL("https://github.com/monitor1394/unity-ugui-XCharts/stargazers");
|
||||
}
|
||||
if (GUILayout.Button("问题反馈"))
|
||||
{
|
||||
Application.OpenURL("https://github.com/monitor1394/unity-ugui-XCharts/issues");
|
||||
}
|
||||
if (mgr.isNetworkError && GUILayout.Button("重新检测"))
|
||||
{
|
||||
|
||||
62
Editor/XChartMgrEditor.cs
Normal file
62
Editor/XChartMgrEditor.cs
Normal file
@@ -0,0 +1,62 @@
|
||||
/******************************************/
|
||||
/* */
|
||||
/* Copyright (c) 2018 monitor1394 */
|
||||
/* https://github.com/monitor1394 */
|
||||
/* */
|
||||
/******************************************/
|
||||
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace XCharts
|
||||
{
|
||||
/// <summary>
|
||||
/// Editor class used to edit UI XChartsMgr.
|
||||
/// </summary>
|
||||
|
||||
[CustomEditor(typeof(XChartsMgr), false)]
|
||||
public class XChartsMgrEditor : Editor
|
||||
{
|
||||
protected XChartsMgr m_Target;
|
||||
protected SerializedProperty m_Script;
|
||||
protected SerializedProperty m_NowVersion;
|
||||
protected SerializedProperty m_NewVersion;
|
||||
|
||||
protected virtual void OnEnable()
|
||||
{
|
||||
m_Target = (XChartsMgr)target;
|
||||
m_Script = serializedObject.FindProperty("m_Script");
|
||||
m_NowVersion = serializedObject.FindProperty("m_NowVersion");
|
||||
m_NewVersion = serializedObject.FindProperty("m_NewVersion");
|
||||
}
|
||||
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
if (m_Target == null && target == null)
|
||||
{
|
||||
base.OnInspectorGUI();
|
||||
return;
|
||||
}
|
||||
serializedObject.Update();
|
||||
EditorGUILayout.PropertyField(m_NowVersion);
|
||||
EditorGUILayout.PropertyField(m_NewVersion);
|
||||
if (GUILayout.Button("检测更新"))
|
||||
{
|
||||
CheckVersionEditor.ShowWindow();
|
||||
}
|
||||
if (GUILayout.Button("去Github主页"))
|
||||
{
|
||||
Application.OpenURL("https://github.com/monitor1394/unity-ugui-XCharts");
|
||||
}
|
||||
if (GUILayout.Button("点Star支持"))
|
||||
{
|
||||
Application.OpenURL("https://github.com/monitor1394/unity-ugui-XCharts/stargazers");
|
||||
}
|
||||
if (GUILayout.Button("问题反馈"))
|
||||
{
|
||||
Application.OpenURL("https://github.com/monitor1394/unity-ugui-XCharts/issues");
|
||||
}
|
||||
serializedObject.ApplyModifiedProperties();
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Editor/XChartMgrEditor.cs.meta
Normal file
11
Editor/XChartMgrEditor.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 69cbbe551cf1f45c984e6b4febc9f697
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -30,8 +30,8 @@ namespace XCharts
|
||||
[ExecuteInEditMode]
|
||||
public class XChartsMgr : MonoBehaviour
|
||||
{
|
||||
public const string version = "1.4.0";
|
||||
public const int date = 20200411;
|
||||
public const string version = "1.5.0";
|
||||
public const int date = 20200522;
|
||||
|
||||
[SerializeField] private string m_NowVersion;
|
||||
[SerializeField] private string m_NewVersion;
|
||||
@@ -92,27 +92,49 @@ namespace XCharts
|
||||
{
|
||||
get
|
||||
{
|
||||
return date < newCheckDate;
|
||||
return !isNetworkError && !m_NowVersion.Equals(m_NewVersion);
|
||||
}
|
||||
}
|
||||
|
||||
public void CheckVersion()
|
||||
{
|
||||
isCheck = true;
|
||||
isNetworkError = false;
|
||||
networkError = "";
|
||||
StartCoroutine(GetVersion());
|
||||
if (date < newCheckDate)
|
||||
{
|
||||
StartCoroutine(GetChangeLog());
|
||||
}
|
||||
}
|
||||
|
||||
IEnumerator GetVersion()
|
||||
{
|
||||
var url = "https://raw.githubusercontent.com/monitor1394/unity-ugui-XCharts/master/Assets/XCharts/version.json";
|
||||
isCheck = true;
|
||||
isNetworkError = false;
|
||||
networkError = "";
|
||||
var url = "https://raw.githubusercontent.com/monitor1394/unity-ugui-XCharts/master/Assets/XCharts/package.json";
|
||||
var web = UnityWebRequest.Get(url);
|
||||
yield return web;
|
||||
yield return web.SendWebRequest();
|
||||
CheckVersionWebRequest(web);
|
||||
if (isNetworkError)
|
||||
{
|
||||
url = "https://gitee.com/monitor1394/unity-ugui-XCharts/raw/master/Assets/XCharts/package.json";
|
||||
web = UnityWebRequest.Get(url);
|
||||
yield return web.SendWebRequest();
|
||||
CheckVersionWebRequest(web);
|
||||
}
|
||||
if (needUpdate)
|
||||
{
|
||||
url = "https://raw.githubusercontent.com/monitor1394/unity-ugui-XCharts/master/Assets/XCharts/CHANGELOG.md";
|
||||
web = UnityWebRequest.Get(url);
|
||||
yield return web.SendWebRequest();
|
||||
if (!CheckLogWebRequest(web))
|
||||
{
|
||||
url = "https://gitee.com/monitor1394/unity-ugui-XCharts/raw/master/Assets/XCharts/CHANGELOG.md";
|
||||
web = UnityWebRequest.Get(url);
|
||||
yield return web.SendWebRequest();
|
||||
CheckLogWebRequest(web);
|
||||
}
|
||||
}
|
||||
isCheck = false;
|
||||
}
|
||||
|
||||
private void CheckVersionWebRequest(UnityWebRequest web)
|
||||
{
|
||||
if (IsNetworkError(web))
|
||||
{
|
||||
isNetworkError = true;
|
||||
@@ -121,49 +143,40 @@ namespace XCharts
|
||||
}
|
||||
else if (web.responseCode == 200)
|
||||
{
|
||||
isNetworkError = false;
|
||||
var cv = JsonUtility.FromJson<XChartsVersion>(web.downloadHandler.text);
|
||||
m_NewVersion = cv.version + " (" + cv.date + ")";
|
||||
m_NewVersion = cv.version + "_" + cv.date;
|
||||
newDate = cv.date;
|
||||
newCheckDate = cv.checkdate;
|
||||
desc = cv.desc;
|
||||
homepage = cv.homepage;
|
||||
web.Dispose();
|
||||
isCheck = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
isCheck = false;
|
||||
isNetworkError = true;
|
||||
if (web.responseCode > 0)
|
||||
networkError = web.responseCode.ToString();
|
||||
else if (!string.IsNullOrEmpty(web.error))
|
||||
networkError = web.error;
|
||||
else
|
||||
if (!string.IsNullOrEmpty(web.error))
|
||||
networkError += "," + web.error;
|
||||
if (string.IsNullOrEmpty(networkError))
|
||||
{
|
||||
networkError = "-";
|
||||
}
|
||||
m_NewVersion = "-";
|
||||
}
|
||||
web.Dispose();
|
||||
}
|
||||
|
||||
IEnumerator GetChangeLog()
|
||||
private bool CheckLogWebRequest(UnityWebRequest web)
|
||||
{
|
||||
isCheck = true;
|
||||
var url = "https://raw.githubusercontent.com/monitor1394/unity-ugui-XCharts/master/Assets/XCharts/CHANGELOG.md";
|
||||
var web = new UnityWebRequest(url);
|
||||
yield return web;
|
||||
if (IsNetworkError(web))
|
||||
{
|
||||
Debug.LogError(web.error);
|
||||
}
|
||||
else if (web.responseCode == 200)
|
||||
bool success = false;
|
||||
if (web.responseCode == 200)
|
||||
{
|
||||
CheckLog(web.downloadHandler.text);
|
||||
web.Dispose();
|
||||
isCheck = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
isCheck = false;
|
||||
success = true;
|
||||
}
|
||||
web.Dispose();
|
||||
return success;
|
||||
}
|
||||
|
||||
private void CheckLog(string text)
|
||||
|
||||
Reference in New Issue
Block a user