Ejemplo n.º 1
0
    // -------------------------------------------------------------------------
    #endregion
    // -------------------------------------------------------------------------


    // -------------------------------------------------------------------------
    #region Unity Functions
    // -------------------------------------------------------------------------
    private void Update()
    {
        // Get the current value for the axis
        float axisValue = Input.GetAxis(axisName);

        // Each frame, check if we should perform actions
        // Before we try to perform any actions, check if we are off cooldown
        if (Time.time >= lastActivate + cooldown)
        {
            // Has the axis value changed?
            if (axisValue != previousAxisValue)
            {
                // The axis has changed since last frame, so perform the actions.
                onAxisChanged.Invoke(axisValue);

                // Record this time in lastActivate so we can check
                // when we next come off cooldown
                lastActivate = Time.time;
            }

            // Did the axis just become active (non-zero)?
            if (previousAxisValue == 0 && axisValue != 0)
            {
                // The axis just became non-zero, so perform actions.
                onAxisStart.Invoke(axisValue);

                // Record this time in lastActivate so we can check
                // when we next come off cooldown
                lastActivate = Time.time;
            }

            // Did the axis just become inactive (zero)?
            if (previousAxisValue != 0 && axisValue == 0)
            {
                // The axis just became zero, so perform actions.
                onAxisEnd.Invoke(axisValue);

                // Record this time in lastActivate so we can check
                // when we next come off cooldown
                lastActivate = Time.time;
            }

            // Is the axis active (non-zero)?
            if (axisValue != 0)
            {
                // The axis just became non-zero, so perform actions.
                onAxisActive.Invoke(axisValue);

                // Record this time in lastActivate so we can check
                // when we next come off cooldown
                lastActivate = Time.time;
            }

            // The current value for the axis now becomes the previous value
            // for the next frame
            previousAxisValue = axisValue;
        }
    }
Ejemplo n.º 2
0
        public virtual void ReadPage(IPage page)
        {
            if (page is KeyInputEvent)
            {
                KeyInputEvent keyEvent = page as KeyInputEvent;
                if (keyEvent.BindKey.ToString() == JoystickID + "TopFace")
                {
                    if (OnTopButton != null)
                    {
                        OnTopButton.Invoke(keyEvent.KeyHitState);
                    }
                }
                if (keyEvent.BindKey.ToString() == JoystickID + "LeftFace")
                {
                    if (OnLeftButton != null)
                    {
                        OnLeftButton.Invoke(keyEvent.KeyHitState);
                    }
                }
                if (keyEvent.BindKey.ToString() == JoystickID + "RightFace")
                {
                    if (OnRightButton != null)
                    {
                        OnRightButton.Invoke(keyEvent.KeyHitState);
                    }
                }
                if (keyEvent.BindKey.ToString() == JoystickID + "BottomFace")
                {
                    if (OnBottomButton != null)
                    {
                        OnBottomButton.Invoke(keyEvent.KeyHitState);
                    }
                }
                if (keyEvent.BindKey.ToString() == JoystickID + "LeftBump")
                {
                    if (OnLeftBumper != null)
                    {
                        OnLeftBumper.Invoke(keyEvent.KeyHitState);
                    }
                }
                if (keyEvent.BindKey.ToString() == JoystickID + "RightBump")
                {
                    if (OnRightBumper != null)
                    {
                        OnRightBumper.Invoke(keyEvent.KeyHitState);
                    }
                }
                if (keyEvent.BindKey.ToString() == JoystickID + "Start")
                {
                    if (OnStart != null)
                    {
                        OnStart.Invoke(keyEvent.KeyHitState);
                    }
                }
                if (keyEvent.BindKey.ToString() == JoystickID + "Select")
                {
                    if (OnSelect != null)
                    {
                        OnSelect.Invoke(keyEvent.KeyHitState);
                    }
                }
                if (keyEvent.BindKey.ToString() == JoystickID + "Home")
                {
                    if (OnHome != null)
                    {
                        OnHome.Invoke(keyEvent.KeyHitState);
                    }
                }
                if (keyEvent.BindKey.ToString() == JoystickID + "LeftAnalogClick")
                {
                    if (OnLeftAnalogButton != null)
                    {
                        OnLeftAnalogButton.Invoke(keyEvent.KeyHitState);
                    }
                }
                if (keyEvent.BindKey.ToString() == JoystickID + "RightAnalogClick")
                {
                    if (OnRightAnalogButton != null)
                    {
                        OnRightAnalogButton.Invoke(keyEvent.KeyHitState);
                    }
                }

                {
                    // handle customs
                    foreach (KeyValuePair <string, KeyBind> pair in LayoutMap.CustomKeyBind.D)
                    {
                        if (keyEvent.BindKey.ToString() == JoystickID + pair.Key)
                        {
                            if (OnCustomKey != null)
                            {
                                OnCustomKey.Invoke(pair.Key, keyEvent.KeyHitState);
                            }
                        }
                    }
                }
            }
            else if (page is AxisInputEvent)
            {
                AxisInputEvent AxisEvent = page as AxisInputEvent;
                if (AxisEvent.BindKey.ToString() == JoystickID + "LeftAnalog")
                {
                    if (OnLeftAnalog != null)
                    {
                        OnLeftAnalog.Invoke(new Vector2(AxisEvent.AxisMap[JoystickID + LayoutMap.LeftAnalogAxisX], AxisEvent.AxisMap[JoystickID + LayoutMap.LeftAnalogAxisY]));
                    }
                }
                else if (AxisEvent.BindKey.ToString() == JoystickID + "RightAnalog")
                {
                    if (OnRightAnalog != null)
                    {
                        OnRightAnalog.Invoke(new Vector2(AxisEvent.AxisMap[JoystickID + LayoutMap.RightAnalogAxisX], AxisEvent.AxisMap[JoystickID + LayoutMap.RightAnalogAxisY]));
                    }
                }
                else if (AxisEvent.BindKey.ToString() == JoystickID + "DPad")
                {
                    if (OnDPad != null)
                    {
                        OnDPad.Invoke(new Vector2(AxisEvent.AxisMap[JoystickID + LayoutMap.DirectionAxisX], AxisEvent.AxisMap[JoystickID + LayoutMap.DirectionAxisY]));
                    }
                }
                else if (AxisEvent.BindKey.ToString() == JoystickID + "LeftTrigger")
                {
                    if (OnLeftTrigger != null)
                    {
                        OnLeftTrigger.Invoke(new Vector2(AxisEvent.AxisMap[JoystickID + LayoutMap.LeftTriggerAxis], 0.0f));
                    }
                }
                else if (AxisEvent.BindKey.ToString() == JoystickID + "RightTrigger")
                {
                    if (OnRightTrigger != null)
                    {
                        OnRightTrigger.Invoke(new Vector2(AxisEvent.AxisMap[JoystickID + LayoutMap.RightTriggerAxis], 0.0f));
                    }
                }
                else
                {
                    // handle customs
                    foreach (KeyValuePair <string, AxisBind> pair in LayoutMap.CustomAxisBind.D)
                    {
                        if (AxisEvent.BindKey.ToString() == JoystickID + pair.Key)
                        {
                            if (OnCustomAxis != null)
                            {
                                OnCustomAxis.Invoke(pair.Key, new Vector2(AxisEvent.AxisMap[JoystickID + pair.Value.PlatformAxisID], 0.0f));
                            }
                        }
                    }
                }
            }
        }