Search Unity

Urgent, how to force input fields to use games font Only.

Discussion in 'Editor & General Support' started by jesusluvsyooh, Jul 10, 2019.

  1. jesusluvsyooh

    jesusluvsyooh

    Joined:
    Jan 10, 2012
    Posts:
    377
    Hi, i have players glitching out player names and such, using custom keyboard fonts and smileys, is there anyway to force the input fields to use the games default font?

    Players are not selecting fonts in-game, for some reason the OnGUI GUI.TextFields default font, gets overridden by whatever keyboard type they use on their phone and tablets.

    I have censors, checks and regex to remove a lot of characters already, but the letter 'a' for example, with certain fonts can be all sorts of crazy stuff.
    I cannot force A-Z english letters as many are from other countries, Tai, Chinese, Russian etc

    If i join the online game using the editor, the following messages are shown, this is causing problem on certain devices, either extreme lag, code not working as expected and maybe even crashes.

    Edit: Added more info



     
    Last edited: Jul 10, 2019
  2. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    How are you letting players select fonts? I think you are misunderstanding the issue.

    I'd white list certain characters, instead of using a black list. Probably using a regex.
     
  3. jesusluvsyooh

    jesusluvsyooh

    Joined:
    Jan 10, 2012
    Posts:
    377
    Edit: I have updated the first post

    Edit: I seem to have got rid of a lot of the problem characters/fonts using a bunch of this below.
    It also seems to still allow many of the 'foreign'
    alphabets which was my main worry of over-censoring everything.

    Judging by my research and the error pictures above, utf8 is fine, utf16 kills the game.

    Code (JavaScript):
    1. inputField = Regex.Replace(inputField, "([\\10000-\\fffff])","");
    Also using some server side php code to temporary help (php):
    Code (CSharp):
    1. if( preg_match( '/[\x{10000}-\x{FFFFF}]+/u', $name ) )
    2. { echo "<p>contains bad"; }
    3. else { echo "<p>no bad"; }
     
    Last edited: Jul 10, 2019
  4. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    Curious why you're using the legacy GUI, which isn't intended or tested for anything bug as a developer only debug UI anymore.

    I'd still suggest going with a white list approach. Figure out all the characters you want to allow, and remove all that don't match the white list.

    As for UTF-8 vs UTF-16, all strings in C# are UTF-16 internally. Encoding generally only comes into play when saving to a text file to disk, or converting to a byte array for sending over the network, and in either case you can force a specific encoding anyways. UTF-8 and UTF-16 contain all the same characters.

    https://docs.microsoft.com/en-us/dotnet/api/system.string?redirectedfrom=MSDN&view=netframework-4.8
     
  5. jesusluvsyooh

    jesusluvsyooh

    Joined:
    Jan 10, 2012
    Posts:
    377
    Some of my games are 8+ years old ;)
    Can't remake them all (yet, sadly will probably have to happen one day)

    Perfect! Just found some examples on Google, a mixture of all this stuff should help me solve the problems, thanks for replying! :)
     
    Last edited: Jul 12, 2019