<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[Infinity Code Forum — Customizing Line Style]]></title>
	<link rel="self" href="https://forum.infinity-code.com/extern.php?action=feed&amp;tid=462&amp;type=atom" />
	<updated>2017-05-21T17:55:19Z</updated>
	<generator>PunBB</generator>
	<id>https://forum.infinity-code.com/viewtopic.php?id=462</id>
		<entry>
			<title type="html"><![CDATA[Re: Customizing Line Style]]></title>
			<link rel="alternate" href="https://forum.infinity-code.com/viewtopic.php?pid=2387#p2387" />
			<content type="html"><![CDATA[<p>Thank you very much, this works great!!</p>]]></content>
			<author>
				<name><![CDATA[DaGround]]></name>
				<uri>https://forum.infinity-code.com/profile.php?id=199</uri>
			</author>
			<updated>2017-05-21T17:55:19Z</updated>
			<id>https://forum.infinity-code.com/viewtopic.php?pid=2387#p2387</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Customizing Line Style]]></title>
			<link rel="alternate" href="https://forum.infinity-code.com/viewtopic.php?pid=2383#p2383" />
			<content type="html"><![CDATA[<p>You can work around this in this way:<br /></p><div class="codebox"><pre><code>using System.Collections.Generic;
using System.Reflection;
using UnityEngine;

public class DrawLineWithTexture:MonoBehaviour
{
    public Texture2D lineTexture;
    private OnlineMapsMarker marker1;
    private OnlineMapsMarker marker2;
    private OnlineMapsDrawingLine line;

    private void Start()
    {
        OnlineMapsControlBase.instance.OnMapClick += OnMapClick;
    }

    private void OnMapClick()
    {
        OnlineMapsMarker marker = OnlineMaps.instance.AddMarker(OnlineMapsControlBase.instance.GetCoords());

        if (marker1 == null)
        {
            marker1 = marker;
            return;
        }

        marker2 = marker;
        List&lt;Vector2&gt; points = new List&lt;Vector2&gt;
        {
            marker1.position,
            marker2.position
        };
        line = new OnlineMapsDrawingLine(points, Color.red, 10);
        line.texture = lineTexture;
        OnlineMaps.instance.AddDrawingElement(line);
        OnlineMaps.instance.OnMapUpdated += OnMapUpdated; // Delay because the line is not yet drawn.

        marker1.OnDrag += OnMarkerDrag;
        marker2.OnDrag += OnMarkerDrag;
        OnlineMapsControlBase.instance.OnMapClick -= OnMapClick;
    }

    private void OnMapUpdated()
    {
        UpdateUVScale();
        OnlineMaps.instance.OnMapUpdated -= OnMapUpdated;
    }

    private void OnMarkerDrag(OnlineMapsMarkerBase marker)
    {
        List&lt;Vector2&gt; points = new List&lt;Vector2&gt;
        {
            marker1.position,
            marker2.position
        };
        line.points = points;

        UpdateUVScale();

        OnlineMaps.instance.Redraw();
    }

    private void UpdateUVScale()
    {
        FieldInfo field = line.GetType().GetField(&quot;gameObject&quot;, BindingFlags.NonPublic | BindingFlags.Instance);
        if (field == null)
        {
            Debug.Log(&quot;No field&quot;);
            return;
        }
        GameObject lineGO = field.GetValue(line) as GameObject;

        MeshFilter meshFilter = lineGO.GetComponent&lt;MeshFilter&gt;();
        Vector3[] vertices = meshFilter.sharedMesh.vertices;

        float distance = 0;

        for (int i = 2; i &lt; vertices.Length; i += 2) distance += (vertices[i - 2] - vertices[i]).magnitude;

        distance /= line.width * 2;

        MeshRenderer meshRenderer = lineGO.GetComponent&lt;MeshRenderer&gt;();
        meshRenderer.sharedMaterials[0].mainTextureScale = new Vector2(1, distance);
    }
}</code></pre></div><p>Yes, this is a bad practice and a dirty hack, but I do not know how to do this without access to the vertices.<br />Theoretically, we can make gameObject field public.</p>]]></content>
			<author>
				<name><![CDATA[Alex Vertax]]></name>
				<uri>https://forum.infinity-code.com/profile.php?id=2</uri>
			</author>
			<updated>2017-05-19T10:47:19Z</updated>
			<id>https://forum.infinity-code.com/viewtopic.php?pid=2383#p2383</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Customizing Line Style]]></title>
			<link rel="alternate" href="https://forum.infinity-code.com/viewtopic.php?pid=2381#p2381" />
			<content type="html"><![CDATA[<p>thanks for the answer, </p><p>i would like to stay with the intuitive DrawingLines, but just settings a texture doesnt help, it is getting scaled so unproportional with inreasing line length. Is there maybe a way to set a material with proper texture scaling for the lines?</p><p>please notice the image for the scaling issue</p><p><span class="postimg"><img src="https://picload.org/image/riricidi/scalings.jpg" alt="PunBB bbcode test" /></span></p>]]></content>
			<author>
				<name><![CDATA[DaGround]]></name>
				<uri>https://forum.infinity-code.com/profile.php?id=199</uri>
			</author>
			<updated>2017-05-18T21:35:44Z</updated>
			<id>https://forum.infinity-code.com/viewtopic.php?pid=2381#p2381</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Customizing Line Style]]></title>
			<link rel="alternate" href="https://forum.infinity-code.com/viewtopic.php?pid=2379#p2379" />
			<content type="html"><![CDATA[<p>Hello</p><p>For example, in this way:<br /><a href="http://infinity-code.com/atlas/online-maps/pages/DottedLineExample.html">http://infinity-code.com/atlas/online-m … ample.html</a></p><p>Or using OnlineMapsDrawingLine.texture:<br /><a href="http://infinity-code.com/doxygen/online-maps/classOnlineMapsDrawingLine.html#a46bc9f411874a5e545a0764322fce7eb">http://infinity-code.com/doxygen/online … 4322fce7eb</a></p>]]></content>
			<author>
				<name><![CDATA[Alex Vertax]]></name>
				<uri>https://forum.infinity-code.com/profile.php?id=2</uri>
			</author>
			<updated>2017-05-18T19:46:09Z</updated>
			<id>https://forum.infinity-code.com/viewtopic.php?pid=2379#p2379</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Customizing Line Style]]></title>
			<link rel="alternate" href="https://forum.infinity-code.com/viewtopic.php?pid=2376#p2376" />
			<content type="html"><![CDATA[<p>When we cannot customize these Lines, do you have an suggestion how i could achieve this effekt?</p><p><span class="postimg"><img src="https://i.ytimg.com/vi/ozryKOSPTk4/maxresdefault.jpg" alt="PunBB bbcode test" /></span></p><br /><br /><p>im currently stuck with linedrawing on this, with a bunch of colors. </p><p><span class="postimg"><img src="https://picload.org/image/rircrgil/035c6bca-56ec-4cd6-b1df-b33560.jpg" alt="PunBB bbcode test" /></span></p><p>I at least need some kind of indicator in wich direction these lines are pointing .</p><p>Thank you!</p>]]></content>
			<author>
				<name><![CDATA[DaGround]]></name>
				<uri>https://forum.infinity-code.com/profile.php?id=199</uri>
			</author>
			<updated>2017-05-18T11:27:03Z</updated>
			<id>https://forum.infinity-code.com/viewtopic.php?pid=2376#p2376</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Customizing Line Style]]></title>
			<link rel="alternate" href="https://forum.infinity-code.com/viewtopic.php?pid=2034#p2034" />
			<content type="html"><![CDATA[<p>Thx for your help.<br />I shoulld use tileset control with mainCamera~!</p>]]></content>
			<author>
				<name><![CDATA[joonyboy]]></name>
				<uri>https://forum.infinity-code.com/profile.php?id=306</uri>
			</author>
			<updated>2017-03-17T01:02:32Z</updated>
			<id>https://forum.infinity-code.com/viewtopic.php?pid=2034#p2034</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Customizing Line Style]]></title>
			<link rel="alternate" href="https://forum.infinity-code.com/viewtopic.php?pid=2026#p2026" />
			<content type="html"><![CDATA[<p>Hello.</p><p>Unfortunately, there is no way to customize the line style.<br />To work around this, you can draw a line using NGUI (of course if NGUI supports this and you have programming experience).<br />Or you can use tileset control. This is supports textures for lines.</p>]]></content>
			<author>
				<name><![CDATA[Alex Vertax]]></name>
				<uri>https://forum.infinity-code.com/profile.php?id=2</uri>
			</author>
			<updated>2017-03-16T11:41:42Z</updated>
			<id>https://forum.infinity-code.com/viewtopic.php?pid=2026#p2026</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Customizing Line Style]]></title>
			<link rel="alternate" href="https://forum.infinity-code.com/viewtopic.php?pid=2024#p2024" />
			<content type="html"><![CDATA[<p>I use AddDrawingElement function to draw the line on Map (NGUI Texture).</p><p>OnlineMaps.instance.AddDrawingElement(new OnlineMapsDrawingLine(list, Color.green, 3f));</p><p>But is there way to customizing the line style? (for example, using my own sprite image to draw line on Map)</p><p>I attached screen shot to help understand the situation.</p>]]></content>
			<author>
				<name><![CDATA[joonyboy]]></name>
				<uri>https://forum.infinity-code.com/profile.php?id=306</uri>
			</author>
			<updated>2017-03-16T04:45:20Z</updated>
			<id>https://forum.infinity-code.com/viewtopic.php?pid=2024#p2024</id>
		</entry>
</feed>
