Change texture of 2D markers

Back
Tags:
Marker
Marker 2D
Texture
Example of a dynamic change texture of 2D marker.
Usage instructions:
Add this script to map GameObject, select marker texture and start the scene.
Important: Make sure «Read / Write Enabled - ON» in Texture Importer.
Click «Change markers» to replace the texture of all markers.
ChangeMarkerTextureExample.cs
/*         INFINITY CODE         */
/*   https://infinity-code.com   */

using UnityEngine;

namespace InfinityCode.OnlineMapsExamples
{
    /// <summary>
    /// Example of a dynamic change texture of 2D marker.
    /// </summary>
    [AddComponentMenu("Infinity Code/Online Maps/Examples (API Usage)/ChangeMarkerTextureExample")]
    public class ChangeMarkerTextureExample : MonoBehaviour
    {
        /// <summary>
        /// Reference to the map. If not specified, the current instance will be used.
        /// </summary>
        public OnlineMaps map;
        
        /// <summary>
        /// New texture for markers. Must have "Read / Write Enabled - ON".
        /// </summary>
        public Texture2D newMarkerTexture;

        private void Start()
        {
            // If map is not specified, use the current instance.
            if (map == null) map = OnlineMaps.instance;
        }

        private void OnGUI()
        {
            // When you click on ...
            if (GUI.Button(new Rect(10, 10, 100, 20), "Change markers"))
            {
                // ... all markers will change the texture.
                foreach (OnlineMapsMarker marker in map.markerManager)
                {
                    marker.texture = newMarkerTexture;
                    marker.Init();
                }

                // Redraw map
                map.Redraw();
            }
        }
    }
}