Topic: How to create a tooltip that acts like a button?

Hey peeps

Im trying to create a tooltip that acts like a button. I'm using the uGUICustomTooltipExample method, so my prefab is just a button in other words.

There are a couple of issues i need help with:

Firstly there is no on click function for the tooltip, how can i make that? this doesn't matter so much, because I'm building for iOS, the hover works like a click on the phone.

Secondly, my button doesn't fire, as soon as i click on the button the tooltip(my button prefab) disappears.

Please if anyone can assist that would be awesome.

Kind Regards

Re: How to create a tooltip that acts like a button?

Hello.

I hope I understood your question correctly.
Example attached.

Post's attachments

Attachment icon uGUICustomTooltipOnClick.cs 2.15 kb, 194 downloads since 2016-03-30 

Kind Regards,
Infinity Code Team.

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

Re: How to create a tooltip that acts like a button?

Hey Alex

That is exactly what i needed. i don't know how to thank you for taking the time to help me. as i am a bigger programmer. can't wait to show you what I've come up with.

your a rock star!

Kind Regards

4 (edited by luke.carelsen 2016-04-05 14:08:51)

Re: How to create a tooltip that acts like a button?

Hey Alex

Again thank you for code. could you please help me with another problem with our code.

We have a prefab with 4 text strings that loads as a tooltip. I would just like to know how its possible to pass the different values. currently in the sample its using GetComponentInChildren and this only sets the value for the first text object in the parent. We have tried doing it by tag and keep getting a  error (UnityEngine.GameObject.FindGameObjectsWithTag(string)' cannot be accessed with an instance reference, qualify it with a type name instead).

how can we solve this?

we are using it like this:

    private void OnUpdateLate()
    {
        if (tooltipMarker != null)
        {
            if (tooltip == null)
            {
                tooltip = Instantiate(tooltipPrefab);
                (tooltip.transform as RectTransform).SetParent(container.transform);
            }

            //Vector2 pos = new Vector2(rect.center.x, rect.yMin + 90);

            Vector2 screenPosition = OnlineMapsControlBase.instance.GetScreenPosition(tooltipMarker.position);
            screenPosition.y += tooltipMarker.height+60;
            Vector2 point;
            RectTransformUtility.ScreenPointToLocalPointInRectangle(container.transform as RectTransform, screenPosition, null, out point);
            (tooltip.transform as RectTransform).localPosition = point;
            //tooltip.GetComponentInChildren<Text>().text = tooltipMarker.label;

            tooltip.FindGameObjectsWithTag("User_Id");

        }
        else
        {
            DestroyImmediate(tooltip);
            tooltip = null;
        }
    }

Could anyone please assist?

Re: How to create a tooltip that acts like a button?

Hello.

There are many ways to do this.

Just as an example:

1. Easiest way:
GetComponentsInChildren
http://docs.unity3d.com/ScriptReference … ldren.html

2. Fastest way:
Create a new script

using UnityEngine;
using UnityEngine.UI;

public class MyTooltip : MonoBehaviour
{
    public Text line1;
    public Text line2;
    public Text line3;
    public Text line4;
}

Add this script to tooltip prefab.

Example of use:

MyTooltip myTooltip = tooltip.GetComponent<MyTooltip>();
myTooltip.line1.text = "Hello";
myTooltip.line2.text = "World";

There are many more ways to do this, but I think this will be enough.

P.S. FindGameObjectsWithTag is a static method.
http://docs.unity3d.com/ScriptReference … thTag.html

Kind Regards,
Infinity Code Team.

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

Re: How to create a tooltip that acts like a button?

Hey Alex thank you so much for the tip I will try it first thing in the morning, just quickly skimmed it on my iPhone.

We tried creating script on the prefab before and then we just told the script to pass the variable that is on the prefab instance but that changed all the values and on all the marker tool tips. Maybe I just don't understand it.

Anyway thanks again will definitely sit down first thing in the morning and go through your suggestion!

Re: How to create a tooltip that acts like a button?

Alex Vertax wrote:

2. Fastest way:
Create a new script

Hey alex

thanks for taking the time to address my question. We tried the script method but what happens is it changes all the values on all the tool tips to be the same. let me show you how i run through the code

    public void ScanTable(){
        authenticator ();
        Table.LoadTableAsync (_client, "hwsh_user_data", (loadTableResult) =>
        {
                var search = Context.ScanAsync<hwsh_user_data> (new ScanCondition ("User_Video_URL", ScanOperator.IsNotNull));
            search.GetRemainingAsync (result =>
            {
                if (result.Exception == null) {
                    FullTableResults = result.Result;
                    // Then to Loop through the data
                    for (int i = 0; i < FullTableResults.Count; i++) {
                        //Do Stuff with the result list.
                        
                        Debug.Log ("UserID: "+ FullTableResults [i].Id + " Username: " + FullTableResults [i].User_Name +
                                   " GeoX: " + FullTableResults [i].GeoX_Longitude + " GeoY: " + FullTableResults [i].GeoY_Latitude +
                                   " User Video: " + FullTableResults [i].User_Video_URL);

                                newGeox = FullTableResults [i].GeoX_Longitude.ToString();

                                Debug.Log(("GEO X = ") +newGeox);
                                marker = OnlineMaps.instance.AddMarker(new Vector2(FullTableResults [i].GeoX_Longitude, FullTableResults [i].GeoY_Latitude), null, FullTableResults [i].User_Name);

                                //tooltip.GetComponent<VariableTest>().myId = newGeox;
                                MakeToolTips();
                
                    
                        }
                            Debug.Log("Tooltip creation complete");
                } else {
                    Debug.Log ("THIS IS WHAT YOU NEED TO LOOK AT!!! : " + result.Exception.ToString ());

                }
                
            }, null);
        });

    
    }

So above: we assign the new value to a public var (GeoX, which is actually our id, just used Geox for testing purposes for testing purposes) that we will convert to string and pass it to the other script with the code below.

    private void OnUpdateLate()
    {
        if (tooltipMarker != null)
        {
            if (tooltip == null)
            {
                tooltip = Instantiate(tooltipPrefab);
                (tooltip.transform as RectTransform).SetParent(container.transform);
            }

            //Vector2 pos = new Vector2(rect.center.x, rect.yMin + 90);

            Vector2 screenPosition = OnlineMapsControlBase.instance.GetScreenPosition(tooltipMarker.position);
            screenPosition.y += tooltipMarker.height+60;
            Vector2 point;
            RectTransformUtility.ScreenPointToLocalPointInRectangle(container.transform as RectTransform, screenPosition, null, out point);
            (tooltip.transform as RectTransform).localPosition = point;
        


            tooltip.GetComponent<VariableTest>().myString = "hello";
            tooltip.GetComponent<VariableTest>().myId = newGeox;


        }
        else
        {
            DestroyImmediate(tooltip);
            tooltip = null;
        }
    }

But the problem here is that it doesn't form part of the instance, or am i missing something here? Please advice.

Kind Regards

Re: How to create a tooltip that acts like a button?

Hello.

You set newGeox in "for", so in OnUpdateLate it always will have the last value.
If you want to store some data in the marker, use OnlineMapsMarkerBase.customData.
http://infinity-code.com/doxygen/online … a199f29dc1

When you need to store one variable, just put it into customData.
When you need to store multiple variables, create a class with the required fields, and put instance into customData.

Example:
http://infinity-code.com/atlas/online-m … ample.html

Kind Regards,
Infinity Code Team.

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

Re: How to create a tooltip that acts like a button?

ok cool I'm  playing with your solution now. thanks

Re: How to create a tooltip that acts like a button?

Alex Vertax wrote:

Hello.
When you need to store one variable, just put it into customData.
When you need to store multiple variables, create a class with the required fields, and put instance into customData.

Ok so we tried it and it still returns only the last number.

private void OnUpdateLate()
    {
        if (tooltipMarker != null)
        {
            if (tooltip == null)
            {
                tooltip = Instantiate(tooltipPrefab);
                (tooltip.transform as RectTransform).SetParent(container.transform);
            }

            //Vector2 pos = new Vector2(rect.center.x, rect.yMin + 90);

            Vector2 screenPosition = OnlineMapsControlBase.instance.GetScreenPosition(tooltipMarker.position);
            screenPosition.y += tooltipMarker.height+60;
            Vector2 point;
            RectTransformUtility.ScreenPointToLocalPointInRectangle(container.transform as RectTransform, screenPosition, null, out point);
            (tooltip.transform as RectTransform).localPosition = point;
        


            tooltip.GetComponent<VariableTest>().myString = "hello";

            OnlineMapsXML xml = marker.customData as OnlineMapsXML;

            if (xml == null)
            {
                Debug.Log("The marker does not contain XML.");
                return;
            }

            // Show xml in console.
            Debug.Log(xml.outerXml);
            Debug.Log(xml.Get("ID"));

            //cloneplanet.GetComponent(NameOfFirstScript).degrees = 50/j;


        }
        else
        {
            DestroyImmediate(tooltip);
            tooltip = null;
        }
    }

    public void ScanTable(){
        authenticator ();
        Table.LoadTableAsync (_client, "hwsh_user_data", (loadTableResult) =>
        {
                var search = Context.ScanAsync<hwsh_user_data> (new ScanCondition ("User_Video_URL", ScanOperator.IsNotNull));
            search.GetRemainingAsync (result =>
            {
                if (result.Exception == null) {
                    FullTableResults = result.Result;
                    // Then to Loop through the data
                    for (int i = 0; i < FullTableResults.Count; i++) {
                        //Do Stuff with the result list.
                        
                        Debug.Log ("UserID: "+ FullTableResults [i].Id + " Username: " + FullTableResults [i].User_Name +
                                   " GeoX: " + FullTableResults [i].GeoX_Longitude + " GeoY: " + FullTableResults [i].GeoY_Latitude +
                                   " User Video: " + FullTableResults [i].User_Video_URL);

                                newGeox = FullTableResults [i].GeoX_Longitude.ToString();

                                Debug.Log(("GEO X = ") +newGeox);
                                marker = OnlineMaps.instance.AddMarker(new Vector2(FullTableResults [i].GeoX_Longitude, FullTableResults [i].GeoY_Latitude), null, FullTableResults [i].User_Name);

                                OnlineMapsXML xml1 = new OnlineMapsXML("MarkerData");
                                xml1.Create("ID", FullTableResults [i].GeoX_Longitude.ToString());
                                marker.customData = xml1;

                                //tooltip.GetComponent<VariableTest>().myId = newGeox;
                                MakeToolTips();
                
                    
                        }
                            Debug.Log("Tooltip creation complete");
                } else {
                    Debug.Log ("THIS IS WHAT YOU NEED TO LOOK AT!!! : " + result.Exception.ToString ());

                }
                
            }, null);
        });

    
    }

what am i missing here?

Re: How to create a tooltip that acts like a button?

oh wait i got it right i put it in the wrong class;

    private void ShowTooltip(OnlineMapsMarkerBase marker)
    {
        tooltipMarker = marker as OnlineMapsMarker;
        Debug.Log ("Showing Tooltip");

        OnlineMapsXML xml = marker.customData as OnlineMapsXML;

        if (xml == null)
        {
            Debug.Log("The marker does not contain XML.");
            return;
        }

        // Show xml in console.
        Debug.Log(xml.outerXml);
        Debug.Log(xml.Get("ID"));

        //myImage = tooltipPrefab.GetComponentInChildren<RawImage>.

        //tooltip.gameObject
    }

thanks again for all your support

Re: How to create a tooltip that acts like a button?

Something like:

public void ScanTable()
...
newGeox = FullTableResults [i].GeoX_Longitude.ToString();
marker = OnlineMaps.instance.AddMarker(new Vector2(FullTableResults [i].GeoX_Longitude, FullTableResults [i].GeoY_Latitude), null, FullTableResults [i].User_Name);
marker.customData = newGeox;
private void OnUpdateLate()
...
tooltip.GetComponent<VariableTest>().myId = (string)tooltipMarker.customData;
Kind Regards,
Infinity Code Team.

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

13 (edited by luke.carelsen 2016-04-06 10:57:23)

Re: How to create a tooltip that acts like a button?

now I'm experiencing something really weird.

everything works like i want it to but it produces an error:

NullReferenceException: Object reference not set to an instance of an object
AWS_Dataload.ShowTooltip (.OnlineMapsMarkerBase marker) (at Assets/Script/AWS_Dataload.cs:85)
OnlineMapsControlBase.OnMapBaseRelease () (at Assets/Infinity Code/Online maps/Scripts/Controls/OnlineMapsControlBase.cs:563)
OnlineMapsUIImageControl.BeforeUpdate () (at Assets/Infinity Code/Online maps/Scripts/Controls/OnlineMapsUIImageControl.cs:46)
OnlineMapsControlBase.Update () (at Assets/Infinity Code/Online maps/Scripts/Controls/OnlineMapsControlBase.cs:630)

here is the code it is referring to.

    private void ShowTooltip(OnlineMapsMarkerBase marker)
    {
        tooltipMarker = marker as OnlineMapsMarker;
        Debug.Log ("Showing Tooltip");

        OnlineMapsXML xml = marker.customData as OnlineMapsXML;


        if (xml == null)
        {
            Debug.Log("The marker does not contain XML.");
            return;
        }

       // here is where the error happens
        tooltip.GetComponent<VariableTest> ().UserName.text = xml.Get ("UserName");
        tooltip.GetComponent<VariableTest> ().UserIdStr = xml.Get ("UserID");
        tooltip.GetComponent<VariableTest> ().PostIdStr = xml.Get ("PostID");
        tooltip.GetComponent<VariableTest> ().VideoUrlStr = xml.Get ("VideoUrl");

    }

do i just ignore it? every happens that is suppose to happen.

Re: How to create a tooltip that acts like a button?

Message has a complete description of the error (tooltip == null).
I do not know your code, and what you wanna do, but 99% that you do not need this method at all.

Kind Regards,
Infinity Code Team.

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

Re: How to create a tooltip that acts like a button?

Hey there, thanks we reversed our logic and now everything is working 100%

rock on!