Ejemplo n.º 1
0
    public static bool IsClickCDPress(this KeyCode key)
    {
        bool             bDn = Input.GetKeyDown(key);
        bool             bUp = Input.GetKeyUp(key);
        ClickCDPressInfo pressInfo;

        if ((bDn || bUp) && NotExcluderByOther() && ClickCDPressInfo.TryGetValue(key, out pressInfo))
        {
            if (Time.time - pressInfo._lastClick < pressInfo._cd)
            {
                return(false);
            }

            if (bDn)
            {
                pressInfo._lastDown = Time.time;
            }
            else if (bUp)
            {
                float deltaTime = Time.time - pressInfo._lastDown;
                if (deltaTime < pressInfo._interval)
                {
                    pressInfo._lastClick = Time.time;
                    return(true);
                }
            }
        }
        return(false);
    }
Ejemplo n.º 2
0
 static void ResetPressInfo()
 {
     ClickPressInfo.Clear();
     ClickCDPressInfo.Clear();
     DoublePressInfo.Clear();
     LongPressInfo.Clear();
     JoyAxisStateInfo.Clear();
 }
Ejemplo n.º 3
0
        public static void Register(KeyCode key, float[] para)
        {
            int idx = s_clickCDPressKeys.FindIndex(x => x._key == key);

            if (idx < 0)
            {
                s_clickCDPressKeys.Add(new ClickCDPressInfo(key, para));
            }
            else
            {
                s_clickCDPressKeys[idx] = new ClickCDPressInfo(key, para);
            }
        }
Ejemplo n.º 4
0
    static Func <bool> CreatePressTestFunc(KeyCode key, KeyPressType pressType, float[] para)
    {
        if (pressType < KeyPressType.JoyStickBegin)
        {
            if (key == KeyCode.None)
            {
                return(() => false);
            }
            int mask = (int)key & KeyMask;                      // use excluder to check key mask
            if (mask != 0)
            {
                key = key - mask;
            }
        }

        switch (pressType)
        {
        default:
        case KeyPressType.Up:                           return(() => Input.GetKeyUp(key) && NotExcluderByOther());

        case KeyPressType.Down:                         return(() => Input.GetKeyDown(key) && NotExcluderByOther());

        case KeyPressType.Press:                        return(() => Input.GetKey(key) && NotExcluderByOther());

        case KeyPressType.UpHPrior:                     return(() => Input.GetKeyUp(key));

        case KeyPressType.PressHPrior:          return(() => Input.GetKey(key));

        case KeyPressType.ClickNoMove:          return(() => key.IsClickNoMove());

        case KeyPressType.Click:                        ClickPressInfo.Register(key, para);             return(() => key.IsClickPress());

        case KeyPressType.ClickCD:                      ClickCDPressInfo.Register(key, para);   return(() => key.IsClickCDPress());

        case KeyPressType.DoublePress:          DoublePressInfo.Register(key, para);    return(() => key.IsDoublePress());

        case KeyPressType.LongPress:            LongPressInfo.Register(key, para);              return(() => key.IsLongPress());

        case KeyPressType.DirU:                         s_keyAxisU = key;       return(delegate { return s_curAxisV > PETools.PEMath.Epsilon; });

        case KeyPressType.DirD:                         s_keyAxisD = key;       return(delegate { return s_curAxisV < -PETools.PEMath.Epsilon; });

        case KeyPressType.DirR:                         s_keyAxisR = key;       return(delegate { return s_curAxisH > PETools.PEMath.Epsilon; });

        case KeyPressType.DirL:                         s_keyAxisL = key;       return(delegate { return s_curAxisH < -PETools.PEMath.Epsilon; });

        case KeyPressType.MouseWheelU:          return(delegate { return Input.GetAxis("Mouse ScrollWheel") > PETools.PEMath.Epsilon; });

        case KeyPressType.MouseWheelD:          return(delegate { return Input.GetAxis("Mouse ScrollWheel") < -PETools.PEMath.Epsilon; });
        }
    }
Ejemplo n.º 5
0
        public static bool TryGetValue(KeyCode key, out ClickCDPressInfo info)
        {
            info = null;

            int idx = s_clickCDPressKeys.FindIndex(x => x._key == key);

            if (idx < 0)
            {
                return(false);
            }

            info = s_clickCDPressKeys [idx];
            return(true);
        }