Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

how figure out the max # of characters in text box?

Discussion in 'UGUI & TextMesh Pro' started by CaoMengde777, Feb 5, 2016.

  1. CaoMengde777

    CaoMengde777

    Joined:
    Nov 5, 2013
    Posts:
    813
    so.. what kind of method do people use to figure out the max number of characters that should fit in a text box?
    seeing as different characters take different space ..

    and, my text would be entered by myself, during development .. although the text is open to modders to make their own text in the boxes..

    (i have my specific font in mind / is being used)


    its a card game, i have text coming from xml

    guess iam wondering, is there a standard way .. or an easy way to find out, does it tell you somehow?
    just have to guess i suppose? lol

    well could figure out the largest character of the font and see how many fit in the text ... but thats dumb since i could get away with more text than that..

    dont really have alot of room on the card..
     
  2. phil-Unity

    phil-Unity

    Unity UI Lead Developer Unity Technologies

    Joined:
    Nov 23, 2012
    Posts:
    1,226
    Yea as you say different character have different sizes and such depending on the character combinations it would change how many fit. I dont really know of a good way to do this without it being a complete guess.
     
  3. jinxed_byte

    jinxed_byte

    Joined:
    Mar 29, 2014
    Posts:
    17
  4. cah029

    cah029

    Joined:
    Sep 1, 2015
    Posts:
    3
    I can't think of an easy way of doing it just from xml. You could have a testing scene specifically for testing potential xml entries. Within this test scene, you can have a text box with the Content Size Fitter component attached to it. You can test each desired xml entry by populating the textbox with the text, waiting one frame for the content size fitter to resize the textbox, then if the textbox is larger than it use to be you can return some kind of message saying that the xml text is too long.

    http://docs.unity3d.com/ScriptReference/UI.ContentSizeFitter.html