Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
Tags

A problem about Ui Wrap

A topic by Wanwu created Jun 05, 2022 Views: 218 Replies: 4
Viewing posts 1 to 2
(2 edits)

Hi, I'm confused about "UI Wrap".If I set UI Wrap false, then the size of a text can be out of the range of the rect Transform( that's what I want). But if the horizontal text is out the of range, then the alignment mode will always be Left.(text start at left side of rect transform, even though I set alignment to center or right. Are there any way to fix it?

Here is the unity text, if I set herizontal Overflow to Overflow, the start point of text will still follow alignment.

 

Developer

Please try attaching a "Content Size Fitter" component to your STM object, and setting "Horizontal Fit" to "Preferred Size" and you should get the result you want!

iirc, the "UI Wrap" and "UI Limit" booleans are holdovers from before I implemented content size fitter, so the toggles are there to change how the two work together. Since... if the text is being set to wrap at it's horizontal limit, but is also being set to it's preferred horizontal size... that would just do nothing anyway. I should probably make it so an "add content size fitter" button pops up if UI Wrap/UI Limit are unchecked and one isn't already attached to STM.

(4 edits)

Thanks for you reply, I tried "Content Size Fitter", But it's still not I wan’t. "Content Size Fitter" will set the width of rect transform same as the width of texts, so the center of text will always stay that center of rect transform. the bottem one(Unity text) is the effect I want. 

Developer

Okay, in this scenario, please try...

Make the STM object the child of a layout group.(Horizontal Layout Group, Vertical Layout Group) and set the layout group to have "upper right" child alignment, and uncheck "child focre expand" width and height.

Next, remove the content size fitter component from the STM object, and it should follow the rules of what you want. (Within the bounds of the layout group) Unity Layout stuff works a bit strangely, so apologies for all this. It's a bit weird to set it all up.

Hi, I find the solution. I can set anchor to CenterRight and Alignment to Right to get the result I want. Thank you so much.