Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
Tags

Break text only for alphabetic writing words?

A topic by iiley created Aug 17, 2022 Views: 251 Replies: 12
Viewing posts 1 to 5
(2 edits)

Please see the screenshot, there's maybe Chinese, English or other languages, I need no-break text for alphabetic words(like English), but do break text for other languages(like Chinese).

How can I achieve that?

Thanks!

This is Unity's build Text component, it works well with Chinese and English. 

Developer

Ah I see, I must have understood this incorrectly when I added this feature. 


Please go to SuperTextMesh.cs, and on lik 1171, you should see some code that looks like this:

private static List<char> linebreakFriendlyChars = new List<char>(){' ', '\n', '\t', '-', '\u00AD', '\u200A', '\u200B', '。', '〜', '、', ',', '…', '‥', ' '};

If you remove  '、' and  ',' from the list like this...

private static List<char> linebreakFriendlyChars = new List<char>(){' ', '\n', '\t', '-', '\u00AD', '\u200A', '\u200B', '。', '〜', '…', '‥', ' '};

...I believe you should get the results you want. Please let me know if this works as you want, and I'll make sure this functionality is changed!

Thank you.

It seems work for Chinese break of my case, but not for English break with "," see screenshot here:

(1 edit)

Well, I compared it with Unity build-in Text, seems it behaves the same. (It will put "Looooooo" on the first line if I use ", " instead of ",").

Developer

Oh, you're right though, maybe the English "," should be added to the list of linebreak-friendly characters, too? I'm trying to think why i wouldn't have included it on the list in the first place... Feel free to give it a shot, and let me know if you prefer it! Either way, I'mm make sure to push the changes for the next update, so thank you for reporting this!

I don't know since I am not native English speaker, maybe "," is not usual for writing English? I saw people write "," always with a " ".  For me, I prefer do not add it, I guess it is good since it performs as same as build-in Text now.

Developer

Yeah, even though I'm a native English speaker, I guess rules like this can escape me... but yes usually  "," is followed by a " " anyway! I'll be sure to adjust STM to have the fix for Asian languages in the next upload I do, so I hope everything works for you!

(1 edit)

I'm native Chinese speaker, so I can give advice for Chinese text. In fact, for Chinese words, you can think each character a word, so you can break a sentence at any position. For example:

我举个例子,这是一个文字比较多比较长断句需要有点讲究的句子给开发者参考一下怎么断句比较好。

You can break it at any position to make the line as long as possible(If our panel width is about 20 characters' width):

我举个例子,这是一个文字比较多比较长断句
需要有点讲究的句子给开发者参考一下怎么断
句比较好。

That is good, first two line take the width as big as possible and have same width, look nice. But if I change the text to :

我举个例子,这是一个文字比较多比较长断句需要有点讲究的句子给开发者参考一下怎么断,会比较好。

我举个例子,这是一个文字比较多比较长断句
需要有点讲究的句子给开发者参考一下怎么断
,会比较好。

You can see there is a "," at the beginning of third line, it is acceptable here, however it is better to make it at the end of the second line if possible.

I guess the complex thing is Chinese English mixtures. For example:

我举个混用的例子,我去Carrefore Stores买了一双鞋。

我举个混用的例子,我去Carrefore Stores
买了一双鞋。

That is good. But it is not good for this:

我举个混用的例子,我去Carrefore
Stores买了一双鞋。

Because it can contains "Stores" at the first line, but it doesn't. The key is that you can break English word before/behind Chinese character.

Developer

Ahh, I see... I hope after this change we made it's working as expected? (I still haven't published it yet, sorry...) If you see any more errors or things that should be working differently, please let me know! I'm still embarrassed I forgot to put that comma character as an acceptable linebreak position...


STM should already try and stop punctuation and close-parenthesis from appearing as the first character on a row already: https://twitter.com/KaiClavier/status/1441149108744454155?s=20&t=FLRVtrizJHyAlRE... ...So hopefully that's still formatting Chinese text correctly.


If I see any strange text formatting, I'll refer back to this post, so thank you so much for the detailed explanation! It really helps a lot.

(1 edit)

I saw the twitter gif for Japanese, it is similar to Chinese, looks great. But I prefer to have a opinion for developers of "refuses to put '(' at the end of a line, and refuses to put ')' and '!' at the beginning", some time we prefer to have regular line width than that. So if I can check or uncheck it for different situation, that would be perfect.

Developer

Hmm... I'll try to think of how to do this, but for now you could manually edit the lists within SuperTextMesh.cs that contain the lists of characters that will attempt to not be put at the start and end of the line. Also, I believe that if you check "break text", text should ignore formatting rules if there are no spaces available to break at... I think.

Thank you, no worry, my project is not hurry I will wait for your release.

For:

Also, I believe that if you check "break text", text should ignore formatting rules if there are no spaces available to break at... I think.

That is not work for me because my player may enter Chinese English mixed sentences, so simply check "break text" will make Chinese looks good but English words looks bad. They key is to make mixed language sentences perform well.