增加Radar雷达组件更多样式配置参数支持

This commit is contained in:
monitor1394
2019-11-05 18:58:32 +08:00
parent 6491660432
commit 70c9dafda3
12 changed files with 32516 additions and 2292 deletions

View File

@@ -1,6 +1,9 @@
# 更新日志
* (2019.11.05) 增加`Radar`雷达组件更多样式配置参数支持,如`positionType`,`rotate`,`fontSize`,`fontStyle`,`offset`
* (2019.11.04) 修复`Unity2018.3`以下版本代码不兼容的问题
* (2019.11.04) 优化`SerieLabel`过多时引起的性能问题
* (2019.11.03) 发布`v1.0.3`版本
* (2019.11.03) 增加`Editor`快捷添加图表:`Hierarchy`试图下右键`XCharts->LineChart`
* (2019.11.02) 优化非配置参数变量命名和访问权限,简化`API`

File diff suppressed because it is too large Load Diff

View File

@@ -15,12 +15,14 @@ namespace XCharts
public class RadarDrawer : PropertyDrawer
{
SerializedProperty m_Shape;
SerializedProperty m_PositionType;
SerializedProperty m_Radius;
SerializedProperty m_SplitNumber;
SerializedProperty m_Center;
SerializedProperty m_LineStyle;
SerializedProperty m_SplitArea;
SerializedProperty m_Indicator;
SerializedProperty m_IndicatorGap;
SerializedProperty m_IndicatorList;
private Dictionary<string, bool> m_RadarModuleToggle = new Dictionary<string, bool>();
@@ -33,12 +35,14 @@ namespace XCharts
private void InitProperty(SerializedProperty prop)
{
m_Shape = prop.FindPropertyRelative("m_Shape");
m_PositionType = prop.FindPropertyRelative("m_PositionType");
m_Radius = prop.FindPropertyRelative("m_Radius");
m_SplitNumber = prop.FindPropertyRelative("m_SplitNumber");
m_Center = prop.FindPropertyRelative("m_Center");
m_LineStyle = prop.FindPropertyRelative("m_LineStyle");
m_SplitArea = prop.FindPropertyRelative("m_SplitArea");
m_Indicator = prop.FindPropertyRelative("m_Indicator");
m_IndicatorGap = prop.FindPropertyRelative("m_IndicatorGap");
m_IndicatorList = prop.FindPropertyRelative("m_IndicatorList");
}
@@ -50,9 +54,9 @@ namespace XCharts
float defaultFieldWidth = EditorGUIUtility.fieldWidth;
drawRect.height = EditorGUIUtility.singleLineHeight;
int index = ChartEditorHelper.GetIndexFromPath(prop);
ChartEditorHelper.MakeFoldout(ref drawRect, ref m_RadarModuleToggle, prop, "Radar " + index, null, false);
ChartEditorHelper.MakeFoldout(ref drawRect, ref m_RadarModuleToggle, prop, "Radar " + index, null, true);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
if (ChartEditorHelper.IsToggle(m_RadarModuleToggle,prop))
if (ChartEditorHelper.IsToggle(m_RadarModuleToggle, prop))
{
++EditorGUI.indentLevel;
@@ -60,6 +64,8 @@ namespace XCharts
EditorGUIUtility.fieldWidth = defaultFieldWidth;
EditorGUI.PropertyField(drawRect, m_Shape);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_PositionType);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.LabelField(drawRect, "Center");
var startX = drawRect.x + EditorGUIUtility.labelWidth - EditorGUI.indentLevel * 15;
@@ -90,6 +96,8 @@ namespace XCharts
drawRect.x = pos.x;
if (ChartEditorHelper.IsToggle(m_IndicatorToggle, prop))
{
EditorGUI.PropertyField(drawRect, m_IndicatorGap);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
ChartEditorHelper.MakeList(ref drawRect, ref m_IndicatorSize, m_IndicatorList);
}
--EditorGUI.indentLevel;
@@ -99,9 +107,9 @@ namespace XCharts
public override float GetPropertyHeight(SerializedProperty prop, GUIContent label)
{
int propNum = 1;
if (ChartEditorHelper.IsToggle(m_RadarModuleToggle,prop))
if (ChartEditorHelper.IsToggle(m_RadarModuleToggle, prop))
{
propNum += 6;
propNum += 7;
if (m_IndicatorJsonAreaToggle) propNum += 4;
float height = propNum * EditorGUIUtility.singleLineHeight + (propNum - 1) * EditorGUIUtility.standardVerticalSpacing;
height += EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_LineStyle"));
@@ -110,7 +118,7 @@ namespace XCharts
if (ChartEditorHelper.IsToggle(m_IndicatorToggle, prop))
{
m_IndicatorList = prop.FindPropertyRelative("m_IndicatorList");
height += EditorGUIUtility.singleLineHeight * 2 + EditorGUIUtility.standardVerticalSpacing;
height += EditorGUIUtility.singleLineHeight * 3 + EditorGUIUtility.standardVerticalSpacing;
for (int i = 0; i < m_IndicatorList.arraySize; i++)
{

View File

@@ -21,7 +21,7 @@ namespace XCharts
SerializedProperty m_Name = prop.FindPropertyRelative("m_Name");
SerializedProperty m_Max = prop.FindPropertyRelative("m_Max");
SerializedProperty m_Min = prop.FindPropertyRelative("m_Min");
SerializedProperty m_Color = prop.FindPropertyRelative("m_Color");
SerializedProperty m_TextStyle = prop.FindPropertyRelative("m_TextStyle");
Rect drawRect = pos;
float defaultLabelWidth = EditorGUIUtility.labelWidth;
float defaultFieldWidth = EditorGUIUtility.fieldWidth;
@@ -30,7 +30,7 @@ namespace XCharts
int index = ChartEditorHelper.GetIndexFromPath(prop);
ChartEditorHelper.MakeFoldout(ref drawRect, ref m_RadarModuleToggle, prop, "Indicator " + index, m_Name, false);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
if (ChartEditorHelper.IsToggle(m_RadarModuleToggle,prop))
if (ChartEditorHelper.IsToggle(m_RadarModuleToggle, prop))
{
++EditorGUI.indentLevel;
@@ -40,8 +40,8 @@ namespace XCharts
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_Max);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_Color);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_TextStyle);
drawRect.y += EditorGUI.GetPropertyHeight(m_TextStyle);
--EditorGUI.indentLevel;
}
@@ -49,9 +49,11 @@ namespace XCharts
public override float GetPropertyHeight(SerializedProperty prop, GUIContent label)
{
if (ChartEditorHelper.IsToggle(m_RadarModuleToggle,prop))
if (ChartEditorHelper.IsToggle(m_RadarModuleToggle, prop))
{
return 5 * EditorGUIUtility.singleLineHeight + 4 * EditorGUIUtility.standardVerticalSpacing;
var height = 4 * EditorGUIUtility.singleLineHeight + 3 * EditorGUIUtility.standardVerticalSpacing;
height += EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_TextStyle"));
return height;
}
else
{

View File

@@ -0,0 +1,63 @@
/******************************************/
/* */
/* Copyright (c) 2018 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/******************************************/
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
namespace XCharts
{
[CustomPropertyDrawer(typeof(TextStyle), true)]
public class TextStyleDrawer : PropertyDrawer
{
private Dictionary<string, bool> m_TextStyleToggle = new Dictionary<string, bool>();
public override void OnGUI(Rect pos, SerializedProperty prop, GUIContent label)
{
Rect drawRect = pos;
drawRect.height = EditorGUIUtility.singleLineHeight;
SerializedProperty m_Rotate = prop.FindPropertyRelative("m_Rotate");
SerializedProperty m_Color = prop.FindPropertyRelative("m_Color");
SerializedProperty m_FontSize = prop.FindPropertyRelative("m_FontSize");
SerializedProperty m_FontStyle = prop.FindPropertyRelative("m_FontStyle");
SerializedProperty m_Offset = prop.FindPropertyRelative("m_Offset");
// ChartEditorHelper.MakeFoldout(ref drawRect, ref m_TextStyleToggle, prop, "Text Style");
// drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
// if (ChartEditorHelper.IsToggle(m_TextStyleToggle, prop))
// {
// ++EditorGUI.indentLevel;
EditorGUI.PropertyField(drawRect, m_Rotate);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_Offset);
drawRect.y += EditorGUI.GetPropertyHeight(m_Offset);
EditorGUI.PropertyField(drawRect, m_Color);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_FontSize);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, m_FontStyle);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
// --EditorGUI.indentLevel;
// }
}
public override float GetPropertyHeight(SerializedProperty prop, GUIContent label)
{
// float height = 0;
// if (ChartEditorHelper.IsToggle(m_TextStyleToggle, prop))
// {
// height += 5 * EditorGUIUtility.singleLineHeight + 4 * EditorGUIUtility.standardVerticalSpacing;
// }
// else
// {
// height += 1 * EditorGUIUtility.singleLineHeight + 1 * EditorGUIUtility.standardVerticalSpacing;
// }
float height = 4 * EditorGUIUtility.singleLineHeight + 3 * EditorGUIUtility.standardVerticalSpacing;
height += EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_Offset"));
return height;
}
}
}

View File

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

View File

@@ -30,6 +30,20 @@ namespace XCharts
Circle
}
/// <summary>
/// 显示位置。
/// </summary>
public enum PositionType
{
/// <summary>
/// 显示在顶点处。
/// </summary>
Vertice,
/// <summary>
/// 显示在两者之间。
/// </summary>
Between,
}
/// <summary>
/// Indicator of radar chart, which is used to assign multiple variables(dimensions) in radar chart.
/// 雷达图的指示器,用来指定雷达图中的多个变量(维度)。
/// </summary>
@@ -39,7 +53,8 @@ namespace XCharts
[SerializeField] private string m_Name;
[SerializeField] private float m_Max;
[SerializeField] private float m_Min;
[SerializeField] private Color m_Color;
[SerializeField] private TextStyle m_TextStyle = new TextStyle();
/// <summary>
/// 指示器名称。
/// </summary>
@@ -55,10 +70,10 @@ namespace XCharts
/// </summary>
public float min { get { return m_Min; } set { m_Min = value; } }
/// <summary>
/// Specfy a color the the indicator.
/// 标签特定的颜色。默认取自主题的axisTextColor
/// the style of text.
/// 文本样式
/// </summary>
public Color color { get { return m_Color; } set { m_Color = value; } }
public TextStyle textStyle { get { return m_TextStyle; } set { m_TextStyle = value; } }
/// <summary>
/// the text conponent of indicator.
/// 指示器的文本组件。
@@ -72,7 +87,7 @@ namespace XCharts
m_Name = name,
m_Max = max,
m_Min = min,
m_Color = color
m_TextStyle = textStyle.Clone()
};
}
@@ -99,7 +114,7 @@ namespace XCharts
return false;
}
return m_Name.Equals(other.name) &&
ChartHelper.IsValueEqualsColor(m_Color, other.color);
m_TextStyle.Equals(other.textStyle);
}
public override int GetHashCode()
@@ -114,6 +129,8 @@ namespace XCharts
[SerializeField] private LineStyle m_LineStyle = new LineStyle();
[SerializeField] private AxisSplitArea m_SplitArea = AxisSplitArea.defaultSplitArea;
[SerializeField] private bool m_Indicator = true;
[SerializeField] private PositionType m_PositionType = PositionType.Vertice;
[SerializeField] private float m_IndicatorGap = 10;
[SerializeField] private List<Indicator> m_IndicatorList = new List<Indicator>();
/// <summary>
/// Radar render type, in which 'Polygon' and 'Circle' are supported.
@@ -153,6 +170,14 @@ namespace XCharts
/// </summary>
public bool indicator { get { return m_Indicator; } set { m_Indicator = value; } }
/// <summary>
/// 指示器和雷达的间距。
/// </summary>
public float indicatorGap { get { return m_IndicatorGap; } set { m_IndicatorGap = value; } }
/// <summary>
/// 指示器显示位置类型。
/// </summary>
public PositionType positionType { get { return m_PositionType; } set { m_PositionType = value; } }
/// <summary>
/// the indicator list.
/// 指示器列表。
/// </summary>
@@ -168,6 +193,7 @@ namespace XCharts
/// 雷达图的运行时实际半径。
/// </summary>
public float runtimeRadius { get; internal set; }
public float runtimeDataRadius { get; internal set; }
/// <summary>
/// the data position list of radar.
/// 雷达图的所有数据坐标点列表。
@@ -216,12 +242,14 @@ namespace XCharts
{
var radar = new Radar();
radar.shape = shape;
radar.positionType = positionType;
radar.radius = radius;
radar.splitNumber = splitNumber;
radar.center[0] = center[0];
radar.center[1] = center[1];
radar.indicatorList.Clear();
radar.indicator = indicator;
radar.indicatorGap = indicatorGap;
foreach (var d in indicatorList) radar.indicatorList.Add(d.Clone());
return radar;
}
@@ -250,10 +278,12 @@ namespace XCharts
}
return radius == other.radius &&
shape == other.shape &&
positionType == other.positionType &&
splitNumber == other.splitNumber &&
center[0] == other.center[0] &&
center[1] == other.center[1] &&
indicator == other.indicator &&
indicatorGap == other.indicatorGap &&
IsEqualsIndicatorList(indicatorList, other.indicatorList);
}
@@ -359,14 +389,32 @@ namespace XCharts
{
runtimeRadius = radius;
}
if (shape == Radar.Shape.Polygon && positionType == PositionType.Between)
{
var angle = Mathf.PI / indicatorList.Count;
runtimeDataRadius = runtimeRadius * Mathf.Cos(angle);
}
else
{
runtimeDataRadius = runtimeRadius;
}
}
public Vector3 GetIndicatorPosition(int index)
{
int indicatorNum = indicatorList.Count;
var angle = 2 * Mathf.PI / indicatorNum * index;
var x = runtimeCenterPos.x + runtimeRadius * Mathf.Sin(angle);
var y = runtimeCenterPos.y + runtimeRadius * Mathf.Cos(angle);
var angle = 0f;
switch (positionType)
{
case PositionType.Vertice:
angle = 2 * Mathf.PI / indicatorNum * index;
break;
case PositionType.Between:
angle = 2 * Mathf.PI / indicatorNum * (index + 0.5f);
break;
}
var x = runtimeCenterPos.x + (runtimeRadius + indicatorGap) * Mathf.Sin(angle);
var y = runtimeCenterPos.y + (runtimeRadius + indicatorGap) * Mathf.Cos(angle);
return new Vector3(x, y);
}
}

View File

@@ -0,0 +1,129 @@
using System.Threading;
/******************************************/
/* */
/* Copyright (c) 2018 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/******************************************/
using System;
using UnityEngine;
namespace XCharts
{
/// <summary>
/// Settings related to text.
/// 文本的相关设置。
/// </summary>
[Serializable]
public class TextStyle : SubComponent, IEquatable<TextStyle>
{
[SerializeField] private float m_Rotate = 0;
[SerializeField] private Vector2 m_Offset = Vector2.zero;
[SerializeField] private Color m_Color = Color.clear;
[SerializeField] private int m_FontSize = 18;
[SerializeField] private FontStyle m_FontStyle = FontStyle.Normal;
/// <summary>
/// Rotation of text.
/// 文本的旋转。
/// </summary>
public float rotate { get { return m_Rotate; } set { m_Rotate = value; } }
/// <summary>
/// the offset of position.
/// 坐标偏移。
/// </summary>
public Vector2 offset { get { return m_Offset; } set { m_Offset = value; } }
/// <summary>
/// the color of text.
/// 文本的颜色。
/// </summary>
public Color color { get { return m_Color; } set { m_Color = value; } }
/// <summary>
/// font size.
/// 文本字体大小。
/// </summary>
public int fontSize { get { return m_FontSize; } set { m_FontSize = value; } }
/// <summary>
/// font style.
/// 文本字体的风格。
/// </summary>
public FontStyle fontStyle { get { return m_FontStyle; } set { m_FontStyle = value; } }
public TextStyle()
{
}
public TextStyle(int fontSize)
{
this.fontSize = fontSize;
}
public TextStyle(int fontSize, FontStyle fontStyle)
{
this.fontSize = fontSize;
this.fontStyle = fontStyle;
}
public TextStyle(int fontSize, FontStyle fontStyle, Color color)
{
this.fontSize = fontSize;
this.fontStyle = fontStyle;
this.color = color;
}
public TextStyle(int fontSize, FontStyle fontStyle, Color color, int rorate)
{
this.fontSize = fontSize;
this.fontStyle = fontStyle;
this.color = color;
this.rotate = rotate;
}
public TextStyle Clone()
{
var textStyle = new TextStyle();
textStyle.rotate = rotate;
textStyle.color = color;
textStyle.fontSize = fontSize;
textStyle.fontStyle = fontStyle;
textStyle.offset = offset;
return textStyle;
}
public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj))
{
return false;
}
else if (obj is TextStyle)
{
return Equals((TextStyle)obj);
}
else
{
return false;
}
}
public bool Equals(TextStyle other)
{
if (ReferenceEquals(null, other))
{
return false;
}
return rotate == other.rotate &&
fontSize == other.fontSize &&
fontStyle == other.fontStyle &&
offset == other.offset &&
ChartHelper.IsValueEqualsColor(m_Color, other.color);
}
public override int GetHashCode()
{
return base.GetHashCode();
}
}
}

View File

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

View File

@@ -17,7 +17,7 @@ namespace XCharts
public static GameObject Get(string name, Transform parent, SerieLabel label, Font font, Color color, SerieData serieData)
{
GameObject element;
if (m_Stack.Count == 0)
if (m_Stack.Count == 0 || !Application.isPlaying)
{
element = ChartHelper.AddSerieLabel(name, parent, font,
color, label.backgroundColor, label.fontSize, label.fontStyle, label.rotate,
@@ -39,7 +39,8 @@ namespace XCharts
ChartHelper.SetActive(element, false);
//if (m_Stack.Count > 0 && ReferenceEquals(m_Stack.Peek(), element))
// Debug.LogError("Internal error. Trying to destroy object that is already released to pool." + element.name);
m_Stack.Push(element);
if (Application.isPlaying)
m_Stack.Push(element);
}
public static void ReleaseAll(Transform parent)

View File

@@ -20,12 +20,10 @@ namespace XCharts
{
private const string INDICATOR_TEXT = "indicator";
//[SerializeField] private Radar radar = Radar.defaultRadar;
[SerializeField] private List<Radar> m_Radars = new List<Radar>();
private List<Radar> m_CheckRadars = new List<Radar>();
private bool m_IsEnterLegendButtom;
//public Radar radar { get { return radar; } }
public List<Radar> radars { get { return m_Radars; } }
/// <summary>
@@ -110,30 +108,31 @@ namespace XCharts
var indicator = radar.indicatorList[i];
var pos = radar.GetIndicatorPosition(i);
TextAnchor anchor = TextAnchor.MiddleCenter;
var textStyle = indicator.textStyle;
var textColor = textStyle.color == Color.clear ? (Color)m_ThemeInfo.axisTextColor : textStyle.color;
var txt = ChartHelper.AddTextObject(INDICATOR_TEXT + "_" + n + "_" + i, transform, m_ThemeInfo.font,
textColor, anchor, new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f),
new Vector2(txtWid, txtHig), textStyle.fontSize, textStyle.rotate, textStyle.fontStyle);
txt.text = radar.indicatorList[i].name;
txt.gameObject.SetActive(radar.indicator);
var txtWidth = txt.preferredWidth;
var sizeDelta = new Vector2(txt.preferredWidth, txt.preferredHeight);
txt.GetComponent<RectTransform>().sizeDelta = sizeDelta;
var diff = pos.x - radar.runtimeCenterPos.x;
if (diff < -1f)
if (diff < -1f) //left
{
pos = new Vector3(pos.x - 5, pos.y);
anchor = TextAnchor.MiddleRight;
pos = new Vector3(pos.x - txtWidth / 2, pos.y);
}
else if (diff > 1f)
else if (diff > 1f) //right
{
anchor = TextAnchor.MiddleLeft;
pos = new Vector3(pos.x + txtWid + 5, pos.y);
pos = new Vector3(pos.x + txtWidth / 2, pos.y);
}
else
{
anchor = TextAnchor.MiddleCenter;
float y = pos.y > radar.runtimeCenterPos.y ? pos.y + txtHig / 2 : pos.y - txtHig / 2;
pos = new Vector3(pos.x + txtWid / 2, y);
pos = new Vector3(pos.x, y);
}
var textColor = indicator.color == Color.clear ? (Color)m_ThemeInfo.axisTextColor : indicator.color;
Text txt = ChartHelper.AddTextObject(INDICATOR_TEXT + "_" + n + "_" + i, transform, m_ThemeInfo.font,
textColor, anchor, Vector2.zero, Vector2.zero, new Vector2(1, 0.5f),
new Vector2(txtWid, txtHig));
txt.transform.localPosition = pos;
txt.text = radar.indicatorList[i].name;
txt.gameObject.SetActive(radar.indicator);
txt.transform.localPosition = pos + new Vector3(textStyle.offset.x, textStyle.offset.y);
}
}
}
@@ -269,9 +268,9 @@ namespace XCharts
serie.GetMinMaxData(n, out min, out max);
min = radar.GetIndicatorMin(n);
}
var radius = max < 0 ? radar.runtimeRadius - radar.runtimeRadius * value / max
: radar.runtimeRadius * value / max;
var currAngle = n * angle;
var radius = max < 0 ? radar.runtimeDataRadius - radar.runtimeDataRadius * value / max
: radar.runtimeDataRadius * value / max;
var currAngle = (n + (radar.positionType == Radar.PositionType.Between ? 0.5f : 0)) * angle;
radius *= rate;
if (n == 0)
{

View File

@@ -156,15 +156,13 @@ namespace XCharts
Text txt = GetOrAddComponent<Text>(txtObj);
txt.font = font;
txt.fontSize = fontSize;
txt.fontStyle = fontStyle;
txt.text = "Text";
txt.alignment = anchor;
txt.horizontalOverflow = HorizontalWrapMode.Overflow;
txt.verticalOverflow = VerticalWrapMode.Overflow;
txt.color = color;
if (rotate > 0)
{
txtObj.transform.localEulerAngles = new Vector3(0, 0, rotate);
}
txtObj.transform.localEulerAngles = new Vector3(0, 0, rotate);
RectTransform rect = GetOrAddComponent<RectTransform>(txtObj);
rect.localPosition = Vector3.zero;