海拔图和小地图

This commit is contained in:
lishuo committed 2021-03-30 17:29:40 +08:00
1 parent 42fa59d103
commit 8ad36c965d
521 files changed
+1985033 -439

No files matched your search

@@ -0,0 +1,155 @@
/************************************************/
/* */
/* Copyright (c) 2018 - 2021 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/************************************************/
using UnityEngine;
using UnityEngine.UI;
namespace XCharts
{
public class ChartLabel : ChartObject
{
private bool m_LabelAutoSize = true;
private float m_LabelPaddingLeftRight = 3f;
private float m_LabelPaddingTopBottom = 3f;
private ChartText m_LabelText;
private RectTransform m_LabelRect;
private RectTransform m_IconRect;
private RectTransform m_ObjectRect;
private Image m_IconImage;
public GameObject gameObject { get { return m_GameObject; } }
public Image icon { get { return m_IconImage; } }
public ChartText label { get { return m_LabelText; } }
public ChartLabel()
{
}
public void SetLabel(GameObject labelObj, bool autoSize, float paddingLeftRight, float paddingTopBottom)
{
m_GameObject = labelObj;
m_LabelAutoSize = autoSize;
m_LabelPaddingLeftRight = paddingLeftRight;
m_LabelPaddingTopBottom = paddingTopBottom;
m_LabelText = new ChartText(labelObj);
m_LabelRect = m_LabelText.gameObject.GetComponent<RectTransform>();
m_ObjectRect = labelObj.GetComponent<RectTransform>();
}
public void SetIcon(Image image)
{
m_IconImage = image;
if (image != null)
{
m_IconRect = m_IconImage.GetComponent<RectTransform>();
}
}
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)
{
if (m_IconImage == null) return;
if (iconStyle.show)
{
ChartHelper.SetActive(m_IconImage.gameObject, true);
m_IconImage.sprite = iconStyle.sprite;
m_IconImage.color = iconStyle.color;
m_IconRect.sizeDelta = new Vector2(iconStyle.width, iconStyle.height);
m_IconImage.transform.localPosition = iconStyle.offset;
if (iconStyle.layer == IconStyle.Layer.UnderLabel)
m_IconRect.SetSiblingIndex(0);
else
m_IconRect.SetSiblingIndex(m_GameObject.transform.childCount - 1);
}
else
{
ChartHelper.SetActive(m_IconImage.gameObject, false);
}
}
public float GetLabelWidth()
{
if (m_LabelRect) return m_LabelRect.sizeDelta.x;
else return 0;
}
public float GetLabelHeight()
{
if (m_LabelRect) return m_LabelRect.sizeDelta.y;
return 0;
}
public void SetLabelColor(Color color)
{
if (m_LabelText != null) m_LabelText.SetColor(color);
}
public void SetLabelRotate(float rotate)
{
if (m_LabelText != null) m_LabelText.SetLocalEulerAngles(new Vector3(0, 0, rotate));
}
public void SetPosition(Vector3 position)
{
if (m_GameObject != null)
{
m_GameObject.transform.localPosition = position;
}
}
public void SetLabelPosition(Vector3 position)
{
if (m_LabelRect) m_LabelRect.localPosition = position;
}
public void SetActive(bool flag)
{
if (m_GameObject) ChartHelper.SetActive(m_GameObject, flag);
}
public void SetLabelActive(bool flag)
{
if (m_LabelText != null) m_LabelText.SetActive(flag);
}
public void SetIconActive(bool flag)
{
if (m_IconImage) ChartHelper.SetActive(m_IconImage, flag);
}
public bool SetText(string text)
{
if (m_LabelRect == null) return false;
if (m_LabelText != null && !m_LabelText.GetText().Equals(text))
{
m_LabelText.SetText(text);
if (m_LabelAutoSize)
{
var newSize = string.IsNullOrEmpty(text) ? Vector2.zero :
new Vector2(m_LabelText.GetPreferredWidth() + m_LabelPaddingLeftRight * 2,
m_LabelText.GetPreferredHeight() + m_LabelPaddingTopBottom * 2);
var sizeChange = newSize.x != m_LabelRect.sizeDelta.x || newSize.y != m_LabelRect.sizeDelta.y;
if (sizeChange)
{
m_LabelRect.sizeDelta = newSize;
m_ObjectRect.sizeDelta = newSize;
}
return sizeChange;
}
}
return false;
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 61287841bdc4142caba8e77985cd8715
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,22 @@
/************************************************/
/* */
/* Copyright (c) 2018 - 2021 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/************************************************/
using System;
using UnityEngine;
namespace XCharts
{
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,255 @@
/************************************************/
/* */
/* Copyright (c) 2018 - 2021 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/************************************************/
using UnityEngine;
using UnityEngine.UI;
#if dUI_TextMeshPro
using TMPro;
#endif
namespace XCharts
{
public class ChartText
{
private Text m_Text;
private TextGenerationSettings m_RelatedTextSettings;
public Text text
{
get { return m_Text; }
set
{
m_Text = value;
if (value != null)
{
m_RelatedTextSettings = m_Text.GetGenerationSettings(Vector2.zero);
}
}
}
#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 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 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)
{
#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;
}
#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) return m_Text.cachedTextGenerator.GetPreferredWidth(content, m_RelatedTextSettings);
#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;
}
#if dUI_TextMeshPro
public void SetAlignment(TextAlignmentOptions alignment)
{
if (m_TMPText != null) m_TMPText.alignment = alignment;
}
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,220 @@
/************************************************/
/* */
/* Copyright (c) 2018 - 2021 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/************************************************/
using System;
using UnityEngine;
using UnityEngine.UI;
namespace XCharts
{
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: