优化结构,分离为XCharts和XChartsDemo两部分

This commit is contained in:
monitor1394
2019-11-09 07:00:58 +08:00
parent dd1416e49e
commit ff4f682a7b
13 changed files with 2 additions and 630878 deletions

View File

@@ -1,6 +1,8 @@
# 更新日志
* (2019.11.09) 优化结构,分离为`XCharts``XChartsDemo`两部分
* (2019.11.05) 发布`v1.0.4`版本
* (2019.11.05) 增加`Radar`雷达组件文本样式参数配置支持
* (2019.11.04) 修复`Unity2018.3`以下版本代码不兼容的问题
* (2019.11.04) 优化`SerieLabel`过多时引起的性能问题

View File

@@ -1,8 +1,6 @@
fileFormatVersion: 2
guid: 5e6b0fb015bc6524d8bab146b6f2ba3a
folderAsset: yes
timeCreated: 1553641866
licenseType: Free
DefaultImporter:
externalObjects: {}
userData:

View File

@@ -1,8 +0,0 @@
fileFormatVersion: 2
guid: 05b7d15b7a92f4c1eb56dbf47522bf6c
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,45 +0,0 @@
/******************************************/
/* */
/* Copyright (c) 2018 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/******************************************/
using UnityEditor;
using UnityEngine;
namespace XCharts
{
[CustomPropertyDrawer(typeof(ChartModule), true)]
public class ChartModuleDrawer : PropertyDrawer
{
public override void OnGUI(Rect pos, SerializedProperty prop, GUIContent label)
{
Rect drawRect = pos;
drawRect.height = EditorGUIUtility.singleLineHeight;
var lastX = drawRect.x;
var lastWid = drawRect.width;
SerializedProperty m_Name = prop.FindPropertyRelative("m_Name");
SerializedProperty m_Title = prop.FindPropertyRelative("m_Title");
SerializedProperty m_Selected = prop.FindPropertyRelative("m_Selected");
SerializedProperty m_Panel = prop.FindPropertyRelative("m_Panel");
var fieldWid = EditorGUIUtility.currentViewWidth - 30 - 5 - 50 - 90;
drawRect.width = 15;
EditorGUI.PropertyField(drawRect,m_Selected,GUIContent.none);
drawRect.x += 15;
drawRect.width = 50;
EditorGUI.PropertyField(drawRect,m_Name,GUIContent.none);
drawRect.x += 52;
drawRect.width = fieldWid;
EditorGUI.PropertyField(drawRect,m_Title,GUIContent.none);
drawRect.x += fieldWid + 2;
drawRect.width = 90;
EditorGUI.PropertyField(drawRect,m_Panel,GUIContent.none);
}
public override float GetPropertyHeight(SerializedProperty prop, GUIContent label)
{
return 1 * EditorGUIUtility.singleLineHeight + 1 * EditorGUIUtility.standardVerticalSpacing;
}
}
}

View File

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

View File

@@ -1,66 +0,0 @@

/******************************************/
/* */
/* Copyright (c) 2018 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/******************************************/
using UnityEditor;
namespace XCharts
{
/// <summary>
/// Editor class used to edit UI BaseChart.
/// </summary>
[CustomEditor(typeof(Demo), false)]
public class DemoEditor : Editor
{
protected Demo m_Target;
protected SerializedProperty m_Script;
protected SerializedProperty m_ButtonNormalColor;
protected SerializedProperty m_ButtonSelectedColor;
protected SerializedProperty m_ButtonHighlightColor;
protected SerializedProperty m_ChartModule;
protected virtual void OnEnable()
{
m_Target = (Demo)target;
m_Script = serializedObject.FindProperty("m_Script");
m_ButtonNormalColor = serializedObject.FindProperty("m_ButtonNormalColor");
m_ButtonSelectedColor = serializedObject.FindProperty("m_ButtonSelectedColor");
m_ButtonHighlightColor = serializedObject.FindProperty("m_ButtonHighlightColor");
m_ChartModule = serializedObject.FindProperty("m_ChartModule");
}
public override void OnInspectorGUI()
{
if (m_Target == null && target == null)
{
base.OnInspectorGUI();
return;
}
serializedObject.Update();
EditorGUILayout.PropertyField(m_ButtonNormalColor);
EditorGUILayout.PropertyField(m_ButtonSelectedColor);
EditorGUILayout.PropertyField(m_ButtonHighlightColor);
var size = m_ChartModule.arraySize;
size = EditorGUILayout.IntField("Chart Module Size", size);
if (size != m_ChartModule.arraySize)
{
while (size > m_ChartModule.arraySize)
m_ChartModule.InsertArrayElementAtIndex(m_ChartModule.arraySize);
while (size < m_ChartModule.arraySize)
m_ChartModule.DeleteArrayElementAtIndex(m_ChartModule.arraySize - 1);
}
for (int i = 0; i < size; i++)
{
EditorGUILayout.PropertyField(m_ChartModule.GetArrayElementAtIndex(i));
}
serializedObject.ApplyModifiedProperties();
}
}
}

View File

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

View File

@@ -1,17 +0,0 @@
{
"name": "XCharts.Editor.Demo",
"references": [
"XCharts.Demo.Runtime",
"XCharts.Runtime"
],
"optionalUnityReferences": [],
"includePlatforms": [
"Editor"
],
"excludePlatforms": [],
"allowUnsafeCode": false,
"overrideReferences": false,
"precompiledReferences": [],
"autoReferenced": true,
"defineConstraints": []
}

View File

@@ -1,7 +0,0 @@
fileFormatVersion: 2
guid: 2d3606aaaf73f468984f4615b496f408
AssemblyDefinitionImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,197 +0,0 @@
/******************************************/
/* */
/* Copyright (c) 2018 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/******************************************/
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
namespace XCharts
{
[System.Serializable]
public class ChartModule
{
[SerializeField] private string m_Name;
[SerializeField] private string m_Title;
[SerializeField] private bool m_Selected;
[SerializeField] private GameObject m_Panel;
public string name { get { return m_Name; } set { m_Name = 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; }
}
[DisallowMultipleComponent]
[ExecuteInEditMode]
public class Demo : MonoBehaviour
{
[SerializeField] private Color m_ButtonNormalColor;
[SerializeField] private Color m_ButtonSelectedColor;
[SerializeField] private Color m_ButtonHighlightColor;
[SerializeField] private List<ChartModule> m_ChartModule;
private GameObject m_BtnClone;
private Theme m_SelectedTheme;
private int m_LastSelectedModuleIndex;
private Button m_DefaultThemeButton;
private Button m_LightThemeButton;
private Button m_DarkThemeButton;
private Text m_Title;
private ScrollRect m_ScrollRect;
private Mask m_Mark;
void Awake()
{
m_SelectedTheme = Theme.Default;
m_ButtonNormalColor = ChartHelper.GetColor("#293C55FF");
m_ButtonSelectedColor = ChartHelper.GetColor("#e43c59ff");
m_ButtonHighlightColor = ChartHelper.GetColor("#0E151FFF");
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();
}
void Update()
{
#if UNITY_EDITOR
if (m_ChartModule.Count <= 0) return;
int selectedModuleIndex = -1;
for (int i = 0; i < m_ChartModule.Count; i++)
{
if (selectedModuleIndex >= 0 && i > selectedModuleIndex)
{
m_ChartModule[i].select = false;
}
else if (m_ChartModule[i].select)
{
selectedModuleIndex = i;
}
}
if (selectedModuleIndex < 0) selectedModuleIndex = 0;
if (selectedModuleIndex != m_LastSelectedModuleIndex)
{
InitModuleButton();
}
if (!Application.isPlaying) m_Mark.enabled = false;
#endif
}
void InitModuleButton()
{
var btnPanel = transform.Find("chart_list");
m_BtnClone = transform.Find("btn_clone").gameObject;
m_BtnClone.SetActive(false);
ChartHelper.DestroyAllChildren(btnPanel);
foreach (var module in m_ChartModule)
{
var btnName = "btn_" + module.name;
GameObject btn;
if (btnPanel.Find(btnName))
{
btn = btnPanel.Find(btnName).gameObject;
btn.SetActive(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.GetComponentInChildren<Text>().text = module.name;
ChartHelper.AddEventListener(btn.gameObject, EventTriggerType.PointerDown, (data) =>
{
ClickModule(module);
});
}
for (int i = 0; i < m_ChartModule.Count; i++)
{
var module = m_ChartModule[i];
if (module.select)
{
ClickModule(module);
m_LastSelectedModuleIndex = i;
break;
}
}
}
void ClickModule(ChartModule selectedModule)
{
foreach (var module in m_ChartModule)
{
if (selectedModule != module)
{
var block = module.button.colors;
block.highlightedColor = m_ButtonHighlightColor;
block.normalColor = m_ButtonNormalColor;
module.button.colors = block;
module.panel.SetActive(false);
module.select = false;
}
else
{
var block = module.button.colors;
block.highlightedColor = m_ButtonSelectedColor;
block.normalColor = m_ButtonSelectedColor;
module.button.colors = block;
module.panel.SetActive(true);
module.select = true;
}
}
m_ScrollRect.content = selectedModule.panel.GetComponent<RectTransform>();
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);
}
}
}
}

View File

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

File diff suppressed because it is too large Load Diff

View File

@@ -1,9 +0,0 @@
fileFormatVersion: 2
guid: 5adbd6df9174d6943b7eb8d23651ffd1
timeCreated: 1553641950
licenseType: Free
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant: