• Unity屏蔽emoji


    在开发网络游戏的聊天功能模块时,需要对字符长度进行限制以免发送超长包,不过因为玩家输入了emoji后会导致长度无法正常处理,此时偷懒的办法就是限制emoji的输入

    在UGUI的InputField进行输入时执行该方法:

    using UnityEngine;
    using UnityEngine.UI;
    using System.Collections;
    using System.Text.RegularExpressions;
    public class InputRestrictionEmoji : MonoBehaviour {

    InputField mtext;

    private void Start()
    {
    mtext = GetComponent<InputField>();
    if(mtext)
    {
    mtext.onValueChanged.AddListener(OnInputValue);
    }
    }

    void OnInputValue(string value)
    {
    try
    {
    string msg = mtext.text;
    //屏蔽emoji
    string result = Regex.Replace(msg, @"p{Cs}", "");
    mtext.text = result;
    }
    catch
    {
    Debug.Log("输入异常文字,出错");
    mtext.text = "";
    }
    }
    }

    如果还是不放心可以try-catch一下,记得还要限制一下字符长度啊

    特别感谢:

    EmojiText https://github.com/zouchunyi/EmojiText

    Unity-UI-emoji https://github.com/mcraiha/Unity-UI-emoji

    twemoji https://github.com/twitter/twemoji

    游戏是由人创造出来的,你如果能够为开发人员提供高质量的工具,并帮助他们更好地完成自己的工作,包括帮助他们提高生产力、尝试新事物并进行实验,那么你就越有可能在这个行业中获得成功。
  • 相关阅读:
    软件测试——一点看法
    软件测试——注意事项
    软件测试——Peer Review
    软件测试——白盒测试
    软件测试——闰年检测程序及异常问题解决
    JS动态,有选择性的改变div颜色
    软件测试——EditBox等价类划分扩展
    软件测试——EditBox等价类划分
    初窥软件测试
    开博第一篇
  • 原文地址:https://www.cnblogs.com/rxs123/p/7054319.html
Copyright © 2020-2023  润新知