Esempio n. 1
0
        public void Update(GameTime gameTime, KeyboardState keyboardState, MouseState mouseState, MouseState prevMouseState)
        {
            if (isBeingClicked)
            {
                var progress = Math.Clamp((mouseState.Position.X - RectOnScreen.Left) / Size.X, 0, 1);
                var value    = Min + (Max - Min) * progress;

                if (mouseState.LeftButton == ButtonState.Released)
                {
                    OnRelease?.Invoke(value);
                    isBeingClicked = false;
                }
                else if (progress != CurrentProgress)
                {
                    OnChange?.Invoke(value);
                }

                CurrentProgress = progress;
                CurrentValue    = value;
            }

            if (mouseState.LeftButton == ButtonState.Pressed && RectOnScreen.Contains(mouseState.Position))
            {
                if (prevMouseState.LeftButton == ButtonState.Released)
                {
                    isBeingClicked = true;
                }
            }
        }
Esempio n. 2
0
        private void Update()
        {
            if (IsTripleTouch)
            {
                OnTripleTouch?.Invoke();
                return;
            }

            if (StaticUtilities.IsPointerOverUIObject())
            {
                return;
            }

            var inputPosition = Input.mousePosition;

            if (IsPressed)
            {
                OnPress?.Invoke(inputPosition);
            }

            if (IsDrag)
            {
                OnDrag?.Invoke(inputPosition);
            }

            if (IsReleased)
            {
                OnRelease?.Invoke();
            }
        }
Esempio n. 3
0
        public virtual void Init()
        {
            var otherButtons = BUTTONS.Where(button => button != Button).ToList();

            otherButtons.ForEach(button => GetButton(button).OnPress += () => { Pressed = false; });

            GetButton(Button).OnPress += () => {
                if (Blocked)
                {
                    return;
                }
                if (otherButtons.Any(id => GetButton(id).isActive))
                {
                    return;
                }
                Pressed = true;
                OnPress?.Invoke();
            };
            GetButton(Button).OnRelease += () => {
                if (Blocked || !Pressed)
                {
                    return;
                }
                if (otherButtons.Any(id => GetButton(id).isActive))
                {
                    return;
                }
                Pressed = false;
                OnRelease?.Invoke();
            };
        }
Esempio n. 4
0
 /// <summary>
 /// 释放
 /// </summary>
 public virtual void OnDistanceRelesae(DistanceInteraction distanceInteraction)
 {
     if (OnRelease != null)
     {
         OnRelease.Invoke(distanceInteraction);
     }
 }
Esempio n. 5
0
    private void HandleInput()
    {
        if (Input.GetMouseButtonDown(0))
        {
            isGrappling = true;
        }

        if (Input.GetMouseButton(0))
        {
            if (isGrappling)
            {
                isGrappling = false;
                var clickResult = OnClicked?.Invoke(player.transform.position);
                if (clickResult.HasValue)
                {
                    var joint = clickResult.Value.Item1;
                    joint.connectedBody = player;
                    OnAttach?.Invoke(joint.transform.position);

                    TravelAmount = clickResult.Value.Item2 + 1;
                    OnScore?.Invoke(TravelAmount);
                }
            }
        }

        if (Input.GetMouseButtonUp(0))
        {
            OnRelease?.Invoke();
        }
    }
Esempio n. 6
0
 protected void InvokeOnRelease(T item)
 {
     if (OnRelease != null)
     {
         OnRelease.Invoke(item);
     }
 }
Esempio n. 7
0
 public override void Init()
 {
     GetButton(ModifierButton).OnRelease += () => {
         if (Blocked || !Pressed)
         {
             return;
         }
         Pressed = false;
         OnRelease?.Invoke();
     };
     GetButton(Button).OnPress += () => {
         if (Blocked || !GetButton(ModifierButton).isActive)
         {
             return;
         }
         Pressed = true;
         OnPress?.Invoke();
     };
     GetButton(Button).OnRelease += () => {
         if (Blocked || !Pressed)
         {
             return;
         }
         if (!GetButton(ModifierButton).isActive)
         {
             return;
         }
         Pressed = false;
         OnRelease?.Invoke();
     };
 }
Esempio n. 8
0
    private void CheckSwipeEditor()
    {
        if (Input.GetMouseButtonDown(0))   //pressed
        {
            startPos = Input.mousePosition;
            holdTime = 0;
        }
        else if (Input.GetMouseButton(0))   //held
        {
            holdTime += Time.deltaTime;
        }
        else if (Input.GetMouseButtonUp(0))   //de-pressed
        {
            Vector2 endPos   = Input.mousePosition;
            Vector2 deltaPos = endPos - startPos;

            //Debug.Log("" + (deltaPos.magnitude > swipeDistanceThreshold) + " and " + (holdTime < swipeTimeThreshold));
            if (deltaPos.magnitude > swipeDistanceThreshold && holdTime < swipeTimeThreshold)
            {
                OnSwipe?.Invoke(deltaPos, endPos);
            }
            else
            {
                OnRelease?.Invoke();
            }
        }
    }
Esempio n. 9
0
        /// <summary>
        /// 释放扩展
        /// </summary>
        /// <param name="extend">扩展实现</param>
        private void InternalRelease(TInterface extend)
        {
            OnRelease?.Invoke(extend);
            var dispose = extend as IDisposable;

            dispose?.Dispose();
        }
Esempio n. 10
0
        internal static void Init()
        {
            PreUpdate();
            LastPosition = Position;

            App.platform.OnMouseButtonDown += id =>
            {
                down[id]    = true;
                pressed[id] = true;
                OnPress?.Invoke((MouseButton)id);
            };

            App.platform.OnMouseButtonUp += id =>
            {
                down[id]     = false;
                released[id] = true;
                OnRelease?.Invoke((MouseButton)id);
            };

            App.platform.OnMouseScroll += (x, y) =>
            {
                Scroll += new Point2((int)(x / Screen.PixelSize), (int)(y / Screen.PixelSize));
                OnScroll?.Invoke();
            };
        }
Esempio n. 11
0
    // Update is called once per frame
    void Update()
    {
        if (Input.touchCount > 0)
        {
            _touch       = Input.GetTouch(0);
            _touchTimer += Time.deltaTime;
            switch (_touch.phase)
            {
            case TouchPhase.Ended:
                if (_touch.tapCount >= 2)
                {
                    StopAllCoroutines();
                    if (OnDoubleClick != null)
                    {
                        OnDoubleClick.Invoke(_touch);
                        Debug.Log("Working");
                    }
                }
                else if (_touchTimer < LongPressThreshold)
                {
                    StartCoroutine(CheckSingleClick());
                }
                else if (_touchTimer > LongPressThreshold)
                {
                    StopAllCoroutines();
                    OnRelease.Invoke(_touch);
                }

                break;

            case TouchPhase.Moved:
                if (_touchTimer > LongPressThreshold)
                {
                    if (OnLongPressing != null)
                    {
                        OnLongPressing.Invoke(_touch);
                    }
                }
                break;

            case TouchPhase.Stationary:
                if (_touchTimer > LongPressThreshold)
                {
                    if (OnLongPressing != null)
                    {
                        OnLongPressing.Invoke(_touch);
                    }
                }
                break;

            default:
                break;
            }
        }
        else
        {
            _touchTimer = 0;
        }
    }
Esempio n. 12
0
 private bool Release(int touchId, Vector2 position)
 {
     if (Pressed && TouchId == touchId)
     {
         OnRelease?.Invoke(position);
         Pressed = false;
         return(true);
     }
     return(false);
 }
Esempio n. 13
0
 private void _buttonPin_ValueChanged(GpioPin sender, GpioPinValueChangedEventArgs e)
 {
     if (e.Edge == GpioPinEdge.FallingEdge)
     {
         OnPress?.Invoke(sender, e);
     }
     else
     {
         OnRelease?.Invoke(sender, e);
     }
 }
Esempio n. 14
0
    public override void OnPointerUp(PointerEventData eventData)
    {
        if (joystickType != JoystickType.Fixed)
        {
            background.gameObject.SetActive(false);
        }

        OnRelease?.Invoke(eventData);

        base.OnPointerUp(eventData);
    }
Esempio n. 15
0
        public virtual void Release()
        {
            if (currentObject == null)
            {
                return;
            }

            OnRelease.Invoke(currentObject.gameObject);
            currentObject.Release(this);
            currentObject = null;
        }
Esempio n. 16
0
 public void Init()
 {
     CaveInputBinding.Flystick(Instance).GetButton(Button).OnPress += () => {
         Pressed = true;
         OnPress?.Invoke();
     };
     CaveInputBinding.Flystick(Instance).GetButton(Button).OnRelease += () => {
         Pressed = false;
         OnRelease?.Invoke();
     };
 }
Esempio n. 17
0
 public void PointerUp()
 {
     if (lastPointerDownTime != null)
     {
         OnClick?.Invoke();
         lastPointerDownTime = null;
     }
     else
     {
         OnRelease?.Invoke();
     }
 }
Esempio n. 18
0
 public void CheckForInput()
 {
     if (ButtonType == ButtonType.Mouse ? Input.GetMouseButtonDown((int)MouseButton) : Input.GetKeyDown(KeyboardButton))
     {
         Pressed = true;
         OnPress?.Invoke();
     }
     if (ButtonType == ButtonType.Mouse ? Input.GetMouseButtonUp((int)MouseButton) : Input.GetKeyUp(KeyboardButton))
     {
         Pressed = false;
         OnRelease?.Invoke();
     }
 }
Esempio n. 19
0
        public void OnPoolRelease()
        {
            if (lifecycleHandlers != null)
            {
                for (var i = 0; i < lifecycleHandlers.Length; i++)
                {
                    var handler = lifecycleHandlers[i];
                    handler.OnPoolRelease();
                }
            }

            OnRelease?.Invoke();
        }
Esempio n. 20
0
        /// <summary>
        /// Release rocker.
        /// </summary>
        protected virtual void OnMouseUp()
        {
            if (!isEnabled)
            {
                return;
            }

            if (revertSpeed > 0)
            {
                InvokeRepeating("Revert", 0, Time.fixedDeltaTime);
            }
            OnRelease.Invoke();
        }
Esempio n. 21
0
        private void _ReleaseSlider()
        {
            Cursor.Margin         = InitialCursorMargin;
            DynamicBar.X2         = DynamicBar.X1;
            CurrentValueText.Text = "";

            OnRelease?.Invoke(this, new OnReleaseArgs()
            {
                Value = (int)CurrentValue
            });

            CurrentValue = 0;
            ToolTipFlyout.Hide();
        }
Esempio n. 22
0
        private void Update()
        {
            if (Input.GetMouseButtonUp(0) && IsPressing) // "OnMouseUp()" is unreliable.
            {
                if (resetOnRelease)
                {
                    transform.position = startWorldPosition;
                }

                OnRelease.Invoke();

                IsPressing = false;
            }
        }
Esempio n. 23
0
 private void OnMouseButton(MouseButton button, InputAction action, KeyModifiers mods)
 {
     if (button == MouseButton.Left && Hovered)
     {
         if (action == InputAction.Press)
         {
             OnClick?.Invoke(this, null);
         }
         else if (action == InputAction.Release)
         {
             OnRelease?.Invoke(this, null);
         }
     }
 }
Esempio n. 24
0
 public void Release(Vector2 input)
 {
     if (joint != null)
     {
         joint.connectedBody = null;
         joint.enabled       = false;
         if (input == Vector2.zero)
         {
             motor.velocity = Vector3.zero;
         }
         OnRelease?.Invoke();
         Destroy(ActiveGrab, .1f);
     }
 }
Esempio n. 25
0
        public void Release(VRHand hand)
        {
            if (Holder != hand)
            {
                return;
            }

            TrackHolder(Holder.position, Holder.rotation);
            rb.velocity        = SmoothVelocity;
            rb.angularVelocity = SmoothSpin;

            OnRelease.Invoke(hand.gameObject);

            Holder = null;
        }
Esempio n. 26
0
        private void HandleKeyReleasedHookEvent(KeyboardHookEventArgs args)
        {
            OnHook?.Invoke(args);

            lock (downKeys)
            {
                bool removed = downKeys.Remove(args.KeyCode);

                OnRelease?.Invoke(args);

                if (removed)
                {
                    OnPress?.Invoke(args);
                }
            }
        }
Esempio n. 27
0
 public override void OnPointerUp(PointerEventData eventData)
 {
     if (_timer <= DoubleTapTreshold)
     {
         _indeterminacy = true;
     }
     if (_timer > DoubleTapTreshold)
     {
         _toTick = false;
         OnRelease?.Invoke(_inputVector, _timer);
         //Debug.LogWarning("LONG RELEASe " + _timer);
         _timer = 0;
     }
     _inputVector            = Vector2.zero;
     Handle.anchoredPosition = Vector2.zero;
 }
Esempio n. 28
0
        private void HandleKeyReleasedHookEvent(MouseHookEventArgs args)
        {
            OnHook?.Invoke(args);

            lock (downButtons)
            {
                bool removed = downButtons.Remove(args.Button);

                OnRelease?.Invoke(args);

                if (removed)
                {
                    OnClick?.Invoke(args);
                }
            }
        }
Esempio n. 29
0
        private void FlipStatus()
        {
            status = !status;
            if (status)
            {
                OnTrigger?.Invoke();
            }
            else if (!status)
            {
                OnRelease?.Invoke();
            }

            if (MouseButton == EMouseButton.WheelDown || MouseButton == EMouseButton.WheelUp)
            {
                status = false;
            }
        }
Esempio n. 30
0
        /// <summary>
        /// Response mouse left button up.
        /// </summary>
        protected virtual void OnMouseUp()
        {
            if (!isEnabled)
            {
                return;
            }

            OnRelease.Invoke();

            if (!adsorbent || adsorbableAngles.Length == 0)
            {
                return;
            }

            Angle = GetAdsorbentAngle(Angle, adsorbableAngles);
            Rotate(Angle);
            OnAdsorbent.Invoke();
        }