mirror of
https://github.com/XCharts-Team/XCharts.git
synced 2026-05-21 16:00:24 +00:00
增加Editor快捷添加图表
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
|
||||
# 更新日志
|
||||
|
||||
* (2019.11.03) 增加`Editor`快捷添加图表:`Hierarchy`试图下右键`XCharts->LineChart`
|
||||
* (2019.10.31) 修复`prefab`预设制作报错的问题
|
||||
* (2019.10.31) 增加访问主题组件API:`BaseChart.themeInfo`
|
||||
* (2019.10.26) 发布`v1.0.1`版本
|
||||
|
||||
102
Assets/XCharts/Editor/XChartEditor.cs
Normal file
102
Assets/XCharts/Editor/XChartEditor.cs
Normal file
@@ -0,0 +1,102 @@
|
||||
/******************************************/
|
||||
/* */
|
||||
/* Copyright (c) 2018 monitor1394 */
|
||||
/* https://github.com/monitor1394 */
|
||||
/* */
|
||||
/******************************************/
|
||||
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace XCharts
|
||||
{
|
||||
public class XChartEditor : EditorWindow
|
||||
{
|
||||
private static Transform GetParent()
|
||||
{
|
||||
GameObject selectObj = Selection.activeGameObject;
|
||||
if (selectObj == null)
|
||||
{
|
||||
var canvas = GameObject.FindObjectOfType<Canvas>();
|
||||
if (canvas != null) return canvas.transform;
|
||||
else
|
||||
{
|
||||
var canvasObject = new GameObject();
|
||||
canvasObject.name = "Canvas";
|
||||
canvas = canvasObject.AddComponent<Canvas>();
|
||||
canvas.renderMode = RenderMode.ScreenSpaceOverlay;
|
||||
canvasObject.AddComponent<CanvasScaler>();
|
||||
canvasObject.AddComponent<GraphicRaycaster>();
|
||||
return canvas.transform;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return selectObj.transform;
|
||||
}
|
||||
}
|
||||
|
||||
private static string GetName(Transform parent, string name)
|
||||
{
|
||||
if (parent.Find(name) == null) return name;
|
||||
for (int i = 1; i <= 10; i++)
|
||||
{
|
||||
var newName = string.Format("{0} ({1})", name, i);
|
||||
if (parent.Find(newName) == null)
|
||||
{
|
||||
return newName;
|
||||
}
|
||||
}
|
||||
return name;
|
||||
}
|
||||
|
||||
private static void AddChart<T>(string chartName) where T : BaseChart
|
||||
{
|
||||
var parent = GetParent();
|
||||
if (parent == null) return;
|
||||
var chart = new GameObject();
|
||||
chart.name = GetName(parent, chartName);
|
||||
chart.AddComponent<T>();
|
||||
chart.transform.SetParent(parent);
|
||||
chart.transform.localScale = Vector3.one;
|
||||
chart.transform.localPosition = Vector3.zero;
|
||||
}
|
||||
|
||||
[MenuItem("GameObject/XCharts/LineChart", priority = 44)]
|
||||
public static void AddLineChart()
|
||||
{
|
||||
AddChart<LineChart>("LineChart");
|
||||
}
|
||||
|
||||
[MenuItem("GameObject/XCharts/BarChart", priority = 45)]
|
||||
public static void AddBarChart()
|
||||
{
|
||||
AddChart<BarChart>("BarChart");
|
||||
}
|
||||
|
||||
[MenuItem("GameObject/XCharts/PieChart", priority = 46)]
|
||||
public static void AddPieChart()
|
||||
{
|
||||
AddChart<PieChart>("PieChart");
|
||||
}
|
||||
|
||||
[MenuItem("GameObject/XCharts/RadarChart", priority = 47)]
|
||||
public static void AddRadarChart()
|
||||
{
|
||||
AddChart<RadarChart>("RadarChart");
|
||||
}
|
||||
|
||||
[MenuItem("GameObject/XCharts/ScatterChart", priority = 48)]
|
||||
public static void AddScatterChart()
|
||||
{
|
||||
AddChart<ScatterChart>("ScatterChart");
|
||||
}
|
||||
|
||||
[MenuItem("GameObject/XCharts/HeatmapChart", priority = 49)]
|
||||
public static void AddHeatmapChart()
|
||||
{
|
||||
AddChart<HeatmapChart>("HeatmapChart");
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/XCharts/Editor/XChartEditor.cs.meta
Normal file
11
Assets/XCharts/Editor/XChartEditor.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 941beb76fdaa64a27a2df6561893157e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user