unityプロジェクトでは、テキストの内容をシステムクリップボード(android,ios,unityeditorの3つの部分を含む)にコピーする必要があります.
unityでテキストをクリップボードにコピーし、android、IOS、エディタの3つの部分に分けます.自分でこの3つの部分のやり方を実現した.コードはスクリプトが1つしかありません.
demoアドレス:https://download.csdn.net/download/u011976408/10364252
using UnityEngine;
using UnityEngine.UI;
using System.Runtime.InteropServices;
using System.Collections;
public class Test : MonoBehaviour
{
public InputField input;
#if UNITY_IOS
[DllImport("__Internal")]
private static extern void _copyTextToClipboard(string text);
#endif
public void OnClickCopyText()
{
#if UNITY_ANDROID
AndroidJavaObject androidObject = new AndroidJavaObject("com.androidclicp.ClipboardTools");
AndroidJavaObject activity = new AndroidJavaClass("com.unity3d.player.UnityPlayer").GetStatic("currentActivity");
if (activity == null)
return;
//
androidObject.Call("copyTextToClipboard", activity, input.text);
//
string text = androidObject.Call("getTextFromClipboard");
#elif UNITY_IOS
_copyTextToClipboard(input.text);
#elif UNITY_EDITOR
TextEditor te = new TextEditor();
te.content = new GUIContent(input.text);
te.SelectAll();
te.Copy();
#endif
}
}
demoアドレス:https://download.csdn.net/download/u011976408/10364252