1 (edited by joonyboy 2017-08-23 01:48:15)

Topic: using UGUI and tileset map

Few month ago, I questioned about line styling and you replied using tileset to change texture.

That day I used NGUI, but know some reason, I changed it to UGUI.

anyway problem is, I don't know how to set clickable both UGUI button and onlinemaps

I attached capture image

Tileset need camera so I created subcamera and set UGUI canvas render mode to screen space camera

I know maybe it is unity issue, not online maps. I tried googling and any try but i need your help sad

Post's attachments

Attachment icon capture.PNG 363.1 kb, 63 downloads since 2017-08-23 

Re: using UGUI and tileset map

Hello.

Please explain in detail what you want to do.
I will try to explain how to do this.

The current formulation of your question can have many answers, and all answers are correct for one case and incorrect for another.

P.S. Your post does not contain an image.

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 joonyboy 2017-08-23 02:13:04)

Re: using UGUI and tileset map

Sorry for long none response..
I had questioned about mixing UGUI and Tileset-OnlineMaps.
well temporally i fixed issue myself. (Not well)
The result is this, attached image.
I changed <Canvas mode> to 'Screen Space Camera' and add <Canvas Group> to use 'Blocks Raycasts' and 'Ignore Parent Groups' to click UGUI Button when the Map active.
Everything is fine but the problem recently found...
I added custom marker on Map. When Map go Up and Down marker still active when Map didn't show marker's coordinate.

The situation is on Image. (On Map Bottom, there is flag image (marker). If I Change Marker Align Top or Bottom still this problem exist top or bottom side)
Anyway to help this problem?

You had suggested some custom line style solution.
Is only works when Tileset Map?? I added this code UIImageControl Map, but not work. (That UIImageControl Map do not have
Marker problem, but could not change Line Texture...
If possible to change line texture in UIImageControl Map, I would change TileSet Map to UIImageControl Map.

I hope you could give me any help, any advice.

Alex Vertax wrote:

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.

Post's attachments

Attachment icon capture2.PNG 87.12 kb, 65 downloads since 2017-08-23 

Re: using UGUI and tileset map

Hello.

Please send your scene (as a package) to support (support@infinity-code.com).
I will check what happens with your marker, and I'll give you recommendations on how to fix the problem.
To make it clear:
I do not need your working project. I need any project where I can see this problem.

Lines with textures support only tileset.
But this does not mean that you can not make a line with the texture for uGUI.
You need to implement your own Drawing API, which will draw the lines.
This depends only on your programming skill.

Kind Regards,
Infinity Code Team.

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