RealWorldTerrainPOIManager.cs 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /* INFINITY CODE 2013-2019 */
  2. /* http://www.infinity-code.com */
  3. using UnityEditor;
  4. using UnityEngine;
  5. namespace InfinityCode.RealWorldTerrain.Tools
  6. {
  7. public class RealWorldTerrainPOIManager : EditorWindow
  8. {
  9. private static RealWorldTerrainPOIManager wnd;
  10. private RealWorldTerrainContainer container;
  11. private RealWorldTerrainPOIItem[] items;
  12. private Vector2 scrollPosition;
  13. private void OnDestroy()
  14. {
  15. wnd = null;
  16. }
  17. private void OnGUI()
  18. {
  19. container = EditorGUILayout.ObjectField("Container", container, typeof(RealWorldTerrainContainer), true) as RealWorldTerrainContainer;
  20. if (container == null) return;
  21. if (GUILayout.Button("Update POI") || items == null) UpdatePOI();
  22. GUILayout.Label("POI:");
  23. if (items == null || items.Length == 0)
  24. {
  25. GUILayout.Label("No POI.");
  26. return;
  27. }
  28. int index = 0;
  29. scrollPosition = EditorGUILayout.BeginScrollView(scrollPosition);
  30. foreach (RealWorldTerrainPOIItem item in items)
  31. {
  32. index++;
  33. EditorGUILayout.BeginHorizontal();
  34. EditorGUILayout.LabelField(index + ": " + item.title);
  35. EditorGUILayout.LabelField("lat: " + item.y, GUILayout.Width(90));
  36. EditorGUILayout.LabelField("lng: " + item.x, GUILayout.Width(90));
  37. if (GUILayout.Button(new GUIContent("S", "Select GameObject"), GUILayout.ExpandWidth(false))) Selection.activeGameObject = item.gameObject;
  38. if (GUILayout.Button(new GUIContent("P", "Open in Object Placer"), GUILayout.ExpandWidth(false))) RealWorldTerrainObjectPlacerWindow.OpenWindow(container, item.x, item.y);
  39. EditorGUILayout.EndHorizontal();
  40. }
  41. EditorGUILayout.EndScrollView();
  42. }
  43. private void UpdatePOI()
  44. {
  45. items = container.GetComponentsInChildren<RealWorldTerrainPOIItem>();
  46. }
  47. [MenuItem("Window/Infinity Code/Real World Terrain/Tools/POI Manager")]
  48. public static void OpenWindow()
  49. {
  50. if (wnd != null) wnd.Close();
  51. wnd = GetWindow<RealWorldTerrainPOIManager>(false, "POI Manager");
  52. wnd.container = FindObjectOfType<RealWorldTerrainContainer>();
  53. }
  54. public static void OpenWindow(RealWorldTerrainContainer container)
  55. {
  56. OpenWindow();
  57. wnd.container = container;
  58. }
  59. }
  60. }