1 (edited by codemogen 2022-10-23 13:57:17)

Topic: [SOLVED!]Single Line to Dotted Line

Hello Alex,

I use FindDirectionExample to create a path between two points. Inside the FindDirectionExample use OnlineMapsDrawingLine to create a single line between two points but I want to turn it into a Dotted line. I review DottedLineExample but I didn't get how to use lon/lat coords with DottedLineExample. Is there any way to create a dotted line between two points with coordinates? (lon/lat)

Thank you.

Re: [SOLVED!]Single Line to Dotted Line

Hello.

In this example, coords is Vector2 array where X is longitude and Y is latitude.

Kind Regards,
Infinity Code Team.

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

3 (edited by codemogen 2022-09-21 08:56:27)

Re: [SOLVED!]Single Line to Dotted Line

Is that enough to give coords as vector2 here? Because I gave the start point coords and end point coords here like ;

coords = new Vector2[2];
coords[0] = new Vector2(longitude, latitude);
coords[1] = new Vector2(longitude, latitude);

and I add it as a component to my map. But doesn't appear on the screen.

I attached screen shot

Parameters which I gave to DottedLineExample :
Size : 10,
Uv Scale : x => 2, y => 1
Material : (I created standard material with random color)

Post's attachments

Attachment icon Screen Shot 2022-09-21 at 11.29.06.png 61.72 kb, 5 downloads since 2022-09-21 

Re: [SOLVED!]Single Line to Dotted Line

Please attach your script and I will check it out.

Kind Regards,
Infinity Code Team.

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

Re: [SOLVED!]Single Line to Dotted Line

Thank You Alex smile

I attached the script File, Actually, It is the same as the DottedLineExample If it works I will move to a new script to do some customize but mainly I would like to see how it works.

Post's attachments

Attachment icon dottedLine.cs 5.08 kb, 12 downloads since 2022-09-21 

Re: [SOLVED!]Single Line to Dotted Line

Here is a short video about it:
https://www.dropbox.com/s/p1ow5e80riuby … e.mp4?dl=0

The shader used is attached.

Post's attachments

Attachment icon TilesetDrawingElementZOffset.shader 762 b, 13 downloads since 2022-09-21 

Kind Regards,
Infinity Code Team.

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

Re: [SOLVED!]Single Line to Dotted Line

Hello Alex, many thanks smile I will check it out

8 (edited by codemogen 2022-10-21 11:46:56)

Re: [SOLVED!]Single Line to Dotted Line

Hello Alex, I applied your solution same to my project and my dotted line look not perfect. Can you help me about this please ? Even I change the values of DottedlineExample componenet solution does not change. In the code as well sad

Post's attachments

Attachment icon Screen Shot 2022-10-21 at 14.44.01.png 758.05 kb, 3 downloads since 2022-10-21 

Re: [SOLVED!]Single Line to Dotted Line

Please explain the problem in more detail and attach your code.
In the screenshot, I see one dot.
This may or may not be correct depending on the context.
If this is not correct, there may be many reasons why.

Kind Regards,
Infinity Code Team.

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

Re: [SOLVED!]Single Line to Dotted Line

Sure Alex,

Here is the
my screenshots

Post's attachments

Attachment icon Screen Shot 2022-10-22 at 13.08.33.png 221.87 kb, 3 downloads since 2022-10-22 

Re: [SOLVED!]Single Line to Dotted Line

namespace InfinityCode.OnlineMapsExamples
{
    /// <summary>
    /// Example how to draw a dotted line in tileset.
    /// </summary>
    [AddComponentMenu("Infinity Code/Online Maps/Examples (API Usage)/DottedLineExample")]
    public class DottedLineExample : MonoBehaviour
    {
        /// <summary>
        /// The thickness of the line.
        /// </summary>
        public float size = 10;

        /// <summary>
        /// Scale UV.
        /// </summary>
        public Vector2 uvScale = new Vector2(2, 1);

        /// <summary>
        /// The material used for line drawing.
        /// </summary>
        public Material material;

        private Vector2[] coords;
        private MeshFilter meshFilter;
        private MeshRenderer meshRenderer;
        private Mesh mesh;

        private float _size;

        private void Start()
        {
            // Create a new GameObject.
            GameObject container = new GameObject("Dotted Line");

            // Create a new Mesh.
            meshFilter = container.AddComponent<MeshFilter>();
            meshRenderer = container.AddComponent<MeshRenderer>();

            mesh = meshFilter.sharedMesh = new Mesh();
            mesh.name = "Dotted Line";
            mesh.MarkDynamic();

            meshRenderer.sharedMaterial = material;

            // Init coordinates of points.
            coords = new Vector2[2];

            //coords[0] = new Vector2();
            coords[0] = new Vector2(29.115323f, 41.021153f);
            coords[1] = new Vector2(29.114771f, 41.019448f);
            //coords[3] = new Vector2(4, 4);
            //coords[4] = new Vector2(1, 6);

            // Subscribe to events of map.
            OnlineMaps.instance.OnChangePosition += UpdateLine;
            OnlineMaps.instance.OnChangeZoom += UpdateLine;

            // Initial update line.
            UpdateLine();
        }

        private void Update()
        {
            // If size changed, then update line.
            if (Math.Abs(size - _size) > float.Epsilon) UpdateLine();
        }

        private void UpdateLine()
        {
            _size = size;

            float totalDistance = 0;
            Vector3 lastPosition = Vector3.zero;

            List<Vector3> vertices = new List<Vector3>();
            List<Vector2> uvs = new List<Vector2>();
            List<Vector3> normals = new List<Vector3>();
            List<int> triangles = new List<int>();

            List<Vector3> positions = new List<Vector3>();

            for (int i = 0; i < coords.Length; i++)
            {
                // Get world position by coordinates
                Vector3 position = OnlineMapsTileSetControl.instance.GetWorldPosition(coords i);
                positions.Add(position);
                if (i != 0)
                {
                    // Calculate angle between coordinates.
                    float a = OnlineMapsUtils.Angle2DRad(lastPosition, position, 90);

                    // Calculate offset
                    Vector3 off = new Vector3(Mathf.Cos(a) * size, 0, Mathf.Sin(a) * size);

                    // Init vertices, normals and triangles.
                    int vCount = vertices.Count;

                    vertices.Add(lastPosition + off);
                    vertices.Add(lastPosition - off);
                    vertices.Add(position + off);
                    vertices.Add(position - off);

                    normals.Add(Vector3.up);
                    normals.Add(Vector3.up);
                    normals.Add(Vector3.up);
                    normals.Add(Vector3.up);

                    triangles.Add(vCount);
                    triangles.Add(vCount + 3);
                    triangles.Add(vCount + 1);
                    triangles.Add(vCount);
                    triangles.Add(vCount + 2);
                    triangles.Add(vCount + 3);

                    totalDistance += (lastPosition - position).magnitude;
                }

                lastPosition = position;
            }

            float tDistance = 0;

            for (int i = 1; i < positions.Count; i++)
            {
                float distance = (positions[i - 1] - positions i).magnitude;

                // Updates UV
                uvs.Add(new Vector2(tDistance / totalDistance, 0));
                uvs.Add(new Vector2(tDistance / totalDistance, 1));

                tDistance += distance;

                uvs.Add(new Vector2(tDistance / totalDistance, 0));
                uvs.Add(new Vector2(tDistance / totalDistance, 1));
            }

            // Update mesh
            mesh.vertices = vertices.ToArray();
            mesh.normals = normals.ToArray();
            mesh.uv = uvs.ToArray();
            mesh.triangles = triangles.ToArray();
            mesh.RecalculateBounds();

            // Scale texture
            Vector2 scale = new Vector2(totalDistance / size, 1);
            scale.Scale(uvScale);
            meshRenderer.material.mainTextureScale = scale;
        }
    }
}

Post's attachments

Attachment icon Screen Shot 2022-10-21 at 14.42.50.png 70.13 kb, 3 downloads since 2022-10-22 

Re: [SOLVED!]Single Line to Dotted Line

Most likely you have a problem in Dot texture import settings.
In the project, select your Dot texture, set Wrap Mode - Repeat and click Apply.

Kind Regards,
Infinity Code Team.

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

Re: [SOLVED!]Single Line to Dotted Line

You are the Best smile thank you it worked!