Topic: Fade in option for changing textures

Hello, can you create a fade in option for textures that come in after zooming/panning? The way it is now is to "raw" and a bit "aggressive" smile.

Thank you!

Re: Fade in option for changing textures

Hello.

Unfortunately, I did not understand your request.
Please explain this in more detail.

Kind Regards,
Infinity Code Team

Re: Fade in option for changing textures

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!

Re: Fade in option for changing textures

Hello.

In the next version we will add this feature.
I'll let you know when it's ready.

Kind Regards,
Infinity Code Team

Re: Fade in option for changing textures

Do you have an approximate time for this? I really need this feature and I'm probably gonna have to implement it myself. In this case can you provide me guidelines?

Re: Fade in option for changing textures

Hello

Example how to do this I will give right now.
The new version of Online Maps, where you can use it, we will release August 5-8.
We have a lot of work, planned for this version, and I'm not sure that we will be able to release it today.

Example (requires Online Maps v2.4.0.61+):

using System.Collections.Generic;
using UnityEngine;

public class TilesetFadeExample2:MonoBehaviour
{
    public static float duration = 0.3f;
    private Dictionary<Material, Item> 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<Material, Item>();

        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<Material, Item> 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 >= 1) data.alpha = 1;
                }
            }
        }

        foreach (KeyValuePair<Material, Item> 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 >= 1)
            {
                if (!isModified) return;

                material.mainTexture = tile.texture;
                material.mainTextureScale = originalScale;
                material.mainTextureOffset = originalOffset;
                material.SetTexture("_OverlayBackTex", 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 < 0) parentOffset.y += 1;

                TileData parentData = cParent.customData as TileData;
                if (parentData.alpha >= 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("_OverlayBackTex", overlayTexture);
            material.SetTextureScale("_OverlayBackTex", scale);
            material.SetTextureOffset("_OverlayBackTex", offset);
            material.SetFloat("_OverlayBackAlpha", (currentTile.customData as TileData).alpha);
            isModified = true;
        }
    }

    internal class TileData
    {
        public float alpha;
    }
}
Kind Regards,
Infinity Code Team

7 (edited by gamar 2016-08-10 15:22:34)

Re: Fade in option for changing textures

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?

Thanks!

Re: Fade in option for changing textures

Hello.

Unfortunately, currently I have no idea how to implement it.
If you have any suggestions how to implement it, we can discuss it.

Kind Regards,
Infinity Code Team

Re: Fade in option for changing textures

I see that you are setting the back texture. Should one set the front texture when zooming out? Or they are not related?

Re: Fade in option for changing textures

Problem 1:
When zoom in, the new texture - a quarter of the old texture.
When zoom out, the new texture - four old textures.

Problem 2:
When zoom out, the old tiles are immediately are unloaded to free memory.

Kind Regards,
Infinity Code Team

Re: Fade in option for changing textures

I tried to mail you but your email server is rejecting my emails. Anything I can do about it?

Re: Fade in option for changing textures

Hello.

Strange. Today, I have already answered a lot of emails in support.
I PM you a few of my personal emails.
Try to write.

Kind Regards,
Infinity Code Team