1 (edited by joonyboy 2017-03-16 06:27:32)

Topic: Customizing Line Style

I use AddDrawingElement function to draw the line on Map (NGUI Texture).

OnlineMaps.instance.AddDrawingElement(new OnlineMapsDrawingLine(list, Color.green, 3f));

But is there way to customizing the line style? (for example, using my own sprite image to draw line on Map)

I attached screen shot to help understand the situation.

Re: Customizing Line Style

Hello.

Unfortunately, there is no way to customize the line style.
To work around this, you can draw a line using NGUI (of course if NGUI supports this and you have programming experience).
Or you can use tileset control. This is supports textures for lines.

Kind Regards,
Infinity Code Team.

Boost your productivity a lot and immediately using Ultimate Editor Enhancer. Trial and non-commerce versions available.

Re: Customizing Line Style

Thx for your help.
I shoulld use tileset control with mainCamera~!

Re: Customizing Line Style

When we cannot customize these Lines, do you have an suggestion how i could achieve this effekt?

PunBB bbcode test



im currently stuck with linedrawing on this, with a bunch of colors.

PunBB bbcode test

I at least need some kind of indicator in wich direction these lines are pointing .

Thank you!

Re: Customizing Line Style

Hello

For example, in this way:
http://infinity-code.com/atlas/online-m … ample.html

Or using OnlineMapsDrawingLine.texture:
http://infinity-code.com/doxygen/online … 4322fce7eb

Kind Regards,
Infinity Code Team.

Boost your productivity a lot and immediately using Ultimate Editor Enhancer. Trial and non-commerce versions available.

Re: Customizing Line Style

thanks for the answer,

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?

please notice the image for the scaling issue

PunBB bbcode test

Re: Customizing Line Style

You can work around this in this way:

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<Vector2> points = new List<Vector2>
        {
            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<Vector2> points = new List<Vector2>
        {
            marker1.position,
            marker2.position
        };
        line.points = points;

        UpdateUVScale();

        OnlineMaps.instance.Redraw();
    }

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

        MeshFilter meshFilter = lineGO.GetComponent<MeshFilter>();
        Vector3[] vertices = meshFilter.sharedMesh.vertices;

        float distance = 0;

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

        distance /= line.width * 2;

        MeshRenderer meshRenderer = lineGO.GetComponent<MeshRenderer>();
        meshRenderer.sharedMaterials[0].mainTextureScale = new Vector2(1, distance);
    }
}

Yes, this is a bad practice and a dirty hack, but I do not know how to do this without access to the vertices.
Theoretically, we can make gameObject field public.

Kind Regards,
Infinity Code Team.

Boost your productivity a lot and immediately using Ultimate Editor Enhancer. Trial and non-commerce versions available.

Re: Customizing Line Style

Thank you very much, this works great!!