纳金网

标题: 鼠标双击事件简单应用 [打印本页]

作者: 烟雨    时间: 2014-12-30 22:13
标题: 鼠标双击事件简单应用
大概原理就是通过第一次点击的时间跟第二次点击的时间进行相减 如果小于 0.2s 就判断为双击  
很简单的一个鼠标双击的判断

using unityEngine;

namespace HutongGames.PlayMaker.Actions
{
[ActionCategory(ActionCategory.Input)]
[Tooltip("Gets the pressed state of the specified Mouse Button and stores it in a Bool Variable. See Unity Input Manager doc.")]
public class GetMouseDLeft : FsmStateAction
{

        [RequiredField]
        public MouseButton button;
        public FsmEvent sendEvent;
        [UIHint(UIHint.Variable)]
        public FsmBool storeResult;
float time=0;
int count=0;
public override void Reset()
{
            button = MouseButton.Left;
            sendEvent = null;
            storeResult = null;
}


public override void OnUpdate()
{
bool buttonDown = Input.GetMouseButtonDown((int)button);
if (buttonDown)
{
if(count==0)
time=Time.time;
count++;
}
if (count == 2)
{
if((Time.time-time)<0.2)
{
if (buttonDown)
Fsm.Event(sendEvent);
storeResult.Value = buttonDown;
count=0;
time=0;
}
else
{
count=0;
time=0;
}
}
}
}
}





欢迎光临 纳金网 (http://go.narkii.com/club/) Powered by Discuz! X2.5