国产成+人+综合+亚洲 欧美-国产成+人+综合+亚洲专-国产成+人欧美+综合在线观看-国产成a人片在线观看视频-国产成a人片在线观看视频99-国产成a人片在线观看视频下载

您現在所在的位置:首頁 >關于奇酷 > 行業動態 > 鄭州unity3d培訓 UGUI長按監測的兩種方法

鄭州unity3d培訓 UGUI長按監測的兩種方法

來源:奇酷教育 發表于:

鄭州unity3d培訓 UGUI長按監測的兩種方法,奇酷(www qikuedu com)老師總結兩種辦法如下: 簡單的demo,隨便建幾個UI,把

        鄭州unity3d培訓 UGUI長按監測的兩種方法,奇酷(www.53542.cn)老師總結兩種辦法如下:
        簡單的demo,隨便建幾個UI,把腳本拖到任意物體,按1秒鐘后有響應事件。以下腳本可避免ScrollView失效,以及重疊UI穿透選擇。
鄭州unity3d培訓,Z???VR1VJ" src="http://uploadfile.qikuedu.com/2019/0319/20190319110022305.jpg" style="width: 480px; height: 270px;" />
方法一:使用EventSystems,適合場景中簡單的UI操作
using UnityEngine;
using UnityEngine.EventSystems;
 
public class RyanPressTest : MonoBehaviour {
        Vector3 lastMousePose;
    EventSystem m_EventSystem;
        float curT = 0;
        // 是否已經被選擇
        bool isPressed = false;
        void Start(){
        m_EventSystem = FindObjectOfType();
        }
        void Update () {
                if(Input.GetMouseButtonDown(0)){
                        lastMousePose = Input.mousePosition;
                }
        if (Input.GetMouseButton(0) && !isPressed && lastMousePose == Input.mousePosition)
        {
                        curT += Time.deltaTime;
                        // 長按1秒
                        if(curT >= 1f){
                    Debug.Log(m_EventSystem.currentSelectedGameObject + " was pressed.");
                                isPressed = true;
                        }
        }
                if(Input.GetMouseButtonUp(0)){
                        isPressed = false;
                        curT = 0;
                }
        }
}
 
方法二:使用射線,適用于鼠標一下選擇多個UI的復雜場景
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
 
public class RyanPressTest : MonoBehaviour {
        Vector3 lastMousePose;
    GraphicRaycaster m_Raycaster;
    PointerEventData m_PointerEventData;
        float curT = 0;
        // 是否已經被選擇
        bool isPressed = false;
        void Start(){
        m_Raycaster = FindObjectOfType ();
        }
        void Update () {
                if(Input.GetMouseButtonDown(0)){
                        lastMousePose = Input.mousePosition;
                }
        if (Input.GetMouseButton(0) && !isPressed && lastMousePose == Input.mousePosition)
        {
                        curT += Time.deltaTime;
            m_PointerEventData = new PointerEventData(null);
                        m_PointerEventData.position = lastMousePose;
 
            List results = new List();
            m_Raycaster.Raycast(m_PointerEventData, results);
                        // 長按1秒
                        if(results.Count > 0 && curT >= 1f){
                                // 當有多個重疊UI,results會返回所有被射線穿透的UI數組,一般我們只需要最上面的那個UI
                    Debug.Log(results[0].gameObject + " was pressed.");
                                isPressed = true;
                        }
        }
                if(Input.GetMouseButtonUp(0)){
                        isPressed = false;
                        curT = 0;
                }
        }
}
 
其實EventTrigger也能監測長按,但用了它ScrollView就失效了,還是用上面兩種方法比較通。
主站蜘蛛池模板: 国内自拍网红在线综合 | 成人亚洲国产综合精品91 | 久久狠狠色狠狠色综合 | 日日摸夜夜添夜夜添毛片 | 日本高清h色视频在线观看 日本高清不卡二区 | 97在线视频免费公开观看 | 中文字幕不卡在线播放 | 国产羞羞视频 | aaa毛片在线| 就操视频 | 激情综合色综合久久综合 | 亚洲欧美国产五月天综合 | 成年人一级黄色片 | 国产国语对白一级毛片 | 99久久99视频 | 亚洲欧美综合区自拍另类 | 欧美亚洲综合在线 | 精品伊人| 天天爽天天干天天操 | 99热这里只有精品一区二 | 中国女人内谢69xxxxx高清 | 色综合天天 | 亚洲精品宾馆在线精品酒店 | 久热在线 | 国产欧美日本在线观看 | 天天干天天插天天射 | 成人免费视频一区二区 | 国产精品麻豆99久久 | 欧美精品成人久久网站 | 天天拍拍夜夜出水 | 热热色视频 | 欧美色综合久久 | 91极品视频在线观看 | 人妖粗暴刺激videos | 激情五月宗合网 | 日本视频播放免费线上观看 | 国产精品区一区二区三 | 国产美女流白浆 | 免费黄色影院 | 伊人久久网国产伊人 | 国产毛片a|