Author Topic: collider fail to match with the size of label  (Read 2088 times)

patrick_activate

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 10
    • View Profile
collider fail to match with the size of label
« on: February 28, 2014, 03:28:12 AM »


the orange color box is the size of label, the text of label are assigned during run time. but the collider (green box) are not match with the size of label.

i have tried to:
1. tick the "auto adjust collider" option under the widget of label.
2. called NGUItools.UpdateWidgetCollider(), pass in the collider of label, after i assign the text of label.
3. called GetComponent<UILabel>().ResizeCollider(), after i assign the text of label.
4. called NGUItools.CalculateRelativeWidgetBounds, calculate the value and manually assign to the size of the collider.

after i tired all above method, the collider still same like what the picture shown. please help :(

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: collider fail to match with the size of label
« Reply #1 on: February 28, 2014, 07:27:20 PM »
What version of NGUI are you using? If it's the latest, how do I reproduce it?

I just tried the following:

1. New scene.
2. Add a label, changed it to Resize Freely.
3. Added this script to it:
  1. using UnityEngine;
  2.  
  3. public class Abcd : MonoBehaviour
  4. {
  5.         void Start ()
  6.         {
  7.                 GetComponent<UILabel>().text = "This one time,\nat band camp?";
  8.         }
  9. }
4. Hit Play, label's size changes, collider adjusts accordingly.

Kerozard

  • Newbie
  • *
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 17
    • View Profile
Re: collider fail to match with the size of label
« Reply #2 on: July 23, 2014, 10:52:57 AM »
I have to dig up this topic, because I am suffering from the same situation right now.

Unity: 4.5.2f1
NGUI: 3.6.8

1. Create a fresh project
2. NGUI -> Create -> Label
3. NGUI -> Attach -> Collider
4. Attach Script:
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class ClickTest : MonoBehaviour {
  5.  
  6.         // Use this for initialization
  7.         void Start () {
  8.        
  9.         }
  10.        
  11.         // Update is called once per frame
  12.         void Update () {
  13.        
  14.         }
  15.  
  16.     void OnClick()
  17.     {
  18.         Debug.Log("Label Click has been triggered");
  19.     }
  20. }
  21.  

When I play the scene this way, everything works fine. I can click left and right of my label and the event does not get triggered.

5. Change "Overflow => Resize Freely"

This is where the problem begins. I can click anywhere left and right of the label and the click event gets triggered even though I am not even near the text. "Overflow => Resize Height" does something similar with the area above and below the label although that way the area does not go all the way up/down but just a fair bit.

EDIT:

This is getting weird. I added more elements to the GUI I am designing and suddenly the colliders work correctly. No idea why, because I haven't touched them again. In my empty scene test the error still exists.
« Last Edit: July 23, 2014, 01:17:59 PM by Kerozard »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: collider fail to match with the size of label
« Reply #3 on: July 23, 2014, 08:00:57 PM »
Everything works fine on my end...