Author Topic: Dynamicly place Sprites in text  (Read 5064 times)

Malzbier

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 93
    • View Profile
Dynamicly place Sprites in text
« on: September 11, 2012, 02:57:28 AM »
I have a big text , about 100 lines with formations and some very text related sprites.

The problem is that the text must be Localizeable.
But with different length of text the placement of the sprites must be happen automatically.

Is there a need way to implement something like : ==Sprite name:scalex:scaley:scalez==

Greetings Malzbier.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Dynamicly place Sprites in text
« Reply #1 on: September 11, 2012, 03:45:06 AM »
You can use UIAnchor to anchor to a side or corner of another sprite, and UIStretch to scale something to fill the dimensions of another sprite.

Malzbier

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 93
    • View Profile
Re: Dynamicly place Sprites in text
« Reply #2 on: September 11, 2012, 07:40:10 AM »
I'm not talking about fitting a background to the size of the text or position something beside the text!
I'm talking about position medium sized sprites inside the text dynamically.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Dynamicly place Sprites in text
« Reply #3 on: September 11, 2012, 10:04:12 AM »
Oh you mean symbols like smiley faces? One of the video tutorials covers how to make them.

Malzbier

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 93
    • View Profile
Re: Dynamicly place Sprites in text
« Reply #4 on: September 12, 2012, 04:04:00 AM »
The problem is that the Sprites are not so small that they could be used in a font as a symbol.
They are like 150X150 and upwards and used in other places in the project too.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Dynamicly place Sprites in text
« Reply #5 on: September 12, 2012, 04:28:37 AM »
Yeah that's problematic.

Malzbier

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 93
    • View Profile
Re: Dynamicly place Sprites in text
« Reply #6 on: September 12, 2012, 05:45:07 AM »
I Like to switch to another way of doing it:
I like to chain Sprites and Label's together using Tables and Anchor's.
But a wired misbehavior is occurring if i have a A table with some elements and i like to anchor another Label to one object of the the Table.
There is a very big offset that should not be there.
If i take the same object out of the Table , everything is working fine and the wrong offset is gone.

Edit:
MMM looks like the Draggable Panel is messing around too ... (All Panel's are uniformed scaled at 1).
My setup is

Panel
---UILabel
---UITable + UIAnchor
------Tabel Content

If i activate The UIAnchor (witch is Anchor to the UI label) the object is moved by -4000 Units in Y direction

Edit:
UIAnchor.cs
  1. else if (widgetContainer != null)
  2.                 {
  3.                         // Widget is used -- use its bounds as the container's bounds
  4.                         Transform t = widgetContainer.cachedTransform;
  5.                         Vector3 ls = t.localScale;
  6.                         Vector3 lp = t.localPosition;
  7.  
  8.                         Vector3 offset = widgetContainer.pivotOffset;
  9.                         offset.y -= widgetContainer.relativeSize.y;
  10.                        
  11.                         if(this.gameObject.name == "2")
  12.                                 Debug.Log( offset.y );
  13. /// ergebnis:                                -12
  14.                         offset.x *= (widgetContainer.relativeSize.x * ls.x);
  15.                         offset.y *= (widgetContainer.relativeSize.y * ls.y);
  16.  
  17.                         rect.x = lp.x + offset.x;
  18.                         rect.y = lp.y + offset.y;
  19.                         rect.width = ls.x;
  20.                         rect.height = ls.y;
  21.                        
  22.                         if(this.gameObject.name == "2")
  23.                                 Debug.Log( rect.y + "   "  +   rect.yMin  +"    " + offset.y +  "   " +widgetContainer.relativeSize.y + "  " + ls.y);
  24.                         ////Ergebis          -4032         -4032                     -4176                      12                     29
  25.                        
  26.                 }

just cant figure out whats going wrong.
« Last Edit: September 12, 2012, 09:33:21 AM by Malzbier »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Dynamicly place Sprites in text
« Reply #7 on: September 12, 2012, 10:15:09 AM »
Assuming I understand your setup correctly, it should work fine provided the scales are indeed uniform. A table is just another game object, so anchoring it should position it where you set the anchor to. I do this myself in a couple of places. Did you specify any kind of relative offset on the anchor?

Malzbier

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 93
    • View Profile
Re: Dynamicly place Sprites in text
« Reply #8 on: September 12, 2012, 11:03:16 AM »
I do no use any kind of Relative offset offset
Looks like the multi line text is generating The wrong values. With a single line it works fine.
(Maybe i can send you private a example scene (Very small , did remove non related stuff))

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Dynamicly place Sprites in text
« Reply #9 on: September 12, 2012, 02:33:05 PM »
Yeah, of course -- support at tasharen.com.

Malzbier

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 93
    • View Profile
Re: Dynamicly place Sprites in text
« Reply #10 on: September 13, 2012, 03:24:10 AM »
Email Is out, Hope that this can be fixed soon :)
I'm just working on like tit would be working fine , so it is correct if the bug is fixed.