<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title><![CDATA[Infinity Code Forum — Interception receiving elevations]]></title>
		<link>https://forum.infinity-code.com/viewtopic.php?id=1538</link>
		<atom:link href="https://forum.infinity-code.com/extern.php?action=feed&amp;tid=1538&amp;type=rss" rel="self" type="application/rss+xml" />
		<description><![CDATA[The most recent posts in Interception receiving elevations.]]></description>
		<lastBuildDate>Tue, 09 Jun 2020 21:29:10 +0000</lastBuildDate>
		<generator>PunBB</generator>
		<item>
			<title><![CDATA[Interception receiving elevations]]></title>
			<link>https://forum.infinity-code.com/viewtopic.php?pid=6345#p6345</link>
			<description><![CDATA[<p>Sometimes you want to use elevation data obtained from your own sources.<br />In this example, I will show you how to make Real World Terrain use your own elevation data.</p><p>How to use this:<br />Place the script in Editor folder.<br />Modify OnGetElevation and OnGetElevationRange methods for your source.<br />To start intercepting values, select RWT / Intercept Elevation and click Intercept.<br />After generating the terrains, click Release.</p><div class="codebox"><pre><code>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(&quot;Intercept&quot;))
        {
            // 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(&quot;Release&quot;))
        {
            RealWorldTerrainElevationGenerator.OnGetElevation -= OnGetElevation;
            RealWorldTerrainElevationGenerator.OnGetElevationRange -= OnGetElevationRange;
            isIntercepted = false;
        }

        EditorGUI.EndDisabledGroup();
    }

    /// &lt;summary&gt;
    /// 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.
    /// &lt;/summary&gt;
    /// &lt;param name=&quot;minEl&quot;&gt;Minimum elevation for the area (meters)&lt;/param&gt;
    /// &lt;param name=&quot;maxEl&quot;&gt;Maximum elevation for the area (meters)&lt;/param&gt;
    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.
    }

    /// &lt;summary&gt;
    /// This method will be called when the RWT wants to get the elevation value from the provider
    /// &lt;/summary&gt;
    /// &lt;param name=&quot;mx&quot;&gt;Mercator position X (0-1)&lt;/param&gt;
    /// &lt;param name=&quot;my&quot;&gt;Mercator position Y (0-1)&lt;/param&gt;
    /// &lt;returns&gt;Elevation value in meters or null (if you need to get elevation value from the provider)&lt;/returns&gt;
    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(&quot;RWT/Intercept Elevation&quot;)]
    private static void OpenWindow()
    {
        GetWindow&lt;InterceptGetElevationExample&gt;(&quot;Intercept Elevation&quot;);
    }
}</code></pre></div>]]></description>
			<author><![CDATA[null@example.com (Alex Vertax)]]></author>
			<pubDate>Tue, 09 Jun 2020 21:29:10 +0000</pubDate>
			<guid>https://forum.infinity-code.com/viewtopic.php?pid=6345#p6345</guid>
		</item>
	</channel>
</rss>
