Author Topic: [Solved] UILabel not wrapping after a -1 scale.x  (Read 3041 times)

Abnaxus

  • Guest
[Solved] UILabel not wrapping after a -1 scale.x
« on: May 06, 2013, 03:19:00 AM »
Hi there,

Here comes a new and weird problem.
I have an object with widgets as childs, and I'm trying to -1 Xscale the object (everything's fine ftm).
Then comes the moment I'm trying to -1 Xscale one widget (the UILabel) to bring it back to normal.
And so the text is no more wrapping when I launch the prog.

Weird thing is, when I -1 Xscale it from editor, it works fine (but I can't do it from editor, needs to be dynamical).

Here comes the reScaling code:
  1. public void FlipReply(bool active)
  2.         {
  3.                 if(active)
  4.                 {
  5.                         Vector3 scale = replyObject.transform.localScale;
  6.                         scale.x *= -1;
  7.                         replyObject.transform.localScale = scale;
  8.                        
  9.                         for(int i=0; i < replyObject.transform.GetChildCount(); i++)
  10.                         {
  11.                                 if(replyObject.transform.GetChild(i).gameObject.GetComponent<UILabel>() != null)
  12.                                 {
  13.                                         scale = replyObject.transform.GetChild(i).localScale;
  14.                                         scale.x *= -1;
  15.                                         replyObject.transform.GetChild(i).localScale = scale;
  16.                                 }
  17.                         }
  18.                 }
  19.         }

So if you have any suggestion on that prob happening, would be cool to hear it.

Thanks in advance.

Greetings,
Abnaxus.
« Last Edit: May 13, 2013, 05:26:19 AM by Abnaxus »

Grhyll

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 32
    • View Profile
Re: UILabel not wrapping after a -1 scale.x
« Reply #1 on: May 06, 2013, 07:52:08 AM »
The scale of a UILabel object is the font size. You should put your UILabel in an otherwise empty GameObject and modify the scale of this game object.

Abnaxus

  • Guest
Re: UILabel not wrapping after a -1 scale.x
« Reply #2 on: May 06, 2013, 09:45:01 AM »
Then why when I do it from Editor it works perfectly fine ?  ???

Anyway, I already tried that and it's still the same prob. :/

Grhyll

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 32
    • View Profile
Re: UILabel not wrapping after a -1 scale.x
« Reply #3 on: May 06, 2013, 10:12:55 AM »
Sorry, I think I don't exactly understand your issue, maybe a picture would help.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UILabel not wrapping after a -1 scale.x
« Reply #4 on: May 06, 2013, 04:32:50 PM »
Why are you doing this?

Abnaxus

  • Guest
Re: UILabel not wrapping after a -1 scale.x
« Reply #5 on: May 07, 2013, 03:15:30 AM »
I have a dial between 2 characters and I need them to have the same "text bubble" (like comics) to display when they talk.

So I have a prefab with my bubble + sprites + label etc.. and I just need to -1 Xscale it for the other char.
So I scale the whole prefab and scale back the label to get it readable.

And I don't want to have 2 prefabs, cause it's taking resources and so I want few of them (in case you tell me to do another prefab  ;) ).

PS: Any idea why it works in editor and not dynamically ? That shouldn't be possible, except if I'm doing it wrong dynamically (but a re-scale, hummm, how could it be wrong ?).

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UILabel not wrapping after a -1 scale.x
« Reply #6 on: May 07, 2013, 05:13:56 AM »
The bubble should be one sprite (sliced sprite), and the triangle that points from the bubble to the speaker should be another sprite (regular sprite). Have two such triangles -- one for left, one for right.

Abnaxus

  • Guest
Re: UILabel not wrapping after a -1 scale.x
« Reply #7 on: May 07, 2013, 07:30:46 AM »
As said, I have many sprites involved for a single "reply".

All I want is a reflection of the full "reply" except the label.
That's why I rescale all my objects but the label (well, in fact the whole "reply" is rescaled and not the objects inside, to keep the localPosition great).

I think I'll watch a bit @ UILabel script to see how you render things, cause it's kinda weird.
I guess the wrapping depends on the scales ?
If it is, why putting negative scale on editor works ? :o

Abnaxus

  • Guest
Re: UILabel not wrapping after a -1 scale.x
« Reply #8 on: May 07, 2013, 08:35:39 AM »
The scale of a UILabel object is the font size. You should put your UILabel in an otherwise empty GameObject and modify the scale of this game object.

My bad, it was working.
I guess I gave it up after encountering some issues.

But since I cleaned my scripts, everything's fine.

Thanks.