Aimbot Enviroment very first
Basic environment include Multi scene, Reward Change, Visible chart, etc....
This commit is contained in:
@@ -0,0 +1,174 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using UnityEngine;
|
||||
|
||||
namespace XCharts.Runtime
|
||||
{
|
||||
public static class ChartCached
|
||||
{
|
||||
private const string NUMERIC_FORMATTER_D = "D";
|
||||
private const string NUMERIC_FORMATTER_d = "d";
|
||||
private const string NUMERIC_FORMATTER_X = "X";
|
||||
private const string NUMERIC_FORMATTER_x = "x";
|
||||
private static readonly string s_DefaultAxis = "axis_";
|
||||
private static CultureInfo ci = new CultureInfo("en-us"); // "en-us", "zh-cn", "ar-iq", "de-de"
|
||||
private static Dictionary<Color, string> s_ColorToStr = new Dictionary<Color, string>(100);
|
||||
private static Dictionary<int, string> s_SerieLabelName = new Dictionary<int, string>(1000);
|
||||
private static Dictionary<Color, string> s_ColorDotStr = new Dictionary<Color, string>(100);
|
||||
private static Dictionary<Type, Dictionary<int, string>> s_ComponentObjectName = new Dictionary<Type, Dictionary<int, string>>();
|
||||
private static Dictionary<int, string> s_AxisLabelName = new Dictionary<int, string>();
|
||||
private static Dictionary<Type, string> s_TypeName = new Dictionary<Type, string>();
|
||||
|
||||
private static Dictionary<double, Dictionary<string, string>> s_NumberToStr = new Dictionary<double, Dictionary<string, string>>();
|
||||
private static Dictionary<int, Dictionary<string, string>> s_PrecisionToStr = new Dictionary<int, Dictionary<string, string>>();
|
||||
|
||||
public static string FloatToStr(double value, string numericFormatter = "F", int precision = 0)
|
||||
{
|
||||
if (precision > 0 && numericFormatter.Length == 1)
|
||||
{
|
||||
if (!s_PrecisionToStr.ContainsKey(precision))
|
||||
{
|
||||
s_PrecisionToStr[precision] = new Dictionary<string, string>();
|
||||
}
|
||||
if (!s_PrecisionToStr[precision].ContainsKey(numericFormatter))
|
||||
{
|
||||
s_PrecisionToStr[precision][numericFormatter] = numericFormatter + precision;
|
||||
}
|
||||
return NumberToStr(value, s_PrecisionToStr[precision][numericFormatter]);
|
||||
}
|
||||
else
|
||||
{
|
||||
return NumberToStr(value, numericFormatter);
|
||||
}
|
||||
}
|
||||
|
||||
public static string NumberToStr(double value, string formatter)
|
||||
{
|
||||
if (!s_NumberToStr.ContainsKey(value))
|
||||
{
|
||||
s_NumberToStr[value] = new Dictionary<string, string>();
|
||||
}
|
||||
if (!s_NumberToStr[value].ContainsKey(formatter))
|
||||
{
|
||||
if (string.IsNullOrEmpty(formatter))
|
||||
{
|
||||
if (value - (int) value == 0)
|
||||
s_NumberToStr[value][formatter] = ((int) value).ToString();
|
||||
else
|
||||
s_NumberToStr[value][formatter] = value.ToString();
|
||||
}
|
||||
else if (formatter.StartsWith(NUMERIC_FORMATTER_D) ||
|
||||
formatter.StartsWith(NUMERIC_FORMATTER_d) ||
|
||||
formatter.StartsWith(NUMERIC_FORMATTER_X) ||
|
||||
formatter.StartsWith(NUMERIC_FORMATTER_x)
|
||||
)
|
||||
{
|
||||
s_NumberToStr[value][formatter] = ((int) value).ToString(formatter, ci);
|
||||
}
|
||||
else
|
||||
{
|
||||
s_NumberToStr[value][formatter] = value.ToString(formatter, ci);
|
||||
}
|
||||
}
|
||||
return s_NumberToStr[value][formatter];
|
||||
}
|
||||
|
||||
public static string IntToStr(int value, string numericFormatter = "")
|
||||
{
|
||||
return NumberToStr(value, numericFormatter);
|
||||
}
|
||||
|
||||
public static string ColorToStr(Color color)
|
||||
{
|
||||
if (s_ColorToStr.ContainsKey(color))
|
||||
{
|
||||
return s_ColorToStr[color];
|
||||
}
|
||||
else
|
||||
{
|
||||
s_ColorToStr[color] = ColorUtility.ToHtmlStringRGBA(color);
|
||||
return s_ColorToStr[color];
|
||||
}
|
||||
}
|
||||
|
||||
public static string ColorToDotStr(Color color)
|
||||
{
|
||||
if (!s_ColorDotStr.ContainsKey(color))
|
||||
{
|
||||
s_ColorDotStr[color] = "<color=#" + ColorToStr(color) + ">● </color>";
|
||||
}
|
||||
return s_ColorDotStr[color];
|
||||
}
|
||||
|
||||
public static string GetSerieLabelName(string prefix, int i, int j)
|
||||
{
|
||||
int key = i * 10000000 + j;
|
||||
if (s_SerieLabelName.ContainsKey(key))
|
||||
{
|
||||
return s_SerieLabelName[key];
|
||||
}
|
||||
else
|
||||
{
|
||||
string name = prefix + "_" + i + "_" + j;
|
||||
s_SerieLabelName[key] = name;
|
||||
return name;
|
||||
}
|
||||
}
|
||||
|
||||
internal static string GetComponentObjectName(MainComponent component)
|
||||
{
|
||||
Dictionary<int, string> dict;
|
||||
var type = component.GetType();
|
||||
if (s_ComponentObjectName.TryGetValue(type, out dict))
|
||||
{
|
||||
string name;
|
||||
if (!dict.TryGetValue(component.index, out name))
|
||||
{
|
||||
name = GetTypeName(type) + component.index;
|
||||
dict[component.index] = name;
|
||||
}
|
||||
return name;
|
||||
}
|
||||
else
|
||||
{
|
||||
var name = GetTypeName(type) + component.index;
|
||||
dict = new Dictionary<int, string>();
|
||||
dict.Add(component.index, name);
|
||||
s_ComponentObjectName[type] = dict;
|
||||
return name;
|
||||
}
|
||||
}
|
||||
|
||||
internal static string GetAxisLabelName(int index)
|
||||
{
|
||||
string name;
|
||||
if (!s_AxisLabelName.TryGetValue(index, out name))
|
||||
{
|
||||
name = s_DefaultAxis + index;
|
||||
s_AxisLabelName[index] = name;
|
||||
return name;
|
||||
}
|
||||
else
|
||||
{
|
||||
return name;
|
||||
}
|
||||
}
|
||||
|
||||
internal static string GetTypeName<T>()
|
||||
{
|
||||
return GetTypeName(typeof(T));
|
||||
}
|
||||
|
||||
internal static string GetTypeName(Type type)
|
||||
{
|
||||
if (s_TypeName.ContainsKey(type)) return s_TypeName[type];
|
||||
else
|
||||
{
|
||||
var name = type.Name;
|
||||
s_TypeName[type] = name;
|
||||
return name;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 403191b8caeb44430b89d9f3260c4a76
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,11 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace XCharts.Runtime
|
||||
{
|
||||
public static class ChartConst
|
||||
{
|
||||
public static readonly Color32 clearColor32 = new Color32(0, 0, 0, 0);
|
||||
public static readonly Color32 greyColor32 = new Color32(128, 128, 128, 255);
|
||||
public static readonly Color clearColor = Color.clear;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e19d8fc0680be46b5ac9babf7dd9fe27
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,151 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using XUGL;
|
||||
|
||||
namespace XCharts.Runtime
|
||||
{
|
||||
public static class ChartDrawer
|
||||
{
|
||||
public static void DrawSymbol(VertexHelper vh, SymbolType type, float symbolSize, float tickness,
|
||||
Vector3 pos, Color32 color, Color32 toColor, float gap, float[] cornerRadius,
|
||||
Color32 emptyColor, Color32 backgroundColor, Color32 borderColor, float smoothness, Vector3 startPos)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case SymbolType.None:
|
||||
break;
|
||||
case SymbolType.Circle:
|
||||
if (gap > 0)
|
||||
{
|
||||
UGL.DrawDoughnut(vh, pos, symbolSize, symbolSize + gap, backgroundColor, backgroundColor, color, smoothness);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (tickness > 0)
|
||||
UGL.DrawDoughnut(vh, pos, symbolSize, symbolSize + tickness, borderColor, borderColor, color, smoothness);
|
||||
else
|
||||
UGL.DrawCricle(vh, pos, symbolSize, color, toColor, smoothness);
|
||||
}
|
||||
break;
|
||||
case SymbolType.EmptyCircle:
|
||||
if (gap > 0)
|
||||
{
|
||||
UGL.DrawCricle(vh, pos, symbolSize + gap, backgroundColor, smoothness);
|
||||
UGL.DrawEmptyCricle(vh, pos, symbolSize, tickness, color, color, emptyColor, smoothness);
|
||||
}
|
||||
else
|
||||
{
|
||||
UGL.DrawEmptyCricle(vh, pos, symbolSize, tickness, color, color, emptyColor, smoothness);
|
||||
}
|
||||
break;
|
||||
case SymbolType.Rect:
|
||||
if (gap > 0)
|
||||
{
|
||||
UGL.DrawSquare(vh, pos, symbolSize + gap, backgroundColor);
|
||||
UGL.DrawSquare(vh, pos, symbolSize, color, toColor);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (tickness > 0)
|
||||
{
|
||||
UGL.DrawRoundRectangle(vh, pos, symbolSize, symbolSize, color, color, 0, cornerRadius, true);
|
||||
UGL.DrawBorder(vh, pos, symbolSize, symbolSize, tickness, borderColor, 0, cornerRadius);
|
||||
}
|
||||
else
|
||||
UGL.DrawRoundRectangle(vh, pos, symbolSize, symbolSize, color, color, 0, cornerRadius, true);
|
||||
}
|
||||
break;
|
||||
case SymbolType.EmptyRect:
|
||||
if (gap > 0)
|
||||
{
|
||||
UGL.DrawSquare(vh, pos, symbolSize + gap, backgroundColor);
|
||||
UGL.DrawBorder(vh, pos, symbolSize / 2, symbolSize / 2, tickness, color);
|
||||
}
|
||||
else
|
||||
{
|
||||
UGL.DrawBorder(vh, pos, symbolSize / 2, symbolSize / 2, tickness, color);
|
||||
}
|
||||
break;
|
||||
case SymbolType.Triangle:
|
||||
if (gap > 0)
|
||||
{
|
||||
UGL.DrawTriangle(vh, pos, symbolSize + gap, backgroundColor);
|
||||
UGL.DrawTriangle(vh, pos, symbolSize, color, toColor);
|
||||
}
|
||||
else
|
||||
{
|
||||
UGL.DrawTriangle(vh, pos, symbolSize, color, toColor);
|
||||
}
|
||||
break;
|
||||
case SymbolType.Diamond:
|
||||
if (gap > 0)
|
||||
{
|
||||
UGL.DrawDiamond(vh, pos, symbolSize + gap, backgroundColor);
|
||||
UGL.DrawDiamond(vh, pos, symbolSize, color, toColor);
|
||||
}
|
||||
else
|
||||
{
|
||||
UGL.DrawDiamond(vh, pos, symbolSize, color, toColor);
|
||||
}
|
||||
break;
|
||||
case SymbolType.Arrow:
|
||||
var arrowWidth = symbolSize * 2;
|
||||
var arrowHeight = arrowWidth * 1.5f;
|
||||
var arrowOffset = 0;
|
||||
var arrowDent = arrowWidth / 3.3f;
|
||||
UGL.DrawArrow(vh, startPos, pos, arrowWidth, arrowHeight,
|
||||
arrowOffset, arrowDent, color);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public static void DrawLineStyle(VertexHelper vh, LineStyle lineStyle, Vector3 startPos, Vector3 endPos,
|
||||
Color32 defaultColor, float themeWidth, LineStyle.Type themeType)
|
||||
{
|
||||
var type = lineStyle.GetType(themeType);
|
||||
var width = lineStyle.GetWidth(themeWidth);
|
||||
var color = lineStyle.GetColor(defaultColor);
|
||||
DrawLineStyle(vh, type, width, startPos, endPos, color, color);
|
||||
}
|
||||
|
||||
public static void DrawLineStyle(VertexHelper vh, LineStyle lineStyle, Vector3 startPos, Vector3 endPos,
|
||||
float themeWidth, LineStyle.Type themeType, Color32 defaultColor, Color32 defaultToColor)
|
||||
{
|
||||
var type = lineStyle.GetType(themeType);
|
||||
var width = lineStyle.GetWidth(themeWidth);
|
||||
var color = lineStyle.GetColor(defaultColor);
|
||||
var toColor = ChartHelper.IsClearColor(defaultToColor) ? color : defaultToColor;
|
||||
DrawLineStyle(vh, type, width, startPos, endPos, color, toColor);
|
||||
}
|
||||
|
||||
public static void DrawLineStyle(VertexHelper vh, LineStyle.Type lineType, float lineWidth,
|
||||
Vector3 startPos, Vector3 endPos, Color32 color)
|
||||
{
|
||||
DrawLineStyle(vh, lineType, lineWidth, startPos, endPos, color, color);
|
||||
}
|
||||
|
||||
public static void DrawLineStyle(VertexHelper vh, LineStyle.Type lineType, float lineWidth,
|
||||
Vector3 startPos, Vector3 endPos, Color32 color, Color32 toColor)
|
||||
{
|
||||
switch (lineType)
|
||||
{
|
||||
case LineStyle.Type.Dashed:
|
||||
UGL.DrawDashLine(vh, startPos, endPos, lineWidth, color, toColor);
|
||||
break;
|
||||
case LineStyle.Type.Dotted:
|
||||
UGL.DrawDotLine(vh, startPos, endPos, lineWidth, color, toColor);
|
||||
break;
|
||||
case LineStyle.Type.Solid:
|
||||
UGL.DrawLine(vh, startPos, endPos, lineWidth, color, toColor);
|
||||
break;
|
||||
case LineStyle.Type.DashDot:
|
||||
UGL.DrawDashDotLine(vh, startPos, endPos, lineWidth, color);
|
||||
break;
|
||||
case LineStyle.Type.DashDotDot:
|
||||
UGL.DrawDashDotDotLine(vh, startPos, endPos, lineWidth, color);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 712f08d71f1bf4ab6a1785526bcd5c30
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,883 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.UI;
|
||||
#if dUI_TextMeshPro
|
||||
using TMPro;
|
||||
#endif
|
||||
#if UNITY_EDITOR
|
||||
using UnityEditor;
|
||||
#endif
|
||||
|
||||
namespace XCharts.Runtime
|
||||
{
|
||||
public static class ChartHelper
|
||||
{
|
||||
private static StringBuilder s_Builder = new StringBuilder();
|
||||
private static Vector3 s_DefaultIngoreDataVector3 = Vector3.zero;
|
||||
|
||||
public static StringBuilder sb { get { return s_Builder; } }
|
||||
public static Vector3 ignoreVector3 { get { return s_DefaultIngoreDataVector3; } }
|
||||
|
||||
public static bool IsIngore(Vector3 pos)
|
||||
{
|
||||
return pos == s_DefaultIngoreDataVector3;
|
||||
}
|
||||
public static string Cancat(string str1, string str2)
|
||||
{
|
||||
s_Builder.Length = 0;
|
||||
s_Builder.Append(str1).Append(str2);
|
||||
return s_Builder.ToString();
|
||||
}
|
||||
|
||||
public static string Cancat(string str1, int i)
|
||||
{
|
||||
s_Builder.Length = 0;
|
||||
s_Builder.Append(str1).Append(ChartCached.IntToStr(i));
|
||||
return s_Builder.ToString();
|
||||
}
|
||||
|
||||
public static void SetActive(GameObject gameObject, bool active)
|
||||
{
|
||||
if (gameObject == null) return;
|
||||
SetActive(gameObject.transform, active);
|
||||
}
|
||||
|
||||
public static void SetActive(Image image, bool active)
|
||||
{
|
||||
if (image == null) return;
|
||||
SetActive(image.gameObject, active);
|
||||
}
|
||||
|
||||
public static void SetActive(Text text, bool active)
|
||||
{
|
||||
if (text == null) return;
|
||||
SetActive(text.gameObject, active);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 通过设置scale实现是否显示,优化性能,减少GC
|
||||
/// </summary>
|
||||
/// <param name="transform"></param>
|
||||
/// <param name="active"></param>
|
||||
public static void SetActive(Transform transform, bool active)
|
||||
{
|
||||
if (transform == null) return;
|
||||
if (active) transform.localScale = Vector3.one;
|
||||
else transform.localScale = Vector3.zero;
|
||||
}
|
||||
public static void HideAllObject(GameObject obj, string match = null)
|
||||
{
|
||||
if (obj == null) return;
|
||||
HideAllObject(obj.transform, match);
|
||||
}
|
||||
|
||||
public static void HideAllObject(Transform parent, string match = null)
|
||||
{
|
||||
if (parent == null) return;
|
||||
ActiveAllObject(parent, false, match);
|
||||
}
|
||||
|
||||
public static void ActiveAllObject(Transform parent, bool active, string match = null)
|
||||
{
|
||||
if (parent == null) return;
|
||||
for (int i = 0; i < parent.childCount; i++)
|
||||
{
|
||||
if (match == null)
|
||||
SetActive(parent.GetChild(i), active);
|
||||
else
|
||||
{
|
||||
var go = parent.GetChild(i);
|
||||
if (go.name.StartsWith(match))
|
||||
{
|
||||
SetActive(go, active);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void DestroyAllChildren(Transform parent)
|
||||
{
|
||||
if (parent == null) return;
|
||||
var childCount = parent.childCount;
|
||||
for (int i = childCount - 1; i >= 0; i--)
|
||||
{
|
||||
var go = parent.GetChild(i);
|
||||
if (go != null)
|
||||
{
|
||||
GameObject.DestroyImmediate(go.gameObject, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void DestoryGameObject(Transform parent, string childName)
|
||||
{
|
||||
if (parent == null) return;
|
||||
var go = parent.Find(childName);
|
||||
if (go != null)
|
||||
{
|
||||
GameObject.DestroyImmediate(go.gameObject, true);
|
||||
}
|
||||
}
|
||||
public static void DestoryGameObjectByMatch(Transform parent, string match)
|
||||
{
|
||||
if (parent == null) return;
|
||||
var childCount = parent.childCount;
|
||||
for (int i = childCount - 1; i >= 0; i--)
|
||||
{
|
||||
var go = parent.GetChild(i);
|
||||
if (go != null && go.name.StartsWith(match))
|
||||
{
|
||||
GameObject.DestroyImmediate(go.gameObject, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void DestoryGameObject(GameObject go)
|
||||
{
|
||||
if (go != null) GameObject.DestroyImmediate(go, true);
|
||||
}
|
||||
|
||||
public static string GetFullName(Transform transform)
|
||||
{
|
||||
string name = transform.name;
|
||||
Transform obj = transform;
|
||||
while (obj.transform.parent)
|
||||
{
|
||||
name = obj.transform.parent.name + "/" + name;
|
||||
obj = obj.transform.parent;
|
||||
}
|
||||
return name;
|
||||
}
|
||||
|
||||
public static void RemoveComponent<T>(GameObject gameObject)
|
||||
{
|
||||
var component = gameObject.GetComponent<T>();
|
||||
if (component != null)
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
if (!Application.isPlaying)
|
||||
GameObject.DestroyImmediate(component as GameObject, true);
|
||||
else
|
||||
GameObject.Destroy(component as GameObject);
|
||||
#else
|
||||
GameObject.Destroy(component as GameObject);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
public static T GetOrAddComponent<T>(Transform transform) where T : Component
|
||||
{
|
||||
return GetOrAddComponent<T>(transform.gameObject);
|
||||
}
|
||||
|
||||
public static T GetOrAddComponent<T>(GameObject gameObject) where T : Component
|
||||
{
|
||||
if (gameObject.GetComponent<T>() == null)
|
||||
{
|
||||
return gameObject.AddComponent<T>();
|
||||
}
|
||||
else
|
||||
{
|
||||
return gameObject.GetComponent<T>();
|
||||
}
|
||||
}
|
||||
|
||||
public static GameObject AddObject(string name, Transform parent, Vector2 anchorMin,
|
||||
Vector2 anchorMax, Vector2 pivot, Vector2 sizeDelta, int replaceIndex = -1)
|
||||
{
|
||||
GameObject obj;
|
||||
if (parent.Find(name))
|
||||
{
|
||||
obj = parent.Find(name).gameObject;
|
||||
SetActive(obj, true);
|
||||
obj.transform.localPosition = Vector3.zero;
|
||||
obj.transform.localScale = Vector3.one;
|
||||
}
|
||||
else if (replaceIndex >= 0 && replaceIndex < parent.childCount)
|
||||
{
|
||||
obj = parent.GetChild(replaceIndex).gameObject;
|
||||
if (!obj.name.Equals(name)) obj.name = name;
|
||||
SetActive(obj, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
obj = new GameObject();
|
||||
obj.name = name;
|
||||
obj.transform.SetParent(parent);
|
||||
obj.transform.localScale = Vector3.one;
|
||||
obj.transform.localPosition = Vector3.zero;
|
||||
}
|
||||
RectTransform rect = GetOrAddComponent<RectTransform>(obj);
|
||||
rect.localPosition = Vector3.zero;
|
||||
rect.sizeDelta = sizeDelta;
|
||||
rect.anchorMin = anchorMin;
|
||||
rect.anchorMax = anchorMax;
|
||||
rect.pivot = pivot;
|
||||
rect.anchoredPosition3D = Vector3.zero;
|
||||
return obj;
|
||||
}
|
||||
|
||||
public static void UpdateRectTransform(GameObject obj, Vector2 anchorMin,
|
||||
Vector2 anchorMax, Vector2 pivot, Vector2 sizeDelta)
|
||||
{
|
||||
if (obj == null) return;
|
||||
RectTransform rect = GetOrAddComponent<RectTransform>(obj);
|
||||
rect.sizeDelta = sizeDelta;
|
||||
rect.anchorMin = anchorMin;
|
||||
rect.anchorMax = anchorMax;
|
||||
rect.pivot = pivot;
|
||||
}
|
||||
|
||||
public static ChartText AddTextObject(string objectName, Transform parent, Vector2 anchorMin, Vector2 anchorMax,
|
||||
Vector2 pivot, Vector2 sizeDelta, TextStyle textStyle, ComponentTheme theme, Color autoColor,
|
||||
TextAnchor autoAlignment, ChartText chartText = null)
|
||||
{
|
||||
GameObject txtObj = AddObject(objectName, parent, anchorMin, anchorMax, pivot, sizeDelta);
|
||||
txtObj.transform.localEulerAngles = new Vector3(0, 0, textStyle.rotate);
|
||||
if (chartText == null)
|
||||
chartText = new ChartText();
|
||||
#if dUI_TextMeshPro
|
||||
RemoveComponent<Text>(txtObj);
|
||||
chartText.tmpText = GetOrAddComponent<TextMeshProUGUI>(txtObj);
|
||||
chartText.tmpText.font = textStyle.tmpFont == null ? theme.tmpFont : textStyle.tmpFont;
|
||||
chartText.tmpText.fontStyle = textStyle.tmpFontStyle;
|
||||
chartText.tmpText.richText = true;
|
||||
chartText.tmpText.raycastTarget = false;
|
||||
chartText.tmpText.enableWordWrapping = textStyle.autoWrap;
|
||||
#else
|
||||
chartText.text = GetOrAddComponent<Text>(txtObj);
|
||||
chartText.text.font = textStyle.font == null ? theme.font : textStyle.font;
|
||||
chartText.text.fontStyle = textStyle.fontStyle;
|
||||
chartText.text.horizontalOverflow = textStyle.autoWrap ? HorizontalWrapMode.Wrap : HorizontalWrapMode.Overflow;
|
||||
chartText.text.verticalOverflow = VerticalWrapMode.Overflow;
|
||||
chartText.text.supportRichText = true;
|
||||
chartText.text.raycastTarget = false;
|
||||
#endif
|
||||
if (textStyle.autoColor && autoColor != Color.clear)
|
||||
chartText.SetColor(autoColor);
|
||||
else
|
||||
chartText.SetColor(textStyle.GetColor(theme.textColor));
|
||||
|
||||
chartText.SetAlignment(textStyle.autoAlign ? autoAlignment : textStyle.alignment);
|
||||
chartText.SetFontSize(textStyle.GetFontSize(theme));
|
||||
chartText.SetText("Text");
|
||||
chartText.SetLineSpacing(textStyle.lineSpacing);
|
||||
chartText.SetActive(textStyle.show);
|
||||
|
||||
RectTransform rect = GetOrAddComponent<RectTransform>(txtObj);
|
||||
rect.localPosition = Vector3.zero;
|
||||
rect.sizeDelta = sizeDelta;
|
||||
rect.anchorMin = anchorMin;
|
||||
rect.anchorMax = anchorMax;
|
||||
rect.pivot = pivot;
|
||||
return chartText;
|
||||
}
|
||||
|
||||
internal static Painter AddPainterObject(string name, Transform parent, Vector2 anchorMin, Vector2 anchorMax,
|
||||
Vector2 pivot, Vector2 sizeDelta, HideFlags hideFlags, int siblingIndex)
|
||||
{
|
||||
var painterObj = ChartHelper.AddObject(name, parent, anchorMin, anchorMax, pivot, sizeDelta);
|
||||
painterObj.hideFlags = hideFlags;
|
||||
painterObj.transform.SetSiblingIndex(siblingIndex);
|
||||
return ChartHelper.GetOrAddComponent<Painter>(painterObj);
|
||||
}
|
||||
|
||||
public static Image AddIcon(string name, Transform parent, IconStyle iconStyle)
|
||||
{
|
||||
return AddIcon(name, parent, iconStyle.width, iconStyle.height, iconStyle.sprite, iconStyle.type);
|
||||
}
|
||||
|
||||
public static Image AddIcon(string name, Transform parent, float width, float height, Sprite sprite = null,
|
||||
Image.Type type = Image.Type.Simple)
|
||||
{
|
||||
var anchorMax = new Vector2(0.5f, 0.5f);
|
||||
var anchorMin = new Vector2(0.5f, 0.5f);
|
||||
var pivot = new Vector2(0.5f, 0.5f);
|
||||
var sizeDelta = new Vector2(width, height);
|
||||
GameObject iconObj = AddObject(name, parent, anchorMin, anchorMax, pivot, sizeDelta);
|
||||
var img = GetOrAddComponent<Image>(iconObj);
|
||||
if (img.raycastTarget != false)
|
||||
img.raycastTarget = false;
|
||||
if (img.type != type)
|
||||
img.type = type;
|
||||
if (sprite != null && img.sprite != sprite)
|
||||
{
|
||||
img.sprite = sprite;
|
||||
if (width == 0 || height == 0)
|
||||
{
|
||||
img.SetNativeSize();
|
||||
}
|
||||
}
|
||||
return img;
|
||||
}
|
||||
|
||||
public static ChartLabel AddAxisLabelObject(int total, int index, string name, Transform parent,
|
||||
Vector2 sizeDelta, Axis axis, ComponentTheme theme,
|
||||
string content, Color autoColor, TextAnchor autoAlignment = TextAnchor.MiddleCenter)
|
||||
{
|
||||
var textStyle = axis.axisLabel.textStyle;
|
||||
var label = AddChartLabel(name, parent, axis.axisLabel, theme, content, autoColor, autoAlignment);
|
||||
var labelShow = axis.axisLabel.show && (axis.axisLabel.interval == 0 || index % (axis.axisLabel.interval + 1) == 0);
|
||||
if (labelShow)
|
||||
{
|
||||
if (!axis.axisLabel.showStartLabel && index == 0) labelShow = false;
|
||||
else if (!axis.axisLabel.showEndLabel && index == total - 1) labelShow = false;
|
||||
}
|
||||
label.UpdateIcon(axis.axisLabel.icon, axis.GetIcon(index));
|
||||
label.text.SetActive(labelShow);
|
||||
return label;
|
||||
}
|
||||
|
||||
public static ChartLabel AddChartLabel(string name, Transform parent, LabelStyle labelStyle,
|
||||
ComponentTheme theme, string content, Color autoColor, TextAnchor autoAlignment = TextAnchor.MiddleCenter)
|
||||
{
|
||||
Vector2 anchorMin, anchorMax, pivot;
|
||||
var sizeDelta = new Vector2(labelStyle.width, labelStyle.height);
|
||||
var textStyle = labelStyle.textStyle;
|
||||
var alignment = textStyle.GetAlignment(autoAlignment);
|
||||
UpdateAnchorAndPivotByTextAlignment(alignment, out anchorMin, out anchorMax, out pivot);
|
||||
var labelObj = AddObject(name, parent, anchorMin, anchorMax, pivot, sizeDelta);
|
||||
// TODO: 为了兼容旧版本,这里后面版本可以去掉
|
||||
#region temp code
|
||||
var oldText = labelObj.GetComponent<Text>();
|
||||
if (oldText != null)
|
||||
{
|
||||
GameObject.DestroyImmediate(oldText);
|
||||
}
|
||||
var oldImage = labelObj.GetComponent<Image>();
|
||||
if (oldImage != null)
|
||||
{
|
||||
GameObject.DestroyImmediate(oldImage);
|
||||
}
|
||||
#endregion
|
||||
|
||||
var label = GetOrAddComponent<ChartLabel>(labelObj);
|
||||
label.text = AddTextObject("Text", label.gameObject.transform, anchorMin, anchorMax, pivot,
|
||||
sizeDelta, textStyle, theme, autoColor, autoAlignment, label.text);
|
||||
label.icon = ChartHelper.AddIcon("Icon", label.gameObject.transform, labelStyle.icon);
|
||||
label.SetSize(labelStyle.width, labelStyle.height);
|
||||
label.SetTextPadding(labelStyle.textPadding);
|
||||
label.SetText(content);
|
||||
label.UpdateIcon(labelStyle.icon);
|
||||
if (labelStyle.background.show)
|
||||
{
|
||||
label.color = (!labelStyle.background.autoColor || autoColor == Color.clear) ?
|
||||
labelStyle.background.color : autoColor;
|
||||
label.sprite = labelStyle.background.sprite;
|
||||
label.type = labelStyle.background.type;
|
||||
}
|
||||
else
|
||||
{
|
||||
label.color = Color.clear;
|
||||
label.sprite = null;
|
||||
}
|
||||
label.transform.localEulerAngles = new Vector3(0, 0, labelStyle.rotate);
|
||||
label.transform.localPosition = labelStyle.offset;
|
||||
return label;
|
||||
}
|
||||
|
||||
private static void UpdateAnchorAndPivotByTextAlignment(TextAnchor alignment, out Vector2 anchorMin, out Vector2 anchorMax,
|
||||
out Vector2 pivot)
|
||||
{
|
||||
switch (alignment)
|
||||
{
|
||||
case TextAnchor.LowerLeft:
|
||||
anchorMin = new Vector2(0f, 0f);
|
||||
anchorMax = new Vector2(0f, 0f);
|
||||
pivot = new Vector2(0f, 0f);
|
||||
break;
|
||||
case TextAnchor.UpperLeft:
|
||||
anchorMin = new Vector2(0f, 1f);
|
||||
anchorMax = new Vector2(0f, 1f);
|
||||
pivot = new Vector2(0f, 1f);
|
||||
break;
|
||||
case TextAnchor.MiddleLeft:
|
||||
anchorMin = new Vector2(0f, 0.5f);
|
||||
anchorMax = new Vector2(0f, 0.5f);
|
||||
pivot = new Vector2(0f, 0.5f);
|
||||
break;
|
||||
case TextAnchor.LowerRight:
|
||||
anchorMin = new Vector2(1f, 0f);
|
||||
anchorMax = new Vector2(1f, 0f);
|
||||
pivot = new Vector2(1f, 0f);
|
||||
break;
|
||||
case TextAnchor.UpperRight:
|
||||
anchorMin = new Vector2(1f, 1f);
|
||||
anchorMax = new Vector2(1f, 1f);
|
||||
pivot = new Vector2(1f, 1f);
|
||||
break;
|
||||
case TextAnchor.MiddleRight:
|
||||
anchorMin = new Vector2(1, 0.5f);
|
||||
anchorMax = new Vector2(1, 0.5f);
|
||||
pivot = new Vector2(1, 0.5f);
|
||||
break;
|
||||
case TextAnchor.LowerCenter:
|
||||
anchorMin = new Vector2(0.5f, 0f);
|
||||
anchorMax = new Vector2(0.5f, 0f);
|
||||
pivot = new Vector2(0.5f, 0f);
|
||||
break;
|
||||
case TextAnchor.UpperCenter:
|
||||
anchorMin = new Vector2(0.5f, 1f);
|
||||
anchorMax = new Vector2(0.5f, 1f);
|
||||
pivot = new Vector2(0.5f, 1f);
|
||||
break;
|
||||
case TextAnchor.MiddleCenter:
|
||||
anchorMin = new Vector2(0.5f, 0.5f);
|
||||
anchorMax = new Vector2(0.5f, 0.5f);
|
||||
pivot = new Vector2(0.5f, 0.5f);
|
||||
break;
|
||||
default:
|
||||
anchorMin = new Vector2(0.5f, 0.5f);
|
||||
anchorMax = new Vector2(0.5f, 0.5f);
|
||||
pivot = new Vector2(0.5f, 0.5f);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
internal static ChartLabel AddTooltipIndicatorLabel(Tooltip tooltip, string name, Transform parent,
|
||||
ThemeStyle theme, TextAnchor alignment)
|
||||
{
|
||||
var label = ChartHelper.AddChartLabel(name, parent, tooltip.indicatorLabelStyle, theme.tooltip,
|
||||
"", Color.clear, alignment);
|
||||
label.SetActive(tooltip.show && tooltip.indicatorLabelStyle.show);
|
||||
return label;
|
||||
}
|
||||
|
||||
public static void GetPointList(ref List<Vector3> posList, Vector3 sp, Vector3 ep, float k = 30f)
|
||||
{
|
||||
Vector3 dir = (ep - sp).normalized;
|
||||
float dist = Vector3.Distance(sp, ep);
|
||||
int segment = (int) (dist / k);
|
||||
posList.Clear();
|
||||
posList.Add(sp);
|
||||
for (int i = 1; i < segment; i++)
|
||||
{
|
||||
posList.Add(sp + dir * dist * i / segment);
|
||||
}
|
||||
posList.Add(ep);
|
||||
}
|
||||
|
||||
public static bool IsValueEqualsColor(Color32 color1, Color32 color2)
|
||||
{
|
||||
return color1.a == color2.a &&
|
||||
color1.b == color2.b &&
|
||||
color1.g == color2.g &&
|
||||
color1.r == color2.r;
|
||||
}
|
||||
|
||||
public static bool IsValueEqualsColor(Color color1, Color color2)
|
||||
{
|
||||
return color1.a == color2.a &&
|
||||
color1.b == color2.b &&
|
||||
color1.g == color2.g &&
|
||||
color1.r == color2.r;
|
||||
}
|
||||
|
||||
public static bool IsValueEqualsString(string str1, string str2)
|
||||
{
|
||||
if (str1 == null && str2 == null) return true;
|
||||
else if (str1 != null && str2 != null) return str1.Equals(str2);
|
||||
else return false;
|
||||
}
|
||||
|
||||
public static bool IsValueEqualsVector2(Vector2 v1, Vector2 v2)
|
||||
{
|
||||
return v1.x == v2.x && v1.y == v2.y;
|
||||
}
|
||||
|
||||
public static bool IsValueEqualsVector3(Vector3 v1, Vector3 v2)
|
||||
{
|
||||
return v1.x == v2.x && v1.y == v2.y && v1.z == v2.z;
|
||||
}
|
||||
|
||||
public static bool IsValueEqualsList<T>(List<T> list1, List<T> list2)
|
||||
{
|
||||
if (list1 == null || list2 == null) return false;
|
||||
if (list1.Count != list2.Count) return false;
|
||||
for (int i = 0; i < list1.Count; i++)
|
||||
{
|
||||
if (list1[i] == null && list2[i] == null) { }
|
||||
else
|
||||
{
|
||||
if (list1[i] != null)
|
||||
{
|
||||
if (!list1[i].Equals(list2[i])) return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!list2[i].Equals(list1[i])) return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static bool IsEquals(double d1, double d2)
|
||||
{
|
||||
return Math.Abs(d1 - d2) < 0.000001d;
|
||||
}
|
||||
|
||||
public static bool IsEquals(float d1, float d2)
|
||||
{
|
||||
return Math.Abs(d1 - d2) < 0.000001f;
|
||||
}
|
||||
|
||||
public static bool IsClearColor(Color32 color)
|
||||
{
|
||||
return color.a == 0 && color.b == 0 && color.g == 0 && color.r == 0;
|
||||
}
|
||||
|
||||
public static bool IsClearColor(Color color)
|
||||
{
|
||||
return color.a == 0 && color.b == 0 && color.g == 0 && color.r == 0;
|
||||
}
|
||||
|
||||
public static bool IsZeroVector(Vector3 pos)
|
||||
{
|
||||
return pos.x == 0 && pos.y == 0 && pos.z == 0;
|
||||
}
|
||||
|
||||
public static bool CopyList<T>(List<T> toList, List<T> fromList)
|
||||
{
|
||||
if (toList == null || fromList == null) return false;
|
||||
toList.Clear();
|
||||
foreach (var item in fromList) toList.Add(item);
|
||||
return true;
|
||||
}
|
||||
public static bool CopyArray<T>(T[] toList, T[] fromList)
|
||||
{
|
||||
if (toList == null || fromList == null) return false;
|
||||
if (toList.Length != fromList.Length)
|
||||
{
|
||||
toList = new T[fromList.Length];
|
||||
}
|
||||
for (int i = 0; i < fromList.Length; i++) toList[i] = fromList[i];
|
||||
return true;
|
||||
}
|
||||
|
||||
public static List<float> ParseFloatFromString(string jsonData)
|
||||
{
|
||||
List<float> list = new List<float>();
|
||||
if (string.IsNullOrEmpty(jsonData)) return list;
|
||||
int startIndex = jsonData.IndexOf("[");
|
||||
int endIndex = jsonData.IndexOf("]");
|
||||
string temp = jsonData.Substring(startIndex + 1, endIndex - startIndex - 1);
|
||||
if (temp.IndexOf("],") > -1 || temp.IndexOf("] ,") > -1)
|
||||
{
|
||||
string[] datas = temp.Split(new string[] { "],", "] ," }, StringSplitOptions.RemoveEmptyEntries);
|
||||
for (int i = 0; i < datas.Length; i++)
|
||||
{
|
||||
temp = datas[i];
|
||||
}
|
||||
return list;
|
||||
}
|
||||
else
|
||||
{
|
||||
string[] datas = temp.Split(',');
|
||||
for (int i = 0; i < datas.Length; i++)
|
||||
{
|
||||
list.Add(float.Parse(datas[i].Trim()));
|
||||
}
|
||||
return list;
|
||||
}
|
||||
}
|
||||
|
||||
public static List<string> ParseStringFromString(string jsonData)
|
||||
{
|
||||
List<string> list = new List<string>();
|
||||
if (string.IsNullOrEmpty(jsonData)) return list;
|
||||
string pattern = "[\"'](.*?)[\"']";
|
||||
if (Regex.IsMatch(jsonData, pattern))
|
||||
{
|
||||
MatchCollection m = Regex.Matches(jsonData, pattern);
|
||||
foreach (Match match in m)
|
||||
{
|
||||
list.Add(match.Groups[1].Value);
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
public static Color32 GetColor(string hexColorStr)
|
||||
{
|
||||
Color color;
|
||||
ColorUtility.TryParseHtmlString(hexColorStr, out color);
|
||||
return (Color32) color;
|
||||
}
|
||||
|
||||
public static double GetMaxDivisibleValue(double max, int ceilRate)
|
||||
{
|
||||
if (max == 0) return 0;
|
||||
if (max > -1 && max < 1)
|
||||
{
|
||||
int count = 1;
|
||||
int intvalue = (int) (max * Mathf.Pow(10, count));
|
||||
while (intvalue == 0 && count < 12)
|
||||
{
|
||||
count++;
|
||||
intvalue = (int) (max * Mathf.Pow(10, count));
|
||||
}
|
||||
var pow = Mathf.Pow(10, count);
|
||||
if (max > 0) return (int) ((max * pow + 1)) / pow;
|
||||
else return (int) ((max * pow - 1)) / pow;
|
||||
}
|
||||
if (ceilRate == 0)
|
||||
{
|
||||
var bigger = Math.Ceiling(Math.Abs(max));
|
||||
int n = 1;
|
||||
while (bigger / (Mathf.Pow(10, n)) > 10)
|
||||
{
|
||||
n++;
|
||||
}
|
||||
double mm = bigger;
|
||||
if (mm > 10 && n < 38)
|
||||
{
|
||||
mm = bigger - bigger % (Mathf.Pow(10, n));
|
||||
mm += max > 0 ? Mathf.Pow(10, n) : -Mathf.Pow(10, n);
|
||||
}
|
||||
var mmm = mm - Mathf.Pow(10, n) / 2;
|
||||
if (max < 0) return -Math.Ceiling(mmm > -max ? mmm : mm);
|
||||
else return Math.Ceiling(mmm > max ? mmm : mm);
|
||||
}
|
||||
else
|
||||
{
|
||||
var mod = max % ceilRate;
|
||||
int rate = (int) (max / ceilRate);
|
||||
return mod == 0 ? max : (max < 0 ? rate : rate + 1) * ceilRate;
|
||||
}
|
||||
}
|
||||
|
||||
public static double GetMinDivisibleValue(double min, int ceilRate)
|
||||
{
|
||||
if (min == 0) return 0;
|
||||
if (min > -1 && min < 1)
|
||||
{
|
||||
int count = 1;
|
||||
int intvalue = (int) (min * Mathf.Pow(10, count));
|
||||
while (intvalue == 0 && count < 12)
|
||||
{
|
||||
count++;
|
||||
intvalue = (int) (min * Mathf.Pow(10, count));
|
||||
}
|
||||
var pow = Mathf.Pow(10, count);
|
||||
if (min > 0) return (int) ((min * pow + 1)) / pow;
|
||||
else return (int) ((min * pow - 1)) / pow;
|
||||
}
|
||||
if (ceilRate == 0)
|
||||
{
|
||||
var bigger = Math.Floor(Math.Abs(min));
|
||||
int n = 1;
|
||||
while (bigger / (Mathf.Pow(10, n)) > 10)
|
||||
{
|
||||
n++;
|
||||
}
|
||||
double mm = bigger;
|
||||
if (mm > 10 && n < 38)
|
||||
{
|
||||
mm = bigger - bigger % (Mathf.Pow(10, n));
|
||||
mm += min < 0 ? Mathf.Pow(10, n) : -Mathf.Pow(10, n);
|
||||
}
|
||||
if (min < 0) return -Math.Floor(mm);
|
||||
else return Math.Floor(mm);
|
||||
}
|
||||
else
|
||||
{
|
||||
var mod = min % ceilRate;
|
||||
int rate = (int) (min / ceilRate);
|
||||
return mod == 0 ? min : (min < 0 ? rate - 1 : rate) * ceilRate;
|
||||
}
|
||||
}
|
||||
|
||||
public static double GetMaxLogValue(double value, float logBase, bool isLogBaseE, out int splitNumber)
|
||||
{
|
||||
splitNumber = 0;
|
||||
if (value <= 0) return 0;
|
||||
double max = 0;
|
||||
while (max < value)
|
||||
{
|
||||
if (isLogBaseE)
|
||||
{
|
||||
max = Math.Exp(splitNumber);
|
||||
}
|
||||
else
|
||||
{
|
||||
max = Math.Pow(logBase, splitNumber);
|
||||
}
|
||||
splitNumber++;
|
||||
}
|
||||
return max;
|
||||
}
|
||||
|
||||
public static double GetMinLogValue(double value, float logBase, bool isLogBaseE, out int splitNumber)
|
||||
{
|
||||
splitNumber = 0;
|
||||
if (value > 1) return 1;
|
||||
double min = 1;
|
||||
while (min > value)
|
||||
{
|
||||
if (isLogBaseE)
|
||||
{
|
||||
min = Math.Exp(-splitNumber);
|
||||
}
|
||||
else
|
||||
{
|
||||
min = Math.Pow(logBase, -splitNumber);
|
||||
}
|
||||
splitNumber++;
|
||||
}
|
||||
return min;
|
||||
}
|
||||
|
||||
public static int GetFloatAccuracy(double value)
|
||||
{
|
||||
if (value > 1 || value < -1) return 0;
|
||||
int count = 1;
|
||||
int intvalue = (int) (value * Mathf.Pow(10, count));
|
||||
while (intvalue == 0 && count < 38)
|
||||
{
|
||||
count++;
|
||||
intvalue = (int) (value * Mathf.Pow(10, count));
|
||||
}
|
||||
if (count == 38 && (value == 0 || value == 1)) return 1;
|
||||
else return count;
|
||||
}
|
||||
|
||||
public static void AddEventListener(GameObject obj, EventTriggerType type,
|
||||
UnityEngine.Events.UnityAction<BaseEventData> call)
|
||||
{
|
||||
EventTrigger trigger = GetOrAddComponent<EventTrigger>(obj.gameObject);
|
||||
EventTrigger.Entry entry = new EventTrigger.Entry();
|
||||
entry.eventID = type;
|
||||
entry.callback = new EventTrigger.TriggerEvent();
|
||||
entry.callback.AddListener(call);
|
||||
trigger.triggers.Add(entry);
|
||||
}
|
||||
|
||||
public static void ClearEventListener(GameObject obj)
|
||||
{
|
||||
EventTrigger trigger = obj.GetComponent<EventTrigger>();
|
||||
if (trigger != null)
|
||||
{
|
||||
trigger.triggers.Clear();
|
||||
}
|
||||
}
|
||||
|
||||
public static Vector3 RotateRound(Vector3 position, Vector3 center, Vector3 axis, float angle)
|
||||
{
|
||||
Vector3 point = Quaternion.AngleAxis(angle, axis) * (position - center);
|
||||
Vector3 resultVec3 = center + point;
|
||||
return resultVec3;
|
||||
}
|
||||
|
||||
public static Vector3 GetPosition(Vector3 center, float angle, float radius)
|
||||
{
|
||||
var rad = angle * Mathf.Deg2Rad;
|
||||
var px = Mathf.Sin(rad) * radius;
|
||||
var py = Mathf.Cos(rad) * radius;
|
||||
return center + new Vector3(px, py);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获得0-360的角度(12点钟方向为0度)
|
||||
/// </summary>
|
||||
/// <param name="from"></param>
|
||||
/// <param name="to"></param>
|
||||
/// <returns></returns>
|
||||
public static float GetAngle360(Vector2 from, Vector2 to)
|
||||
{
|
||||
float angle;
|
||||
|
||||
Vector3 cross = Vector3.Cross(from, to);
|
||||
angle = Vector2.Angle(from, to);
|
||||
angle = cross.z > 0 ? -angle : angle;
|
||||
angle = (angle + 360) % 360;
|
||||
return angle;
|
||||
}
|
||||
|
||||
public static Vector3 GetPos(Vector3 center, float radius, float angle, bool isDegree = false)
|
||||
{
|
||||
angle = isDegree ? angle * Mathf.Deg2Rad : angle;
|
||||
return new Vector3(center.x + radius * Mathf.Sin(angle), center.y + radius * Mathf.Cos(angle));
|
||||
}
|
||||
|
||||
public static Vector3 GetDire(float angle, bool isDegree = false)
|
||||
{
|
||||
angle = isDegree ? angle * Mathf.Deg2Rad : angle;
|
||||
return new Vector3(Mathf.Sin(angle), Mathf.Cos(angle));
|
||||
}
|
||||
|
||||
public static Vector3 GetVertialDire(Vector3 dire)
|
||||
{
|
||||
if (dire.x == 0)
|
||||
{
|
||||
return new Vector3(-1, 0, 0);
|
||||
}
|
||||
if (dire.y == 0)
|
||||
{
|
||||
return new Vector3(0, -1, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
return new Vector3(-dire.y / dire.x, 1, 0).normalized;
|
||||
}
|
||||
}
|
||||
|
||||
public static Vector3 GetLastValue(List<Vector3> list)
|
||||
{
|
||||
if (list.Count <= 0) return Vector3.zero;
|
||||
else return list[list.Count - 1];
|
||||
}
|
||||
|
||||
public static void SetColorOpacity(ref Color32 color, float opacity)
|
||||
{
|
||||
if (color.a != 0 && opacity != 1)
|
||||
{
|
||||
color.a = (byte) (color.a * opacity);
|
||||
}
|
||||
}
|
||||
|
||||
public static Color32 GetHighlightColor(Color32 color, float rate = 0.8f)
|
||||
{
|
||||
var newColor = color;
|
||||
newColor.r = (byte) (color.r * rate);
|
||||
newColor.g = (byte) (color.g * rate);
|
||||
newColor.b = (byte) (color.b * rate);
|
||||
return newColor;
|
||||
}
|
||||
|
||||
public static bool IsPointInQuadrilateral(Vector3 P, Vector3 A, Vector3 B, Vector3 C, Vector3 D)
|
||||
{
|
||||
Vector3 v0 = Vector3.Cross(A - D, P - D);
|
||||
Vector3 v1 = Vector3.Cross(B - A, P - A);
|
||||
Vector3 v2 = Vector3.Cross(C - B, P - B);
|
||||
Vector3 v3 = Vector3.Cross(D - C, P - C);
|
||||
if (Vector3.Dot(v0, v1) < 0 || Vector3.Dot(v0, v2) < 0 || Vector3.Dot(v0, v3) < 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public static bool IsInRect(Vector3 pos, float xMin, float xMax, float yMin, float yMax)
|
||||
{
|
||||
return pos.x >= xMin && pos.x <= xMax && pos.y <= yMax && pos.y >= yMin;
|
||||
}
|
||||
|
||||
public static bool IsColorAlphaZero(Color color)
|
||||
{
|
||||
return !ChartHelper.IsClearColor(color) && color.a == 0;
|
||||
}
|
||||
|
||||
public static float GetActualValue(float valueOrRate, float total, float maxRate = 1.5f)
|
||||
{
|
||||
if (valueOrRate >= -maxRate && valueOrRate <= maxRate) return valueOrRate * total;
|
||||
else return valueOrRate;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 47cfa7bd879be4069bd187e46346d73d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,75 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace XCharts.Runtime
|
||||
{
|
||||
public static class ComponentHelper
|
||||
{
|
||||
public static AngleAxis GetAngleAxis(List<MainComponent> components, int polarIndex)
|
||||
{
|
||||
foreach (var component in components)
|
||||
{
|
||||
if (component is AngleAxis)
|
||||
{
|
||||
var axis = component as AngleAxis;
|
||||
if (axis.polarIndex == polarIndex) return axis;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static RadiusAxis GetRadiusAxis(List<MainComponent> components, int polarIndex)
|
||||
{
|
||||
foreach (var component in components)
|
||||
{
|
||||
if (component is RadiusAxis)
|
||||
{
|
||||
var axis = component as RadiusAxis;
|
||||
if (axis.polarIndex == polarIndex) return axis;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static float GetXAxisOnZeroOffset(List<MainComponent> components, XAxis axis)
|
||||
{
|
||||
if (!axis.axisLine.onZero) return 0;
|
||||
foreach (var component in components)
|
||||
{
|
||||
if (component is YAxis)
|
||||
{
|
||||
var yAxis = component as YAxis;
|
||||
if (yAxis.IsValue() && yAxis.gridIndex == axis.gridIndex) return yAxis.context.offset;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public static float GetYAxisOnZeroOffset(List<MainComponent> components, YAxis axis)
|
||||
{
|
||||
if (!axis.axisLine.onZero) return 0;
|
||||
foreach (var component in components)
|
||||
{
|
||||
if (component is XAxis)
|
||||
{
|
||||
var xAxis = component as XAxis;
|
||||
if (xAxis.IsValue() && xAxis.gridIndex == axis.gridIndex) return xAxis.context.offset;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public static bool IsAnyCategoryOfYAxis(List<MainComponent> components)
|
||||
{
|
||||
foreach (var component in components)
|
||||
{
|
||||
if (component is YAxis)
|
||||
{
|
||||
var yAxis = component as YAxis;
|
||||
if (yAxis.type == Axis.AxisType.Category)
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1b7af706293fe4e63b4d079dbe5c0ea2
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,110 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace XCharts.Runtime
|
||||
{
|
||||
internal static class DataHelper
|
||||
{
|
||||
public static double DataAverage(ref List<SerieData> showData, SampleType sampleType,
|
||||
int minCount, int maxCount, int rate)
|
||||
{
|
||||
double totalAverage = 0;
|
||||
if (rate > 1 && sampleType == SampleType.Peak)
|
||||
{
|
||||
double total = 0;
|
||||
for (int i = minCount; i < maxCount; i++)
|
||||
{
|
||||
total += showData[i].data[1];
|
||||
}
|
||||
totalAverage = total / (maxCount - minCount);
|
||||
}
|
||||
return totalAverage;
|
||||
}
|
||||
|
||||
public static double SampleValue(ref List<SerieData> showData, SampleType sampleType, int rate,
|
||||
int minCount, int maxCount, double totalAverage, int index, float dataChangeDuration,
|
||||
ref bool dataChanging, Axis axis)
|
||||
{
|
||||
var inverse = axis.inverse;
|
||||
var minValue = axis.context.minValue;
|
||||
var maxValue = axis.context.maxValue;
|
||||
if (rate <= 1 || index == minCount)
|
||||
{
|
||||
if (showData[index].IsDataChanged())
|
||||
dataChanging = true;
|
||||
|
||||
return showData[index].GetCurrData(1, dataChangeDuration, inverse, minValue, maxValue);
|
||||
}
|
||||
switch (sampleType)
|
||||
{
|
||||
case SampleType.Sum:
|
||||
case SampleType.Average:
|
||||
double total = 0;
|
||||
var count = 0;
|
||||
for (int i = index; i > index - rate; i--)
|
||||
{
|
||||
count++;
|
||||
total += showData[i].GetCurrData(1, dataChangeDuration, inverse, minValue, maxValue);
|
||||
if (showData[i].IsDataChanged())
|
||||
dataChanging = true;
|
||||
}
|
||||
if (sampleType == SampleType.Average)
|
||||
return total / rate;
|
||||
else
|
||||
return total;
|
||||
|
||||
case SampleType.Max:
|
||||
double max = double.MinValue;
|
||||
for (int i = index; i > index - rate; i--)
|
||||
{
|
||||
var value = showData[i].GetCurrData(1, dataChangeDuration, inverse, minValue, maxValue);
|
||||
if (value > max)
|
||||
max = value;
|
||||
|
||||
if (showData[i].IsDataChanged())
|
||||
dataChanging = true;
|
||||
}
|
||||
return max;
|
||||
|
||||
case SampleType.Min:
|
||||
double min = double.MaxValue;
|
||||
for (int i = index; i > index - rate; i--)
|
||||
{
|
||||
var value = showData[i].GetCurrData(1, dataChangeDuration, inverse, minValue, maxValue);
|
||||
if (value < min)
|
||||
min = value;
|
||||
|
||||
if (showData[i].IsDataChanged())
|
||||
dataChanging = true;
|
||||
}
|
||||
return min;
|
||||
|
||||
case SampleType.Peak:
|
||||
max = double.MinValue;
|
||||
min = double.MaxValue;
|
||||
total = 0;
|
||||
for (int i = index; i > index - rate; i--)
|
||||
{
|
||||
var value = showData[i].GetCurrData(1, dataChangeDuration, inverse, minValue, maxValue);
|
||||
total += value;
|
||||
if (value < min)
|
||||
min = value;
|
||||
if (value > max)
|
||||
max = value;
|
||||
|
||||
if (showData[i].IsDataChanged())
|
||||
dataChanging = true;
|
||||
}
|
||||
var average = total / rate;
|
||||
if (average >= totalAverage)
|
||||
return max;
|
||||
else
|
||||
return min;
|
||||
}
|
||||
if (showData[index].IsDataChanged())
|
||||
dataChanging = true;
|
||||
|
||||
return showData[index].GetCurrData(1, dataChangeDuration, inverse, minValue, maxValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c982f1be15b204c9190197803101f2db
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,226 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace XCharts.Runtime
|
||||
{
|
||||
public static class LayerHelper
|
||||
{
|
||||
private static Vector2 s_Vector0And0 = new Vector2(0, 0);
|
||||
private static Vector2 s_Vector0And0Dot5 = new Vector2(0, 0.5f);
|
||||
private static Vector2 s_Vector0And1 = new Vector2(0, 1f);
|
||||
private static Vector2 s_Vector0Dot5And1 = new Vector2(0.5f, 1f);
|
||||
private static Vector2 s_Vector0Dot5And0Dot5 = new Vector2(0.5f, 0.5f);
|
||||
private static Vector2 s_Vector0Dot5And0 = new Vector2(0.5f, 0f);
|
||||
private static Vector2 s_Vector1And1 = new Vector2(1f, 1f);
|
||||
private static Vector2 s_Vector1And0Dot5 = new Vector2(1f, 0.5f);
|
||||
private static Vector2 s_Vector1And0 = new Vector2(1f, 0);
|
||||
|
||||
internal static Vector2 ResetChartPositionAndPivot(Vector2 minAnchor, Vector2 maxAnchor, float width,
|
||||
float height, ref float chartX, ref float chartY)
|
||||
{
|
||||
if (IsLeftTop(minAnchor, maxAnchor))
|
||||
{
|
||||
chartX = 0;
|
||||
chartY = -height;
|
||||
return s_Vector0And1;
|
||||
}
|
||||
else if (IsLeftCenter(minAnchor, maxAnchor))
|
||||
{
|
||||
chartX = 0;
|
||||
chartY = -height / 2;
|
||||
return s_Vector0And0Dot5;
|
||||
}
|
||||
else if (IsLeftBottom(minAnchor, maxAnchor))
|
||||
{
|
||||
chartX = 0;
|
||||
chartY = 0;
|
||||
return s_Vector0And0;
|
||||
}
|
||||
else if (IsCenterTop(minAnchor, maxAnchor))
|
||||
{
|
||||
chartX = -width / 2;
|
||||
chartY = -height;
|
||||
return s_Vector0Dot5And1;
|
||||
}
|
||||
else if (IsCenterCenter(minAnchor, maxAnchor))
|
||||
{
|
||||
chartX = -width / 2;
|
||||
chartY = -height / 2;
|
||||
return s_Vector0Dot5And0Dot5;
|
||||
}
|
||||
else if (IsCenterBottom(minAnchor, maxAnchor))
|
||||
{
|
||||
chartX = -width / 2;
|
||||
chartY = 0;
|
||||
return s_Vector0Dot5And0;
|
||||
}
|
||||
else if (IsRightTop(minAnchor, maxAnchor))
|
||||
{
|
||||
chartX = -width;
|
||||
chartY = -height;
|
||||
return s_Vector1And1;
|
||||
}
|
||||
else if (IsRightCenter(minAnchor, maxAnchor))
|
||||
{
|
||||
chartX = -width;
|
||||
chartY = -height / 2;
|
||||
return s_Vector1And0Dot5;
|
||||
}
|
||||
else if (IsRightBottom(minAnchor, maxAnchor))
|
||||
{
|
||||
chartX = -width;
|
||||
chartY = 0;
|
||||
return s_Vector1And0;
|
||||
}
|
||||
else if (IsStretchTop(minAnchor, maxAnchor))
|
||||
{
|
||||
chartX = -width / 2;
|
||||
chartY = -height;
|
||||
return s_Vector0Dot5And1;
|
||||
}
|
||||
else if (IsStretchMiddle(minAnchor, maxAnchor))
|
||||
{
|
||||
chartX = -width / 2;
|
||||
chartY = -height / 2;
|
||||
return s_Vector0Dot5And0Dot5;
|
||||
}
|
||||
else if (IsStretchBottom(minAnchor, maxAnchor))
|
||||
{
|
||||
chartX = -width / 2;
|
||||
chartY = 0;
|
||||
return s_Vector0Dot5And0;
|
||||
}
|
||||
else if (IsStretchLeft(minAnchor, maxAnchor))
|
||||
{
|
||||
chartX = 0;
|
||||
chartY = -height / 2;
|
||||
return s_Vector0And0Dot5;
|
||||
}
|
||||
else if (IsStretchCenter(minAnchor, maxAnchor))
|
||||
{
|
||||
chartX = -width / 2;
|
||||
chartY = -height / 2;
|
||||
return s_Vector0Dot5And0Dot5;
|
||||
}
|
||||
else if (IsStretchRight(minAnchor, maxAnchor))
|
||||
{
|
||||
chartX = -width;
|
||||
chartY = -height / 2;
|
||||
return s_Vector1And0Dot5;
|
||||
}
|
||||
else if (IsStretchStrech(minAnchor, maxAnchor))
|
||||
{
|
||||
chartX = -width / 2;
|
||||
chartY = -height / 2;
|
||||
return s_Vector0Dot5And0Dot5;
|
||||
}
|
||||
chartX = 0;
|
||||
chartY = 0;
|
||||
return Vector2.zero;
|
||||
}
|
||||
|
||||
private static bool IsLeftTop(Vector2 minAnchor, Vector2 maxAnchor)
|
||||
{
|
||||
return minAnchor == s_Vector0And1 && maxAnchor == s_Vector0And1;
|
||||
}
|
||||
|
||||
private static bool IsLeftCenter(Vector2 minAnchor, Vector2 maxAnchor)
|
||||
{
|
||||
return minAnchor == s_Vector0And0Dot5 && maxAnchor == s_Vector0And0Dot5;
|
||||
}
|
||||
|
||||
private static bool IsLeftBottom(Vector2 minAnchor, Vector2 maxAnchor)
|
||||
{
|
||||
return minAnchor == Vector2.zero && maxAnchor == Vector2.zero;
|
||||
}
|
||||
|
||||
private static bool IsCenterTop(Vector2 minAnchor, Vector2 maxAnchor)
|
||||
{
|
||||
return minAnchor == s_Vector0Dot5And1 && maxAnchor == s_Vector0Dot5And1;
|
||||
}
|
||||
|
||||
private static bool IsCenterCenter(Vector2 minAnchor, Vector2 maxAnchor)
|
||||
{
|
||||
return minAnchor == s_Vector0Dot5And0Dot5 && maxAnchor == s_Vector0Dot5And0Dot5;
|
||||
}
|
||||
|
||||
private static bool IsCenterBottom(Vector2 minAnchor, Vector2 maxAnchor)
|
||||
{
|
||||
return minAnchor == s_Vector0Dot5And0 && maxAnchor == s_Vector0Dot5And0;
|
||||
}
|
||||
|
||||
private static bool IsRightTop(Vector2 minAnchor, Vector2 maxAnchor)
|
||||
{
|
||||
return minAnchor == s_Vector1And1 && maxAnchor == s_Vector1And1;
|
||||
}
|
||||
|
||||
private static bool IsRightCenter(Vector2 minAnchor, Vector2 maxAnchor)
|
||||
{
|
||||
return minAnchor == s_Vector1And0Dot5 && maxAnchor == s_Vector1And0Dot5;
|
||||
}
|
||||
|
||||
private static bool IsRightBottom(Vector2 minAnchor, Vector2 maxAnchor)
|
||||
{
|
||||
return minAnchor == s_Vector1And0 && maxAnchor == s_Vector1And0;
|
||||
}
|
||||
|
||||
private static bool IsStretchTop(Vector2 minAnchor, Vector2 maxAnchor)
|
||||
{
|
||||
return minAnchor == s_Vector0And1 && maxAnchor == s_Vector1And1;
|
||||
}
|
||||
|
||||
private static bool IsStretchMiddle(Vector2 minAnchor, Vector2 maxAnchor)
|
||||
{
|
||||
return minAnchor == s_Vector0And0Dot5 && maxAnchor == s_Vector1And0Dot5;
|
||||
}
|
||||
|
||||
private static bool IsStretchBottom(Vector2 minAnchor, Vector2 maxAnchor)
|
||||
{
|
||||
return minAnchor == s_Vector0And0 && maxAnchor == s_Vector1And0;
|
||||
}
|
||||
|
||||
private static bool IsStretchLeft(Vector2 minAnchor, Vector2 maxAnchor)
|
||||
{
|
||||
return minAnchor == s_Vector0And0 && maxAnchor == s_Vector0And1;
|
||||
}
|
||||
|
||||
private static bool IsStretchCenter(Vector2 minAnchor, Vector2 maxAnchor)
|
||||
{
|
||||
return minAnchor == s_Vector0Dot5And0 && maxAnchor == s_Vector0Dot5And1;
|
||||
}
|
||||
|
||||
private static bool IsStretchRight(Vector2 minAnchor, Vector2 maxAnchor)
|
||||
{
|
||||
return minAnchor == s_Vector1And0 && maxAnchor == s_Vector1And1;
|
||||
}
|
||||
|
||||
private static bool IsStretchStrech(Vector2 minAnchor, Vector2 maxAnchor)
|
||||
{
|
||||
return minAnchor == s_Vector0And0 && maxAnchor == s_Vector1And1;
|
||||
}
|
||||
|
||||
public static bool IsStretchPivot(RectTransform rt)
|
||||
{
|
||||
return IsStretchTop(rt.anchorMin, rt.anchorMax) ||
|
||||
IsStretchMiddle(rt.anchorMin, rt.anchorMax) ||
|
||||
IsStretchBottom(rt.anchorMin, rt.anchorMax) ||
|
||||
IsStretchLeft(rt.anchorMin, rt.anchorMax) ||
|
||||
IsStretchCenter(rt.anchorMin, rt.anchorMax) ||
|
||||
IsStretchRight(rt.anchorMin, rt.anchorMax) ||
|
||||
IsStretchStrech(rt.anchorMin, rt.anchorMax);
|
||||
}
|
||||
|
||||
public static bool IsFixedWidthHeight(RectTransform rt)
|
||||
{
|
||||
return IsLeftTop(rt.anchorMin, rt.anchorMax) ||
|
||||
IsLeftCenter(rt.anchorMin, rt.anchorMax) ||
|
||||
IsLeftBottom(rt.anchorMin, rt.anchorMax) ||
|
||||
IsCenterTop(rt.anchorMin, rt.anchorMax) ||
|
||||
IsCenterCenter(rt.anchorMin, rt.anchorMax) ||
|
||||
IsCenterBottom(rt.anchorMin, rt.anchorMax) ||
|
||||
IsRightTop(rt.anchorMin, rt.anchorMax) ||
|
||||
IsRightCenter(rt.anchorMin, rt.anchorMax) ||
|
||||
IsRightBottom(rt.anchorMin, rt.anchorMax);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8d6eeea6fc2824cc891fec0674bf2d71
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,45 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace XCharts.Runtime
|
||||
{
|
||||
public static class MathUtil
|
||||
{
|
||||
public static double Abs(double d)
|
||||
{
|
||||
return d > 0 ? d : -d;
|
||||
}
|
||||
|
||||
public static double Clamp(double d, double min, double max)
|
||||
{
|
||||
if (d >= min && d <= max) return d;
|
||||
else if (d < min) return min;
|
||||
else return max;
|
||||
}
|
||||
|
||||
public static bool Approximately(double a, double b)
|
||||
{
|
||||
return Math.Abs(b - a) < Math.Max(0.000001f * Math.Max(Math.Abs(a), Math.Abs(b)), Mathf.Epsilon * 8);
|
||||
}
|
||||
|
||||
public static double Clamp01(double value)
|
||||
{
|
||||
if (value < 0F)
|
||||
return 0F;
|
||||
else if (value > 1F)
|
||||
return 1F;
|
||||
else
|
||||
return value;
|
||||
}
|
||||
|
||||
public static double Lerp(double a, double b, double t)
|
||||
{
|
||||
return a + (b - a) * Clamp01(t);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 094dc7b90e3a049b48f15f990c050db1
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user