<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[Infinity Code Forum — Fade in option for changing textures]]></title>
	<link rel="self" href="https://forum.infinity-code.com/extern.php?action=feed&amp;tid=177&amp;type=atom" />
	<updated>2016-08-18T16:05:21Z</updated>
	<generator>PunBB</generator>
	<id>https://forum.infinity-code.com/viewtopic.php?id=177</id>
		<entry>
			<title type="html"><![CDATA[Re: Fade in option for changing textures]]></title>
			<link rel="alternate" href="https://forum.infinity-code.com/viewtopic.php?pid=1133#p1133" />
			<content type="html"><![CDATA[<p>Hello.</p><p>Strange. Today, I have already answered a lot of emails in support.<br />I PM you a few of my personal emails.<br />Try to write.</p>]]></content>
			<author>
				<name><![CDATA[Alex Vertax]]></name>
				<uri>https://forum.infinity-code.com/profile.php?id=2</uri>
			</author>
			<updated>2016-08-18T16:05:21Z</updated>
			<id>https://forum.infinity-code.com/viewtopic.php?pid=1133#p1133</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Fade in option for changing textures]]></title>
			<link rel="alternate" href="https://forum.infinity-code.com/viewtopic.php?pid=1132#p1132" />
			<content type="html"><![CDATA[<p>I tried to mail you but your email server is rejecting my emails. Anything I can do about it?</p>]]></content>
			<author>
				<name><![CDATA[gamar]]></name>
				<uri>https://forum.infinity-code.com/profile.php?id=162</uri>
			</author>
			<updated>2016-08-18T15:58:28Z</updated>
			<id>https://forum.infinity-code.com/viewtopic.php?pid=1132#p1132</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Fade in option for changing textures]]></title>
			<link rel="alternate" href="https://forum.infinity-code.com/viewtopic.php?pid=1099#p1099" />
			<content type="html"><![CDATA[<p>Problem 1:<br />When zoom in, the new texture - a quarter of the old texture.<br />When zoom out, the new texture - four old textures.</p><p>Problem 2:<br />When zoom out, the old tiles are immediately are unloaded to free memory.</p>]]></content>
			<author>
				<name><![CDATA[Alex Vertax]]></name>
				<uri>https://forum.infinity-code.com/profile.php?id=2</uri>
			</author>
			<updated>2016-08-11T17:58:13Z</updated>
			<id>https://forum.infinity-code.com/viewtopic.php?pid=1099#p1099</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Fade in option for changing textures]]></title>
			<link rel="alternate" href="https://forum.infinity-code.com/viewtopic.php?pid=1096#p1096" />
			<content type="html"><![CDATA[<p>I see that you are setting the back texture. Should one set the front texture when zooming out? Or they are not related?</p>]]></content>
			<author>
				<name><![CDATA[gamar]]></name>
				<uri>https://forum.infinity-code.com/profile.php?id=162</uri>
			</author>
			<updated>2016-08-11T16:51:11Z</updated>
			<id>https://forum.infinity-code.com/viewtopic.php?pid=1096#p1096</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Fade in option for changing textures]]></title>
			<link rel="alternate" href="https://forum.infinity-code.com/viewtopic.php?pid=1095#p1095" />
			<content type="html"><![CDATA[<p>Hello.</p><p>Unfortunately, currently I have no idea how to implement it.<br />If you have any suggestions how to implement it, we can discuss it.</p>]]></content>
			<author>
				<name><![CDATA[Alex Vertax]]></name>
				<uri>https://forum.infinity-code.com/profile.php?id=2</uri>
			</author>
			<updated>2016-08-11T14:46:37Z</updated>
			<id>https://forum.infinity-code.com/viewtopic.php?pid=1095#p1095</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Fade in option for changing textures]]></title>
			<link rel="alternate" href="https://forum.infinity-code.com/viewtopic.php?pid=1084#p1084" />
			<content type="html"><![CDATA[<p>Hey, for some reason the code you gave only fades when zooming in and not zooming out. I tried to look at it but I have no idea why to be honest. Can you please help me out? </p><p>Thanks!</p>]]></content>
			<author>
				<name><![CDATA[gamar]]></name>
				<uri>https://forum.infinity-code.com/profile.php?id=162</uri>
			</author>
			<updated>2016-08-10T15:21:57Z</updated>
			<id>https://forum.infinity-code.com/viewtopic.php?pid=1084#p1084</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Fade in option for changing textures]]></title>
			<link rel="alternate" href="https://forum.infinity-code.com/viewtopic.php?pid=1047#p1047" />
			<content type="html"><![CDATA[<p>Hello</p><p>Example how to do this I will give right now.<br />The new version of Online Maps, where you can use it, we will release August 5-8.<br />We have a lot of work, planned for this version, and I&#039;m not sure that we will be able to release it today.</p><p>Example (requires Online Maps v2.4.0.61+):<br /></p><div class="codebox"><pre><code>using System.Collections.Generic;
using UnityEngine;

public class TilesetFadeExample2:MonoBehaviour
{
    public static float duration = 0.3f;
    private Dictionary&lt;Material, Item&gt; items;

    private void OnDrawTile(OnlineMapsTile tile, Material material)
    {
        if (!items.ContainsKey(material)) items.Add(material, new Item(material));
        items[material].SetTile(tile);
    }

    private void Start()
    {
        items = new Dictionary&lt;Material, Item&gt;();

        OnlineMaps.instance.OnStartDownloadTile += OnStartDownloadTile;
        OnlineMapsTileSetControl.instance.OnDrawTile += OnDrawTile;
    }

    private void OnStartDownloadTile(OnlineMapsTile tile)
    {
        tile.customData = new TileData();
        tile.OnDisposed += OnTileDisposed;
        OnlineMaps.instance.StartDownloadTile(tile);
    }

    private void OnTileDisposed(OnlineMapsTile tile)
    {
        foreach (KeyValuePair&lt;Material, Item&gt; pair in items)
        {
            pair.Value.RemoveReference(tile);
        }
    }

    private void LateUpdate()
    {
        float alphaDelta = Time.deltaTime / duration;
        lock (OnlineMapsTile.tiles)
        {
            foreach (OnlineMapsTile tile in OnlineMapsTile.tiles)
            {
                if (tile.status == OnlineMapsTileStatus.loaded)
                {
                    TileData data = tile.customData as TileData;
                    data.alpha += alphaDelta;
                    if (data.alpha &gt;= 1) data.alpha = 1;
                }
            }
        }

        foreach (KeyValuePair&lt;Material, Item&gt; item in items)
        {
            item.Value.UpdateMaterial();
        }
    }

    internal class Item
    {
        private OnlineMapsTile tile;
        private TileData tileData;
        private bool isModified;
        private Material material;
        private Vector2 originalScale;
        private Vector2 originalOffset;

        public Item(Material material)
        {
            this.material = material;
        }

        public void SetTile(OnlineMapsTile tile)
        {
            this.tile = tile;
            tileData = tile.customData as TileData;
            isModified = false;
            originalScale = material.mainTextureScale;
            originalOffset = material.mainTextureOffset;
        }

        public void RemoveReference(OnlineMapsTile disposedTile)
        {
            if (tile == disposedTile)
            {
                tile = null;
                tileData = null;
            }
        }

        public void UpdateMaterial()
        {
            if (tile == null || tileData == null) return;
            if (tileData.alpha &gt;= 1)
            {
                if (!isModified) return;

                material.mainTexture = tile.texture;
                material.mainTextureScale = originalScale;
                material.mainTextureOffset = originalOffset;
                material.SetTexture(&quot;_OverlayBackTex&quot;, null);
                return;
            }

            OnlineMapsTile currentTile = tile;
            OnlineMapsTile parent = null;
            Vector2 scale = originalScale;
            Vector2 offset = originalOffset;
            Vector2 parentScale = Vector2.one;
            Vector2 parentOffset = Vector2.zero;

            while (currentTile.parent != null)
            {
                OnlineMapsTile cParent = currentTile.parent;

                parentScale = scale / 2;
                parentOffset.x = offset.x / 2 + (currentTile.x % 2 == 0 ? 0 : 0.5f);
                parentOffset.y = offset.y / 2 + (currentTile.y % 2 == 0 ? 0.5f: 0);
                if (parentOffset.y &lt; 0) parentOffset.y += 1;

                TileData parentData = cParent.customData as TileData;
                if (parentData.alpha &gt;= 1)
                {
                    parent = cParent;
                    break;
                }

                currentTile = cParent;
                offset = parentOffset;
                scale = parentScale;
            }

            if (parent == null)
            {
                parentScale = Vector2.one;
                parentOffset = Vector2.zero;
            }

            Texture mainTexture = parent != null ? parent.texture : OnlineMapsTile.emptyColorTexture;
            Texture overlayTexture = currentTile.texture;
            material.mainTexture = mainTexture;
            material.mainTextureScale = parentScale;
            material.mainTextureOffset = parentOffset;
            material.SetTexture(&quot;_OverlayBackTex&quot;, overlayTexture);
            material.SetTextureScale(&quot;_OverlayBackTex&quot;, scale);
            material.SetTextureOffset(&quot;_OverlayBackTex&quot;, offset);
            material.SetFloat(&quot;_OverlayBackAlpha&quot;, (currentTile.customData as TileData).alpha);
            isModified = true;
        }
    }

    internal class TileData
    {
        public float alpha;
    }
}</code></pre></div>]]></content>
			<author>
				<name><![CDATA[Alex Vertax]]></name>
				<uri>https://forum.infinity-code.com/profile.php?id=2</uri>
			</author>
			<updated>2016-08-05T11:52:56Z</updated>
			<id>https://forum.infinity-code.com/viewtopic.php?pid=1047#p1047</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Fade in option for changing textures]]></title>
			<link rel="alternate" href="https://forum.infinity-code.com/viewtopic.php?pid=1031#p1031" />
			<content type="html"><![CDATA[<p>Do you have an approximate time for this? I really need this feature and I&#039;m probably gonna have to implement it myself. In this case can you provide me guidelines?</p>]]></content>
			<author>
				<name><![CDATA[gamar]]></name>
				<uri>https://forum.infinity-code.com/profile.php?id=162</uri>
			</author>
			<updated>2016-08-04T12:42:52Z</updated>
			<id>https://forum.infinity-code.com/viewtopic.php?pid=1031#p1031</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Fade in option for changing textures]]></title>
			<link rel="alternate" href="https://forum.infinity-code.com/viewtopic.php?pid=813#p813" />
			<content type="html"><![CDATA[<p>Hello.</p><p>In the next version we will add this feature.<br />I&#039;ll let you know when it&#039;s ready.</p>]]></content>
			<author>
				<name><![CDATA[Alex Vertax]]></name>
				<uri>https://forum.infinity-code.com/profile.php?id=2</uri>
			</author>
			<updated>2016-06-29T16:59:25Z</updated>
			<id>https://forum.infinity-code.com/viewtopic.php?pid=813#p813</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Fade in option for changing textures]]></title>
			<link rel="alternate" href="https://forum.infinity-code.com/viewtopic.php?pid=807#p807" />
			<content type="html"><![CDATA[<p>On the tileset control, when new images(textures of map snippets are added) and basically replacing the old ones. Can you do a transition of fading from the previous to the new one? (something like the functionality available in apps like Google Maps). Thank you!</p>]]></content>
			<author>
				<name><![CDATA[gamar]]></name>
				<uri>https://forum.infinity-code.com/profile.php?id=162</uri>
			</author>
			<updated>2016-06-28T12:47:36Z</updated>
			<id>https://forum.infinity-code.com/viewtopic.php?pid=807#p807</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Fade in option for changing textures]]></title>
			<link rel="alternate" href="https://forum.infinity-code.com/viewtopic.php?pid=802#p802" />
			<content type="html"><![CDATA[<p>Hello.</p><p>Unfortunately, I did not understand your request.<br />Please explain this in more detail.</p>]]></content>
			<author>
				<name><![CDATA[Alex Vertax]]></name>
				<uri>https://forum.infinity-code.com/profile.php?id=2</uri>
			</author>
			<updated>2016-06-27T13:59:55Z</updated>
			<id>https://forum.infinity-code.com/viewtopic.php?pid=802#p802</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Fade in option for changing textures]]></title>
			<link rel="alternate" href="https://forum.infinity-code.com/viewtopic.php?pid=800#p800" />
			<content type="html"><![CDATA[<p>Hello, can you create a fade in option for textures that come in after zooming/panning? The way it is now is to &quot;raw&quot; and a bit &quot;aggressive&quot; <img src="https://forum.infinity-code.com/img/smilies/smile.png" width="15" height="15" alt="smile" />.</p><p>Thank you!</p>]]></content>
			<author>
				<name><![CDATA[gamar]]></name>
				<uri>https://forum.infinity-code.com/profile.php?id=162</uri>
			</author>
			<updated>2016-06-27T10:45:56Z</updated>
			<id>https://forum.infinity-code.com/viewtopic.php?pid=800#p800</id>
		</entry>
</feed>
