Page 1 of 1

Variable Size Portrait Name

Posted: Wed Jun 14, 2017 3:54 pm
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 699 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

Re: Variable Size Portrait Name

Posted: Wed Jun 14, 2017 6:30 pm
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.

Re: Variable Size Portrait Name

Posted: Thu Jun 15, 2017 11:56 am
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()

Re: Variable Size Portrait Name

Posted: Thu Jun 15, 2017 12:51 pm
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?

Re: Variable Size Portrait Name

Posted: Thu Jun 15, 2017 12:57 pm
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!