<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[Infinity Code Forum — Tutorials]]></title>
	<link rel="self" href="https://forum.infinity-code.com/extern.php?action=feed&amp;tid=659&amp;type=atom" />
	<updated>2017-09-25T18:06:38Z</updated>
	<generator>PunBB</generator>
	<id>https://forum.infinity-code.com/viewtopic.php?id=659</id>
		<entry>
			<title type="html"><![CDATA[Re: Tutorials]]></title>
			<link rel="alternate" href="https://forum.infinity-code.com/viewtopic.php?pid=2848#p2848" />
			<content type="html"><![CDATA[<p>No, it is not enough to clear the cache.</p><p>Another way is to create your own provider:<br /></p><div class="codebox"><pre><code>using System;
using System.Reflection;
using UnityEngine;

public class ChangeCustomStyle2:MonoBehaviour
{
    public string style1;
    public string style2;

    private bool useFirstStyle = true;

    private void OnGUI()
    {
        if (GUILayout.Button(&quot;Change Style&quot;))
        {
            useFirstStyle = !useFirstStyle;
            OnlineMaps.instance.mapType = &quot;myprovider.style&quot; + (useFirstStyle? &quot;1&quot;: &quot;2&quot;);
        }
    }

    private void Start()
    {
        // Online Maps v2.5.17 or less
        ConstructorInfo constructor = typeof(OnlineMapsProvider).GetConstructor(BindingFlags.NonPublic | BindingFlags.Instance, null, new[]{typeof(string)}, null);
        OnlineMapsProvider provider = (OnlineMapsProvider)constructor.Invoke(new []{&quot;myprovider&quot;});

        OnlineMapsProvider.MapType[] types =
        {
            new OnlineMapsProvider.MapType(&quot;style1&quot;)
            {
                urlWithLabels = style1,
                provider = provider,
                fullID = &quot;myprovider.style1&quot;
            },
            new OnlineMapsProvider.MapType(&quot;style2&quot;)
            {
                urlWithLabels = style2,
                provider = provider,
                fullID = &quot;myprovider.style2&quot;
            }
        };

        OnlineMapsProvider[] providers = OnlineMapsProvider.GetProviders();
        Array.Resize(ref providers, providers.Length + 1);
        providers[providers.Length - 1] = provider;

        typeof(OnlineMapsProvider).GetField(&quot;_types&quot;, BindingFlags.NonPublic | BindingFlags.Instance).SetValue(provider, types);
        typeof(OnlineMapsProvider).GetField(&quot;providers&quot;, BindingFlags.NonPublic | BindingFlags.Static).SetValue(null, providers);

        // Online Maps v2.5.18+
        /*OnlineMapsProvider.Create(&quot;myprovider&quot;).AppendTypes(
            new OnlineMapsProvider.MapType(&quot;style1&quot;) { urlWithLabels = style1, },
            new OnlineMapsProvider.MapType(&quot;style2&quot;) { urlWithLabels = style2, }
        );*/

        OnlineMaps.instance.mapType = &quot;myprovider.style1&quot;;
    }
}</code></pre></div><p>Note: the current version of Online Maps (2.5.17) does not have a good way to create your own provider, so I implemented this through reflection.<br />In Online Maps v2.5.18 we will add a way to dynamically create providers and map types.<br />So I showed you both ways.</p>]]></content>
			<author>
				<name><![CDATA[Alex Vertax]]></name>
				<uri>https://forum.infinity-code.com/profile.php?id=2</uri>
			</author>
			<updated>2017-09-25T18:06:38Z</updated>
			<id>https://forum.infinity-code.com/viewtopic.php?pid=2848#p2848</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Tutorials]]></title>
			<link rel="alternate" href="https://forum.infinity-code.com/viewtopic.php?pid=2845#p2845" />
			<content type="html"><![CDATA[<p>Do I just need to clear the cache?</p>]]></content>
			<author>
				<name><![CDATA[jamescorymills96]]></name>
				<uri>https://forum.infinity-code.com/profile.php?id=526</uri>
			</author>
			<updated>2017-09-25T01:43:14Z</updated>
			<id>https://forum.infinity-code.com/viewtopic.php?pid=2845#p2845</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Tutorials]]></title>
			<link rel="alternate" href="https://forum.infinity-code.com/viewtopic.php?pid=2844#p2844" />
			<content type="html"><![CDATA[<p>Thanks so much for the reply.</p><p>Sorry to be a bother, but how would I do it with the cache. For my project it is important that the cache updates as well.</p>]]></content>
			<author>
				<name><![CDATA[jamescorymills96]]></name>
				<uri>https://forum.infinity-code.com/profile.php?id=526</uri>
			</author>
			<updated>2017-09-24T23:45:47Z</updated>
			<id>https://forum.infinity-code.com/viewtopic.php?pid=2844#p2844</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Tutorials]]></title>
			<link rel="alternate" href="https://forum.infinity-code.com/viewtopic.php?pid=2839#p2839" />
			<content type="html"><![CDATA[<p>Hello.</p><p>Yes, you can change the style at runtime.<br />Example:<br /></p><div class="codebox"><pre><code>using UnityEngine;

public class ChangeCustomStyle:MonoBehaviour
{
    public string style1;
    public string style2;

    private bool useFirstStyle = true;

    private void OnGUI()
    {
        if (GUILayout.Button(&quot;Change Style&quot;))
        {
            useFirstStyle = !useFirstStyle;
            OnlineMaps.instance.customProviderURL = useFirstStyle? style1: style2;
            foreach (OnlineMapsTile tile in OnlineMapsTile.tiles) tile.Dispose();
            OnlineMapsTile.tiles.Clear();
            OnlineMaps.instance.Redraw();
        }
    }

    private void Start()
    {
        OnlineMaps.instance.customProviderURL = style1;
    }
}</code></pre></div><p>But keep in mind, this way will not work with Online Maps Cache.</p><p>This is not the only way.<br />There are many ways, each of which will have its advantages and disadvantages.</p>]]></content>
			<author>
				<name><![CDATA[Alex Vertax]]></name>
				<uri>https://forum.infinity-code.com/profile.php?id=2</uri>
			</author>
			<updated>2017-09-22T20:19:32Z</updated>
			<id>https://forum.infinity-code.com/viewtopic.php?pid=2839#p2839</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Tutorials]]></title>
			<link rel="alternate" href="https://forum.infinity-code.com/viewtopic.php?pid=2838#p2838" />
			<content type="html"><![CDATA[<p>Rather, I found the tutorial to add a custom map style, however, I would like to know if there is anyway to change the custom map style runtime?</p>]]></content>
			<author>
				<name><![CDATA[jamescorymills96]]></name>
				<uri>https://forum.infinity-code.com/profile.php?id=526</uri>
			</author>
			<updated>2017-09-22T07:37:45Z</updated>
			<id>https://forum.infinity-code.com/viewtopic.php?pid=2838#p2838</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Tutorials]]></title>
			<link rel="alternate" href="https://forum.infinity-code.com/viewtopic.php?pid=2837#p2837" />
			<content type="html"><![CDATA[<p>Could someone please point me to the tutorials for the google maps styling stuff? I can&#039;t seem to find them anywhere <img src="https://forum.infinity-code.com/img/smilies/sad.png" width="15" height="15" alt="sad" /></p>]]></content>
			<author>
				<name><![CDATA[jamescorymills96]]></name>
				<uri>https://forum.infinity-code.com/profile.php?id=526</uri>
			</author>
			<updated>2017-09-22T05:52:55Z</updated>
			<id>https://forum.infinity-code.com/viewtopic.php?pid=2837#p2837</id>
		</entry>
</feed>
