Пример #1
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);
     }
 }
Пример #2
0
        protected virtual void Awake()
        {
            //register interactions:
            Register(_leftIndexStatus);
            Register(_leftIndexMCPStatus);
            Register(_leftMiddleMCPStatus);
            Register(_rightIndexStatus);
            Register(_rightIndexMCPStatus);
            Register(_rightMiddleMCPStatus);
            Register(_colliderStatus);

            //refs:
            _audioSource = GetComponent <AudioSource>();

            //trigger volume:
            _trigger           = gameObject.AddComponent <BoxCollider>();
            _trigger.isTrigger = true;
            _trigger.size      = Vector3.zero;

            //hooks:
            OnPressUpdated.AddListener(HandlePressUpdated);
            OnHoverUpdated.AddListener(HandleHoverUpdated);
            OnPressed.AddListener(HandlePressed);
            OnReleased.AddListener(HandleReleased);
            OnTouchEnd.AddListener(HandleTouchEnd);
            OnHoverEnd.AddListener(HandleHoverEnd);
            OnCanceled.AddListener(HandleCanceled);

            //sets:
            ResetElement();
            ResetFrame();
            ResetColors();
        }
Пример #3
0
 private void OnHotkeyTriggered(HotkeyTriggered e)
 {
     if (e.Hotkey == Hotkey)
     {
         OnPressed.Invoke();
     }
 }
        protected override Control MakeUI(object value)
        {
            if (value == null)
            {
                return(new Label {
                    Text = "null", Align = Label.AlignMode.Right
                });
            }

            // NOTE: value is NOT always the actual object.
            // Only thing we can really rely on is that ToString works out correctly.
            // This is because of reference tokens, but due to simplicity the object ref is still passed.

            var button = new Button
            {
                Text                = $"Reference: {value}",
                ClipText            = true,
                SizeFlagsHorizontal = Control.SizeFlags.FillExpand
            };

            button.OnPressed += _ =>
            {
                OnPressed?.Invoke();
            };
            return(button);
        }
Пример #5
0
            /// <summary>
            /// Handles watching the given key for
            /// </summary>
            /// <param name="myCurrentState"></param>
            /// <param name="myPrevState"></param>
            /// <param name="key"></param>
            public void Watch(KeyboardState myCurrentState, KeyboardState myPrevState)
            {
                bool wasPressed = myPrevState.IsKeyDown(myKey);
                bool isPressed  = myCurrentState.IsKeyDown(myKey);

                ButtonDelta deltaState =
                    isPressed != wasPressed ?
                    isPressed ? ButtonDelta.Pressed : ButtonDelta.Released :
                    isPressed ? ButtonDelta.Down : ButtonDelta.Up;

                if (deltaState == ButtonDelta.Pressed)
                {
                    OnPressed?.Invoke(this, new KeyPressEventArgs(myKey, deltaState));
                }

                if (deltaState == ButtonDelta.Released)
                {
                    OnReleased?.Invoke(this, new KeyPressEventArgs(myKey, deltaState));
                }

                if (deltaState == ButtonDelta.Down)
                {
                    OnDown?.Invoke(this, new KeyPressEventArgs(myKey, deltaState));
                }

                if (deltaState == ButtonDelta.Up)
                {
                    OnUp?.Invoke(this, new KeyPressEventArgs(myKey, deltaState));
                }

                OnEvent?.Invoke(this, new KeyPressEventArgs(myKey, deltaState));
            }
Пример #6
0
 public void OpenInfos()
 {
     if (isActive)
     {
         OnPressed.Invoke(locationData.name, "Open" + locationData.opening_hours.open_now.ToString(), locationDetails);
     }
 }
Пример #7
0
 private void KeyPressed()
 {
     if (!string.IsNullOrEmpty(keyValue))
     {
         OnPressed?.Invoke(keyValue);
     }
 }
Пример #8
0
 public void PressOption()
 {
     if (OnPressed != null)
     {
         OnPressed.Invoke();
     }
 }
Пример #9
0
        public void OnPointerDown(PointerEventData eventData)
        {
            m_pointerDownPosition = transform.position;
            m_isPointerDown       = true;

            OnPressed.Call(this);

            StartCoroutine(DragInitiationCoroutine());
        }
Пример #10
0
 public ShareView(
     Key key                 = null,
     OnPressed onPressed     = null,
     ProjectType projectType = ProjectType.article
     ) : base(key)
 {
     this.onPressed   = onPressed;
     this.projectType = projectType;
 }
Пример #11
0
        private void Press()
        {
            _startDragPosition = Touch.Position;

            SetPressStyle();

            ButtonState = ButtonClickState.Pressed;

            OnPressed?.Invoke(Touch);
        }
Пример #12
0
    public override void OnMouseReleased()
    {
        base.OnMouseReleased();

        if (Enabled)
        {
            OnPressed?.Invoke();
            pressed = false;
            Children.ForEach((child) => child.Offset = Vector2.Zero);
        }
    }
Пример #13
0
 internal void onMouseButtonPressed(object sender, MouseButtonEventArgs e)
 {
     if (e.X >= Position.X && e.Y >= Position.Y)
     {
         int xLimit = Position.X + Size.Width;
         int yLimit = Position.Y + Size.Height;
         if (e.X < xLimit && e.Y < yLimit)
         {
             OnPressed?.Invoke(this, EventArgs.Empty);
         }
     }
 }
Пример #14
0
 private void Update()
 {
     foreach (var command in _toRemove)
     {
         _commands.Remove(command);
         _isPressed.Remove(command);
         _wasPressed.Remove(command);
     }
     _toRemove.Clear();
     foreach (var command in _commands)
     {
         if (_toRemove.Contains(command))
         {
             continue;
         }
         var blockFlag = command.GetValue <bool>("_blockNextRelease");
         if (command.IsNewlyPressed())
         {
             OnNewlyPressed?.Invoke(command);
         }
         if (command.IsNewlyHeld(MinimalPressDuration))
         {
             OnNewlyHeld?.Invoke(command);
         }
         if (command.IsPressed())
         {
             OnPressed?.Invoke(command);
             _isPressed[command] = true;
         }
         else
         {
             _wasPressed[command] = _isPressed[command];
             _isPressed[command]  = false;
         }
         if (command.IsNewlyReleased())
         {
             OnNewlyReleased?.Invoke(command);
         }
         if (command.IsHeld(MinimalPressDuration))
         {
             OnHeld?.Invoke(command);
         }
         if (command.IsTapped(MaximalTapDuration))
         {
             OnTapped?.Invoke(command);
         }
         if (blockFlag)//damn you, Mobius Digital
         {
             var toReblock = _wasPressed[command] || _isPressed[command];
             command.SetValue("_blockNextRelease", toReblock);
         }
     }
 }
Пример #15
0
            public void Watch(DeltaMouseState change)
            {
                ButtonDelta deltaState = ButtonDelta.Invalid;

                switch (myButton)
                {
                case MouseButton.Left:
                    deltaState = change.LeftButton;
                    break;

                case MouseButton.Right:
                    deltaState = change.RightButton;
                    break;

                case MouseButton.Middle:
                    deltaState = change.MiddleButton;
                    break;

                case MouseButton.XButton1:
                    deltaState = change.XButton1;
                    break;

                case MouseButton.XButton2:
                    deltaState = change.XButton2;
                    break;
                }

                if (deltaState != ButtonDelta.Invalid)
                {
                    if (deltaState == ButtonDelta.Pressed)
                    {
                        OnPressed?.Invoke(this, change);
                    }

                    if (deltaState == ButtonDelta.Released)
                    {
                        OnReleased?.Invoke(this, change);
                    }

                    if (deltaState == ButtonDelta.Down)
                    {
                        OnDown?.Invoke(this, change);
                    }

                    if (deltaState == ButtonDelta.Up)
                    {
                        OnUp?.Invoke(this, change);
                    }

                    OnEvent?.Invoke(this, change);
                }
            }
Пример #16
0
        public void KillAllSubscribers()
        {
            if (OnClicked != null)
            {
                foreach (var del in OnClicked?.GetInvocationList())
                {
                    OnClicked -= (Action)del;
                }
            }

            if (OnHovered != null)
            {
                foreach (var del in OnHovered?.GetInvocationList())
                {
                    OnHovered -= (Action)del;
                }
            }

            if (OnUnhovered != null)
            {
                foreach (var del in OnUnhovered?.GetInvocationList())
                {
                    OnUnhovered -= (Action)del;
                }
            }

            if (OnPressed != null)
            {
                foreach (var del in OnPressed?.GetInvocationList())
                {
                    OnPressed -= (Action)del;
                }
            }

            if (OnReleased != null)
            {
                foreach (var del in OnReleased?.GetInvocationList())
                {
                    OnReleased -= (Action)del;
                }
            }

            if (OnHold != null)
            {
                foreach (var del in OnHold?.GetInvocationList())
                {
                    OnHold -= (Action)del;
                }
            }
        }
Пример #17
0
 private void Input_DigitalValueChanged(object sender, DigitalInValueChangedEventArgs e)
 {
     PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("Pressed"));
     if (e.NewValue ^ activeLow)
     {
         OnPressed?.Invoke(this, new ButtonPressedEventArgs {
             ButtonPressed = true
         });
     }
     else
     {
         OnReleased?.Invoke(this, new ButtonReleasedEventArgs {
             ButtonReleased = true
         });
     }
 }
Пример #18
0
 public void Compute()
 {
     output = Input.GetAxis(name);
     value  = Mathf.Abs(Input.GetAxisRaw(name));
     if (value > 0f && oldValue == 0f)
     {
         OnDown.Invoke(output);
     }
     if (value < 1f && oldValue == 1f)
     {
         OnUp.Invoke(output);
     }
     if (value > 0f && oldValue > 0f)
     {
         OnPressed.Invoke(output);
     }
     oldValue = value;
 }
Пример #19
0
    public void OnPointerDown(PointerEventData eventData)
    {
        buttonPressed           = true;
        PlayerScript.blockShoot = true;

        //switch(button_type)
        if (!(pointerDown || locked))
        {
            pointerDown = true;

            //Do stuff on press:
            //image.color = new Color(1, 1, 1, 0.75f);
            image.sprite = clickedSprite;
            OnPressed.Invoke();
            if (useHold)
            {
                StartCoroutine(HoldCounter());
            }
        }
    }
Пример #20
0
        private static void OnSceneRender(SceneView scene)
        {
            Event e = Event.current;

            HandleFilthyShiftInput(e);
            if (e.keyCode == KeyCode.None)
            {
                return;     //Sometimes returns none for some reason, might be unity input lag.
            }
            switch (e.type)
            {
            case EventType.KeyDown:
            {
                s_HeldDown.Add(e.keyCode);
                OnPressed?.Invoke(e.keyCode);
                break;
            }

            case EventType.KeyUp:
            {
                s_HeldDown.Remove(e.keyCode);
                OnRelease?.Invoke(e.keyCode);
                break;
            }

            case EventType.MouseDown:
            {
                s_HeldDown.Add(e.keyCode);
                OnPressed?.Invoke(e.keyCode);
                break;
            }

            case EventType.MouseUp:
            {
                s_HeldDown.Remove(e.keyCode);
                OnRelease?.Invoke(e.keyCode);
                break;
            }
            }
        }
Пример #21
0
        internal override void Update(GuiMouseState mouseState)
        {
            if (this.ContainsPoint(mouseState.MouseX, mouseState.MouseY))
            {
                if (!this.Hovered)
                {
                    this.Hovered = true;
                    Gui.InvalidateVisual();
                }

                if (mouseState.MouseLeftDown && !this.Active)
                {
                    this.Active = true;
                    OnPressed?.Invoke(this, EventArgs.Empty);
                    Gui.InvalidateVisual();
                }
                else if (!mouseState.MouseLeftDown && this.Active)
                {
                    this.Active = false;
                    OnReleased?.Invoke(this, EventArgs.Empty);
                    OnClick?.Invoke(this, EventArgs.Empty);
                    Gui.InvalidateVisual();
                }
            }
            else
            {
                if (this.Hovered)
                {
                    if (this.Active)
                    {
                        this.Active = false;
                    }

                    this.Hovered = false;

                    Gui.InvalidateVisual();
                }
            }
        }
Пример #22
0
    void Update()
    {
        if (animator != null)
        {
            animator.SetBool(ANIM_PARAM_ON, On);
            animator.SetBool(ANIM_PARAM_DOWN, Down);
            animator.SetBool(ANIM_PARAM_HOVER, Hover);
        }

        if (!_percent.HasValue)
        {
            _percent = lever.OpenPercent;
        }
        else
        {
            _percent = Mathf.Lerp(_percent.Value, lever.OpenPercent, Mathf.Clamp(Time.deltaTime * lerp, 0f, 1f));
        }
        transform.localEulerAngles = axis.normalized * CosLerp(start, end, _percent.Value);

        if (On && _percent >= activateThreshold)
        {
            if (OnPressed != null)
            {
                OnPressed.Invoke();
            }
            _timePressed      = Time.time;
            lever.OpenPercent = 1f;
            On = false;
        }

        //if we've released, set the position to zero
        if ((!On || !Down) && (Time.time - _timePressed >= timeStuckAtEnd))
        {
            lever.OpenPercent = 0f;
        }
    }
Пример #23
0
 void Press()
 {
     OnPressed.Invoke();
     Audio.Play();
     Anim.Play("ButtonPressing");
 }
Пример #24
0
    public override void ButtonPressAction()
    {
        base.ButtonPressAction();

        OnPressed?.Invoke();
    }
Пример #25
0
 private void onClick()
 {
     OnPressed?.Invoke(this, EventArgs.Empty);
 }
Пример #26
0
 void IBeginDragHandler.OnBeginDrag(PointerEventData eventData)
 {
     pressed = true;
     OnPressed?.Invoke();
 }
Пример #27
0
 public override void OnPointerDown(PointerEventData eventData)
 {
     base.OnPointerDown(eventData);
     OnPressed?.Invoke();
 }
Пример #28
0
 public virtual void FireOnPressed()
 {
     OnPressed?.Invoke();
     NotifyChanged();
 }
Пример #29
0
 public void Press()
 {
     OnPressed?.Invoke(this, EventArgs.Empty);
 }
Пример #30
0
 public void Pressed()
 {
     OnPressed?.Invoke(BaseProduct);
 }