Fist Sub
based on aimbot multi seane
This commit is contained in:
@@ -0,0 +1,340 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace XCharts.Runtime
|
||||
{
|
||||
public class ChartLabel : Image
|
||||
{
|
||||
[SerializeField] private ChartText m_LabelText;
|
||||
|
||||
private bool m_HideIconIfTextEmpty = false;
|
||||
private bool m_AutoSize = true;
|
||||
private float m_PaddingLeft = 0;
|
||||
private float m_PaddingRight = 0;
|
||||
private float m_PaddingTop = 0;
|
||||
private float m_PaddingBottom = 0;
|
||||
private float m_Width = 0;
|
||||
private float m_Height = 0;
|
||||
private RectTransform m_TextRect;
|
||||
private RectTransform m_IconRect;
|
||||
private RectTransform m_ObjectRect;
|
||||
private Vector3 m_IconOffest;
|
||||
private Align m_Align = Align.Left;
|
||||
private Image m_IconImage;
|
||||
|
||||
public Image icon
|
||||
{
|
||||
get { return m_IconImage; }
|
||||
set { SetIcon(value); }
|
||||
}
|
||||
public ChartText text
|
||||
{
|
||||
get { return m_LabelText; }
|
||||
set
|
||||
{
|
||||
m_LabelText = value;
|
||||
if (value != null) m_TextRect = m_LabelText.gameObject.GetComponent<RectTransform>();
|
||||
}
|
||||
}
|
||||
|
||||
public bool hideIconIfTextEmpty { set { m_HideIconIfTextEmpty = value; } }
|
||||
public bool isIconActive { get; private set; }
|
||||
public bool isAnimationEnd { get; internal set; }
|
||||
|
||||
internal RectTransform objectRect
|
||||
{
|
||||
get
|
||||
{
|
||||
if (m_ObjectRect == null)
|
||||
m_ObjectRect = gameObject.GetComponent<RectTransform>();
|
||||
return m_ObjectRect;
|
||||
}
|
||||
}
|
||||
|
||||
protected override void Awake()
|
||||
{
|
||||
raycastTarget = false;
|
||||
}
|
||||
|
||||
public void SetTextPadding(TextPadding padding)
|
||||
{
|
||||
m_PaddingLeft = padding.left;
|
||||
m_PaddingRight = padding.right;
|
||||
m_PaddingTop = padding.top;
|
||||
m_PaddingBottom = padding.bottom;
|
||||
UpdatePadding();
|
||||
}
|
||||
public void SetPadding(float[] padding)
|
||||
{
|
||||
if (padding.Length >= 4)
|
||||
{
|
||||
m_PaddingLeft = padding[3];
|
||||
m_PaddingRight = padding[1];
|
||||
m_PaddingTop = padding[0];
|
||||
m_PaddingBottom = padding[2];
|
||||
}
|
||||
else if (padding.Length >= 2)
|
||||
{
|
||||
m_PaddingLeft = padding[1];
|
||||
m_PaddingRight = padding[1];
|
||||
m_PaddingTop = padding[0];
|
||||
m_PaddingBottom = padding[0];
|
||||
}
|
||||
else if (padding.Length == 1)
|
||||
{
|
||||
m_PaddingLeft = padding[0];
|
||||
m_PaddingRight = padding[0];
|
||||
m_PaddingTop = padding[0];
|
||||
m_PaddingBottom = padding[0];
|
||||
}
|
||||
UpdatePadding();
|
||||
}
|
||||
|
||||
public void SetIcon(Image image)
|
||||
{
|
||||
m_IconImage = image;
|
||||
if (image != null)
|
||||
{
|
||||
m_IconRect = m_IconImage.GetComponent<RectTransform>();
|
||||
}
|
||||
}
|
||||
|
||||
public float GetWidth()
|
||||
{
|
||||
return m_Width;
|
||||
}
|
||||
|
||||
public float GetHeight()
|
||||
{
|
||||
return m_Height;
|
||||
}
|
||||
|
||||
public void SetSize(float width, float height)
|
||||
{
|
||||
this.m_Width = width;
|
||||
this.m_Height = height;
|
||||
m_AutoSize = width == 0 && height == 0;
|
||||
objectRect.sizeDelta = new Vector2(width, height);
|
||||
}
|
||||
|
||||
public void SetIconSprite(Sprite sprite)
|
||||
{
|
||||
if (m_IconImage != null) m_IconImage.sprite = sprite;
|
||||
}
|
||||
|
||||
public void SetIconSize(float width, float height)
|
||||
{
|
||||
if (m_IconRect != null) m_IconRect.sizeDelta = new Vector3(width, height);
|
||||
}
|
||||
|
||||
public void UpdateIcon(IconStyle iconStyle, Sprite sprite = null)
|
||||
{
|
||||
if (m_IconImage == null || iconStyle == null)
|
||||
return;
|
||||
|
||||
SetIconActive(iconStyle.show);
|
||||
if (iconStyle.show)
|
||||
{
|
||||
m_IconImage.sprite = sprite == null ? iconStyle.sprite : sprite;
|
||||
m_IconImage.color = iconStyle.color;
|
||||
m_IconImage.type = iconStyle.type;
|
||||
m_IconRect.sizeDelta = new Vector2(iconStyle.width, iconStyle.height);
|
||||
m_IconOffest = iconStyle.offset;
|
||||
m_Align = iconStyle.align;
|
||||
m_HideIconIfTextEmpty = iconStyle.autoHideWhenLabelEmpty;
|
||||
AdjustIconPos();
|
||||
if (iconStyle.layer == IconStyle.Layer.UnderText)
|
||||
m_IconRect.SetSiblingIndex(0);
|
||||
else
|
||||
m_IconRect.SetSiblingIndex(transform.childCount - 1);
|
||||
}
|
||||
}
|
||||
|
||||
public float GetTextWidth()
|
||||
{
|
||||
if (m_TextRect) return m_TextRect.sizeDelta.x;
|
||||
else return 0;
|
||||
}
|
||||
|
||||
public float GetTextHeight()
|
||||
{
|
||||
if (m_TextRect) return m_TextRect.sizeDelta.y;
|
||||
return 0;
|
||||
}
|
||||
|
||||
public void SetTextColor(Color color)
|
||||
{
|
||||
if (m_LabelText != null) m_LabelText.SetColor(color);
|
||||
}
|
||||
|
||||
public void SetTextRotate(float rotate)
|
||||
{
|
||||
if (m_LabelText != null) m_LabelText.SetLocalEulerAngles(new Vector3(0, 0, rotate));
|
||||
}
|
||||
|
||||
public void SetPosition(Vector3 position)
|
||||
{
|
||||
transform.localPosition = position;
|
||||
}
|
||||
|
||||
public void SetRectPosition(Vector3 position)
|
||||
{
|
||||
objectRect.anchoredPosition3D = position;
|
||||
}
|
||||
|
||||
public Vector3 GetPosition()
|
||||
{
|
||||
return transform.localPosition;
|
||||
}
|
||||
|
||||
public void SetActive(bool flag)
|
||||
{
|
||||
ChartHelper.SetActive(gameObject, flag);
|
||||
}
|
||||
public void SetTextActive(bool flag)
|
||||
{
|
||||
if (m_LabelText != null) m_LabelText.SetActive(flag);
|
||||
}
|
||||
public void SetIconActive(bool flag)
|
||||
{
|
||||
isIconActive = flag;
|
||||
if (m_IconImage) ChartHelper.SetActive(m_IconImage, flag);
|
||||
}
|
||||
|
||||
public bool SetText(string text)
|
||||
{
|
||||
if (m_TextRect == null || m_LabelText == null)
|
||||
return false;
|
||||
|
||||
if (text == null)
|
||||
text = "";
|
||||
if (!m_LabelText.GetText().Equals(text))
|
||||
{
|
||||
m_LabelText.SetText(text);
|
||||
if (m_AutoSize)
|
||||
{
|
||||
var newSize = string.IsNullOrEmpty(text) ? Vector2.zero :
|
||||
new Vector2(m_LabelText.GetPreferredWidth(),
|
||||
m_LabelText.GetPreferredHeight());
|
||||
var sizeChange = newSize.x != m_TextRect.sizeDelta.x || newSize.y != m_TextRect.sizeDelta.y;
|
||||
this.m_Width = newSize.x;
|
||||
this.m_Height = newSize.y;
|
||||
if (sizeChange)
|
||||
{
|
||||
m_TextRect.sizeDelta = newSize;
|
||||
UpdateSize();
|
||||
UpdatePadding();
|
||||
AdjustIconPos();
|
||||
}
|
||||
return sizeChange;
|
||||
}
|
||||
AdjustIconPos();
|
||||
if (m_HideIconIfTextEmpty && isIconActive)
|
||||
{
|
||||
ChartHelper.SetActive(m_IconImage.gameObject, !string.IsNullOrEmpty(text));
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private void UpdateSize()
|
||||
{
|
||||
if (m_AutoSize)
|
||||
{
|
||||
var sizeDelta = m_TextRect.sizeDelta;
|
||||
m_Width = sizeDelta.x + m_PaddingLeft + m_PaddingRight;
|
||||
m_Height = sizeDelta.y + m_PaddingTop + m_PaddingBottom;
|
||||
objectRect.sizeDelta = new Vector2(m_Width, m_Height);
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdatePadding()
|
||||
{
|
||||
if (m_TextRect == null) return;
|
||||
switch (text.alignment)
|
||||
{
|
||||
case TextAnchor.LowerLeft:
|
||||
m_TextRect.anchoredPosition = new Vector2(m_PaddingLeft, m_PaddingBottom);
|
||||
break;
|
||||
case TextAnchor.UpperLeft:
|
||||
m_TextRect.anchoredPosition = new Vector2(m_PaddingLeft, -m_PaddingTop);
|
||||
break;
|
||||
case TextAnchor.MiddleLeft:
|
||||
m_TextRect.anchoredPosition = new Vector2(m_PaddingLeft, m_Height / 2 - m_PaddingTop - m_TextRect.sizeDelta.y / 2);
|
||||
break;
|
||||
case TextAnchor.LowerRight:
|
||||
m_TextRect.anchoredPosition = new Vector2(-m_PaddingRight, m_PaddingBottom);
|
||||
break;
|
||||
case TextAnchor.UpperRight:
|
||||
m_TextRect.anchoredPosition = new Vector2(-m_PaddingRight, -m_PaddingTop);
|
||||
break;
|
||||
case TextAnchor.MiddleRight:
|
||||
m_TextRect.anchoredPosition = new Vector2(-m_PaddingRight, m_Height / 2 - m_PaddingTop - m_TextRect.sizeDelta.y / 2);
|
||||
break;
|
||||
case TextAnchor.LowerCenter:
|
||||
m_TextRect.anchoredPosition = new Vector2(-(m_Width / 2 - m_PaddingLeft - m_TextRect.sizeDelta.x / 2), m_PaddingBottom);
|
||||
break;
|
||||
case TextAnchor.UpperCenter:
|
||||
m_TextRect.anchoredPosition = new Vector2(-(m_Width / 2 - m_PaddingLeft - m_TextRect.sizeDelta.x / 2), -m_PaddingTop);
|
||||
break;
|
||||
case TextAnchor.MiddleCenter:
|
||||
m_TextRect.anchoredPosition = new Vector2(-(m_Width / 2 - m_PaddingLeft - m_TextRect.sizeDelta.x / 2), m_Height / 2 - m_PaddingTop - m_TextRect.sizeDelta.y / 2);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void AdjustIconPos()
|
||||
{
|
||||
if (m_IconImage && m_IconRect && m_LabelText != null && m_TextRect != null)
|
||||
{
|
||||
var iconX = 0f;
|
||||
switch (m_Align)
|
||||
{
|
||||
case Align.Left:
|
||||
switch (m_LabelText.alignment)
|
||||
{
|
||||
case TextAnchor.LowerLeft:
|
||||
case TextAnchor.UpperLeft:
|
||||
case TextAnchor.MiddleLeft:
|
||||
iconX = -m_TextRect.sizeDelta.x / 2 - m_IconRect.sizeDelta.x / 2;
|
||||
break;
|
||||
case TextAnchor.LowerRight:
|
||||
case TextAnchor.UpperRight:
|
||||
case TextAnchor.MiddleRight:
|
||||
iconX = m_TextRect.sizeDelta.x / 2 - m_LabelText.GetPreferredWidth() - m_IconRect.sizeDelta.x / 2;
|
||||
break;
|
||||
case TextAnchor.LowerCenter:
|
||||
case TextAnchor.UpperCenter:
|
||||
case TextAnchor.MiddleCenter:
|
||||
iconX = -m_LabelText.GetPreferredWidth() / 2 - m_IconRect.sizeDelta.x / 2;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case Align.Right:
|
||||
switch (m_LabelText.alignment)
|
||||
{
|
||||
case TextAnchor.LowerLeft:
|
||||
case TextAnchor.UpperLeft:
|
||||
case TextAnchor.MiddleLeft:
|
||||
iconX = m_TextRect.sizeDelta.x / 2 + m_IconRect.sizeDelta.x / 2;
|
||||
break;
|
||||
case TextAnchor.LowerRight:
|
||||
case TextAnchor.UpperRight:
|
||||
case TextAnchor.MiddleRight:
|
||||
iconX = m_IconRect.sizeDelta.x / 2;
|
||||
break;
|
||||
case TextAnchor.LowerCenter:
|
||||
case TextAnchor.UpperCenter:
|
||||
case TextAnchor.MiddleCenter:
|
||||
iconX = m_LabelText.GetPreferredWidth() / 2 + m_IconRect.sizeDelta.x / 2;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
m_IconRect.anchoredPosition = m_IconOffest + new Vector3(iconX, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 61287841bdc4142caba8e77985cd8715
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,14 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace XCharts.Runtime
|
||||
{
|
||||
public class ChartObject
|
||||
{
|
||||
protected GameObject m_GameObject;
|
||||
|
||||
public virtual void Destroy()
|
||||
{
|
||||
GameObject.Destroy(m_GameObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0fe3102b0eea042938d30af910ca86d6
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,319 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
#if dUI_TextMeshPro
|
||||
using TMPro;
|
||||
#endif
|
||||
|
||||
namespace XCharts.Runtime
|
||||
{
|
||||
[System.Serializable]
|
||||
public class ChartText
|
||||
{
|
||||
private Text m_Text;
|
||||
private TextAnchor m_TextAlignment;
|
||||
public Text text
|
||||
{
|
||||
get { return m_Text; }
|
||||
set { m_Text = value; }
|
||||
}
|
||||
#if dUI_TextMeshPro
|
||||
private TextMeshProUGUI m_TMPText;
|
||||
public TextMeshProUGUI tmpText { get { return m_TMPText; } set { m_TMPText = value; } }
|
||||
#endif
|
||||
public GameObject gameObject
|
||||
{
|
||||
get
|
||||
{
|
||||
#if dUI_TextMeshPro
|
||||
if (m_TMPText != null) return m_TMPText.gameObject;
|
||||
#else
|
||||
if (m_Text != null) return m_Text.gameObject;
|
||||
#endif
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public TextAnchor alignment
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_TextAlignment;
|
||||
}
|
||||
set
|
||||
{
|
||||
SetAlignment(alignment);
|
||||
}
|
||||
}
|
||||
|
||||
public ChartText()
|
||||
{ }
|
||||
|
||||
public ChartText(GameObject textParent)
|
||||
{
|
||||
#if dUI_TextMeshPro
|
||||
m_TMPText = textParent.GetComponentInChildren<TextMeshProUGUI>();
|
||||
if (m_TMPText == null)
|
||||
{
|
||||
Debug.LogError("can't find TextMeshProUGUI component:" + textParent);
|
||||
}
|
||||
#else
|
||||
m_Text = textParent.GetComponentInChildren<Text>();
|
||||
if (m_Text == null)
|
||||
{
|
||||
Debug.LogError("can't find Text component:" + textParent);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
public void SetFontSize(float fontSize)
|
||||
{
|
||||
#if dUI_TextMeshPro
|
||||
if (m_TMPText != null) m_TMPText.fontSize = fontSize;
|
||||
#else
|
||||
if (m_Text != null) m_Text.fontSize = (int) fontSize;
|
||||
#endif
|
||||
}
|
||||
|
||||
public void SetText(string text)
|
||||
{
|
||||
if (text == null) text = string.Empty;
|
||||
else text = text.Replace("\\n", "\n");
|
||||
#if dUI_TextMeshPro
|
||||
if (m_TMPText != null) m_TMPText.text = text;
|
||||
#else
|
||||
if (m_Text != null) m_Text.text = text;
|
||||
#endif
|
||||
}
|
||||
|
||||
public string GetText()
|
||||
{
|
||||
#if dUI_TextMeshPro
|
||||
if (m_TMPText != null) return m_TMPText.text;
|
||||
#else
|
||||
if (m_Text != null) return m_Text.text;
|
||||
#endif
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
public void SetColor(Color color)
|
||||
{
|
||||
#if dUI_TextMeshPro
|
||||
if (m_TMPText != null) m_TMPText.color = color;
|
||||
#else
|
||||
if (m_Text != null) m_Text.color = color;
|
||||
#endif
|
||||
}
|
||||
|
||||
public void SetLineSpacing(float lineSpacing)
|
||||
{
|
||||
#if dUI_TextMeshPro
|
||||
if (m_TMPText != null) m_TMPText.lineSpacing = lineSpacing;
|
||||
#else
|
||||
if (m_Text != null) m_Text.lineSpacing = lineSpacing;
|
||||
#endif
|
||||
}
|
||||
|
||||
public void SetActive(bool flag)
|
||||
{
|
||||
#if dUI_TextMeshPro
|
||||
//m_TMPText.gameObject.SetActive(flag);
|
||||
if (m_TMPText != null) ChartHelper.SetActive(m_TMPText.gameObject, flag);
|
||||
#else
|
||||
//m_Text.gameObject.SetActive(flag);
|
||||
if (m_Text != null) ChartHelper.SetActive(m_Text.gameObject, flag);
|
||||
#endif
|
||||
}
|
||||
|
||||
public void SetLocalPosition(Vector3 position)
|
||||
{
|
||||
#if dUI_TextMeshPro
|
||||
if (m_TMPText != null) m_TMPText.transform.localPosition = position;
|
||||
#else
|
||||
if (m_Text != null) m_Text.transform.localPosition = position;
|
||||
#endif
|
||||
}
|
||||
|
||||
public void SetRectPosition(Vector3 position)
|
||||
{
|
||||
#if dUI_TextMeshPro
|
||||
if (m_TMPText != null) m_TMPText.GetComponent<RectTransform>().anchoredPosition3D = position;
|
||||
#else
|
||||
if (m_Text != null) m_Text.GetComponent<RectTransform>().anchoredPosition3D = position;
|
||||
#endif
|
||||
}
|
||||
|
||||
public void SetSizeDelta(Vector2 sizeDelta)
|
||||
{
|
||||
#if dUI_TextMeshPro
|
||||
if (m_TMPText != null) m_TMPText.GetComponent<RectTransform>().sizeDelta = sizeDelta;
|
||||
#else
|
||||
if (m_Text != null) m_Text.GetComponent<RectTransform>().sizeDelta = sizeDelta;
|
||||
#endif
|
||||
}
|
||||
|
||||
public void SetLocalEulerAngles(Vector3 position)
|
||||
{
|
||||
#if dUI_TextMeshPro
|
||||
if (m_TMPText != null) m_TMPText.transform.localEulerAngles = position;
|
||||
#else
|
||||
if (m_Text != null) m_Text.transform.localEulerAngles = position;
|
||||
#endif
|
||||
}
|
||||
|
||||
public void SetAlignment(TextAnchor alignment)
|
||||
{
|
||||
m_TextAlignment = alignment;
|
||||
#if dUI_TextMeshPro
|
||||
if (m_TMPText == null) return;
|
||||
switch (alignment)
|
||||
{
|
||||
case TextAnchor.LowerCenter:
|
||||
m_TMPText.alignment = TextAlignmentOptions.Bottom;
|
||||
break;
|
||||
case TextAnchor.LowerLeft:
|
||||
m_TMPText.alignment = TextAlignmentOptions.BottomLeft;
|
||||
break;
|
||||
case TextAnchor.LowerRight:
|
||||
m_TMPText.alignment = TextAlignmentOptions.BottomRight;
|
||||
break;
|
||||
case TextAnchor.MiddleCenter:
|
||||
m_TMPText.alignment = TextAlignmentOptions.Center;
|
||||
break;
|
||||
case TextAnchor.MiddleLeft:
|
||||
m_TMPText.alignment = TextAlignmentOptions.Left;
|
||||
break;
|
||||
case TextAnchor.MiddleRight:
|
||||
m_TMPText.alignment = TextAlignmentOptions.Right;
|
||||
break;
|
||||
case TextAnchor.UpperCenter:
|
||||
m_TMPText.alignment = TextAlignmentOptions.Top;
|
||||
break;
|
||||
case TextAnchor.UpperLeft:
|
||||
m_TMPText.alignment = TextAlignmentOptions.TopLeft;
|
||||
break;
|
||||
case TextAnchor.UpperRight:
|
||||
m_TMPText.alignment = TextAlignmentOptions.TopRight;
|
||||
break;
|
||||
default:
|
||||
m_TMPText.alignment = TextAlignmentOptions.Center;
|
||||
m_TextAlignment = TextAnchor.MiddleCenter;
|
||||
break;
|
||||
}
|
||||
#else
|
||||
if (m_Text != null) m_Text.alignment = alignment;
|
||||
#endif
|
||||
}
|
||||
|
||||
public void SetFont(Font font)
|
||||
{
|
||||
if (m_Text) m_Text.font = font;
|
||||
}
|
||||
|
||||
public void SetFontStyle(FontStyle fontStyle)
|
||||
{
|
||||
#if dUI_TextMeshPro
|
||||
if (m_TMPText == null) return;
|
||||
switch (fontStyle)
|
||||
{
|
||||
case FontStyle.Normal:
|
||||
m_TMPText.fontStyle = FontStyles.Normal;
|
||||
break;
|
||||
case FontStyle.Bold:
|
||||
m_TMPText.fontStyle = FontStyles.Bold;
|
||||
break;
|
||||
case FontStyle.BoldAndItalic:
|
||||
m_TMPText.fontStyle = FontStyles.Bold | FontStyles.Italic;
|
||||
break;
|
||||
case FontStyle.Italic:
|
||||
m_TMPText.fontStyle = FontStyles.Italic;
|
||||
break;
|
||||
}
|
||||
#else
|
||||
if (m_Text != null) m_Text.fontStyle = fontStyle;
|
||||
#endif
|
||||
}
|
||||
|
||||
public void SetFontAndSizeAndStyle(TextStyle textStyle, ComponentTheme theme)
|
||||
{
|
||||
#if dUI_TextMeshPro
|
||||
if (m_TMPText == null) return;
|
||||
m_TMPText.font = textStyle.tmpFont == null ? theme.tmpFont : textStyle.tmpFont;
|
||||
m_TMPText.fontSize = textStyle.fontSize == 0 ? theme.fontSize : textStyle.fontSize;
|
||||
m_TMPText.fontStyle = textStyle.tmpFontStyle;
|
||||
#else
|
||||
if (m_Text != null)
|
||||
{
|
||||
m_Text.font = textStyle.font == null ? theme.font : textStyle.font;
|
||||
m_Text.fontSize = textStyle.fontSize == 0 ? theme.fontSize : textStyle.fontSize;
|
||||
m_Text.fontStyle = textStyle.fontStyle;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
public float GetPreferredWidth(string content)
|
||||
{
|
||||
#if dUI_TextMeshPro
|
||||
if (m_TMPText != null) return 0; // TODO:
|
||||
#else
|
||||
if (m_Text != null)
|
||||
{
|
||||
var tg = m_Text.cachedTextGeneratorForLayout;
|
||||
var setting = m_Text.GetGenerationSettings(Vector2.zero);
|
||||
return tg.GetPreferredWidth(content, setting) / m_Text.pixelsPerUnit;
|
||||
}
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
public float GetPreferredWidth()
|
||||
{
|
||||
#if dUI_TextMeshPro
|
||||
if (m_TMPText != null) return m_TMPText.preferredWidth;
|
||||
#else
|
||||
if (m_Text != null) return m_Text.preferredWidth;
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
public float GetPreferredHeight()
|
||||
{
|
||||
#if dUI_TextMeshPro
|
||||
if (m_TMPText != null) return m_TMPText.preferredHeight;
|
||||
#else
|
||||
if (m_Text != null) return m_Text.preferredHeight;
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
public string GetPreferredText(string content, string suffix, float maxWidth)
|
||||
{
|
||||
#if dUI_TextMeshPro
|
||||
if (m_TMPText != null) return content; // TODO:
|
||||
#else
|
||||
if (m_Text != null)
|
||||
{
|
||||
var sourWid = GetPreferredWidth(content);
|
||||
if (sourWid < maxWidth) return content;
|
||||
var suffixWid = GetPreferredWidth(suffix);
|
||||
var textWid = maxWidth - 1.3f * suffixWid;
|
||||
for (int i = content.Length; i > 0; i--)
|
||||
{
|
||||
var temp = content.Substring(0, i);
|
||||
if (GetPreferredWidth(temp) < textWid)
|
||||
{
|
||||
return temp + suffix;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
#if dUI_TextMeshPro
|
||||
|
||||
public void SetFont(TMP_FontAsset font)
|
||||
{
|
||||
if (m_TMPText != null) m_TMPText.font = font;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4e2466c1fe5874bea8373b071405a930
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,213 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace XCharts.Runtime
|
||||
{
|
||||
public class LegendItem
|
||||
{
|
||||
private int m_Index;
|
||||
private string m_Name;
|
||||
private string m_LegendName;
|
||||
private GameObject m_GameObject;
|
||||
private Button m_Button;
|
||||
private Image m_Icon;
|
||||
private ChartText m_Text;
|
||||
private Image m_TextBackground;
|
||||
private RectTransform m_Rect;
|
||||
private RectTransform m_IconRect;
|
||||
private RectTransform m_TextRect;
|
||||
private RectTransform m_TextBackgroundRect;
|
||||
private float m_Gap = 0f;
|
||||
private float m_LabelPaddingLeftRight = 0f;
|
||||
private float m_LabelPaddingTopBottom = 0f;
|
||||
private bool m_LabelAutoSize = true;
|
||||
|
||||
public int index { get { return m_Index; } set { m_Index = value; } }
|
||||
public string name { get { return m_Name; } set { m_Name = value; } }
|
||||
public string legendName { get { return m_LegendName; } set { m_LegendName = value; } }
|
||||
public GameObject gameObject { get { return m_GameObject; } }
|
||||
public Button button { get { return m_Button; } }
|
||||
public float width
|
||||
{
|
||||
get
|
||||
{
|
||||
if (m_IconRect && m_TextBackgroundRect)
|
||||
{
|
||||
return m_IconRect.sizeDelta.x + m_Gap + m_TextBackgroundRect.sizeDelta.x;
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public float height
|
||||
{
|
||||
get
|
||||
{
|
||||
if (m_IconRect && m_TextBackgroundRect)
|
||||
{
|
||||
return Mathf.Max(m_IconRect.sizeDelta.y, m_TextBackgroundRect.sizeDelta.y);
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void SetObject(GameObject obj)
|
||||
{
|
||||
m_GameObject = obj;
|
||||
m_Button = obj.GetComponent<Button>();
|
||||
m_Rect = obj.GetComponent<RectTransform>();
|
||||
m_Icon = obj.transform.Find("icon").gameObject.GetComponent<Image>();
|
||||
m_TextBackground = obj.transform.Find("content").gameObject.GetComponent<Image>();
|
||||
m_Text = new ChartText(obj);
|
||||
m_IconRect = m_Icon.gameObject.GetComponent<RectTransform>();
|
||||
m_TextRect = m_Text.gameObject.GetComponent<RectTransform>();
|
||||
m_TextBackgroundRect = m_TextBackground.gameObject.GetComponent<RectTransform>();
|
||||
}
|
||||
|
||||
public void SetButton(Button button)
|
||||
{
|
||||
m_Button = button;
|
||||
}
|
||||
|
||||
public void SetIcon(Image icon)
|
||||
{
|
||||
m_Icon = icon;
|
||||
}
|
||||
|
||||
public void SetText(ChartText text)
|
||||
{
|
||||
m_Text = text;
|
||||
}
|
||||
|
||||
public void SetTextBackground(Image image)
|
||||
{
|
||||
m_TextBackground = image;
|
||||
}
|
||||
|
||||
public void SetIconSize(float width, float height)
|
||||
{
|
||||
if (m_IconRect)
|
||||
{
|
||||
m_IconRect.sizeDelta = new Vector2(width, height);
|
||||
}
|
||||
}
|
||||
|
||||
public Rect GetIconRect()
|
||||
{
|
||||
if (m_GameObject && m_IconRect)
|
||||
{
|
||||
var pos = m_GameObject.transform.localPosition;
|
||||
var sizeDelta = m_IconRect.sizeDelta;
|
||||
var y = pos.y - (m_Rect.sizeDelta.y - sizeDelta.y) / 2 - sizeDelta.y;
|
||||
return new Rect(pos.x, y, m_IconRect.sizeDelta.x, m_IconRect.sizeDelta.y);
|
||||
}
|
||||
else
|
||||
{
|
||||
return Rect.zero;
|
||||
}
|
||||
}
|
||||
|
||||
public Color GetIconColor()
|
||||
{
|
||||
if (m_Icon) return m_Icon.color;
|
||||
else return Color.clear;
|
||||
}
|
||||
|
||||
public void SetIconColor(Color color)
|
||||
{
|
||||
if (m_Icon)
|
||||
{
|
||||
m_Icon.color = color;
|
||||
}
|
||||
}
|
||||
|
||||
public void SetIconImage(Sprite image)
|
||||
{
|
||||
if (m_Icon)
|
||||
{
|
||||
m_Icon.sprite = image;
|
||||
}
|
||||
}
|
||||
|
||||
public void SetIconActive(bool active)
|
||||
{
|
||||
if (m_Icon)
|
||||
{
|
||||
m_Icon.gameObject.SetActive(active);
|
||||
}
|
||||
}
|
||||
|
||||
public void SetContentColor(Color color)
|
||||
{
|
||||
if (m_Text != null)
|
||||
{
|
||||
m_Text.SetColor(color);
|
||||
}
|
||||
}
|
||||
|
||||
public void SetContentBackgroundColor(Color color)
|
||||
{
|
||||
if (m_TextBackground)
|
||||
{
|
||||
m_TextBackground.color = color;
|
||||
}
|
||||
}
|
||||
|
||||
public void SetContentPosition(Vector3 offset)
|
||||
{
|
||||
m_Gap = offset.x;
|
||||
if (m_TextBackgroundRect)
|
||||
{
|
||||
var posX = m_IconRect.sizeDelta.x + offset.x;
|
||||
m_TextBackgroundRect.anchoredPosition3D = new Vector3(posX, offset.y, 0);
|
||||
}
|
||||
}
|
||||
|
||||
public bool SetContent(string content)
|
||||
{
|
||||
if (m_Text != null && !m_Text.GetText().Equals(content))
|
||||
{
|
||||
m_Text.SetText(content);
|
||||
if (m_LabelAutoSize)
|
||||
{
|
||||
var newSize = string.IsNullOrEmpty(content) ? Vector2.zero :
|
||||
new Vector2(m_Text.GetPreferredWidth(), m_Text.GetPreferredHeight());
|
||||
var sizeChange = newSize.x != m_TextRect.sizeDelta.x || newSize.y != m_TextRect.sizeDelta.y;
|
||||
if (sizeChange)
|
||||
{
|
||||
m_TextRect.sizeDelta = newSize;
|
||||
m_TextRect.anchoredPosition3D = new Vector3(m_LabelPaddingLeftRight, 0);
|
||||
m_TextBackgroundRect.sizeDelta = new Vector2(m_Text.GetPreferredWidth() + m_LabelPaddingLeftRight * 2,
|
||||
m_Text.GetPreferredHeight() + m_LabelPaddingTopBottom * 2 - 4);
|
||||
m_Rect.sizeDelta = new Vector3(width, height);
|
||||
}
|
||||
return sizeChange;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void SetPosition(Vector3 position)
|
||||
{
|
||||
if (m_GameObject)
|
||||
{
|
||||
m_GameObject.transform.localPosition = position;
|
||||
}
|
||||
}
|
||||
|
||||
public void SetActive(bool active)
|
||||
{
|
||||
if (m_GameObject)
|
||||
{
|
||||
m_GameObject.SetActive(active);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3e5abcb8f339f41f5b3680ecdab67509
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user