Browse Source

视角归位长按出来模拟鼠标

lvjincheng 3 năm trước cách đây
mục cha
commit
9db6d11fcd

+ 39 - 0
Assets/BowArrow/Scripts/Components/LongPressMonitor.cs

@@ -0,0 +1,39 @@
+using UnityEngine;
+using UnityEngine.EventSystems;
+using System;
+
+public class LongPressMonitor : MonoBehaviour, IPointerDownHandler, IPointerUpHandler, IPointerExitHandler
+{
+    public Action onLongPress;
+    public float interval = 1.0f;
+    bool isDown;
+    float downTime;
+    [NonSerialized] public bool isLongPress; //最后一次点击是否为长按
+
+    void Update()
+    {
+        if (isDown)
+        {
+            if (Time.time - downTime > interval)
+            {
+                isDown = false;
+                isLongPress = true;
+                onLongPress?.Invoke();           
+            }
+        }
+    }
+    public void OnPointerDown(PointerEventData eventData)
+    {
+        isDown = true;
+        isLongPress = false;
+        downTime = Time.time;
+    }
+    public void OnPointerExit(PointerEventData eventData)
+    {
+        isDown = false;
+    }
+    public void OnPointerUp(PointerEventData eventData)
+    {
+        isDown = false;
+    }
+}

+ 11 - 0
Assets/BowArrow/Scripts/Components/LongPressMonitor.cs.meta

@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: 1811f5b04c8631f468beeee17d48ada6
+MonoImporter:
+  externalObjects: {}
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 5 - 0
Assets/BowArrow/Scripts/Game/GameAssistUI.cs

@@ -58,9 +58,14 @@ public class GameAssistUI : MonoBehaviour
         });
         Button btnIdentity = this.transform.Find("Button4").GetComponent<Button>();
         btnIdentity.onClick.AddListener(delegate(){
+            if (btnIdentity.GetComponent<LongPressMonitor>().isLongPress) return;
             AudioMgr.ins.PlayBtn();
             AutoResetView.DoIdentity();
         });
+        btnIdentity.gameObject.AddComponent<LongPressMonitor>().onLongPress += () => {
+            AudioMgr.ins.PlayBtn();
+            if (SB_EventSystem.ins) SB_EventSystem.ins.AwakenSimulateMouse(); 
+        };
 
         // ------ 查看靶子 ------
         Transform targetView = this.transform.Find("TargetView");