Topic: Use TilesetOverlayUsingShader as layers
Hi Alex, I hope all is well.
I've done some testing with your "TilesetOverlayUsingShader" and it's great for my needs. It's just missing one feature that I can't implement and it would be perfect for me. I would like to have more GameObjects with OverlayShader in the scene and use them as real superimposable "LAYERS" like Photoshop layers so to speak. Now if I add a new GameObject with OverlayShader it "deletes" the previous one. I hope I explained myself correctly. Thanks Alex. Here is the script I tested:
using System;
using UnityEngine;
using UnityEngine.UI;
public class TilesetOverlayUsingShader : MonoBehaviour
{
public OnlineMapsTileSetControl control;
// Overlay texture in mercator projection
public Texture texture;
/// <summary>
/// Border coordinates of the overlay
/// </summary>
public double Nord_topLatitude;
public double Ovest_leftLongitude;
public double Est_rightLongitude;
public double Sud_bottomLatitude;
// Reference to the UI Slider
public Slider alphaSlider;
// Overlay transparency
[Range(0, 1)]
public float alpha = 1;
private float _alpha = 1;
private void Start()
{
if (control == null) control = OnlineMapsTileSetControl.instance;
// Subscribe to events
OnlineMapsTileSetControl.instance.OnMeshUpdated += UpdateOverlay;
UpdateOverlay();
}
private void Update()
{
if (_alpha != alpha)
{
_alpha = alpha;
UpdateOverlay();
}
}
private void UpdateOverlay()
{
Vector3 p1 = control.GetWorldPosition(Ovest_leftLongitude, Nord_topLatitude);
Vector3 p2 = control.GetWorldPosition(Est_rightLongitude, Sud_bottomLatitude);
Shader.SetGlobalTexture("_OverlayTex", texture);
Shader.SetGlobalFloat("_OverlayAlpha", _alpha);
Shader.SetGlobalVector("_OverlayTL", p1);
Shader.SetGlobalVector("_OverlayBR", p2);
}
public void OnAlphaSliderValueChanged(float value)
{
alpha = value;
UpdateOverlay();
}
}