using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.EventSystems; using UnityEngine.UI; public class Copytext : MonoBehaviour,IPointerDownHandler, IPointerUpHandler { float pressedTime = 0; // 按下的时间 private bool isDown; // 是否按下 Coroutine coroutine; public void OnPointerDown(PointerEventData eventData) { Debug.Log("TextCopyExtend Component is Down..."); isDown = true; coroutine = StartCoroutine(CalculatePressedTime()); // 按下开携程 } private IEnumerator CalculatePressedTime() { while (isDown) // 只有按下了才启动 { yield return null; pressedTime += Time.deltaTime; if (pressedTime >= 0.5f) // 超过一秒 { Debug.Log("复制文本"); // UIMgr.Instance.Notice(ConfigMgr.Instance.GetLanguage(400)); // 提示复制成功 GUIUtility.systemCopyBuffer = GetComponent().text; // 获取文本内容 isDown = false; } } } public void OnPointerUp(PointerEventData eventData) { Debug.Log("TextCopyExtend Component is Up..."); isDown = false; pressedTime = 0; if (coroutine != null) { StopCoroutine(CalculatePressedTime()); } } }