您好,登錄后才能下訂單哦!
上次做項目時用到雙擊了,這次又想用,但是上次沒總結,這次又的再寫一遍,這次就直接掛出來,下次直接就能用了,附件密碼:mouse;
Update里面執行:
if(Input.GetMouseButtonDown(0)) { if(!this.mouseDownStatus) { this.mouseDownStatus = true; //Debug.Log("Click !"); if(this.clickCallback != null) this.clickCallback(); if(this.mouseDownCount == 0) { this.lastTime = Time.realtimeSinceStartup; } this.mouseDownCount ++; } } if(Input.GetMouseButtonUp(0)) { //Debug.Log("Up !"); this.mouseDownStatus = false; } if(this.mouseDownStatus) { //Debug.Log("Hold !"); if(this.mouseDownCount >= 2) { this.currentTime = Time.realtimeSinceStartup; if(this.currentTime - this.lastTime < 0.3f) { this.lastTime = this.currentTime; this.mouseDownCount = 0; //Debug.Log("Double Click"); if(this.doubleCallback != null) this.doubleCallback(); } else { this.lastTime = Time.realtimeSinceStartup; this.mouseDownCount = 1; } } } //雙擊調用方法 public class MouseResponseManager { public static void Register(GameObject objectItem, Action clickCallback, Action doubleCallback) { if(objectItem == null) { objectItem = new GameObject(); objectItem.name = "MouseResponseItem"; } MouseResponseItem mouseResponseItem = objectItem.AddComponent<MouseResponseItem> (); mouseResponseItem.Init (clickCallback, doubleCallback); } } 在就直接調用: MouseResponseManager.Register(null, ()=> { 。。。。。 }, ()=>{ 。。。。。 });
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。