static void ResetPressInfo() { ClickPressInfo.Clear(); ClickCDPressInfo.Clear(); DoublePressInfo.Clear(); LongPressInfo.Clear(); JoyAxisStateInfo.Clear(); }
public static void Register(KeyCode key, float[] para) { int idx = s_longPressKeys.FindIndex(x => x._key == key); if (idx < 0) { s_longPressKeys.Add(new LongPressInfo(key, para)); } else { s_longPressKeys[idx] = new LongPressInfo(key, para); } }
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; }); } }
public static bool TryGetValue(KeyCode key, out LongPressInfo info) { info = null; int idx = s_longPressKeys.FindIndex(x => x._key == key); if (idx < 0) { return(false); } info = s_longPressKeys [idx]; return(true); }
public static bool IsLongPress(this KeyCode key) { LongPressInfo pressInfo; if (LongPressInfo.TryGetValue(key, out pressInfo)) { if (!Input.GetKey(key) || !NotExcluderByOther()) { pressInfo._startDown = 0.0f; return(false); } if (pressInfo._startDown < PETools.PEMath.Epsilon) { pressInfo._startDown = Time.time; return(false); } return(Time.time - pressInfo._startDown > pressInfo._term); } return(false); }