上次做项目时用到双击了,这次又想用,但是上次没总结,这次又的再写一遍,这次就直接挂出来,下次直接就能用了,附件密码: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进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。