This repository has been archived on 2025-04-28. You can view files and clone it, but cannot push or open issues or pull requests.
ARPlusSystem/ARPlusSystem-250418/Assets/Editor/GeoDataViewer.cs

62 lines
1.8 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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},已跳过。");
}
}
}
}