功能批量实现 优化 服务端 新浮动小游戏框架 新界面UI
This commit is contained in:
@@ -3,6 +3,8 @@ using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using UnityEngine;
|
||||
|
||||
namespace EasyChart
|
||||
@@ -506,18 +508,8 @@ namespace EasyChart
|
||||
// Try Newtonsoft.Json first
|
||||
try
|
||||
{
|
||||
var jsonConvertType = Type.GetType("Newtonsoft.Json.JsonConvert, Newtonsoft.Json")
|
||||
?? Type.GetType("Newtonsoft.Json.JsonConvert, Unity.Newtonsoft.Json");
|
||||
if (jsonConvertType != null)
|
||||
{
|
||||
var deserialize = jsonConvertType.GetMethod("DeserializeObject", new[] { typeof(string), typeof(Type) });
|
||||
if (deserialize != null)
|
||||
{
|
||||
var obj = deserialize.Invoke(null, new object[] { json, typeof(ChartFeed) });
|
||||
feed = obj as ChartFeed;
|
||||
if (feed != null) return true;
|
||||
}
|
||||
}
|
||||
feed = JsonConvert.DeserializeObject<ChartFeed>(json);
|
||||
if (feed != null) return true;
|
||||
}
|
||||
catch
|
||||
{
|
||||
@@ -590,27 +582,14 @@ namespace EasyChart
|
||||
|
||||
try
|
||||
{
|
||||
var jObjectType = Type.GetType("Newtonsoft.Json.Linq.JObject, Newtonsoft.Json")
|
||||
?? Type.GetType("Newtonsoft.Json.Linq.JObject, Unity.Newtonsoft.Json");
|
||||
var jArrayType = Type.GetType("Newtonsoft.Json.Linq.JArray, Newtonsoft.Json")
|
||||
?? Type.GetType("Newtonsoft.Json.Linq.JArray, Unity.Newtonsoft.Json");
|
||||
if (jObjectType == null || jArrayType == null) return false;
|
||||
|
||||
var parse = jObjectType.GetMethod("Parse", new[] { typeof(string) });
|
||||
if (parse == null) return false;
|
||||
|
||||
var root = parse.Invoke(null, new object[] { json });
|
||||
if (root == null) return false;
|
||||
JObject root = JObject.Parse(json);
|
||||
|
||||
feed = new ChartFeed();
|
||||
|
||||
var itemProp = jObjectType.GetProperty("Item", new[] { typeof(string) });
|
||||
if (itemProp == null) return false;
|
||||
|
||||
string ReadString(object obj, string key)
|
||||
string ReadString(JToken obj, string key)
|
||||
{
|
||||
if (obj == null) return null;
|
||||
var token = itemProp.GetValue(obj, new object[] { key });
|
||||
var token = obj[key];
|
||||
if (token == null) return null;
|
||||
var s = token.ToString();
|
||||
if (string.IsNullOrEmpty(s)) return null;
|
||||
@@ -618,7 +597,7 @@ namespace EasyChart
|
||||
return s;
|
||||
}
|
||||
|
||||
float ReadFloat(object obj, string key, float defaultValue = 0f)
|
||||
float ReadFloat(JToken obj, string key, float defaultValue = 0f)
|
||||
{
|
||||
var s = ReadString(obj, key);
|
||||
if (string.IsNullOrEmpty(s)) return defaultValue;
|
||||
@@ -626,7 +605,7 @@ namespace EasyChart
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
bool ReadBool(object obj, string key, bool defaultValue = false)
|
||||
bool ReadBool(JToken obj, string key, bool defaultValue = false)
|
||||
{
|
||||
var s = ReadString(obj, key);
|
||||
if (string.IsNullOrEmpty(s)) return defaultValue;
|
||||
@@ -634,10 +613,10 @@ namespace EasyChart
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
object GetToken(object obj, string key)
|
||||
JToken GetToken(JToken obj, string key)
|
||||
{
|
||||
if (obj == null) return null;
|
||||
return itemProp.GetValue(obj, new object[] { key });
|
||||
return obj[key];
|
||||
}
|
||||
|
||||
feed.chartId = ReadString(root, "chartId");
|
||||
@@ -645,10 +624,10 @@ namespace EasyChart
|
||||
|
||||
// Axes
|
||||
var axesToken = GetToken(root, "axes");
|
||||
if (axesToken != null && jArrayType.IsInstanceOfType(axesToken))
|
||||
if (axesToken is JArray axesArray)
|
||||
{
|
||||
var axes = new List<AxisFeed>();
|
||||
foreach (var axisObj in (System.Collections.IEnumerable)axesToken)
|
||||
foreach (var axisObj in axesArray)
|
||||
{
|
||||
if (axisObj == null) continue;
|
||||
|
||||
@@ -657,10 +636,10 @@ namespace EasyChart
|
||||
|
||||
var labelsToken = GetToken(axisObj, "labels");
|
||||
string[] labels = null;
|
||||
if (labelsToken != null && jArrayType.IsInstanceOfType(labelsToken))
|
||||
if (labelsToken is JArray labelsArray)
|
||||
{
|
||||
var list = new List<string>();
|
||||
foreach (var l in (System.Collections.IEnumerable)labelsToken)
|
||||
foreach (var l in labelsArray)
|
||||
{
|
||||
if (l == null) continue;
|
||||
var s = l.ToString();
|
||||
@@ -677,10 +656,10 @@ namespace EasyChart
|
||||
|
||||
// Series
|
||||
var seriesToken = GetToken(root, "series");
|
||||
if (seriesToken != null && jArrayType.IsInstanceOfType(seriesToken))
|
||||
if (seriesToken is JArray seriesArray)
|
||||
{
|
||||
var series = new List<SerieFeed>();
|
||||
foreach (var serieObj in (System.Collections.IEnumerable)seriesToken)
|
||||
foreach (var serieObj in seriesArray)
|
||||
{
|
||||
if (serieObj == null) continue;
|
||||
|
||||
@@ -699,12 +678,11 @@ namespace EasyChart
|
||||
}
|
||||
|
||||
var datasToken = GetToken(serieObj, "datas");
|
||||
if (datasToken != null && jArrayType.IsInstanceOfType(datasToken))
|
||||
if (datasToken is JArray datasArray)
|
||||
{
|
||||
var datas = new List<DataFeed>();
|
||||
|
||||
object first = null;
|
||||
foreach (var tmp in (System.Collections.IEnumerable)datasToken) { first = tmp; break; }
|
||||
JToken first = datasArray.Count > 0 ? datasArray[0] : null;
|
||||
|
||||
if (first != null)
|
||||
{
|
||||
@@ -716,7 +694,7 @@ namespace EasyChart
|
||||
{
|
||||
// Values mode: datas: [1,2,3]
|
||||
int dataIdx = 0;
|
||||
foreach (var vToken in (System.Collections.IEnumerable)datasToken)
|
||||
foreach (var vToken in datasArray)
|
||||
{
|
||||
if (vToken == null) { dataIdx++; continue; }
|
||||
var vs = vToken.ToString();
|
||||
@@ -728,7 +706,7 @@ namespace EasyChart
|
||||
else if (firstIsArray)
|
||||
{
|
||||
// Tuple mode: datas: [[x,value], [x,value]] or [[x,y,value], ...]
|
||||
foreach (var tupleToken in (System.Collections.IEnumerable)datasToken)
|
||||
foreach (var tupleToken in datasArray)
|
||||
{
|
||||
if (tupleToken == null) continue;
|
||||
var tupleText = tupleToken.ToString();
|
||||
@@ -756,7 +734,7 @@ namespace EasyChart
|
||||
else
|
||||
{
|
||||
// Standard/Full object mode
|
||||
foreach (var dpObj in (System.Collections.IEnumerable)datasToken)
|
||||
foreach (var dpObj in datasArray)
|
||||
{
|
||||
if (dpObj == null) continue;
|
||||
var df = new DataFeed();
|
||||
|
||||
@@ -11,8 +11,22 @@ namespace EasyChart
|
||||
get
|
||||
{
|
||||
if (s_isInstalled.HasValue) return s_isInstalled.Value;
|
||||
var t = Type.GetType("EasyChart.Pro.EasyChartProBootstrap, EasyChart.Pro.Runtime");
|
||||
s_isInstalled = t != null;
|
||||
const string bootstrapTypeName = "EasyChart.Pro.EasyChartProBootstrap";
|
||||
var assemblies = AppDomain.CurrentDomain.GetAssemblies();
|
||||
for (int i = 0; i < assemblies.Length; i++)
|
||||
{
|
||||
var assembly = assemblies[i];
|
||||
if (assembly == null) continue;
|
||||
|
||||
var type = assembly.GetType(bootstrapTypeName, false);
|
||||
if (type != null)
|
||||
{
|
||||
s_isInstalled = true;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
s_isInstalled = false;
|
||||
return s_isInstalled.Value;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user