mirror of
https://github.com/XCharts-Team/XCharts.git
synced 2026-05-25 02:10:16 +00:00
增加GanttChart甘特图
This commit is contained in:
@@ -5,14 +5,24 @@
|
||||
/* */
|
||||
/************************************************/
|
||||
|
||||
using System.Collections.Generic;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace XChartsDemo
|
||||
{
|
||||
[CustomPropertyDrawer(typeof(ChartModule), true)]
|
||||
public class ChartModuleDrawer : PropertyDrawer
|
||||
internal class ChartModuleDrawer : PropertyDrawer
|
||||
{
|
||||
public class Styles
|
||||
{
|
||||
public static readonly GUIContent iconAdd = new GUIContent("+", "Add");
|
||||
public static readonly GUIContent iconRemove = new GUIContent("-", "Remove");
|
||||
public static readonly GUIContent iconUp = new GUIContent("↑", "Up");
|
||||
public static readonly GUIContent iconDown = new GUIContent("↓", "Down");
|
||||
public static readonly GUIStyle invisibleButton = "InvisibleButton";
|
||||
}
|
||||
|
||||
public override void OnGUI(Rect pos, SerializedProperty prop, GUIContent label)
|
||||
{
|
||||
Rect drawRect = pos;
|
||||
@@ -25,9 +35,29 @@ namespace XChartsDemo
|
||||
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 - 40 - 80 - 50 - 100 - 6 * 2;
|
||||
var fieldWid = EditorGUIUtility.currentViewWidth - 30 - 5 - 40 - 80 - 50 - 100 - 6 * 2 - 70;
|
||||
drawRect.width = 15;
|
||||
EditorGUI.BeginChangeCheck();
|
||||
var oldFlag = m_Selected.boolValue;
|
||||
EditorGUI.PropertyField(drawRect, m_Selected, GUIContent.none);
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
var demo = prop.serializedObject.targetObject as Demo;
|
||||
var index = GetIndex(prop);
|
||||
var selectedIndex = demo.GetSelectedModule();
|
||||
if (selectedIndex != index)
|
||||
{
|
||||
for (int i = 0; i < demo.chartModules.Count; i++)
|
||||
{
|
||||
demo.chartModules[i].select = i == index && m_Selected.boolValue;
|
||||
}
|
||||
demo.InitModuleButton();
|
||||
}
|
||||
else
|
||||
{
|
||||
m_Selected.boolValue = oldFlag;
|
||||
}
|
||||
}
|
||||
drawRect.x += 17;
|
||||
drawRect.width = 80;
|
||||
EditorGUI.PropertyField(drawRect, m_Name, GUIContent.none);
|
||||
@@ -43,11 +73,83 @@ namespace XChartsDemo
|
||||
drawRect.x += 102;
|
||||
drawRect.width = 40;
|
||||
EditorGUI.PropertyField(drawRect, m_Column, GUIContent.none);
|
||||
|
||||
var btnWidth = 12;
|
||||
drawRect.x += 42;
|
||||
drawRect.width = btnWidth;
|
||||
if (GUI.Button(drawRect, Styles.iconUp, Styles.invisibleButton))
|
||||
{
|
||||
var demo = prop.serializedObject.targetObject as Demo;
|
||||
var index = GetIndex(prop);
|
||||
if (index >= 0)
|
||||
{
|
||||
Swap(demo.chartModules, index, index - 1);
|
||||
demo.InitModuleButton();
|
||||
}
|
||||
}
|
||||
drawRect.x += btnWidth + 1;
|
||||
if (GUI.Button(drawRect, Styles.iconDown, Styles.invisibleButton))
|
||||
{
|
||||
var demo = prop.serializedObject.targetObject as Demo;
|
||||
var index = GetIndex(prop);
|
||||
if (index >= 0)
|
||||
{
|
||||
Swap(demo.chartModules, index, index + 1);
|
||||
demo.InitModuleButton();
|
||||
}
|
||||
}
|
||||
drawRect.x += btnWidth + 1;
|
||||
if (GUI.Button(drawRect, Styles.iconAdd, Styles.invisibleButton))
|
||||
{
|
||||
var demo = prop.serializedObject.targetObject as Demo;
|
||||
var index = GetIndex(prop);
|
||||
if (index >= 0)
|
||||
{
|
||||
demo.chartModules.Insert(index + 1, new ChartModule());
|
||||
demo.InitModuleButton();
|
||||
}
|
||||
}
|
||||
drawRect.x += 16;
|
||||
if (GUI.Button(drawRect, Styles.iconRemove, Styles.invisibleButton))
|
||||
{
|
||||
var demo = prop.serializedObject.targetObject as Demo;
|
||||
var index = GetIndex(prop);
|
||||
if (index >= 0)
|
||||
{
|
||||
demo.chartModules.RemoveAt(index);
|
||||
demo.InitModuleButton();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override float GetPropertyHeight(SerializedProperty prop, GUIContent label)
|
||||
{
|
||||
return 1 * EditorGUIUtility.singleLineHeight + 1 * EditorGUIUtility.standardVerticalSpacing;
|
||||
}
|
||||
|
||||
private int GetIndex(SerializedProperty prop)
|
||||
{
|
||||
int index = -1;
|
||||
var sindex = prop.propertyPath.LastIndexOf('[');
|
||||
var eindex = prop.propertyPath.LastIndexOf(']');
|
||||
if (sindex >= 0 && eindex >= 0)
|
||||
{
|
||||
var str = prop.propertyPath.Substring(sindex + 1, eindex - sindex - 1);
|
||||
int.TryParse(str, out index);
|
||||
}
|
||||
return index;
|
||||
}
|
||||
|
||||
private static bool Swap<T>(List<T> list, int index1, int index2)
|
||||
{
|
||||
if (index1 < 0 || index1 >= list.Count) return false;
|
||||
if (index2 < 0 || index2 >= list.Count) return false;
|
||||
var temp = list[index1];
|
||||
list[index1] = list[index2];
|
||||
list[index2] = temp;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -15,7 +15,7 @@ namespace XChartsDemo
|
||||
/// </summary>
|
||||
|
||||
[CustomEditor(typeof(Demo), false)]
|
||||
public class DemoEditor : Editor
|
||||
internal class DemoEditor : Editor
|
||||
{
|
||||
protected Demo m_Target;
|
||||
protected SerializedProperty m_Script;
|
||||
|
||||
@@ -16,11 +16,11 @@ namespace XChartsDemo
|
||||
[System.Serializable]
|
||||
public class ChartModule
|
||||
{
|
||||
[SerializeField] private string m_Name;
|
||||
[SerializeField] private string m_SubName;
|
||||
[SerializeField] private string m_Name = "Name";
|
||||
[SerializeField] private string m_SubName = "SubName";
|
||||
[SerializeField] private int m_Column = 3;
|
||||
|
||||
[SerializeField] private string m_Title;
|
||||
[SerializeField] private string m_Title = "Title";
|
||||
[SerializeField] private bool m_Selected;
|
||||
[SerializeField] private GameObject m_Panel;
|
||||
|
||||
@@ -31,6 +31,7 @@ namespace XChartsDemo
|
||||
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]
|
||||
@@ -44,6 +45,7 @@ namespace XChartsDemo
|
||||
[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;
|
||||
@@ -60,6 +62,8 @@ namespace XChartsDemo
|
||||
private ScrollRect m_ScrollRect;
|
||||
private Mask m_Mark;
|
||||
|
||||
public List<ChartModule> chartModules { get { return m_ChartModule; } }
|
||||
|
||||
void Awake()
|
||||
{
|
||||
m_SelectedTheme = Theme.Default;
|
||||
@@ -118,6 +122,7 @@ namespace XChartsDemo
|
||||
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);
|
||||
@@ -137,23 +142,6 @@ namespace XChartsDemo
|
||||
{
|
||||
#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;
|
||||
|
||||
if (m_LastCheckLeftWidth != m_LeftWidth)
|
||||
@@ -164,14 +152,25 @@ namespace XChartsDemo
|
||||
#endif
|
||||
}
|
||||
|
||||
void InitModuleButton()
|
||||
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.HideAllObject(btnPanel);
|
||||
foreach (var module in m_ChartModule)
|
||||
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))
|
||||
@@ -193,19 +192,19 @@ namespace XChartsDemo
|
||||
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);
|
||||
m_LastSelectedModuleIndex = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -213,28 +212,38 @@ namespace XChartsDemo
|
||||
|
||||
void ClickModule(ChartModule selectedModule)
|
||||
{
|
||||
if (lastSelectedModuleIndex >= 0)
|
||||
{
|
||||
m_ChartModule[lastSelectedModuleIndex].select = false;
|
||||
}
|
||||
lastSelectedModuleIndex = selectedModule.index;
|
||||
foreach (var module in m_ChartModule)
|
||||
{
|
||||
if (selectedModule != module)
|
||||
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;
|
||||
module.panel.SetActive(false);
|
||||
module.select = false;
|
||||
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;
|
||||
module.panel.SetActive(true);
|
||||
module.select = true;
|
||||
if (module.panel != null)
|
||||
module.panel.SetActive(true);
|
||||
// module.select = true;
|
||||
}
|
||||
}
|
||||
m_ScrollRect.content = selectedModule.panel.GetComponent<RectTransform>();
|
||||
if (selectedModule.panel != null)
|
||||
m_ScrollRect.content = selectedModule.panel.GetComponent<RectTransform>();
|
||||
SetChartRootInfo(selectedModule);
|
||||
m_Title.text = string.IsNullOrEmpty(selectedModule.title) ?
|
||||
selectedModule.name : selectedModule.title;
|
||||
|
||||
@@ -14,7 +14,7 @@ namespace XChartsDemo
|
||||
{
|
||||
[DisallowMultipleComponent]
|
||||
[ExecuteInEditMode]
|
||||
public class Demo_Animation : MonoBehaviour
|
||||
internal class Demo_Animation : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private int m_FadeInDuration = 1000;
|
||||
[SerializeField] private int m_FadeOutDuration = 1000;
|
||||
|
||||
@@ -14,7 +14,7 @@ namespace XChartsDemo
|
||||
{
|
||||
[DisallowMultipleComponent]
|
||||
[ExecuteInEditMode]
|
||||
public class Demo_Performance : MonoBehaviour
|
||||
internal class Demo_Performance : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private float fps = 0;
|
||||
[SerializeField] private int m_MaxCacheDataNumber = 3000;
|
||||
|
||||
@@ -10,7 +10,7 @@ using UnityEngine.UI;
|
||||
|
||||
namespace XChartsDemo
|
||||
{
|
||||
public static class UIUtil
|
||||
internal static class UIUtil
|
||||
{
|
||||
|
||||
public static RectTransform GetRectTransform(Transform transform, string path)
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user