海拔图和小地图
This commit is contained in:
1 parent
42fa59d103
commit
8ad36c965d
521 files changed
+1985033
-439
No files matched your search
@@ -0,0 +1,282 @@
|
||||
/************************************************/
|
||||
/* */
|
||||
/* Copyright (c) 2018 - 2021 monitor1394 */
|
||||
/* https://github.com/monitor1394 */
|
||||
/* */
|
||||
/************************************************/
|
||||
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.UI;
|
||||
using XCharts;
|
||||
|
||||
namespace XChartsDemo
|
||||
{
|
||||
[System.Serializable]
|
||||
public class ChartModule
|
||||
{
|
||||
[SerializeField] private string m_Name = "Name";
|
||||
[SerializeField] private string m_SubName = "SubName";
|
||||
[SerializeField] private int m_Column = 3;
|
||||
|
||||
[SerializeField] private string m_Title = "Title";
|
||||
[SerializeField] private bool m_Selected;
|
||||
[SerializeField] private GameObject m_Panel;
|
||||
|
||||
public int column { get { return m_Column; } set { m_Column = value; } }
|
||||
public string name { get { return m_Name; } set { m_Name = value; } }
|
||||
public string subName { get { return m_SubName; } set { m_SubName = value; } }
|
||||
public string title { get { return m_Title; } set { m_Title = value; } }
|
||||
public bool select { get { return m_Selected; } set { m_Selected = value; } }
|
||||
public GameObject panel { get { return m_Panel; } set { m_Panel = value; } }
|
||||
public Button button { get; set; }
|
||||
public int index { get; internal set; }
|
||||
}
|
||||
|
||||
[DisallowMultipleComponent]
|
||||
[ExecuteInEditMode]
|
||||
public class Demo : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private float m_LeftWidth = 150;
|
||||
[SerializeField] private float m_LeftButtonHeight = 60;
|
||||
[SerializeField] private Vector2 m_ChartSpacing = new Vector2(5, 5);
|
||||
[SerializeField] private Vector2 m_ChartSizeRatio = new Vector2(5, 3);
|
||||
[SerializeField] private Color m_ButtonNormalColor;
|
||||
[SerializeField] private Color m_ButtonSelectedColor;
|
||||
[SerializeField] private Color m_ButtonHighlightColor;
|
||||
[SerializeField] public int lastSelectedModuleIndex = -1;
|
||||
[SerializeField] private List<ChartModule> m_ChartModule = new List<ChartModule>();
|
||||
|
||||
private GameObject m_BtnClone;
|
||||
private Theme m_SelectedTheme;
|
||||
private int m_LastSelectedModuleIndex;
|
||||
private float m_LastCheckLeftWidth;
|
||||
|
||||
private Button m_DefaultThemeButton;
|
||||
private Button m_LightThemeButton;
|
||||
private Button m_DarkThemeButton;
|
||||
|
||||
private Text m_Title;
|
||||
|
||||
private ScrollRect m_ScrollRect;
|
||||
private Mask m_Mark;
|
||||
|
||||
public List<ChartModule> chartModules { get { return m_ChartModule; } }
|
||||
|
||||
void Awake()
|
||||
{
|
||||
m_SelectedTheme = Theme.Default;
|
||||
|
||||
m_ButtonNormalColor = ChartHelper.GetColor("#293C55FF");
|
||||
m_ButtonSelectedColor = ChartHelper.GetColor("#e43c59ff");
|
||||
m_ButtonHighlightColor = ChartHelper.GetColor("#0E151FFF");
|
||||
Init();
|
||||
}
|
||||
|
||||
|
||||
void Init()
|
||||
{
|
||||
m_ScrollRect = transform.Find("chart_detail").GetComponent<ScrollRect>();
|
||||
m_Mark = transform.Find("chart_detail/Viewport").GetComponent<Mask>();
|
||||
m_Mark.enabled = true;
|
||||
m_Title = transform.Find("chart_title/Text").GetComponent<Text>();
|
||||
InitThemeButton();
|
||||
InitModuleButton();
|
||||
|
||||
InitSize();
|
||||
}
|
||||
|
||||
void InitSize()
|
||||
{
|
||||
UIUtil.SetRectTransformWidth(transform, m_LeftWidth, "chart_list");
|
||||
UIUtil.SetRectTransformLeft(transform, m_LeftWidth, "chart_detail");
|
||||
UIUtil.SetRectTransformLeft(transform, m_LeftWidth, "chart_title");
|
||||
UIUtil.SetGridLayoutGroup(transform, new Vector2(m_LeftWidth, m_LeftButtonHeight), new Vector2(0, 2), "chart_list");
|
||||
foreach (var module in m_ChartModule)
|
||||
{
|
||||
SetChartRootInfo(module);
|
||||
}
|
||||
}
|
||||
|
||||
private void SetChartGridLayoutGroup(GridLayoutGroup grid, int column)
|
||||
{
|
||||
if (grid == null) return;
|
||||
var screenWidth = Screen.width;
|
||||
var screenHeight = Screen.height;
|
||||
#if UNITY_EDITOR
|
||||
screenWidth = Camera.main.pixelWidth;
|
||||
#endif
|
||||
var chartWidth = (screenWidth - m_LeftWidth - m_ChartSpacing.x * (column + 1)) / column;
|
||||
|
||||
var rect = grid.gameObject.GetComponent<RectTransform>();
|
||||
rect.anchorMin = new Vector2(0, 1);
|
||||
rect.anchorMax = new Vector2(1, 1);
|
||||
rect.pivot = new Vector2(0, 1);
|
||||
rect.anchoredPosition = Vector2.zero;
|
||||
rect.sizeDelta = new Vector2(0, rect.sizeDelta.y);
|
||||
grid.spacing = m_ChartSpacing;
|
||||
grid.cellSize = new Vector2(chartWidth, chartWidth * m_ChartSizeRatio.y / m_ChartSizeRatio.x);
|
||||
}
|
||||
|
||||
private void SetChartRootInfo(ChartModule module)
|
||||
{
|
||||
var chartRoot = module.panel;
|
||||
if (chartRoot == null) return;
|
||||
var grid = chartRoot.GetComponent<GridLayoutGroup>();
|
||||
var hig = Mathf.CeilToInt(chartRoot.transform.childCount * 1f / module.column) * (grid.cellSize.y + grid.spacing.y);
|
||||
SetChartGridLayoutGroup(grid, module.column);
|
||||
UIUtil.SetRectTransformHeight(chartRoot.transform, hig);
|
||||
}
|
||||
|
||||
void ResetParam()
|
||||
{
|
||||
var charts = transform.GetComponentsInChildren<BaseChart>();
|
||||
foreach (var chart in charts)
|
||||
{
|
||||
chart.RemoveChartObject();
|
||||
}
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
if (m_ChartModule.Count <= 0) return;
|
||||
if (!Application.isPlaying) m_Mark.enabled = false;
|
||||
|
||||
if (m_LastCheckLeftWidth != m_LeftWidth)
|
||||
{
|
||||
m_LastCheckLeftWidth = m_LeftWidth;
|
||||
InitSize();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
public int GetSelectedModule()
|
||||
{
|
||||
for (int i = 0; i < m_ChartModule.Count; i++)
|
||||
{
|
||||
if (m_ChartModule[i].select) return i;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
public void InitModuleButton()
|
||||
{
|
||||
var btnPanel = transform.Find("chart_list");
|
||||
m_BtnClone = transform.Find("btn_clone").gameObject;
|
||||
m_BtnClone.SetActive(false);
|
||||
ChartHelper.DestroyAllChildren(btnPanel.transform);
|
||||
for (int i = 0; i < m_ChartModule.Count; i++)
|
||||
{
|
||||
var module = m_ChartModule[i];
|
||||
module.index = i;
|
||||
var btnName = "btn_" + module.name;
|
||||
GameObject btn;
|
||||
if (btnPanel.Find(btnName))
|
||||
{
|
||||
btn = btnPanel.Find(btnName).gameObject;
|
||||
btn.name = btnName;
|
||||
ChartHelper.SetActive(btn, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
btn = GameObject.Instantiate(m_BtnClone);
|
||||
btn.SetActive(true);
|
||||
btn.name = btnName;
|
||||
btn.transform.SetParent(btnPanel);
|
||||
btn.transform.localPosition = Vector3.zero;
|
||||
}
|
||||
btn.transform.localScale = Vector3.one;
|
||||
module.button = btn.GetComponent<Button>();
|
||||
module.button.transform.Find("Text").GetComponent<Text>().text = module.name.Replace("\\n", "\n");
|
||||
module.button.transform.Find("SubText").GetComponent<Text>().text = module.subName.Replace("\\n", "\n");
|
||||
|
||||
ChartHelper.ClearEventListener(btn.gameObject);
|
||||
ChartHelper.AddEventListener(btn.gameObject, EventTriggerType.PointerDown, (data) =>
|
||||
{
|
||||
ClickModule(module);
|
||||
});
|
||||
}
|
||||
for (int i = 0; i < m_ChartModule.Count; i++)
|
||||
{
|
||||
var module = m_ChartModule[i];
|
||||
module.index = i;
|
||||
if (module.select)
|
||||
{
|
||||
ClickModule(module);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ClickModule(ChartModule selectedModule)
|
||||
{
|
||||
if (lastSelectedModuleIndex >= 0)
|
||||
{
|
||||
m_ChartModule[lastSelectedModuleIndex].select = false;
|
||||
}
|
||||
lastSelectedModuleIndex = selectedModule.index;
|
||||
foreach (var module in m_ChartModule)
|
||||
{
|
||||
if (module.index != lastSelectedModuleIndex)
|
||||
{
|
||||
var block = module.button.colors;
|
||||
block.highlightedColor = m_ButtonHighlightColor;
|
||||
block.selectedColor = m_ButtonNormalColor;
|
||||
block.normalColor = m_ButtonNormalColor;
|
||||
module.button.colors = block;
|
||||
if (module.panel != null)
|
||||
module.panel.SetActive(false);
|
||||
//module.select = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
var block = module.button.colors;
|
||||
block.highlightedColor = m_ButtonSelectedColor;
|
||||
block.selectedColor = m_ButtonSelectedColor;
|
||||
block.normalColor = m_ButtonSelectedColor;
|
||||
module.button.colors = block;
|
||||
if (module.panel != null)
|
||||
module.panel.SetActive(true);
|
||||
// module.select = true;
|
||||
}
|
||||
}
|
||||
if (selectedModule.panel != null)
|
||||
m_ScrollRect.content = selectedModule.panel.GetComponent<RectTransform>();
|
||||
SetChartRootInfo(selectedModule);
|
||||
m_Title.text = string.IsNullOrEmpty(selectedModule.title) ?
|
||||
selectedModule.name : selectedModule.title;
|
||||
}
|
||||
|
||||
void InitThemeButton()
|
||||
{
|
||||
m_DefaultThemeButton = transform.Find("chart_theme/btn_default").GetComponent<Button>();
|
||||
m_LightThemeButton = transform.Find("chart_theme/btn_light").GetComponent<Button>();
|
||||
m_DarkThemeButton = transform.Find("chart_theme/btn_dark").GetComponent<Button>();
|
||||
|
||||
m_DefaultThemeButton.transform.Find("selected").gameObject.SetActive(m_SelectedTheme == Theme.Default);
|
||||
m_LightThemeButton.transform.Find("selected").gameObject.SetActive(m_SelectedTheme == Theme.Light);
|
||||
m_DarkThemeButton.transform.Find("selected").gameObject.SetActive(m_SelectedTheme == Theme.Dark);
|
||||
|
||||
m_DefaultThemeButton.onClick.AddListener(delegate () { SelecteTheme(Theme.Default); });
|
||||
m_LightThemeButton.onClick.AddListener(delegate () { SelecteTheme(Theme.Light); });
|
||||
m_DarkThemeButton.onClick.AddListener(delegate () { SelecteTheme(Theme.Dark); });
|
||||
|
||||
//SelecteTheme(Theme.Default);
|
||||
}
|
||||
|
||||
void SelecteTheme(Theme theme)
|
||||
{
|
||||
m_SelectedTheme = theme;
|
||||
m_DefaultThemeButton.transform.Find("selected").gameObject.SetActive(m_SelectedTheme == Theme.Default);
|
||||
m_LightThemeButton.transform.Find("selected").gameObject.SetActive(m_SelectedTheme == Theme.Light);
|
||||
m_DarkThemeButton.transform.Find("selected").gameObject.SetActive(m_SelectedTheme == Theme.Dark);
|
||||
var charts = transform.GetComponentsInChildren<BaseChart>();
|
||||
foreach (var chart in charts)
|
||||
{
|
||||
chart.UpdateTheme(theme);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f81ca580204024b8db33b4646c549c4f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,185 @@
|
||||
/************************************************/
|
||||
/* */
|
||||
/* Copyright (c) 2018 - 2021 monitor1394 */
|
||||
/* https://github.com/monitor1394 */
|
||||
/* */
|
||||
/************************************************/
|
||||
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using UnityEngine.Events;
|
||||
using XCharts;
|
||||
|
||||
namespace XChartsDemo
|
||||
{
|
||||
[DisallowMultipleComponent]
|
||||
[ExecuteInEditMode]
|
||||
internal class Demo_Animation : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private int m_FadeInDuration = 1000;
|
||||
[SerializeField] private int m_FadeOutDuration = 1000;
|
||||
[SerializeField] private int m_DataChangeDuration = 500;
|
||||
void Awake()
|
||||
{
|
||||
InitCharts();
|
||||
TryInitButton("buttons/btnFadeIn", AnimationFadeIn);
|
||||
TryInitButton("buttons/btnFadeOut", AnimationFadeOut);
|
||||
TryInitButton("buttons/btnDataAdd", AnimationDataAdd);
|
||||
TryInitButton("buttons/btnDataChange", AnimationDataChange);
|
||||
TryInitButton("buttons/btnPause", AnimationPause);
|
||||
TryInitButton("buttons/btnResume", AnimationResume);
|
||||
TryInitButton("buttons/btnReset", AnimationReset);
|
||||
}
|
||||
|
||||
void InitCharts()
|
||||
{
|
||||
var charts = transform.GetComponentsInChildren<BaseChart>();
|
||||
foreach (var chart in charts)
|
||||
{
|
||||
foreach (var serie in chart.series.list)
|
||||
{
|
||||
serie.animation.fadeInDuration = m_FadeInDuration;
|
||||
serie.animation.fadeOutDuration = m_FadeOutDuration;
|
||||
serie.animation.dataChangeDuration = m_DataChangeDuration;
|
||||
}
|
||||
}
|
||||
SetInputField("settings/fadeIn/InputField", m_FadeInDuration, OnFadeInDurationChanged);
|
||||
SetInputField("settings/fadeOut/InputField", m_FadeOutDuration, OnFadeOutDurationChanged);
|
||||
SetInputField("settings/dataChange/InputField", m_DataChangeDuration, OnDataChangeDurationChanged);
|
||||
}
|
||||
|
||||
void SetInputField(string path, int value, UnityAction<string> act)
|
||||
{
|
||||
var input = transform.Find(path).gameObject.GetComponent<InputField>();
|
||||
input.onEndEdit.AddListener(act);
|
||||
input.text = value.ToString();
|
||||
}
|
||||
|
||||
Button TryInitButton(string name, UnityAction act)
|
||||
{
|
||||
var trans = transform.Find(name);
|
||||
if (trans)
|
||||
{
|
||||
var btn = trans.gameObject.GetComponent<Button>();
|
||||
btn.onClick.AddListener(act);
|
||||
return btn;
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
void AnimationFadeIn()
|
||||
{
|
||||
var charts = transform.GetComponentsInChildren<BaseChart>();
|
||||
foreach (var chart in charts)
|
||||
{
|
||||
chart.AnimationFadeIn();
|
||||
}
|
||||
}
|
||||
|
||||
void AnimationFadeOut()
|
||||
{
|
||||
var charts = transform.GetComponentsInChildren<BaseChart>();
|
||||
foreach (var chart in charts)
|
||||
{
|
||||
chart.AnimationFadeOut();
|
||||
}
|
||||
}
|
||||
|
||||
void AnimationDataAdd()
|
||||
{
|
||||
var charts = transform.GetComponentsInChildren<BaseChart>();
|
||||
foreach (var chart in charts)
|
||||
{
|
||||
chart.AnimationFadeOut();
|
||||
}
|
||||
}
|
||||
|
||||
void AnimationDataChange()
|
||||
{
|
||||
var charts = transform.GetComponentsInChildren<BaseChart>();
|
||||
foreach (var chart in charts)
|
||||
{
|
||||
if (chart is RingChart)
|
||||
{
|
||||
var serieData = chart.series.GetSerie(0).GetSerieData(0);
|
||||
chart.UpdateData(0, 0, 0, Random.Range(0, serieData.GetData(1)));
|
||||
}
|
||||
else
|
||||
{
|
||||
var dataCount = chart.series.list[0].dataCount;
|
||||
var index = UnityEngine.Random.Range(0, dataCount);
|
||||
chart.UpdateData(0, index, UnityEngine.Random.Range(1, 100));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void AnimationPause()
|
||||
{
|
||||
var charts = transform.GetComponentsInChildren<BaseChart>();
|
||||
foreach (var chart in charts)
|
||||
{
|
||||
chart.AnimationPause();
|
||||
}
|
||||
}
|
||||
|
||||
void AnimationResume()
|
||||
{
|
||||
var charts = transform.GetComponentsInChildren<BaseChart>();
|
||||
foreach (var chart in charts)
|
||||
{
|
||||
chart.AnimationResume();
|
||||
}
|
||||
}
|
||||
|
||||
void AnimationReset()
|
||||
{
|
||||
var charts = transform.GetComponentsInChildren<BaseChart>();
|
||||
foreach (var chart in charts)
|
||||
{
|
||||
chart.AnimationReset();
|
||||
}
|
||||
}
|
||||
|
||||
void OnFadeInDurationChanged(string content)
|
||||
{
|
||||
var charts = transform.GetComponentsInChildren<BaseChart>();
|
||||
m_FadeInDuration = int.Parse(content);
|
||||
foreach (var chart in charts)
|
||||
{
|
||||
foreach (var serie in chart.series.list)
|
||||
{
|
||||
serie.animation.fadeInDuration = m_FadeInDuration;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void OnFadeOutDurationChanged(string content)
|
||||
{
|
||||
var charts = transform.GetComponentsInChildren<BaseChart>();
|
||||
m_FadeOutDuration = int.Parse(content);
|
||||
foreach (var chart in charts)
|
||||
{
|
||||
foreach (var serie in chart.series.list)
|
||||
{
|
||||
serie.animation.fadeOutDuration = m_FadeOutDuration;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void OnDataChangeDurationChanged(string content)
|
||||
{
|
||||
var charts = transform.GetComponentsInChildren<BaseChart>();
|
||||
m_DataChangeDuration = int.Parse(content);
|
||||
foreach (var chart in charts)
|
||||
{
|
||||
foreach (var serie in chart.series.list)
|
||||
{
|
||||
serie.animation.dataChangeDuration = m_DataChangeDuration;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 13a697cc1196d43fdb8f329026a721e5
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,131 @@
|
||||
/************************************************/
|
||||
/* */
|
||||
/* Copyright (c) 2018 - 2021 monitor1394 */
|
||||
/* https://github.com/monitor1394 */
|
||||
/* */
|
||||
/************************************************/
|
||||
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using UnityEngine.Events;
|
||||
using XCharts;
|
||||
|
||||
namespace XChartsDemo
|
||||
{
|
||||
[DisallowMultipleComponent]
|
||||
[ExecuteInEditMode]
|
||||
internal class Demo_Performance : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private float fps = 0;
|
||||
[SerializeField] private int m_MaxCacheDataNumber = 3000;
|
||||
|
||||
private const float INTERVAL = 0.2f;
|
||||
private int frameCount = 0;
|
||||
private float lastTime = 0f;
|
||||
private int initCount = 0;
|
||||
private System.DateTime timeNow;
|
||||
|
||||
private LineChart fpsChart;
|
||||
private LineChart lineChart;
|
||||
private BarChart barChart;
|
||||
private Text fpsText;
|
||||
|
||||
void Awake()
|
||||
{
|
||||
fpsChart = transform.Find("fps/FpsChart").gameObject.GetComponent<LineChart>();
|
||||
lineChart = transform.Find("charts/LineChart").gameObject.GetComponent<LineChart>();
|
||||
barChart = transform.Find("charts/BarChart").gameObject.GetComponent<BarChart>();
|
||||
fpsText = transform.Find("settings/txtFps").gameObject.GetComponent<Text>();
|
||||
fpsChart.ClearData();
|
||||
lineChart.ClearData();
|
||||
barChart.ClearData();
|
||||
InitCharts();
|
||||
}
|
||||
|
||||
void Start()
|
||||
{
|
||||
lastTime = Time.realtimeSinceStartup;
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
frameCount++;
|
||||
if (initCount < m_MaxCacheDataNumber)
|
||||
{
|
||||
for (int i = 0; i < 10; i++)
|
||||
{
|
||||
initCount++;
|
||||
if (initCount > m_MaxCacheDataNumber) break;
|
||||
AddOneData();
|
||||
}
|
||||
}
|
||||
if (Time.realtimeSinceStartup - lastTime >= INTERVAL)
|
||||
{
|
||||
fps = frameCount / (Time.realtimeSinceStartup - lastTime);
|
||||
frameCount = 0;
|
||||
lastTime = Time.realtimeSinceStartup;
|
||||
fpsChart.AddData(0, fps);
|
||||
fpsChart.AddXAxisData(Time.frameCount.ToString());
|
||||
fpsText.text = string.Format("FPS:{0:f1}", fps);
|
||||
if (initCount >= m_MaxCacheDataNumber)
|
||||
{
|
||||
AddOneData();
|
||||
initCount++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void AddOneData()
|
||||
{
|
||||
lineChart.title.text = initCount + "数据";
|
||||
barChart.title.text = initCount + "数据";
|
||||
timeNow = timeNow.AddSeconds(1);
|
||||
string category = timeNow.ToString("hh:mm:ss");
|
||||
float xvalue = Mathf.PI / 180 * initCount;
|
||||
float yvalue = 15 + Mathf.Sin(xvalue) * 2;
|
||||
|
||||
lineChart.AddData(0, yvalue);
|
||||
lineChart.AddXAxisData(category);
|
||||
barChart.AddData(0, yvalue);
|
||||
barChart.AddXAxisData(category);
|
||||
}
|
||||
|
||||
void InitCharts()
|
||||
{
|
||||
fpsChart.SetMaxCache(1000);
|
||||
lineChart.SetMaxCache(m_MaxCacheDataNumber);
|
||||
barChart.SetMaxCache(m_MaxCacheDataNumber);
|
||||
SetInputField("settings/fadeIn/InputField", m_MaxCacheDataNumber, OnFadeInDurationChanged);
|
||||
}
|
||||
|
||||
void SetInputField(string path, int value, UnityAction<string> act)
|
||||
{
|
||||
var input = transform.Find(path).gameObject.GetComponent<InputField>();
|
||||
input.onEndEdit.AddListener(act);
|
||||
input.text = value.ToString();
|
||||
}
|
||||
|
||||
Button TryInitButton(string name, UnityAction act)
|
||||
{
|
||||
var trans = transform.Find(name);
|
||||
if (trans)
|
||||
{
|
||||
var btn = trans.gameObject.GetComponent<Button>();
|
||||
btn.onClick.AddListener(act);
|
||||
return btn;
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void OnFadeInDurationChanged(string content)
|
||||
{
|
||||
m_MaxCacheDataNumber = int.Parse(content);
|
||||
lineChart.SetMaxCache(m_MaxCacheDataNumber);
|
||||
barChart.SetMaxCache(m_MaxCacheDataNumber);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d9d68a9ea64234d42af215ee70dd20af
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,74 @@
|
||||
/************************************************/
|
||||
/* */
|
||||
/* Copyright (c) 2018 - 2021 monitor1394 */
|
||||
/* https://github.com/monitor1394 */
|
||||
/* */
|
||||
/************************************************/
|
||||
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace XChartsDemo
|
||||
{
|
||||
internal static class UIUtil
|
||||
{
|
||||
|
||||
public static RectTransform GetRectTransform(Transform transform, string path)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(path))
|
||||
{
|
||||
transform = transform.Find(path);
|
||||
}
|
||||
if (transform != null)
|
||||
{
|
||||
return transform.gameObject.GetComponent<RectTransform>();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public static void SetRectTransformWidth(Transform transform, float width, string path = null)
|
||||
{
|
||||
var rect = GetRectTransform(transform, path);
|
||||
if (rect != null)
|
||||
{
|
||||
rect.sizeDelta = new Vector2(width, rect.sizeDelta.y);
|
||||
}
|
||||
}
|
||||
public static void SetRectTransformHeight(Transform transform, float height, string path = null)
|
||||
{
|
||||
var rect = GetRectTransform(transform, path);
|
||||
if (rect != null)
|
||||
{
|
||||
rect.sizeDelta = new Vector2(rect.sizeDelta.x, height);
|
||||
}
|
||||
}
|
||||
public static void SetRectTransformLeft(Transform transform, float width, string path = null)
|
||||
{
|
||||
var rect = GetRectTransform(transform, path);
|
||||
if (rect != null)
|
||||
{
|
||||
rect.anchoredPosition = new Vector2(width, rect.anchoredPosition.y);
|
||||
}
|
||||
}
|
||||
|
||||
public static void SetGridLayoutGroup(Transform transform, Vector2 cellSize, Vector2 spacing, string path = null)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(path))
|
||||
{
|
||||
transform = transform.Find(path);
|
||||
}
|
||||
if (transform != null)
|
||||
{
|
||||
var com = transform.gameObject.GetComponent<GridLayoutGroup>();
|
||||
if (com != null)
|
||||
{
|
||||
com.cellSize = cellSize;
|
||||
com.spacing = spacing;
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogError("SetGridLayoutGroupSize ERROR:can't find GridLayoutGroup: " + (transform.name + "/" + path));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0c48d683ad65245e7838578f46c55202
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in new issue
Block a user