void ButtonPushed()
    {
        Debug.Log("Button pushed: " + this.name);

        /*if(LightAndSoundManager.instance.buttonTones[ID] != null){
         *
         *      LightAndSoundManager.instance.StartClip(8, LightAndSoundManager.instance.buttonTones[ID]);
         *      Debug.Log(LightAndSoundManager.instance.buttonTones[ID]);
         * }*/

        buttonDown = true;

        onDown.Invoke();
        if (onStateChanged != null)
        {
            onStateChanged.Invoke(true);
        }

        On = !On;

        /*if (EventCaller != null && InteractiveControlManager.instance != null && ID >= 0)
         * {
         *  InteractiveControlManager.instance.SendMessage(EventCaller, SendMessageOptions.DontRequireReceiver);
         *
         *
         *  InteractiveControlManager.instance.WobblyButtonPressed(ID);
         * }*/
        //AudioSource.PlayClipAtPoint(down, this.transform.position, volume);

        source.clip  = down;
        source.pitch = pitchOffset + Random.Range(0.95f, 1.05f);
        source.Play();
    }
Example #2
0
    public void OnButtonDown()
    {
        buttonKnob.Translate(-transform.right * transform.lossyScale.y * buttonClickDistance);
        OnButtonClicked.Invoke(true);

        LightMatInstance.color = ClickedColor;
    }
        private async Task _loop()
        {
            while (_running)
            {
                try
                {
                    var result = await _mouseDevice.ReadAsync();

                    if (result.BytesRead >= 7)
                    {
                        if (result.Data[0] == (int)EventType.Translation)
                        {
                            CurrentTranslation = toVector3(result.Data) * TranslationScale;
                            TranslationEvent?.Invoke(this, CurrentTranslation);
                        }
                        else if (result.Data[0] == (int)EventType.Rotation)
                        {
                            CurrentRotation = toVector3(result.Data) * RotationScale;
                            RotationEvent?.Invoke(this, CurrentRotation);
                        }
                        else if (result.Data[0] == (int)EventType.Buttons)
                        {
                            CurrentButtons = ConvertByteArrayToBoolArray(result.Data.Skip(1).ToArray());
                            ButtonEvent?.Invoke(this, CurrentButtons);
                        }
                    }
                } catch (Exception ex) { }
            }
        }
Example #4
0
        /// <summary>
        /// 移入移出处理
        /// </summary>
        public void OnEnterHandle(int handIndex)
        {
            if (IsAreaContains(handIndex))
            {
                //如果以及有手移入了,在移入则什么都不处理
                if (IsEnter)
                {
                    return;
                }

                onEnter?.Invoke(handIndex);

                IsEnter        = true;
                enterHandIndex = handIndex;
            }
            else
            {
                if (!IsEnter)
                {
                    return;
                }

                if (enterHandIndex != handIndex)
                {
                    return;
                }

                onExit?.Invoke(handIndex);

                IsEnter        = false;
                enterHandIndex = -1;
            }
        }
Example #5
0
    private void UpdateButtonState(InputDevice device, InputFeatureUsage <bool> button,
                                   ButtonEvent buttonPressEvent)
    {
        bool tempState;
        bool invalidDeviceFound = false;
        bool buttonState        = false;

        tempState = device.isValid && // the device is still valid
                    device.TryGetFeatureValue(button, out buttonState) && // did get a value
                    buttonState;    // the value we got

        if (!device.isValid)
        {
            invalidDeviceFound = true;
        }

        if (tempState != buttonPressEvent.Value) // Button state changed since last frame
        {
            buttonPressEvent.Invoke(tempState);
            buttonPressEvent.Value = tempState;
        }

        if (invalidDeviceFound) // refresh device lists
        {
            SetDevices();
        }
    }
Example #6
0
    void Update()
    {
        // If our distance is greater than what we specified as a press
        // set it to our max distance and register a press if we haven't already
        float distance = Mathf.Abs(transform.position.y - startPos.y);

        if (distance >= pressLength)
        {
            // Prevent the button from going past the pressLength
            transform.position = new Vector3(transform.position.x, startPos.y - pressLength, transform.position.z);
            if (!pressed)
            {
                pressed = true;
                // If we have an event, invoke it
                downEvent?.Invoke();
            }

            if (pressed)
            {
                GameObject.Find("Image").GetComponent <Image>().sprite = sprites[0];
            }
        }
        else
        {
            // If we aren't all the way down, reset our press
            pressed = false;
        }
        // Prevent button from springing back up past its original position
        if (transform.position.y > startPos.y)
        {
            transform.position = new Vector3(transform.position.x, startPos.y, transform.position.z);
        }
    }
Example #7
0
 /// <summary>
 /// 持续执行按下
 /// </summary>
 /// <param name="handIndex"></param>
 public virtual void OnDownStay(int handIndex)
 {
     if (onDownStay != null)
     {
         onDownStay.Invoke(handIndex);
     }
 }
    void Start()
    {
        _pagemap        = new Dictionary <string, Canvas>();
        _inputmap       = new Dictionary <string, InputField>();
        _buttonmap      = new Dictionary <string, List <Button> >();
        _buttonTextures = new Dictionary <Button, List <Sprite> >();

        foreach (var page in FindObjectsOfType <Canvas>())
        {
            _pagemap.Add(page.name, page);
            var buttons = page.GetComponentsInChildren <Button>().ToList();
            _buttonmap.Add(page.name, buttons);
            foreach (Button b in buttons)
            {
                b.onClick.AddListener(() => {
                    ButtonEvent?.Invoke(b, page);
                });
                switch (b.name)
                {
                case "ChangeView":
                    ButtonTextures.Add(b, ResourceManager.GetResourceList <Sprite>("/texture", new string[] { "ViewMode_F", "ViewMode_T" }));
                    break;
                }
            }
            var inputs = page.GetComponentsInChildren <InputField>().ToList();
            foreach (InputField ipt in inputs)
            {
                _inputmap.Add(ipt.name, ipt);
            }
        }
    }
Example #9
0
        private void button_Click(object sender, EventArgs e)
        {
            var accion = ((MyButton)sender).Accion;

            Accion = accion;
            ButtonEvent?.Invoke(accion);
        }
Example #10
0
        private void Update()
        {
            ButtonUp = ButtonDown = false;

            var pressed = host.IsButtonPressed(tracker, channel);

            if (ButtonHold)
            {
                if (pressed)
                {
                    OnButtonHold.Invoke(channel);
                }

                else
                {
                    ButtonUp = true;
                    OnButtonUp.Invoke(channel);
                }
            }
            else if (pressed)
            {
                ButtonDown = true;
                OnButtonDown.Invoke(channel);
            }

            ButtonHold = pressed;
        }
Example #11
0
        /// <summary>
        /// 鼠标抬起
        /// </summary>
        public override void OnDown(int handIndex)
        {
            base.OnDown(handIndex);

            if (onDown != null)
            {
                onDown.Invoke(handIndex);
            }
        }
Example #12
0
        /// <summary>
        /// 鼠标释放
        /// </summary>
        public override void OnUp(int handIndex)
        {
            base.OnUp(handIndex);

            if (onUp != null)
            {
                onUp.Invoke(handIndex);
            }
        }
Example #13
0
    // Update is called once per frame
    void Update()
    {
        var x   = Input.GetAxis("Horizontal");
        var y   = Input.GetAxis("Vertical");
        var run = Input.GetButton("Run");

        OnRun?.Invoke(run);
        OnAxis?.Invoke(new Vector3(x, 0, y));
    }
Example #14
0
        /// <summary>
        /// 按钮按下
        /// </summary>
        public virtual void OnClick(int handIndex)
        {
            OnHandle("click");

            if (onClick != null)
            {
                onClick.Invoke(handIndex);
            }
        }
Example #15
0
        private IntPtr LowLevelMouseHookCallback(int nCode, IntPtr wParam, IntPtr lParam)
        {
            if (nCode >= 0)
            {
                var hookStruct = (MSLLHOOKSTRUCT)Marshal.PtrToStructure(lParam, typeof(MSLLHOOKSTRUCT));
                var highWord   = hookStruct.mouseData >> 16;
                var injected   = (hookStruct.flags & (LLMHF_INJECTED | LLMHF_LOWER_IL_INJECTED)) != 0;
                var position   = new Point(hookStruct.pt.x, hookStruct.pt.y);

                switch ((MouseMessages)wParam)
                {
                case MouseMessages.WM_LBUTTONDOWN:
                    ButtonEvent?.Invoke(this, new ButtonEventArgs(position, State.ButtonDown, Button.Left, injected));
                    break;

                case MouseMessages.WM_LBUTTONUP:
                    ButtonEvent?.Invoke(this, new ButtonEventArgs(position, State.ButtonUp, Button.Left, injected));
                    break;

                case MouseMessages.WM_RBUTTONDOWN:
                    ButtonEvent?.Invoke(this, new ButtonEventArgs(position, State.ButtonDown, Button.Right, injected));
                    break;

                case MouseMessages.WM_RBUTTONUP:
                    ButtonEvent?.Invoke(this, new ButtonEventArgs(position, State.ButtonUp, Button.Right, injected));
                    break;

                case MouseMessages.WM_XBUTTONDOWN:
                    switch (highWord)
                    {
                    case (uint)XButtons.XBUTTON1:
                        ButtonEvent?.Invoke(this, new ButtonEventArgs(position, State.ButtonDown, Button.Back, injected));
                        break;

                    case (uint)XButtons.XBUTTON2:
                        ButtonEvent?.Invoke(this, new ButtonEventArgs(position, State.ButtonDown, Button.Forward, injected));
                        break;
                    }
                    break;

                case MouseMessages.WM_XBUTTONUP:
                    switch (highWord)
                    {
                    case (uint)XButtons.XBUTTON1:
                        ButtonEvent?.Invoke(this, new ButtonEventArgs(position, State.ButtonUp, Button.Back, injected));
                        break;

                    case (uint)XButtons.XBUTTON2:
                        ButtonEvent?.Invoke(this, new ButtonEventArgs(position, State.ButtonUp, Button.Forward, injected));
                        break;
                    }
                    break;
                }
            }

            return(CallNextHookEx(lowLevelMouseHandle, nCode, wParam, lParam));
        }
Example #16
0
        void TouchControl()
        {
            //Finding current touch by fingerId
            if (clicked)
            {
                for (int i = 0; i < Input.touchCount; i++)
                {
                    if (Input.GetTouch(i).fingerId == fingerId)
                    {
                        touch = Input.GetTouch(i);
                        break;
                    }
                }
            }

            //Get fingerId from suitable touch
            for (int i = 0; i < Input.touchCount && !clicked; i++)
            {
                if (Input.GetTouch(i).phase == TouchPhase.Began)
                {
                    Vector2 touchWorldPos = cam.ScreenToWorldPoint(Input.GetTouch(i).position);
                    if (Vector2.Distance(touchWorldPos, (Vector2)transform.position) < touchZoneSize)
                    {
                        touch    = Input.GetTouch(i);
                        fingerId = touch.fingerId;
                        clicked  = true;

                        onClick.Invoke(new ButtonInfo(ButtonPhase.Down));
                    }
                }
            }

            if (touch.phase == TouchPhase.Ended)
            {
                Vector2 touchWorldPos = cam.ScreenToWorldPoint(touch.position);
                clicked = false;

                if (Vector2.Distance(touchWorldPos, (Vector2)transform.position) < touchZoneSize)
                {
                    onClick.Invoke(new ButtonInfo(ButtonPhase.Up));
                }
            }
        }
Example #17
0
        private void HandleButtonDown()
        {
            _onButtonDown.Invoke();
            _stabStartTime = Time.time;

            if (_midiSyncStab)
            {
                _stabLength = MidiDriver.Instance.lastbeatLength * _numBeatsStab;
            }
        }
 private void CheckButton(string controlName, ButtonEvent EventCallback)
 {
     if (Input.GetButton(controlName))
     {
         if (showDebug)
         {
             Debug.Log(controlName);
         }
         EventCallback.Invoke(controlName);
     }
 }
        void Update()
        {
            if (GvrControllerInput.AppButtonUp)
            {
                OnAppUp.Invoke();
            }

            if (GvrControllerInput.AppButtonDown)
            {
                OnAppDown.Invoke();
            }
        }
Example #20
0
        void Update()
        {
            if (Gvr.Internal.ControllerUtils.AnyButtonUp(GvrControllerButton.App))
            {
                OnAppUp.Invoke();
            }

            if (Gvr.Internal.ControllerUtils.AnyButtonDown(GvrControllerButton.App))
            {
                OnAppDown.Invoke();
            }
        }
 private void Update()
 {
     if (Input != null)
     {
         foreach (var name in ButtonNames)
         {
             if (Input.GetButtonDown(name))
             {
                 _ButtonDownEvent.Invoke(name);
             }
         }
     }
 }
Example #22
0
 public override void OnPointerUp(PointerEventData eventData)
 {
     if (!IsActive() || !IsInteractable())
     {
         return;
     }
     if (eventData.button != PointerEventData.InputButton.Left)
     {
         return;
     }
     base.OnPointerUp(eventData);
     _onButtonUp.Invoke();
 }
Example #23
0
        public override void OnInspectorGUI()
        {
            script.position    = EditorGUILayout.Vector3Field("Position", script.position);
            script.eulerAngles = EditorGUILayout.Vector3Field("Rotation", script.eulerAngles);
            script.localScale  = EditorGUILayout.Vector3Field("Scale", script.localScale);

            foreach (var btn in Buttons)
            {
                if (GUI.Button(btn.Position, btn.Label))
                {
                    OnButton.Invoke(btn.Label);
                }
            }
        }
Example #24
0
    public void OnDrag(PointerEventData eventData)
    {
        if (!interactable)
        {
            return;
        }

        if (eventData.button != PointerEventData.InputButton.Left)
        {
            return;
        }

        _onDrag.Invoke();
    }
Example #25
0
        /// <summary>
        /// 鼠标抬起
        /// </summary>
        public override void OnDown(int handIndex)
        {
            base.OnDown(handIndex);

            if (audioStatus == AudioStatus.Down && IsStartAudio && audioSource != null)
            {
                audioSource.Play();
            }

            if (onDown != null)
            {
                onDown.Invoke(handIndex);
            }
        }
Example #26
0
        void Update()
        {
            if (TouchToClick == false)
            {
                if (GvrController.ClickButtonUp)
                {
                    OnClickUp.Invoke();
                }

                if (GvrController.ClickButtonDown)
                {
                    OnClickDown.Invoke();
                }

                if (GvrController.ClickButton)
                {
                    OnClickHeld.Invoke();
                }
            }
            else
            {
                if (GvrController.TouchUp)
                {
                    OnClickUp.Invoke();
                }

                if (GvrController.TouchDown)
                {
                    OnClickDown.Invoke();
                }

                if (GvrController.IsTouching)
                {
                    OnClickHeld.Invoke();
                }
            }
        }
Example #27
0
    public override void OnPointerClick(PointerEventData eventData)
    {
        if (!interactable)
        {
            return;
        }
        base.OnPointerClick(eventData);

        if (eventData.button != PointerEventData.InputButton.Left)
        {
            return;
        }

        _onEnterUp.Invoke();
    }
Example #28
0
        private void ButtonEventTimer(object state)
        {
            ((Timer)state).Change(Timeout.Infinite, 0);
            if (_lastSequence == 1)
            {
                ButtonEvent?.Invoke(this, new ButtonEventArguments()
                {
                    ButtonEventType = ButtonEventType.Hold, DateTimeEvent = DateTime.Now
                });
            }
            else if (_lastSequence == 2)
            {
                ButtonEvent?.Invoke(this, new ButtonEventArguments()
                {
                    ButtonEventType = ButtonEventType.Click, DateTimeEvent = DateTime.Now
                });
            }
            else if (_lastSequence == 3)
            {
                ButtonEvent?.Invoke(this, new ButtonEventArguments()
                {
                    ButtonEventType = ButtonEventType.ClickAndHold, DateTimeEvent = DateTime.Now
                });
            }
            else if (_lastSequence == 4)
            {
                ButtonEvent?.Invoke(this, new ButtonEventArguments()
                {
                    ButtonEventType = ButtonEventType.DoubleClick, DateTimeEvent = DateTime.Now
                });
            }
            else if (_lastSequence == 5)
            {
                ButtonEvent?.Invoke(this, new ButtonEventArguments()
                {
                    ButtonEventType = ButtonEventType.ClickAndHold, DateTimeEvent = DateTime.Now
                });
            }
            else if (_lastSequence == 6)
            {
                ButtonEvent?.Invoke(this, new ButtonEventArguments()
                {
                    ButtonEventType = ButtonEventType.TripleClick, DateTimeEvent = DateTime.Now
                });
            }

            _lastSequence = 0;
        }
Example #29
0
        /// <summary>
        /// 鼠标移出
        /// </summary>
        public virtual void OnExit(int handIndex)
        {
            if (!IsEnter)
            {
                return;
            }

            OnHandle("normal");

            if (onExit != null)
            {
                onExit.Invoke(handIndex);
            }

            IsEnter = false;
        }
Example #30
0
        /// <summary>
        /// 鼠标移入
        /// </summary>
        public virtual void OnEnter(int handIndex)
        {
            if (IsEnter)
            {
                return;
            }

            OnHandle("enter");

            IsEnter = true;

            if (onEnter != null)
            {
                onEnter.Invoke(handIndex);
            }
        }