请选择 进入手机版 | 继续访问电脑版
MSIPO技术圈 首页 IT技术 查看内容

untiy 过滤 安卓原生输入法表情

2023-07-13

using System.Collections;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using UnityEngine;
using UnityEngine.UI;

public class NewBehaviourScript : MonoBehaviour
{
    // Start is called before the first frame update
    void Start()
    {
        GameObject.Find("com_btn").GetComponent<Button>().onClick.AddListener(() => {

            string str = GameObject.Find("com_inp").GetComponent<InputField>().text;

            if (str.Length <= 0)
            {
                str = "输入为空";
            }

            GameObject.Find("com_txt").GetComponent<Text>().text = str;

        });

        GameObject.Find("com_btn2").GetComponent<Button>().onClick.AddListener(() => {

            string str = GameObject.Find("com_inp").GetComponent<InputField>().text;
            str = FilterEmoji(str);
            if (str.Length <= 0)
            {
                str = "输入为空";
            }

            GameObject.Find("com_txt2").GetComponent<Text>().text = str;

        });
    }

    List<string> patten = new List<string>() { @"\p{Cs}", @"\p{Co}", @"\p{Cn}", @"[\u2702-\u27B0]" };

    private string FilterEmoji(string str)
    {
        for (int i = 0; i < patten.Count; i++)
        {
            str = Regex.Replace(str, patten[i], "");//屏蔽emoji   
        }
        return str;
    }
}

unity场景

 

相关阅读

手机版|MSIPO技术圈 皖ICP备19022944号-2

Copyright © 2023, msipo.com

返回顶部