mirror of
https://github.com/XCharts-Team/XCharts.git
synced 2026-05-17 14:00:12 +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;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user