示例#1
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();
            };
        }
示例#2
0
 protected void InvokeOnRelease(T item)
 {
     if (OnRelease != null)
     {
         OnRelease.Invoke(item);
     }
 }
示例#3
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();
        }
    }
示例#4
0
 /// <summary>
 /// 释放
 /// </summary>
 public virtual void OnDistanceRelesae(DistanceInteraction distanceInteraction)
 {
     if (OnRelease != null)
     {
         OnRelease.Invoke(distanceInteraction);
     }
 }
示例#5
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;
                }
            }
        }
示例#6
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();
     };
 }
示例#7
0
        /// <summary>
        /// 释放扩展
        /// </summary>
        /// <param name="extend">扩展实现</param>
        private void InternalRelease(TInterface extend)
        {
            OnRelease?.Invoke(extend);
            var dispose = extend as IDisposable;

            dispose?.Dispose();
        }
示例#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();
            }
        }
    }
示例#9
0
 public virtual void Consume(TouchInfo ti)
 {
     if (ti.TouchState == TouchState.Pressed)
     {
         mouseOver = true;
         if (OnPressed != null)
         {
             OnPressed.Fire(ti);
         }
     }
     else if (ti.TouchState == TouchState.Released)
     {
         mouseOver = false;
         if (ti.Delta.Length2() < 2500f / 480 / 480)
         {
             if (OnRelease != null)
             {
                 OnRelease.Fire(ti);
             }
         }
     }
     else if (ti.TouchState == TouchState.Moved)
     {
         mouseOver = true;
         OnMoved.Fire(ti);
     }
 }
示例#10
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();
            };
        }
示例#11
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();
            }
        }
示例#12
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;
        }
    }
示例#13
0
        private void _timer_Tick(object sender, EventArgs e)
        {
            var dt = DateTime.Now - _lastClick;

            if (dt.TotalMilliseconds > Interval)
            {
                OnRelease?.Execute(null);
                _timer.Stop();
            }
        }
示例#14
0
 private bool Release(int touchId, Vector2 position)
 {
     if (Pressed && TouchId == touchId)
     {
         OnRelease?.Invoke(position);
         Pressed = false;
         return(true);
     }
     return(false);
 }
示例#15
0
 public Button(GameObject owner, Rectangle bounds, SpriteFont fnt, string label, Color clr, OnRelease releaseAction, string name = null) : base(owner, name)
 {
     relativeBounds  = bounds;
     idleColor       = clr;
     texture         = Graphics.TextureFromURL(@"https://megachuck64.github.io/assets/defaultButton.png");
     text            = label;
     drawLayer       = 0.1f;
     font            = fnt;
     startWindowSize = owner.game.Window.ClientBounds.Size.ToVector2();
     onRelease       = releaseAction;
 }
示例#16
0
        public virtual void Release()
        {
            if (currentObject == null)
            {
                return;
            }

            OnRelease.Invoke(currentObject.gameObject);
            currentObject.Release(this);
            currentObject = null;
        }
示例#17
0
 public void Init()
 {
     CaveInputBinding.Flystick(Instance).GetButton(Button).OnPress += () => {
         Pressed = true;
         OnPress?.Invoke();
     };
     CaveInputBinding.Flystick(Instance).GetButton(Button).OnRelease += () => {
         Pressed = false;
         OnRelease?.Invoke();
     };
 }
示例#18
0
    public override void OnPointerUp(PointerEventData eventData)
    {
        if (joystickType != JoystickType.Fixed)
        {
            background.gameObject.SetActive(false);
        }

        OnRelease?.Invoke(eventData);

        base.OnPointerUp(eventData);
    }
示例#19
0
 private void _buttonPin_ValueChanged(GpioPin sender, GpioPinValueChangedEventArgs e)
 {
     if (e.Edge == GpioPinEdge.FallingEdge)
     {
         OnPress?.Invoke(sender, e);
     }
     else
     {
         OnRelease?.Invoke(sender, e);
     }
 }
示例#20
0
 public Action(KeyCode key,
               string name,
               OnTrigger onTrigger = null,
               OnHold onHold       = null,
               OnRelease onRelease = null)
 {
     Key             = key;
     Name            = name;
     OnTriggerMethod = onTrigger;
     OnHoldMethod    = onHold;
     OnReleaseMethod = onRelease;
 }
示例#21
0
 public void PointerUp()
 {
     if (lastPointerDownTime != null)
     {
         OnClick?.Invoke();
         lastPointerDownTime = null;
     }
     else
     {
         OnRelease?.Invoke();
     }
 }
示例#22
0
        public void OnPoolRelease()
        {
            if (lifecycleHandlers != null)
            {
                for (var i = 0; i < lifecycleHandlers.Length; i++)
                {
                    var handler = lifecycleHandlers[i];
                    handler.OnPoolRelease();
                }
            }

            OnRelease?.Invoke();
        }
示例#23
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();
     }
 }
示例#24
0
        /// <summary>
        /// Release rocker.
        /// </summary>
        protected virtual void OnMouseUp()
        {
            if (!isEnabled)
            {
                return;
            }

            if (revertSpeed > 0)
            {
                InvokeRepeating("Revert", 0, Time.fixedDeltaTime);
            }
            OnRelease.Invoke();
        }
示例#25
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();
        }
示例#26
0
        private void Update()
        {
            if (Input.GetMouseButtonUp(0) && IsPressing) // "OnMouseUp()" is unreliable.
            {
                if (resetOnRelease)
                {
                    transform.position = startWorldPosition;
                }

                OnRelease.Invoke();

                IsPressing = false;
            }
        }
示例#27
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);
         }
     }
 }
示例#28
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);
     }
 }
示例#29
0
        public void CleanUp()
        {
            filename = null;
#if UNITY_EDITOR
            tag = "";
#endif
            if (OnRelease != null)
            {
                foreach (Delegate d in OnRelease.GetInvocationList())
                {
                    OnRelease -= (ReleaseEvent)d;
                }
            }
        }
示例#30
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;
        }