1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- /* INFINITY CODE 2013-2019 */
- /* http://www.infinity-code.com */
- using UnityEditor;
- using UnityEngine;
- namespace InfinityCode.RealWorldTerrain.Tools
- {
- public class RealWorldTerrainCurrentLatLon : EditorWindow
- {
- private RealWorldTerrainContainer rwt;
- private Vector3 lastCursorPosition;
- private static RealWorldTerrainCurrentLatLon wnd;
- private void OnDestroy()
- {
- EditorApplication.update -= OnUpdate;
- #if UNITY_2019_1_OR_NEWER
- SceneView.duringSceneGui -= OnSceneGUI;
- #else
- SceneView.onSceneGUIDelegate -= OnSceneGUI;
- #endif
- wnd = null;
- }
- private void OnEnable()
- {
- OnDestroy();
- wnd = this;
- EditorApplication.update += OnUpdate;
- #if UNITY_2019_1_OR_NEWER
- SceneView.duringSceneGui += OnSceneGUI;
- #else
- SceneView.onSceneGUIDelegate += OnSceneGUI;
- #endif
- }
- private void OnGUI()
- {
- rwt = (RealWorldTerrainContainer)EditorGUILayout.ObjectField("Real World Terrain", rwt, typeof(RealWorldTerrainContainer), true);
- if (rwt == null) return;
- SceneView view = SceneView.lastActiveSceneView;
- if (view == null) return;
- Vector3 cp = view.camera.transform.position;
- double longitude, latitude, altitude;
- rwt.GetCoordinatesByWorldPosition(cp, out longitude, out latitude, out altitude);
-
- EditorGUILayout.LabelField("Scene camera latitude: " + latitude);
- EditorGUILayout.LabelField("Scene camera longitude: " + longitude);
- EditorGUILayout.LabelField("Scene camera altitude: " + altitude);
- if (lastCursorPosition == Vector3.zero) return;
- rwt.GetCoordinatesByWorldPosition(lastCursorPosition, out longitude, out latitude, out altitude);
- EditorGUILayout.LabelField("Scene cursor latitude: " + latitude);
- EditorGUILayout.LabelField("Scene cursor longitude: " + longitude);
- EditorGUILayout.LabelField("Scene cursor altitude: " + altitude.ToString("F2") + " meters");
- }
- private void OnSceneGUI(SceneView view)
- {
- RaycastHit hit;
- Ray ray = HandleUtility.GUIPointToWorldRay(Event.current.mousePosition);
- if (Physics.Raycast(ray.origin, ray.direction, out hit)) lastCursorPosition = hit.point;
- else lastCursorPosition = Vector3.zero;
- }
- private void OnUpdate()
- {
- Repaint();
- }
- [MenuItem("Window/Infinity Code/Real World Terrain/Tools/Current Position")]
- public static void OpenWindow()
- {
- if (wnd != null) wnd.Close();
- wnd = GetWindow<RealWorldTerrainCurrentLatLon>(false, "Current Position");
- wnd.rwt = FindObjectOfType<RealWorldTerrainContainer>();
- }
- public static void OpenWindow(RealWorldTerrainContainer container)
- {
- if (wnd != null) wnd.Close();
- wnd = GetWindow<RealWorldTerrainCurrentLatLon>(false, "Current Position");
- wnd.rwt = container;
- }
- }
- }
|