Variable Size Portrait Name

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
User avatar
HawkX
Posts: 147
Joined: Mon Feb 27, 2017 1:50 pm
Location: Quebec
Contact:

Variable Size Portrait Name

Post by HawkX »

Hi Tony! :)

I am trying to add a background image to my portrait name... but since I really dont understand half of the Unity UI system, I figured I might as well write here... and it could perhaps help someone oneday that tries to do the same thing :)

As you can see in the picture below
PortraitNameFrame.jpg
PortraitNameFrame.jpg (31.89 KiB) Viewed 701 times
I created a framing for the name... it is positionned properly in SLICED mode... so I can adjust the width and it will stretch to the right side to acomodate super long character names... or contract to the left for much smaller names... I'd like to automate that "stretching" based on the character names... but I fear the template I am using might not work for that... Any tips/help you could provide on how I could achieve that? :)

As always, THANKS SO MUCH for all your amazing support! :D
User avatar
Tony Li
Posts: 22062
Joined: Thu Jul 18, 2013 1:27 pm

Re: Variable Size Portrait Name

Post by Tony Li »

This may be a little hard to describe since it will depend on how the parent UI elements are configured.

Let's assume the GameObject hierarchy is like this:

Code: Select all

Canvas
    ...
        PortraitNameBackground
            PortraitName
PortraitName:
  • Add a Layout Element component to PortraitName. You can leave all of the checkboxes unticked.
PortraitNameBackground:
  • Set the Rect Transform to Anchor: top left. Pivot X=0, Y=1.
  • Add a Horizontal Layout Group to PortraitNameBackground. Tick Control Child Size > Width; leave the others unticked. Set the Padding values if you want.
  • Add a Content Size Fitter. Set Horizontal Fit to Preferred.
User avatar
HawkX
Posts: 147
Joined: Mon Feb 27, 2017 1:50 pm
Location: Quebec
Contact:

Re: Variable Size Portrait Name

Post by HawkX »

2 things...

1st, IT WORKS!! you are so amazing its crazy!! :)

hehe...

2nd, i am getting the following warning after testing it...
Unexpected top level layout group! Missing GUILayout.EndScrollView/EndVertical/EndHorizontal?
UnityEditor.DockArea:OnGUI()
User avatar
Tony Li
Posts: 22062
Joined: Thu Jul 18, 2013 1:27 pm

Re: Variable Size Portrait Name

Post by Tony Li »

Glad I could help with the 1st one!

For the 2nd one, this may be a relatively-harmless glitch in the Dialogue Editor window. Does it still happen if the Dialogue Editor window is closed?
User avatar
HawkX
Posts: 147
Joined: Mon Feb 27, 2017 1:50 pm
Location: Quebec
Contact:

Re: Variable Size Portrait Name

Post by HawkX »

Well, it only happened twice the first time after i did the changes... so it might have been a fluke... ;)

Consider this done/closed :)

Thanks again!
Post Reply