62 lines
1.8 KiB
C#
62 lines
1.8 KiB
C#
using System.Collections.Generic;
|
||
using UnityEngine;
|
||
using UnityEditor;
|
||
|
||
[CustomEditor(typeof(GeoDataContainer))]
|
||
public class GeoDataViewer : Editor
|
||
{
|
||
private Dictionary<string, List<Coords>> geoDataDictionary;
|
||
|
||
public override void OnInspectorGUI()
|
||
{
|
||
base.OnInspectorGUI();
|
||
|
||
GeoDataContainer dataAsset = (GeoDataContainer)target;
|
||
|
||
if (dataAsset.geoDatas == null)
|
||
{
|
||
EditorGUILayout.HelpBox("GeoDatas 列表为空!", MessageType.Warning);
|
||
return;
|
||
}
|
||
|
||
if (GUILayout.Button("刷新并生成 Dictionary"))
|
||
{
|
||
BuildDictionary(dataAsset.geoDatas);
|
||
}
|
||
|
||
if (geoDataDictionary != null)
|
||
{
|
||
EditorGUILayout.Space();
|
||
EditorGUILayout.LabelField("Dictionary 预览", EditorStyles.boldLabel);
|
||
foreach (var kvp in geoDataDictionary)
|
||
{
|
||
EditorGUILayout.BeginVertical("box");
|
||
EditorGUILayout.LabelField($"Key: {kvp.Key} ({kvp.Value.Count} Groups)");
|
||
EditorGUI.indentLevel++;
|
||
foreach (var coords in kvp.Value)
|
||
{
|
||
EditorGUILayout.LabelField($"Coords Group: {coords.coords.Count} Points");
|
||
}
|
||
EditorGUI.indentLevel--;
|
||
EditorGUILayout.EndVertical();
|
||
}
|
||
}
|
||
}
|
||
|
||
private void BuildDictionary(List<GeoData> geoDatas)
|
||
{
|
||
geoDataDictionary = new Dictionary<string, List<Coords>>();
|
||
|
||
foreach (var geoData in geoDatas)
|
||
{
|
||
if (!geoDataDictionary.ContainsKey(geoData.key))
|
||
{
|
||
geoDataDictionary.Add(geoData.key, geoData.values);
|
||
}
|
||
else
|
||
{
|
||
Debug.LogWarning($"重复的 Key:{geoData.key},已跳过。");
|
||
}
|
||
}
|
||
}
|
||
} |