Topic: Overlay Issue

Hello!
I've used the overlay example below to create an overlay with a toggle button
https://infinity-code.com/atlas/online- … ample.html

The issue I'm facing is that the overlay always shows no matter what the alpha is set to.
It is worth noting that I don't have the full content to use yet so I've only been using one zoom level of another map, but I don't think that should affect it.

Am I missing something with regard to how this works? Code is below but I believe this would happen with the unedited code from the overlay page.

Thanks

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class ShipwrecksToggle : MonoBehaviour
{
    public string overlayPath;
    public Sprite toggleOn;
    public Sprite toggleOff;
    public Image toggleImage;
    private bool toggle = false;

    // Overlay transparency
    [Range(0, 1)]
    public float alpha = 1;

    private float _alpha = 1;

    private void Start()
    {
        toggle = false;
        toggleImage.sprite = toggleOff;
        alpha = 0f;

        if (OnlineMapsCache.instance != null)
        {
            // Subscribe to the cache events.
            OnlineMapsCache.instance.OnLoadedFromCache += LoadTileOverlay;
        }

        // Subscribe to the tile download event.
        OnlineMapsTileManager.OnStartDownloadTile += OnStartDownloadTile;
    }

    private static void LoadTileOverlay(OnlineMapsTile tile)
    {
        // Load overlay for tile from Resources.
        string path = string.Format("OnlineMapsOverlay/{0}/{1}/{2}", tile.zoom, tile.x, tile.y);
        Texture2D texture = Resources.Load<Texture2D>(path);

        if (texture != null)
        {
            tile.overlayBackTexture = Instantiate(texture);
            Resources.UnloadAsset(texture);
        }
    }

    private void OnStartDownloadTile(OnlineMapsTile tile)
    {
        // Load overlay for tile.
        LoadTileOverlay(tile);

        // Load the tile using a standard loader.
        OnlineMapsTileManager.StartDownloadTile(tile);
    }

    private void Update()
    {
        // Update the transparency of overlay.
        if (Math.Abs(_alpha - alpha) > float.Epsilon)
        {
            _alpha = alpha;
            lock (OnlineMapsTile.lockTiles)
            {
                foreach (OnlineMapsTile tile in OnlineMaps.instance.tileManager.tiles) tile.overlayBackAlpha = alpha;
            }
        }
    }

    public void ToggleOverlay()
    {
        toggle = !toggle;

        if(toggle == true)
        {
            toggleImage.sprite = toggleOn;
            alpha = 1f;
        }
        else
        {
            toggleImage.sprite = toggleOff;
            alpha = 0f;
        }
    }
}

Re: Overlay Issue

Hello.

In Update, after you have set overlayBackAlpha for all tiles, you need to call OnlineMaps.instance.Redraw().

Kind Regards,
Infinity Code Team.

Boost your productivity a lot and immediately using Ultimate Editor Enhancer. Trial and non-commerce versions available.

Re: Overlay Issue

Alex Vertax wrote:

Hello.

In Update, after you have set overlayBackAlpha for all tiles, you need to call OnlineMaps.instance.Redraw().

Ahhh of course I see.
Thanks very much.

What about if I wanted to set the alpha to 0 after the start btw?
It seems to lock to lock to 1 even if I set it in a few places in the start

Re: Overlay Issue

You can't set this to Start because the tiles might not exist yet.
You have two ways:
1. Use OnlineMapsTileManager.OnPrepareDownloadTile to set alpha = 0.
2. (not recommended) Modify the source code to set 0 as the default value.

Kind Regards,
Infinity Code Team.

Boost your productivity a lot and immediately using Ultimate Editor Enhancer. Trial and non-commerce versions available.

Re: Overlay Issue

Legend thanks!