// Normal button events void OnPowerButtonDown(GameObject sender) { if (sender == powerButton.gameObject && CrossPlatformInputManager.ButtonExists(powerButton.GetButtonName())) { #if MOBILE_INPUT CrossPlatformInputManager.SetButtonDown(powerButton.GetButtonName()); #endif } }
void OnEnable() { // Get power component powerJoystick = GetComponent <PowerJoystick> (); powerDPad = GetComponent <PowerDPad> (); powerButton = GetComponent <PowerButton> (); if (powerJoystick != null) { powerType = PowerType.Joystick; } else if (powerDPad != null) { powerType = PowerType.DPad; } else if (powerButton != null) { powerType = PowerType.Button; } // Subscribe to trigger events if (powerType == PowerType.Joystick) { PowerJoystick.OnJoyPosHTriggerButtonDown += PosHTriggerButtonDown; PowerJoystick.OnJoyPosHTriggerButtonUp += PosHTriggerButtonUp; PowerJoystick.OnJoyNegHTriggerButtonDown += NegHTriggerButtonDown; PowerJoystick.OnJoyNegHTriggerButtonUp += NegHTriggerButtonUp; PowerJoystick.OnJoyPosVTriggerButtonDown += PosVTriggerButtonDown; PowerJoystick.OnJoyPosVTriggerButtonUp += PosVTriggerButtonUp; PowerJoystick.OnJoyNegVTriggerButtonDown += NegVTriggerButtonDown; PowerJoystick.OnJoyNegVTriggerButtonUp += NegVTriggerButtonUp; } if (powerType == PowerType.DPad) { PowerDPad.OnDPadPosHTriggerButtonDown += PosHTriggerButtonDown; PowerDPad.OnDPadPosHTriggerButtonUp += PosHTriggerButtonUp; PowerDPad.OnDPadNegHTriggerButtonDown += NegHTriggerButtonDown; PowerDPad.OnDPadNegHTriggerButtonUp += NegHTriggerButtonUp; PowerDPad.OnDPadPosVTriggerButtonDown += PosVTriggerButtonDown; PowerDPad.OnDPadPosVTriggerButtonUp += PosVTriggerButtonUp; PowerDPad.OnDPadNegVTriggerButtonDown += NegVTriggerButtonDown; PowerDPad.OnDPadNegVTriggerButtonUp += NegVTriggerButtonUp; } // Subscribe to normal button events if (powerType == PowerType.Button) { PowerButton.OnPowerButtonDown += OnPowerButtonDown; PowerButton.OnPowerButtonUp += OnPowerButtonUp; } // Register joystick axis if (powerType == PowerType.Joystick) { if (powerJoystick.useAxis == PowerJoystick.UseAxis.Both || powerJoystick.useAxis == PowerJoystick.UseAxis.Horizontal) { if (powerJoystick.GetHorizontalAxisName() != "" && !CrossPlatformInputManager.AxisExists(powerJoystick.GetHorizontalAxisName())) { horizontalAxis = new CrossPlatformInputManager.VirtualAxis(powerJoystick.GetHorizontalAxisName()); CrossPlatformInputManager.RegisterVirtualAxis(horizontalAxis); } // Unregister doesn't work correctly / Get axis reference (necessary if joysticks gets disbled and enabled again) if (powerJoystick.GetHorizontalAxisName() != "" && CrossPlatformInputManager.AxisExists(powerJoystick.GetHorizontalAxisName())) { horizontalAxis = CrossPlatformInputManager.VirtualAxisReference(powerJoystick.GetHorizontalAxisName()); } } if (powerJoystick.useAxis == PowerJoystick.UseAxis.Both || powerJoystick.useAxis == PowerJoystick.UseAxis.Vertical) { if (powerJoystick.GetVerticalAxisName() != "" && !CrossPlatformInputManager.AxisExists(powerJoystick.GetVerticalAxisName())) { verticalAxis = new CrossPlatformInputManager.VirtualAxis(powerJoystick.GetVerticalAxisName()); CrossPlatformInputManager.RegisterVirtualAxis(verticalAxis); } // Unregister doesn't work correctly / Get axis reference (necessary if joysticks gets disbled and enabled again) if (powerJoystick.GetVerticalAxisName() != "" && CrossPlatformInputManager.AxisExists(powerJoystick.GetVerticalAxisName())) { verticalAxis = CrossPlatformInputManager.VirtualAxisReference(powerJoystick.GetVerticalAxisName()); } } } // Register d-pad axis if (powerType == PowerType.DPad) { if (powerDPad.useAxis == PowerDPad.UseAxis.Both || powerDPad.useAxis == PowerDPad.UseAxis.Horizontal) { if (powerDPad.GetHorizontalAxisName() != "" && !CrossPlatformInputManager.AxisExists(powerDPad.GetHorizontalAxisName())) { horizontalAxis = new CrossPlatformInputManager.VirtualAxis(powerDPad.GetHorizontalAxisName()); CrossPlatformInputManager.RegisterVirtualAxis(horizontalAxis); } // Unregister doesn't work correctly / Get axis reference (necessary if d-pad gets disbled and enabled again) if (powerDPad.GetHorizontalAxisName() != "" && CrossPlatformInputManager.AxisExists(powerDPad.GetHorizontalAxisName())) { horizontalAxis = CrossPlatformInputManager.VirtualAxisReference(powerDPad.GetHorizontalAxisName()); } } if (powerDPad.useAxis == PowerDPad.UseAxis.Both || powerDPad.useAxis == PowerDPad.UseAxis.Vertical) { if (powerDPad.GetVerticalAxisName() != "" && !CrossPlatformInputManager.AxisExists(powerDPad.GetVerticalAxisName())) { verticalAxis = new CrossPlatformInputManager.VirtualAxis(powerDPad.GetVerticalAxisName()); CrossPlatformInputManager.RegisterVirtualAxis(verticalAxis); } // Unregister doesn't work correctly / Get axis reference (necessary if d-pad gets disbled and enabled again) if (powerDPad.GetVerticalAxisName() != "" && CrossPlatformInputManager.AxisExists(powerDPad.GetVerticalAxisName())) { verticalAxis = CrossPlatformInputManager.VirtualAxisReference(powerDPad.GetVerticalAxisName()); } } } // Register button if (powerType == PowerType.Button) { if (powerButton.GetButtonName() != null) { if (!CrossPlatformInputManager.ButtonExists(powerButton.GetButtonName())) { button = new CrossPlatformInputManager.VirtualButton(powerButton.GetButtonName()); CrossPlatformInputManager.RegisterVirtualButton(button); } } } // Register button axis if (powerType == PowerType.Button) { if (powerButton.GetButtonToAxis() && powerButton.GetAxisName() != "") { buttonAxisName = powerButton.GetAxisName(); if (!CrossPlatformInputManager.AxisExists(buttonAxisName)) { buttonAxis = new CrossPlatformInputManager.VirtualAxis(buttonAxisName); CrossPlatformInputManager.RegisterVirtualAxis(buttonAxis); } // Unregister doesn't work correctly / Get axis reference (necessary if button gets disbled and enabled again) if (powerButton.GetAxisName() != "" && CrossPlatformInputManager.AxisExists(powerButton.GetAxisName())) { buttonAxis = CrossPlatformInputManager.VirtualAxisReference(powerButton.GetAxisName()); } } } }