Unity | 实现粘贴、复制功能

 最近做的项目里有个需求是这样的:对一张图片里的公式进行截图,通过调用公式识别API,获得该公式的Latex文本,通过点击按钮复制、快捷键ctrl+v粘贴。

using UnityEngine;
using UnityEngine.UI;

public class Test : MonoBehaviour
{
    TextEditor te = new TextEditor();
    public Text oldText;
    public Text newText;

    void Update()
    {
        if (Input.GetMouseButtonDown(0))
        {
            te.text = oldText.text;
            //以下两行代码,相当于ctrl+c操作
            te.SelectAll();
            te.Copy();
        }
        if (Input.GetMouseButtonDown(1))
        {
            newText.text = te.text;
            //以下代码,相当于ctrl+v操作
            te.Paste();
        }
    }
}
发布了162 篇原创文章 · 获赞 20 · 访问量 7万+

猜你喜欢

转载自blog.csdn.net/weixin_39766005/article/details/90672297