<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[Infinity Code Forum — Overlay Issue]]></title>
	<link rel="self" href="https://forum.infinity-code.com/extern.php?action=feed&amp;tid=2062&amp;type=atom" />
	<updated>2022-11-18T15:49:18Z</updated>
	<generator>PunBB</generator>
	<id>https://forum.infinity-code.com/viewtopic.php?id=2062</id>
		<entry>
			<title type="html"><![CDATA[Re: Overlay Issue]]></title>
			<link rel="alternate" href="https://forum.infinity-code.com/viewtopic.php?pid=8749#p8749" />
			<content type="html"><![CDATA[<p>Legend thanks!</p>]]></content>
			<author>
				<name><![CDATA[AT_Mike]]></name>
				<uri>https://forum.infinity-code.com/profile.php?id=2328</uri>
			</author>
			<updated>2022-11-18T15:49:18Z</updated>
			<id>https://forum.infinity-code.com/viewtopic.php?pid=8749#p8749</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Overlay Issue]]></title>
			<link rel="alternate" href="https://forum.infinity-code.com/viewtopic.php?pid=8748#p8748" />
			<content type="html"><![CDATA[<p>You can&#039;t set this to Start because the tiles might not exist yet.<br />You have two ways:<br />1. Use OnlineMapsTileManager.OnPrepareDownloadTile to set alpha = 0.<br />2. (not recommended) Modify the source code to set 0 as the default value.</p>]]></content>
			<author>
				<name><![CDATA[Alex Vertax]]></name>
				<uri>https://forum.infinity-code.com/profile.php?id=2</uri>
			</author>
			<updated>2022-11-18T15:19:52Z</updated>
			<id>https://forum.infinity-code.com/viewtopic.php?pid=8748#p8748</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Overlay Issue]]></title>
			<link rel="alternate" href="https://forum.infinity-code.com/viewtopic.php?pid=8747#p8747" />
			<content type="html"><![CDATA[<div class="quotebox"><cite>Alex Vertax wrote:</cite><blockquote><p>Hello.</p><p>In Update, after you have set overlayBackAlpha for all tiles, you need to call OnlineMaps.instance.Redraw().</p></blockquote></div><p>Ahhh of course I see.<br />Thanks very much.</p><p>What about if I wanted to set the alpha to 0 after the start btw?<br />It seems to lock to lock to 1 even if I set it in a few places in the start</p>]]></content>
			<author>
				<name><![CDATA[AT_Mike]]></name>
				<uri>https://forum.infinity-code.com/profile.php?id=2328</uri>
			</author>
			<updated>2022-11-18T14:59:58Z</updated>
			<id>https://forum.infinity-code.com/viewtopic.php?pid=8747#p8747</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Overlay Issue]]></title>
			<link rel="alternate" href="https://forum.infinity-code.com/viewtopic.php?pid=8744#p8744" />
			<content type="html"><![CDATA[<p>Hello.</p><p>In Update, after you have set overlayBackAlpha for all tiles, you need to call OnlineMaps.instance.Redraw().</p>]]></content>
			<author>
				<name><![CDATA[Alex Vertax]]></name>
				<uri>https://forum.infinity-code.com/profile.php?id=2</uri>
			</author>
			<updated>2022-11-18T14:21:16Z</updated>
			<id>https://forum.infinity-code.com/viewtopic.php?pid=8744#p8744</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Overlay Issue]]></title>
			<link rel="alternate" href="https://forum.infinity-code.com/viewtopic.php?pid=8742#p8742" />
			<content type="html"><![CDATA[<p>Hello!<br />I&#039;ve used the overlay example below to create an overlay with a toggle button<br /><a href="https://infinity-code.com/atlas/online-maps/pages/TilesetMapTilerOverlayExample.html">https://infinity-code.com/atlas/online- … ample.html</a></p><p>The issue I&#039;m facing is that the overlay always shows no matter what the alpha is set to.<br />It is worth noting that I don&#039;t have the full content to use yet so I&#039;ve only been using one zoom level of another map, but I don&#039;t think that should affect it.</p><p>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.</p><p>Thanks</p><div class="codebox"><pre><code>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(&quot;OnlineMapsOverlay/{0}/{1}/{2}&quot;, tile.zoom, tile.x, tile.y);
        Texture2D texture = Resources.Load&lt;Texture2D&gt;(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) &gt; 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;
        }
    }
}</code></pre></div>]]></content>
			<author>
				<name><![CDATA[AT_Mike]]></name>
				<uri>https://forum.infinity-code.com/profile.php?id=2328</uri>
			</author>
			<updated>2022-11-18T12:20:46Z</updated>
			<id>https://forum.infinity-code.com/viewtopic.php?pid=8742#p8742</id>
		</entry>
</feed>
