3.0 - unitypackage

This commit is contained in:
monitor1394
2022-01-05 21:40:48 +08:00
parent c160867765
commit 228a4b2840
846 changed files with 105 additions and 467693 deletions

View File

@@ -0,0 +1,23 @@
using UnityEngine;
namespace XCharts
{
public static class ColorUtil
{
public static readonly Color32 clearColor32 = new Color32(0, 0, 0, 0);
public static readonly Vector2 zeroVector2 = Vector2.zero;
/// <summary>
/// Convert the html string to color.
/// 将字符串颜色值转成Color。
/// </summary>
/// <param name="hexColorStr"></param>
/// <returns></returns>
public static Color32 GetColor(string hexColorStr)
{
Color color;
ColorUtility.TryParseHtmlString(hexColorStr, out color);
return (Color32)color;
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 4260c3b8fdaff435a8bc10375b812bd8
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,167 @@
using System;
using System.Collections.Generic;
using UnityEngine;
namespace XCharts
{
public static class DateTimeUtil
{
private static readonly DateTime k_DateTime1970 = TimeZoneInfo.ConvertTime(new DateTime(1970, 1, 1), TimeZoneInfo.Local);
public static readonly int ONE_SECOND = 1;
public static readonly int ONE_MINUTE = ONE_SECOND * 60;
public static readonly int ONE_HOUR = ONE_MINUTE * 60;
public static readonly int ONE_DAY = ONE_HOUR * 24;
public static readonly int ONE_MONTH = ONE_DAY * 30;
public static readonly int ONE_YEAR = ONE_DAY * 365;
public static readonly int MIN_TIME_SPLIT_NUMBER = 4;
private static string s_YearDateFormatter = "yyyy";
//private static string s_MonthDateFormatter = "MM";
//private static string s_DayDateFormatter = "dd";
private static string s_HourDateFormatter = "HH:mm";
private static string s_MinuteDateFormatter = "HH:mm";
private static string s_SecondDateFormatter = "HH:mm:ss";
//private static string s_DateFormatter = "yyyy-MM-dd HH:mm:ss";
public static int GetTimestamp()
{
return (int)(DateTime.Now - k_DateTime1970).TotalSeconds;
}
public static int GetTimestamp(DateTime time)
{
return (int)(time - k_DateTime1970).TotalSeconds;
}
public static DateTime GetDateTime(int timestamp)
{
long span = ((long)timestamp) * 10000000;
return k_DateTime1970.Add(new TimeSpan(span));
}
internal static string GetDateTimeFormatString(DateTime dateTime, double range)
{
var dateString = String.Empty;
if (range >= DateTimeUtil.ONE_YEAR * DateTimeUtil.MIN_TIME_SPLIT_NUMBER)
{
dateString = dateTime.ToString(s_YearDateFormatter);
}
else if (range >= DateTimeUtil.ONE_MONTH * DateTimeUtil.MIN_TIME_SPLIT_NUMBER)
{
dateString = dateTime.Month == 1
? dateTime.ToString(s_YearDateFormatter)
: XCSettings.lang.GetMonthAbbr(dateTime.Month);
}
else if (range >= DateTimeUtil.ONE_DAY * DateTimeUtil.MIN_TIME_SPLIT_NUMBER)
{
dateString = dateTime.Day == 1
? XCSettings.lang.GetMonthAbbr(dateTime.Month)
: XCSettings.lang.GetDay(dateTime.Day);
}
else if (range >= DateTimeUtil.ONE_HOUR * DateTimeUtil.MIN_TIME_SPLIT_NUMBER)
{
dateString = dateTime.ToString(s_HourDateFormatter);
}
else if (range >= DateTimeUtil.ONE_MINUTE * DateTimeUtil.MIN_TIME_SPLIT_NUMBER)
{
dateString = dateTime.ToString(s_MinuteDateFormatter);
}
else
{
dateString = dateTime.ToString(s_SecondDateFormatter);
}
return dateString;
}
/// <summary>
/// 根据给定的最大最小时间戳范围计算合适的Tick值
/// </summary>
/// <param name="list"></param>
/// <param name="minTimestamp"></param>
/// <param name="maxTimestamp"></param>
/// <param name="splitNumber"></param>
internal static void UpdateTimeAxisDateTimeList(List<double> list, int minTimestamp, int maxTimestamp, int splitNumber)
{
list.Clear();
var range = maxTimestamp - minTimestamp;
if (range <= 0) return;
var dtMin = DateTimeUtil.GetDateTime(minTimestamp);
var dtMax = DateTimeUtil.GetDateTime(maxTimestamp);
if (range >= ONE_YEAR * MIN_TIME_SPLIT_NUMBER)
{
var num = Math.Max(range / (splitNumber * ONE_YEAR), 1);
var dtStart = new DateTime(dtMin.Year + 1, 1, 1);
while (dtStart.Ticks < dtMax.Ticks)
{
list.Add(DateTimeUtil.GetTimestamp(dtStart));
dtStart = dtStart.AddYears(num);
}
}
else if (range >= ONE_MONTH * MIN_TIME_SPLIT_NUMBER)
{
var num = Math.Max(range / (splitNumber * ONE_MONTH), 1);
var dtStart = new DateTime(dtMin.Year, dtMin.Month, 1).AddMonths(1);
while (dtStart.Ticks < dtMax.Ticks)
{
list.Add(DateTimeUtil.GetTimestamp(dtStart));
dtStart = dtStart.AddMonths(num);
}
}
else if (range >= ONE_DAY * MIN_TIME_SPLIT_NUMBER)
{
var tick = GetTickSecond(range, splitNumber, ONE_DAY);
var startTimestamp = (minTimestamp - minTimestamp % tick) + tick;
AddTickTimestamp(list, startTimestamp, maxTimestamp, tick);
}
else if (range >= ONE_HOUR * MIN_TIME_SPLIT_NUMBER)
{
var tick = GetTickSecond(range, splitNumber, ONE_HOUR);
var startTimestamp = (minTimestamp - minTimestamp % tick) + tick;
AddTickTimestamp(list, startTimestamp, maxTimestamp, tick);
}
else if (range >= ONE_MINUTE * MIN_TIME_SPLIT_NUMBER)
{
var tick = GetTickSecond(range, splitNumber, ONE_MINUTE);
var startTimestamp = (minTimestamp - minTimestamp % tick) + tick;
AddTickTimestamp(list, startTimestamp, maxTimestamp, tick);
}
else
{
var tick = GetTickSecond(range, splitNumber, ONE_SECOND);
var startTimestamp = (minTimestamp - minTimestamp % tick) + tick;
AddTickTimestamp(list, startTimestamp, maxTimestamp, tick);
}
}
private static int GetTickSecond(int range, int splitNumber, int tickSecond)
{
var num = 0;
if (splitNumber > 0)
{
num = Math.Max(range / (splitNumber * tickSecond), 1);
}
else
{
num = 1;
var tick = tickSecond;
while (range / tick > 8)
{
num++;
tick = num * tickSecond;
}
}
return num * tickSecond;
}
private static void AddTickTimestamp(List<double> list, int startTimestamp, int maxTimestamp, int tickSecond)
{
while (startTimestamp < maxTimestamp)
{
list.Add(startTimestamp);
startTimestamp += tickSecond;
}
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 0f0ac80f189a04b5c826f40c8bc8af64
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,89 @@
#if UNITY_EDITOR
using System;
using System.Reflection;
using System.Text;
using UnityEditor;
using UnityEngine;
namespace XCharts
{
public static class DefineSymbolsUtil
{
private static readonly StringBuilder s_StringBuilder = new StringBuilder();
public static void AddGlobalDefine(string symbol)
{
var flag = false;
var num = 0;
foreach (var buildTargetGroup in (BuildTargetGroup[])Enum.GetValues(typeof(BuildTargetGroup)))
{
if (IsValidBuildTargetGroup(buildTargetGroup))
{
var symbols = PlayerSettings.GetScriptingDefineSymbolsForGroup(buildTargetGroup);
symbols = symbols.Replace(" ", "");
if (Array.IndexOf(symbols.Split(';'), symbol) != -1) continue;
flag = true;
num++;
var defines = symbols + (symbols.Length > 0 ? ";" + symbol : symbol);
PlayerSettings.SetScriptingDefineSymbolsForGroup(buildTargetGroup, defines);
}
}
if (flag)
{
Debug.LogFormat("Added global define symbol \"{0}\" to {1} BuildTargetGroups.", symbol, num);
}
}
public static void RemoveGlobalDefine(string symbol)
{
var flag = false;
var num = 0;
foreach (var buildTargetGroup in (BuildTargetGroup[])Enum.GetValues(typeof(BuildTargetGroup)))
{
if (IsValidBuildTargetGroup(buildTargetGroup))
{
var symbols = PlayerSettings.GetScriptingDefineSymbolsForGroup(buildTargetGroup).Split(';');
if (Array.IndexOf(symbols, symbol) == -1) continue;
flag = true;
num++;
s_StringBuilder.Length = 0;
foreach (var str in symbols)
{
if (!str.Equals(symbol))
{
if (s_StringBuilder.Length > 0) s_StringBuilder.Append(";");
s_StringBuilder.Append(str);
}
}
PlayerSettings.SetScriptingDefineSymbolsForGroup(buildTargetGroup, s_StringBuilder.ToString());
}
}
if (flag)
{
Debug.LogFormat("Removed global define symbol \"{0}\" to {1} BuildTargetGroups.", symbol, num);
}
}
private static bool IsValidBuildTargetGroup(BuildTargetGroup group)
{
if (group == BuildTargetGroup.Unknown) return false;
var type = Type.GetType("UnityEditor.Modules.ModuleManager, UnityEditor.dll");
if (type == null) return true;
var method1 = type.GetMethod("GetTargetStringFromBuildTargetGroup", BindingFlags.Static | BindingFlags.NonPublic);
var method2 = typeof(PlayerSettings).GetMethod("GetPlatformName", BindingFlags.Static | BindingFlags.NonPublic);
if (method1 == null || method2 == null) return true;
var str1 = (string)method1.Invoke(null, new object[] { group });
var str2 = (string)method2.Invoke(null, new object[] { group });
if (string.IsNullOrEmpty(str1))
{
return !string.IsNullOrEmpty(str2);
}
else
{
return true;
}
}
}
}
#endif

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 91545951242fa441eb1a9bba3a6ad5a7
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,53 @@
using System.Collections.Generic;
using UnityEngine;
namespace XCharts
{
public static class PropertyUtil
{
public static bool SetColor(ref Color currentValue, Color newValue)
{
if (currentValue.r == newValue.r && currentValue.g == newValue.g && currentValue.b == newValue.b && currentValue.a == newValue.a)
return false;
currentValue = newValue;
return true;
}
public static bool SetColor(ref Color32 currentValue, Color32 newValue)
{
if (currentValue.r == newValue.r && currentValue.g == newValue.g && currentValue.b == newValue.b && currentValue.a == newValue.a)
return false;
currentValue = newValue;
return true;
}
public static bool SetStruct<T>(ref T currentValue, T newValue) where T : struct
{
if (EqualityComparer<T>.Default.Equals(currentValue, newValue))
return false;
currentValue = newValue;
return true;
}
public static bool SetClass<T>(ref T currentValue, T newValue, bool notNull = false) where T : class
{
if (notNull)
{
if (newValue == null)
{
Debug.LogError("can not be null.");
return false;
}
}
if ((currentValue == null && newValue == null) || (currentValue != null && currentValue.Equals(newValue)))
return false;
currentValue = newValue;
return true;
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: b1f52eadd805d43aea47947fb81e761f
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,48 @@
using System;
using System.Reflection;
namespace XCharts
{
public static class ReflectionUtil
{
public static void InvokeListClear(object obj, FieldInfo field)
{
var list = field.GetValue(obj);
var method = list.GetType().GetMethod("Clear");
method.Invoke(list, new object[] { });
}
public static int InvokeListCount(object obj, FieldInfo field)
{
var list = field.GetValue(obj);
return (int)list.GetType().GetProperty("Count").GetValue(list);
}
public static void InvokeListAdd(object obj, FieldInfo field, object item)
{
var list = field.GetValue(obj);
var method = list.GetType().GetMethod("Add");
method.Invoke(list, new object[] { item });
}
public static T InvokeListGet<T>(object obj, FieldInfo field, int i)
{
var list = field.GetValue(obj);
var item = list.GetType().GetProperty("Item").GetValue(list, new object[] { i });
return (T)item;
}
public static void InvokeListAddTo<T>(object obj, FieldInfo field, Action<T> callback)
{
var list = field.GetValue(obj);
var listType = list.GetType();
var count = Convert.ToInt32(listType.GetProperty("Count").GetValue(list));
for (int i = 0; i < count; i++)
{
var item = listType.GetProperty("Item").GetValue(list, new object[] { i });
callback((T)item);
}
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 03acc4ee710ff4bad9a1740391c86cb9
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,100 @@
using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using UnityEngine;
using UnityEngine.Assertions;
namespace XCharts
{
public static class RuntimeUtil
{
public static bool HasSubclass(Type type)
{
var typeMap = GetAllTypesDerivedFrom(type);
foreach (var t in typeMap)
{
return true;
}
return false;
}
public static IEnumerable<Type> GetAllTypesDerivedFrom<T>()
{
#if UNITY_EDITOR && UNITY_2019_2_OR_NEWER
return UnityEditor.TypeCache.GetTypesDerivedFrom<T>();
#else
return GetAllAssemblyTypes().Where(t => t.IsSubclassOf(typeof(T)));
#endif
}
public static IEnumerable<Type> GetAllTypesDerivedFrom(Type type)
{
#if UNITY_EDITOR && UNITY_2019_2_OR_NEWER
return UnityEditor.TypeCache.GetTypesDerivedFrom(type);
#else
return GetAllAssemblyTypes().Where(t => t.IsSubclassOf(type));
#endif
}
static IEnumerable<Type> m_AssemblyTypes;
public static IEnumerable<Type> GetAllAssemblyTypes()
{
if (m_AssemblyTypes == null)
{
m_AssemblyTypes = AppDomain.CurrentDomain.GetAssemblies()
.SelectMany(t =>
{
var innerTypes = new Type[0];
try
{
innerTypes = t.GetTypes();
}
catch { }
return innerTypes;
});
}
return m_AssemblyTypes;
}
public static T GetAttribute<T>(this Type type) where T : Attribute
{
Assert.IsTrue(type.IsDefined(typeof(T), false), "Attribute not found:" + type.Name);
return (T)type.GetCustomAttributes(typeof(T), false)[0];
}
public static bool CopyFolder(string sourPath, string destPath)
{
try
{
if (!Directory.Exists(destPath))
{
Directory.CreateDirectory(destPath);
}
var files = Directory.GetFiles(sourPath);
foreach (var file in files)
{
var name = Path.GetFileName(file);
var path = Path.Combine(destPath, name);
File.Copy(file, path);
}
var folders = Directory.GetDirectories(sourPath);
foreach (var folder in folders)
{
var name = Path.GetFileName(folder);
var path = Path.Combine(destPath, name);
CopyFolder(folder, path);
}
return true;
}
catch (Exception e)
{
Debug.LogError("CopyFolder:" + e.Message);
return false;
}
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 44becf1664ae64397b44adcf65e6d8d2
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: