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;
}
}
}