Beispiel #1
0
    private void OnEnable()
    {
        state  = gameObject.AddComponent <ButtonState>();
        effect = Instantiate(buttonEffect, transform);
        effect.GetComponent <ParticleSystem>().Stop();

        // タップ判定
        var eventTrigger = GetComponent <ObservableEventTrigger>();

        eventTrigger.OnPointerDownAsObservable()
        .Subscribe((_) => OnButtonDown.Invoke(this, state.Index));

        eventTrigger
        .OnPointerUpAsObservable()
        .Subscribe(_ => OnButtonUp.Invoke(this, state.Index));

        // キーボード判定
        this.UpdateAsObservable()
        .Where(_ => Input.GetKeyDown(keys[state.Index]))
        .Subscribe(_ => OnButtonDown.Invoke(this, state.Index));

        this.UpdateAsObservable()
        .Where(_ => Input.GetKeyUp(keys[state.Index]))
        .Subscribe(_ => OnButtonUp.Invoke(this, state.Index));

        OnButtonDown += ButtonController_OnButtonDown;
        OnButtonUp   += ButtonController_OnButtonUp;
    }
    public void Update()
    {
        for (Axis i = Axis.MoveHorizontal; i <= Axis.Shoot; i++)
        {
            float value = Input.GetAxisRaw(string.Format("{0} {1}", Controller, i.ToString()));
            OnCurrentAxis?.Invoke(i, value, this);

            //Keyboard uses mouse for rotation
            if (controller == ControllerType.Keyboard && i == Axis.MoveVertical)
            {
                break;
            }
        }

        for (Action i = Action.Start; i <= Action.Heal; i++)
        {
            //Joysticks shoots with triggers (axis)
            if (controller != ControllerType.Keyboard && i == Action.Shoot)
            {
                continue;
            }

            string s = string.Format("{0} {1}", Controller, i.ToString());

            if (Input.GetButtonDown(s))
            {
                OnButtonDown?.Invoke(i, this);
            }

            if (Input.GetButtonUp(s))
            {
                OnButtonUp?.Invoke(i, this);
            }
        }
    }
        private void OnDPadPress(object sender, GamepadDPadEventArgs args)
        {
            ButtonConfig currentButton = GetCurrentButton(args.Buttons);

            if (lastDPadButton == null)
            {
                if (currentButton != null)
                {
                    OnButtonDown?.Invoke(this, new GamepadHelperEventArgs(currentButton));
                }
                lastDPadButton = currentButton;
            }
            else
            {
                if (lastDPadButton != currentButton)
                {
                    if (lastDPadButton != null)
                    {
                        OnButtonUp?.Invoke(this, new GamepadHelperEventArgs(lastDPadButton));
                    }
                    if (currentButton != null)
                    {
                        OnButtonDown?.Invoke(this, new GamepadHelperEventArgs(currentButton));
                    }
                    lastDPadButton = currentButton;
                }
            }
        }
        public void OnPointerExit(PointerEventData eventData)
        {
            IsPressDown = false;

            if (OnButtonUp != null)
            {
                OnButtonUp.Invoke();
            }
        }
Beispiel #5
0
        protected override void ButtonUpFeedback(PointerEventData eventData)
        {
            if (buttonMovementCoroutine != null)
            {
                StopCoroutine(buttonMovementCoroutine);
            }
            StartCoroutine(transform.LerpLocal(originPos, 0.3f, curvesPreset.EaseOut));

            // Hover in sound
            // Hover in effect

            OnButtonUp?.Invoke(buttonType);
        }
        private void OnTriggerPress(object sender, GamepadTriggerEventArgs args)
        {
            ButtonConfig currentButton = args.Trigger == GamepadTriggers.Left ? profile.LT : profile.RT;

            if (args.Value > 0)
            {
                OnButtonDown?.Invoke(this, new GamepadHelperEventArgs(currentButton));
            }
            else
            {
                OnButtonUp?.Invoke(this, new GamepadHelperEventArgs(currentButton));
            }
        }
        private void OnButtonPress(object sender, GamepadButtonEventArgs args)
        {
            ButtonConfig currentButton = GetCurrentButton(args.Button);

            if (currentButton != null && args.IsPressed)
            {
                OnButtonDown?.Invoke(this, new GamepadHelperEventArgs(currentButton));
            }
            else
            {
                OnButtonUp?.Invoke(this, new GamepadHelperEventArgs(currentButton));
            }
        }
Beispiel #8
0
        private void FireMouseEvents()
        {
            foreach (MouseButton button in ButtonList)
            {
                if (button == MouseButton.LEFT)
                {
                    // Button is held down
                    if (CurrentMouseState.LeftButton == ButtonState.Pressed)
                    {
                        OnButtonDown?.Invoke(this, new MouseEventArgs(button, CurrentMouseState, PrevMouseState));
                    }

                    // Button is pressed once
                    if (PrevMouseState.LeftButton == ButtonState.Released &&
                        CurrentMouseState.LeftButton == ButtonState.Pressed)
                    {
                        OnButtonPressed?.Invoke(this, new MouseEventArgs(button, CurrentMouseState, PrevMouseState));
                    }


                    // Button is just released once
                    if (PrevMouseState.LeftButton == ButtonState.Pressed &&
                        CurrentMouseState.LeftButton == ButtonState.Released)
                    {
                        OnButtonUp?.Invoke(this, new MouseEventArgs(button, CurrentMouseState, PrevMouseState));
                    }
                }
                else if (button == MouseButton.RIGHT)
                {
                    // Button is held down
                    if (CurrentMouseState.RightButton == ButtonState.Pressed)
                    {
                        OnButtonDown?.Invoke(this, new MouseEventArgs(button, CurrentMouseState, PrevMouseState));
                    }

                    // Button is pressed once
                    if (PrevMouseState.RightButton == ButtonState.Released &&
                        CurrentMouseState.RightButton == ButtonState.Pressed)
                    {
                        OnButtonPressed?.Invoke(this, new MouseEventArgs(button, CurrentMouseState, PrevMouseState));
                    }

                    // Button is just released
                    if (PrevMouseState.RightButton == ButtonState.Pressed &&
                        CurrentMouseState.RightButton == ButtonState.Released)
                    {
                        OnButtonUp?.Invoke(this, new MouseEventArgs(button, CurrentMouseState, PrevMouseState));
                    }
                }
            }
        }
Beispiel #9
0
        public override void OnButtonUpAction()
        {
            if (!gameObject.activeInHierarchy)
            {
                return;
            }

            if (DebugLog)
            {
                UnityEngine.Debug.Log("Button UP");
            }

            OnButtonUp.Invoke();
        }
 public void CheckInput()
 {
     if (Input.GetButtonDown(ButtonName))
     {
         OnButtonDown?.Invoke();
     }
     if (Input.GetButtonUp(ButtonName))
     {
         OnButtonUp?.Invoke();
     }
     if (Input.GetButton(ButtonName))
     {
         OnButton?.Invoke();
     }
 }
Beispiel #11
0
 private void Update()
 {
     OVRInput.Update();
     foreach (OVRInput.Button button in buttons)
     {
         if (inputStates[button] && OVRInput.Get(button))
         {
             inputStates[button] = false;
             OnButtonDown?.Invoke(button);
         }
         else if (!inputStates[button] && !OVRInput.Get(button))
         {
             inputStates[button] = true;
             OnButtonUp?.Invoke(button);
         }
     }
 }
        internal void InitGamePadHandlers()
        {
            _gamePadHandlers = new GamePadHandler[MaxGamePads];
            for (int i = 0; i < MaxGamePads; i++)
            {
                var handle = _gamePadHandlers[i] = new GamePadHandler(i);

                // Redirect Events.
                handle.OnConnection += () => OnConnection?.Invoke(handle);
                handle.OnDisconnect += () => OnDisconnected?.Invoke(handle);

                handle.OnButtonDown     += (button, value) => OnButtonDown?.Invoke(handle, button, value);
                handle.OnButtonUp       += (button, value) => OnButtonUp?.Invoke(handle, button, value);
                handle.OnButtonPressed  += (button, value) => OnButtonPressed?.Invoke(handle, button, value);
                handle.OnButtonClicked  += (button, value) => OnButtonClicked?.Invoke(handle, button, value);
                handle.OnButtonReleased += (button, value) => OnButtonReleased?.Invoke(handle, button, value);
            }
        }
Beispiel #13
0
 public override void HandleState(XRController controller)
 {
     if (controller.inputDevice.IsPressed(button, out bool pressed, controller.axisToPressThreshold))
     {
         if (previousPress != pressed)
         {
             previousPress = pressed;
             if (pressed)
             {
                 OnButtonDown?.Invoke(controller);
             }
             else
             {
                 OnButtonUp?.Invoke(controller);
             }
         }
     }
 }
Beispiel #14
0
    private void Init()
    {
        dir = selectedType.Equals(ButtonType.Left) ? -1 : +1;

        var DownEntry = new EventTrigger.Entry();

        DownEntry.eventID = EventTriggerType.PointerDown;
        DownEntry.callback.AddListener((data) => OnButtonDown?.Invoke(dir, true));

        var UpEntry = new EventTrigger.Entry();

        UpEntry.eventID = EventTriggerType.PointerUp;
        UpEntry.callback.AddListener((data) => OnButtonUp?.Invoke(false));

        button = GetComponent <EventTrigger>();
        button.triggers.Add(DownEntry);
        button.triggers.Add(UpEntry);
    }
Beispiel #15
0
    void Update()
    {
        if (Image != null)
        {
            if (!DontModifyImageSprite)
            {
                Image.sprite = GetDesiredSprite();
            }

            Image.color = GetDesiredColor();
        }

        if (gameObject.HasComponent <ClickDetector>() ?
            WasClicked :
            IsTouched && InputUtility.WasMouseLeftReleased)
        {
            OnButtonUp.Invoke();
        }
    }
Beispiel #16
0
        public void Update()
        {
            var currentButtons = GamePadButtonsHelper.GetPressedButtons(0);

            previousUpdateButtons.Except(currentButtons).ToList().ForEach(button =>
                                                                          OnButtonUp?.Invoke(0, new GamePadButtonEventArgs(button)));
            currentButtons.Except(previousUpdateButtons).ToList().ForEach(button =>
                                                                          OnButtonDown?.Invoke(0, new GamePadButtonEventArgs(button)));
            previousUpdateButtons.Clear();
            previousUpdateButtons.AddRange(currentButtons);

            var currentDPadButtons = GamePadButtonsHelper.GetPressedDPadButtons(0);

            previousUpdateDPadButtons.Except(currentDPadButtons).ToList().ForEach(button =>
                                                                                  OnButtonUp?.Invoke(0, new GamePadButtonEventArgs(button)));
            currentDPadButtons.Except(previousUpdateDPadButtons).ToList().ForEach(button =>
                                                                                  OnButtonDown?.Invoke(0, new GamePadButtonEventArgs(button)));
            previousUpdateDPadButtons.Clear();
            previousUpdateDPadButtons.AddRange(currentDPadButtons);
        }
Beispiel #17
0
        /// <summary>
        /// Handles incoming HID reports.
        /// </summary>
        /// <param name="report">The input report.</param>
        private void OnReport(HidReport report)
        {
            if (!device.IsConnected)
            {
                Console.WriteLine("But device not connected?");
                return;
            }

            if (report.Data.Length != 16)
            {
                Console.WriteLine("Unknown input");
                return;
            }

            lock (lastInput) {
                InputMessage input = new InputMessage(report.Data);

                for (int i = 0; i < 15; i++)
                {
                    bool keyPressed = input.IsButtonPressed(i);
                    if (keyPressed != lastInput.IsButtonPressed(i))
                    {
                        if (keyPressed)
                        {
                            Console.WriteLine("Press: {0}", i);
                            OnButtonDown?.Invoke(i);
                        }
                        else
                        {
                            Console.WriteLine("Release: {0}", i);
                            OnButtonUp?.Invoke(i);
                        }
                    }
                }

                lastInput = input;
            }

            device.ReadReport(OnReport);
        }
Beispiel #18
0
 void Read(SerialPort port)
 {
     while (readPorts)
     {
         try
         {
             var msg = port.ReadLine();
             if (msg.StartsWith("btn1.down"))
             {
                 var args = new ButtonEventArgs("btn1", ButtonState.Down);
                 OnButtonDown?.Invoke(this, args);
                 OnButtonChange?.Invoke(this, args);
             }
             else if (msg.StartsWith("btn1.up"))
             {
                 var args = new ButtonEventArgs("btn1", ButtonState.Up);
                 OnButtonUp?.Invoke(this, args);
                 OnButtonChange?.Invoke(this, args);
             }
         }
         catch (TimeoutException e) { }
     }
 }
Beispiel #19
0
 public void GetButtonUp()
 {
     OnButtonUp?.Invoke(Input.GetButtonUp(AxisManager.SWORD_ATTACK));
 }
 public override void OnReleased()
 {
     base.OnReleased();
     OnButtonUp?.Invoke(this, null);
 }
Beispiel #21
0
 public void GetButtonUp()
 {
     OnButtonUp?.Invoke(Input.GetButtonUp(AxisManager.FIREBALL_ATTACK));
 }
Beispiel #22
0
 public void GetButtonUp()
 {
     OnButtonUp?.Invoke(Input.GetButtonUp(AxisManager.BLOCK));
 }
Beispiel #23
0
 public void InvokeUpEvent(XRController controller)
 {
     previousPress = false;
     OnButtonUp?.Invoke(controller);
 }
Beispiel #24
0
    public static void RegisterButtonUpCallback(InputKey button, OnButtonUp callback)
    {
        var key = GetKeyString(button);

        instance.ButtonUpCallbacks[key] += callback;
    }