Exemplo n.º 1
0
        public static bool GetKey(KeyMapping[] lKeys)
        {
            if (lKeys == null)
            {
                return(false);
            }

            for (int i = 0; i < lKeys.Length; i++)
            {
                KeyMapping lKey = lKeys[i];

                if (!lKey.Valid)
                {
                    continue;
                }
                else if (lKey.AxisName != null && lKey.AxisName.Length > 0)
                {
                    float lAxisValue = Input.GetAxisRaw(lKey.AxisName);

                    if ((lKey.Direction == AxisDirection.Positive &&
                         lAxisValue > 0.1f) ||
                        (lKey.Direction == AxisDirection.Negative &&
                         lAxisValue < -0.1f))
                    {
                        return(true);
                    }
                }
                else if (Input.GetKey(lKey.Key))
                {
                    return(true);
                }
            }

            return(false);
        }
Exemplo n.º 2
0
        public static bool GetKeyDown(KeyMapping[] lKeys)
        {
            if (lKeys == null)
            {
                return(false);
            }

            for (int i = 0; i < lKeys.Length; i++)
            {
                KeyMapping lKey = lKeys[i];

                if (!lKey.Valid)
                {
                    continue;
                }
                else if (lKey.AxisName != null && lKey.AxisName.Length > 0)
                {
                    if (!s_PreviousAxisKey.ContainsKey(lKey.AxisName))
                    {
                        s_PreviousAxisKey.Add(lKey.AxisName, false);
                    }

                    float lAxisValue = Input.GetAxisRaw(lKey.AxisName);

                    if ((lKey.Direction == AxisDirection.Positive &&
                         lAxisValue > 0.001f) ||
                        (lKey.Direction == AxisDirection.Negative &&
                         lAxisValue < -0.001f))
                    {
                        if (!s_PreviousAxisKey[lKey.AxisName])
                        {
                            s_PreviousAxisKey[lKey.AxisName] = true;
                            return(true);
                        }
                    }
                    else if (s_PreviousAxisKey[lKey.AxisName])
                    {
                        s_PreviousAxisKey[lKey.AxisName] = false;
                    }
                }
                else if (Input.GetKeyDown(lKey.Key))
                {
                    return(true);
                }
            }

            return(false);
        }
Exemplo n.º 3
0
        public static bool GetAnyKeyPressed(out KeyMapping lKeyCode)
        {
            if (s_AxisNames == null)
            {
                s_AxisNames = Enum.GetNames(typeof(AxisCode));
            }

            if (s_KeyCodes == null)
            {
                s_KeyCodes = Enum.GetValues(typeof(KeyCode)) as KeyCode[];
            }

            for (int i = 0; i < s_AxisNames.Length; i++)
            {
                string lAxisName = s_AxisNames[i];

                if (Input.GetAxisRaw(lAxisName) > 0.001f)
                {
                    lKeyCode = new KeyMapping(lAxisName, AxisDirection.Positive);
                    return(true);
                }
                else if (Input.GetAxisRaw(lAxisName) < -0.001f)
                {
                    lKeyCode = new KeyMapping(lAxisName, AxisDirection.Negative);
                    return(true);
                }
            }

            for (int i = 0; i < s_KeyCodes.Length; i++)
            {
                if (Input.GetKey(s_KeyCodes[i]))
                {
                    lKeyCode = new KeyMapping(s_KeyCodes[i]);

                    return(true);
                }
            }

            lKeyCode = new KeyMapping(KeyCode.None);

            return(false);
        }
Exemplo n.º 4
0
        public static bool GetKeyUp(KeyMapping[] lKeys)
        {
            if (lKeys == null)
            {
                return(false);
            }

            for (int i = 0; i < lKeys.Length; i++)
            {
                KeyMapping lKey = lKeys[i];

                if (!lKey.Valid)
                {
                    continue;
                }
                else if (lKey.AxisName != null && lKey.AxisName.Length > 0)
                {
                    if (!s_PreviousAxisKey.ContainsKey(lKey.AxisName))
                    {
                        s_PreviousAxisKey.Add(lKey.AxisName, false);
                    }

                    float lAxisValue = Input.GetAxisRaw(lKey.AxisName);

                    if (lAxisValue > -0.001f &&
                        lAxisValue < 0.001f &&
                        s_PreviousAxisKey[lKey.AxisName])
                    {
                        s_PreviousAxisKey[lKey.AxisName] = false;
                        return(true);
                    }
                }
                else if (Input.GetKeyUp(lKey.Key))
                {
                    return(true);
                }
            }

            return(false);
        }