/// <summary> /// 释放生成的网络频道 /// </summary> /// <param name="name">解决方案名</param> public new void Release(string name = null) { lock (syncRoot) { var channel = Get(name); var tick = channel as ITick; base.Release(name); if (makeHash.Contains(name)) { ReleaseExtend(name); makeHash.Remove(name); } if (tick != null) { lock (syncRoot) { ticks.Remove(tick); } } channel.Disconnect(); UnregisterEvent(channel); if (OnReleased != null) { OnReleased.Invoke(channel); } } }
/// <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)); }
public override void onUpdate() { //only handle the update if the button is enabled and the parent screen is visible if (screenVisible && render) { //hovering logic if (isMouseHovering() && selectable && enabled) { Parent.FocusedComponent = this; if (isHovered == false) { isHovered = true; if (OnHover != null) { OnHover.Invoke(this, null); } } if (InputManager.IsPressed("gui.click")) { if (isClicked == false) { isClicked = true; } } if (InputManager.Released("gui.click")) { if (isClicked && Parent.FocusedComponent != null && Parent.FocusedComponent == this) { isClicked = false; if (OnClicked != null) { OnClicked.Invoke(this, null); } } } } //unhover logic else { if (isHovered) { isHovered = false; } if (!InputManager.IsPressed("gui.click")) { if (isClicked == true) { isClicked = false; if (OnReleased != null) { OnReleased.Invoke(this, null); } } } } } }
protected virtual void Update() { Touch[] touches = UnityEngine.Input.touches; if (touches.Length <= _index) { return; } Touch touch = touches[_index]; if (touch.phase == TouchPhase.Began) { _currentTouchID = touch.fingerId; OnDown?.Invoke(createArg(ButtonState.Down)); } else if (touch.phase == TouchPhase.Canceled || touch.phase == TouchPhase.Ended) { _currentTouchID = int.MinValue; OnReleased?.Invoke(createArg(ButtonState.Released)); } else if (touch.phase == TouchPhase.Moved || touch.phase == TouchPhase.Stationary) { if (_currentTouchID != touch.fingerId) { throw new ArgumentException("The touch iD change before entering Canceled or Ended state!"); } OnPress?.Invoke(createArg(ButtonState.Pressed)); } }
public void Release(IPoolObject obj) { obj.OnReleased(); OnReleased?.Invoke(obj); // remove from active object and send back to pool ActiveObjects.Remove(obj); _poolObjects[obj.ObjId].Enqueue(obj); }
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); } }
public virtual void OnPointerUp(PointerEventData eventData) { PlayerScript.blockShoot = false; pointerDown = false; if (!locked) { //pointerDown = false; buttonPressed = false; //Do stuff on release: image.sprite = normal; OnTipped.Invoke(); } OnReleased.Invoke(); }
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 }); } }
protected virtual void Update() { if (UnityEngine.Input.GetKeyDown(_key)) { OnDown?.Invoke(createArg(ButtonState.Down)); } else if (UnityEngine.Input.GetKey(_key)) { _stateDuration += Time.deltaTime; OnPress?.Invoke(createArg(ButtonState.Pressed)); } else if (UnityEngine.Input.GetKeyUp(_key)) { _stateDuration += Time.deltaTime; OnReleased?.Invoke(createArg(ButtonState.Released)); _stateDuration = 0; } }
/// <summary>Function for controller trigger unpressed</summary> public void Release() { //Do the holding object calls and sets if (holdingObj != null) { if (holdingObj.GetComponent <GrabLock>()) { return; } OnBeforeReleased?.Invoke(this, holdingObj); if (squeezing) { holdingObj.OnUnsqueeze(this); } holdingObj.OnRelease(this, true); OnReleased?.Invoke(this, holdingObj); } BreakGrabConnection(); }
public void Release(ref T element) { if (element == null) { throw new PoolException("[Release] Element to release cannot be null."); } if (Count == 0) { throw new PoolException("[Release] Impossible to release element, pool is full."); } if (!acquired.Remove(element)) { throw new PoolException("[Release] Element allocated outside of pool and cannot be released."); } OnReleased?.Invoke(ref element); this.freelist[--Count] = element; element = null; }
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(); } } }
/// <summary> /// Checks to see whether the attached base object's collider is pressed and if so triggers the appropriate event /// </summary> /// <param name="elapsedGameTime"></param> /// <param name="mousePosition"></param> public override void HandleInput(float elapsedGameTime, Vector2 mousePosition) { base.HandleInput(elapsedGameTime, mousePosition); DebugUtils.AssertNotNull(AttachedBaseObject.Collider); if (AttachedBaseObject.Collider.IsPressed) { Debug.Assert(OnLeftPressed != null && OnMiddlePressed != null && OnRightPressed != null); if (OnLeftPressed != null && InputManager.Instance.CheckInputEvent(InputManager.ScreenPressed, new object[] { MouseButton.kLeftButton })) { OnLeftPressed.Invoke(AttachedBaseObject); } else if (OnMiddlePressed != null && InputManager.Instance.CheckInputEvent(InputManager.ScreenPressed, new object[] { MouseButton.kMiddleButton })) { OnMiddlePressed.Invoke(AttachedBaseObject); } else if (OnRightPressed != null && InputManager.Instance.CheckInputEvent(InputManager.ScreenPressed, new object[] { MouseButton.kRightButton })) { OnRightPressed.Invoke(AttachedBaseObject); } } else { if (PressedLastFrame) { OnReleased.Invoke(AttachedBaseObject); } } PressedLastFrame = AttachedBaseObject.Collider.IsPressed; }
public override void onUpdate() { //only handle the update if the button is enabled and the parent screen is visible if (screenVisible && render) { #region Mouse Logic //hovering logic (checks if the slider is hovered) if (isMouseHovering() && selectable && enabled) { var prevPosition = caretPosition; Mouse.SetCursor(MouseCursor.IBeam); Parent.FocusedComponent = this; if (isHovered == false) { isHovered = true; if (OnHover != null) { OnHover.Invoke(null, null); } } #region Focusing Logic if (InputManager.IsPressed("gui.click")) { if (isClicked == false) { isClicked = true; if (OnClicked != null) { OnClicked.Invoke(null, null); } isEditing = true; } #region Mouse Highlighting Logic if (isEditing) { GetCaretUnderMouse(); if (selectedCaretPositionTMP == -1) { selectedCaretPositionTMP = caretPosition; } if (selectedCaretPositionTMP != caretPosition) { //is holding selectedPosition = selectedCaretPositionTMP; } } #endregion } #endregion #region Double Click Logic if (InputManager.Released("gui.click")) { if (isClicked && Parent.FocusedComponent != null && Parent.FocusedComponent == this) { isClicked = false; if (OnReleased != null) { OnReleased.Invoke(null, null); } selectedCaretPositionTMP = -1; caretTimer = 0f; //empty text boxes shouldnt crash if (text.Length > 0) { //Double click logic if (previousClickTime - timingMachine > 0f && previousClickTime - timingMachine <= 0.5f) //Check the time frame { if (selectedPosition == -1) { //If we moved more than 5 pixels from the last click in any direction then it doesnt count as a double click if (prevMouseLocation.X - 5 <= InputManager.MouseX && prevMouseLocation.X + 5 >= InputManager.MouseX && prevMouseLocation.Y - 5 <= InputManager.MouseY && prevMouseLocation.Y + 5 >= InputManager.MouseY) { GetCaretUnderMouse(); //Get the bounds of the current word int end = IndexOfNextCharAfterWhitespace(); caretPosition = end; int start = IndexOfLastCharBeforeWhitespace(); selectedPosition = start; timingMachine = 0f; previousClickTime = 0f; } } else { selectedPosition = -1; } } timingMachine = previousClickTime; } prevMouseLocation = new Point(InputManager.MouseX, InputManager.MouseY); } } #endregion if (InputManager.PressedStart("gui.click")) { selectedPosition = -1; } } #region Unhover Logic else { if (!isMouseHovering() && Parent.FocusedComponent == this) { Mouse.SetCursor(MouseCursor.Arrow); } if (isHovered) { isHovered = false; } if (!InputManager.IsPressed("gui.click")) { if (isClicked == true) { isClicked = false; if (OnClicked != null) { OnClicked.Invoke(null, null); } if (OnReleased != null) { OnReleased.Invoke(null, null); } caretTimer = 0f; isEditing = false; } } } #endregion #endregion caretTimer += Time.DeltaTime; #region Losing Focus to Another Component if (isEditing) { previousClickTime += Time.DeltaTime; } if (Parent.FocusedComponent != this) { if (Parent.FocusedComponent != null) { previousComponent = Parent.FocusedComponent; } else { isEditing = false; } } //Focusing logic (on click on unfocused = unfocused) if (InputManager.Released("gui.click")) { if (!isMouseHovering()) { isEditing = false; timingChars = 0f; } } #endregion #region Keyboard Handling //Get Textbox input if (isEditing) { bool isShiftPressed = InputManager.IsPressed("misc.shift") || InputManager.IsPressed("misc.shift.alt"); bool isControlHeld = InputManager.IsPressed("misc.control") || InputManager.IsPressed("misc.control.alt"); bool isAltHeld = InputManager.IsPressed("misc.alternate") || InputManager.IsPressed("misc.alternate.alt"); #region Misc Input Handling #region Caret Movement timingChars += Time.DeltaTime; if (InputManager.Released("misc.left") || InputManager.Released("misc.right")) { timingChars = 0f; } //Arrow hold timings if ((timingChars < 1f && timingChars % 0.5f < 0.1f) || //First second delay (timingChars > 1f && timingChars < 2f && timingChars % 0.25f < 0.1f) || //Second second delay (timingChars > 2f && timingChars < 3f && timingChars % 0.1f < 0.05f)) //Hold delay { //Movement if (InputManager.IsPressed("misc.left") && !isAltHeld) //Left Arrow { if (isShiftPressed) { if (selectedPosition == -1) { selectedPosition = FastMath.FastClamp(caretPosition, 0, text.Length); } } else { if (selectedPosition != -1) { caretPosition = Math.Min(caretPosition, selectedPosition); selectedPosition = -1; caretPosition++; } } if (isControlHeld) { caretPosition = IndexOfLastCharBeforeWhitespace() + 1; } caretPosition = FastMath.FastClamp(caretPosition - 1, 0, text.Length); //Minimum position = 0 } if (InputManager.IsPressed("misc.right") && !isAltHeld) //Right Arrow { if (isShiftPressed) { if (selectedPosition == -1) { selectedPosition = FastMath.FastClamp(caretPosition, 0, text.Length); } } else { if (selectedPosition != -1) { caretPosition = Math.Max(caretPosition, selectedPosition); selectedPosition = -1; caretPosition--; } } if (isControlHeld) { caretPosition = IndexOfNextCharAfterWhitespace() - 1; } caretPosition = FastMath.FastClamp(caretPosition + 1, 0, text.Length); //Maximum position = text.Length } } //Home key if (InputManager.Released("misc.home")) { caretPosition = 0; } //End key if (InputManager.Released("misc.end")) { caretPosition = text.Length; } #endregion #region Clipboard (Copy / Cut / Paste) //Control things if (isControlHeld) { //CTRL + A if (InputManager.Released("misc.A")) { selectedPosition = 0; caretPosition = text.Length; } //Clipboard if (InputManager.Released("misc.X")) { if (text.Length > 0) { if (selectedPosition != -1) { //Get the selected text string toCopy = text.Substring(Math.Min(selectedPosition, caretPosition), Math.Max(selectedPosition, caretPosition)); Clipboard.SetText(toCopy); //Same logic as backspace / delete Replace(Math.Min(selectedPosition, caretPosition), Math.Max(selectedPosition, caretPosition), string.Empty); if (selectedPosition < caretPosition) { caretPosition -= caretPosition - selectedPosition; } selectedPosition = -1; } } } if (InputManager.Released("misc.C")) { if (text.Length > 0) { if (selectedPosition != -1) { int min = Math.Min(selectedPosition, caretPosition); int max = Math.Max(selectedPosition, caretPosition); //Get the selected text string toCopy = text.Substring(min, max - min); Clipboard.SetText(toCopy); } } } if (InputManager.Released("misc.V")) { string toAdd = Clipboard.GetText(); //remove newlines toAdd = toAdd.Replace("\n", string.Empty); toAdd = toAdd.Replace("\r", string.Empty); toAdd = toAdd.Replace("\t", string.Empty); //Append the clipboard text if (text.Length > 0) { if (selectedPosition == -1) { text = text.Substring(0, caretPosition) + toAdd + text.Substring(caretPosition); //caretPosition += toAdd.Length; } else { Replace(Math.Min(selectedPosition, caretPosition), Math.Max(selectedPosition, caretPosition), toAdd.ToString()); if (selectedPosition < caretPosition) { caretPosition -= caretPosition - selectedPosition; } selectedPosition = -1; } } else { text += toAdd; } caretPosition += toAdd.Length; } } #endregion //Escape means lose focus if (InputManager.Released("misc.pause")) { //lose focus isEditing = false; //reset the cursor Mouse.SetCursor(MouseCursor.Arrow); //reset GameClient.CurrentCharacter = (char)0; GameClient.CurrentKey = Keys.None; return; } #region Text Removal if (GameClient.CurrentKey == Keys.Back) //Backspace { //If no highlighted text if (selectedPosition == -1 || text.Length == 0) { text = text.Substring(0, Math.Max(0, caretPosition - 1)) + text.Substring(Math.Min(caretPosition, text.Length)); caretPosition = FastMath.FastClamp(caretPosition, 0, text.Length); } else { Replace(Math.Min(selectedPosition, caretPosition), Math.Max(selectedPosition, caretPosition), string.Empty); if (selectedPosition < caretPosition) { caretPosition -= caretPosition - selectedPosition; } selectedPosition = -1; } } if (GameClient.CurrentKey == Keys.Delete) //Delete? { //If no highlighted text if (selectedPosition == -1) { text = text.Substring(0, caretPosition) + text.Substring(Math.Min(caretPosition + 1, text.Length)); caretPosition = FastMath.FastClamp(caretPosition, 0, text.Length); } else { Replace(Math.Min(selectedPosition, caretPosition), Math.Max(selectedPosition, caretPosition), string.Empty); if (selectedPosition < caretPosition) { caretPosition -= caretPosition - selectedPosition; } selectedPosition = -1; } } #endregion #endregion #region Input Handling //Appending text if (!(GameClient.CurrentKey == Keys.Back || GameClient.CurrentKey == Keys.Delete || GameClient.CurrentKey == Keys.Escape || GameClient.CurrentKey == Keys.Tab)) //If the current key isn't a printable character { #region Regular Text Input if (GameClient.CurrentKey != Keys.None) { //Append the character if (text.Length > 0) { if (selectedPosition == -1) { text = text.Substring(0, caretPosition) + GameClient.CurrentCharacter + text.Substring(caretPosition); } else { Replace(Math.Min(selectedPosition, caretPosition), Math.Max(selectedPosition, caretPosition), GameClient.CurrentCharacter.ToString()); if (selectedPosition < caretPosition) { caretPosition -= caretPosition - selectedPosition; } selectedPosition = -1; } } else { text += GameClient.CurrentCharacter; } caretPosition++; } #endregion #region Modifier Characters else if (GameClient.CurrentCharacter != '\0') { char toAdd = GameClient.CurrentCharacter; //if uppercase if (isShiftPressed) { toAdd = char.ToUpper(toAdd); } //Caps Lock #if DESKTOP if (InputManager.IsPressed("misc.capslock")) { toAdd = char.ToUpper(toAdd); } #endif //Append the character if (text.Length > 0) { if (selectedPosition == -1) { text = text.Substring(0, caretPosition) + toAdd + text.Substring(caretPosition); } else { Replace(Math.Min(selectedPosition, caretPosition), Math.Max(selectedPosition, caretPosition), toAdd.ToString()); if (selectedPosition < caretPosition) { caretPosition -= caretPosition - selectedPosition; } selectedPosition = -1; } } else { text += toAdd; } caretPosition++; } #endregion } #endregion //Reset GameClient.CurrentCharacter = (char)0; GameClient.CurrentKey = Keys.None; } #endregion else { //Reset highlighting selectedPosition = -1; } } }
public void OnRelease() { gameObject.SetLayerRecursively(LayerName.InteractableItem); OnReleased?.Invoke(); }
private void Timer_OnRelease() { OnReleased.Invoke(); }
public virtual void FireOnRelease() { OnReleased?.Invoke(); NotifyChanged(); }
public void OnButtonReleased(VirtualButtonBehaviour vb) { OnReleased.Invoke(); }
public override void OnPointerUp(PointerEventData eventData) { base.OnPointerUp(eventData); OnReleased?.Invoke(); }
void IEndDragHandler.OnEndDrag(PointerEventData eventData) { pressed = false; OnReleased?.Invoke(); }
public override void onUpdate() { //only handle the update if the button is enabled and the parent screen is visible if (screenVisible && render) { //hovering logic (checks if the slider is hovered) if (isMouseHovering() && selectable && enabled) { Parent.FocusedComponent = this; if (isMouseHovering(new Point(FastMath.FastClamp(location.X + (_value * size.X / (_maxValue - _minValue)), location.X, location.X + size.X - HandleWidth * GameSettings.UIScale), location.Y), new Point(HandleWidth * GameSettings.UIScale, size.Y))) { if (isHovered == false) { isHovered = true; if (OnHover != null) { OnHover.Invoke(null, null); } } } if (InputManager.IsPressed("gui.click")) { if (isClicked == false) { isClicked = true; if (OnClicked != null) { OnClicked.Invoke(null, null); } } } if (InputManager.Released("gui.click")) { if (isClicked && Parent.FocusedComponent != null && Parent.FocusedComponent == this) { isClicked = false; if (OnReleased != null) { OnReleased.Invoke(null, null); } } } if (isClicked) { if (isSliding == false) { //If we are hovering on the handle then: if (isMouseHovering(new Point(FastMath.FastClamp(location.X + (_value * size.X / (_maxValue - _minValue)), location.X, location.X + size.X - HandleWidth * GameSettings.UIScale), location.Y), new Point(HandleWidth * GameSettings.UIScale, size.Y))) { MouseOffset = new Point(handleX - InputManager.MouseX, location.Y - InputManager.MouseY); } //We are not hovering on the handle, so assume its half the width else { MouseOffset = new Point(-HandleWidth * GameSettings.UIScale / 2, location.Y - InputManager.MouseY); } isSliding = true; } } } //unhover logic else { if (isHovered) { isHovered = false; } if (!InputManager.IsPressed("gui.click")) { if (isClicked == true) { isClicked = false; if (OnClicked != null) { OnClicked.Invoke(null, null); } if (OnReleased != null) { OnReleased.Invoke(null, null); } } } } if (isClicked == false || Parent.FocusedComponent != this) { isSliding = false; } //Handle the slider position if (isSliding) { //Get the mouse relative to the component int localPosition = InputManager.MouseX - location.X; float coef = (float)(_maxValue) / (float)(size.X - 3); int value = (int)(localPosition * coef); value = FastMath.FastClamp(value, 0, _maxValue); if (value != _value) { _value = value; if (OnValueChanged != null) { OnValueChanged.Invoke(null, null); } } } } }