UniBudouX is BudouX (the machine learning powered line break organizer tool) for Unity.
Note: This project contains the deliverables of the BudouX project.
Confirmed the operation with Unity 2021.3.0f1.
Clone or download the project to run the demo. You can check the operation of UniBudou X + WordWrapper in DemoScene.
You can change the display text and range by pressing the Button A
and Button B
buttons.
If you resize the frame while it's running in the editor, you'll see something like this:
You can add https://github.com/Accky/UniBudouX.git?path=Assets/Scripts
to Package Manager.
Or, add "com.accky.unibudoux": "https://github.com/Accky/UniBudouX.git?path=Assets/Scripts"
to Packages/manifest.json
.
You can use the UniBudouX Parser
by using the UniBudouX namespace.
using UniBudouX;
Use the Parser.Parse
method to split the text into chunks.
// separete text
string text = "一人の下人が、羅生門の下で雨やみを待っていた。";
List<string> chunks = Parser.Parse(text);
// Result => {"一人の", "下人が、", "羅生門の", "下で", "雨やみを", "待っていた。"}
WordWrapper component uses chunks. They automatically break the characters in TextMeshProUGUI.
If you need to change the model, change the Mode or use the trained json file.
// Use Japanese model
Parser.Mode = Parser.KnbcMode.Japanese;
// Use ZnHans model
Parser.Mode = Parser.KnbcMode.ZnHans;
[SerializeField] private TextAsset jsonModel;
private void Start()
{
// Original Model Test
if (jsonModel == null) { return;}
Parser.MakeModel(jsonModel.text);
}
Use the BucouX CLI to create your custom model.
On Windows, you may get a string encoding error. If an error occurs, change line 50 of train.py and specify the encoding.
with open(entries_filename, encoding='utf-8') as f:
entries = [row.strip().split('\t') for row in f.read().splitlines()]
The WordWrapper component embeds a line feed code according to the width of the RectTransform. Used by adding to a game object that has TextMeshProUGUI.
However, due to the timing of execution of TMPro_EventManager.TEXT_CHANGED_EVENT, it is necessary to use the SetText function of this component.
public class WordWrapper : MonoBehaviour
{
public void SetText(string text)
{
if (tmpText == null) { return; }
// TODO: Actually, I would like to process this with a callback on the text is changed.
chunks = Parser.Parse(text);
tmpText.text = text;
hasTextChanged = true;
}
...