using InfinityCode.RealWorldTerrain.Generators; using UnityEditor; using UnityEngine; public class InterceptGetElevationExample : EditorWindow { public static bool isIntercepted = false; private void OnGUI() { EditorGUI.BeginDisabledGroup(isIntercepted); if (GUILayout.Button("Intercept")) { // Subscribe to OnGetElevation event, to intercept receiving elevation from the provider. RealWorldTerrainElevationGenerator.OnGetElevation += OnGetElevation; // If you want to use the range of values from the selected elevation provider, just do not subscribe to RealWorldTerrainElevationGenerator.OnGetElevationRange. RealWorldTerrainElevationGenerator.OnGetElevationRange += OnGetElevationRange; isIntercepted = true; } EditorGUI.EndDisabledGroup(); EditorGUI.BeginDisabledGroup(!isIntercepted); if (GUILayout.Button("Release")) { RealWorldTerrainElevationGenerator.OnGetElevation -= OnGetElevation; RealWorldTerrainElevationGenerator.OnGetElevationRange -= OnGetElevationRange; isIntercepted = false; } EditorGUI.EndDisabledGroup(); } /// /// This method will be called when the RWT wants to get the range of elevation values. /// If you want to use the range of values from the selected elevation provider, just do not subscribe to RealWorldTerrainElevationGenerator.OnGetElevationRange. /// /// Minimum elevation for the area (meters) /// Maximum elevation for the area (meters) private void OnGetElevationRange(out double minEl, out double maxEl) { minEl = maxEl = 0; // Here you calculate the maximum and minimum elevation value, // or return the pre-calculated values. } /// /// This method will be called when the RWT wants to get the elevation value from the provider /// /// Mercator position X (0-1) /// Mercator position Y (0-1) /// Elevation value in meters or null (if you need to get elevation value from the provider) private double? OnGetElevation(double mx, double my) { // Mercator position is a tile position for zoom 0. // https://www.maptiler.com/google-maps-coordinates-tile-bounds-projection/ // https://docs.microsoft.com/en-us/bingmaps/articles/bing-maps-tile-system?redirectedfrom=MSDN // Here you calculate your elevation value in meters, and return that value. // Or return null if you need to get elevation value from the provider. // Points of interest: // Use RealWorldTerrainUtils.MercatToLatLong if you need to convert Mercator position to geographic coordinates. return null; } [MenuItem("RWT/Intercept Elevation")] private static void OpenWindow() { GetWindow("Intercept Elevation"); } }