void Update() { if (touchDriveManager == null) { return; } if (ButtonTexture == null) { return; } if (touchDriveManager.TouchBank != null) { foreach (TouchItemData touch in touchDriveManager.TouchBank) { if (ButtonTexture.HitTest(touch.Position)) { myTouch = touch; break; } } } if (OneShot && !canTouchAgain) { ButtonState = ButtonTouchState.Released; IsPressed = false; } if (myTouch != null) { if (myTouch.Phase == TouchPhase.Stationary && ButtonTexture.HitTest(myTouch.Position) && canTouchAgain) { ButtonState = ButtonTouchState.Pressed; IsPressed = true; ChangeAlpha(ButtonTexture, true); if (OneShot) { canTouchAgain = false; } } else if (myTouch.Phase == TouchPhase.Ended) { ButtonState = ButtonTouchState.Released; IsPressed = false; ChangeAlpha(ButtonTexture, false); myTouch = null; } } else { canTouchAgain = true; } }
TouchItemData GetTouchItem(int FID) { TouchItemData rTouch = null; foreach (TouchItemData iTouch in TouchBank) { if (iTouch.ID == FID) { rTouch = iTouch; break; } } return(rTouch); }
void Update() { foreach (Touch inputTouchItem in Input.touches) { TouchItemData touchItem = GetTouchItem(inputTouchItem.fingerId); if (touchItem == null) { TouchItemData newTouchItem = GetTouchItem(-1); if (newTouchItem != null) { newTouchItem.Set(inputTouchItem); } } else { touchItem.Checked = true; touchItem.PositionDelta = inputTouchItem.position - touchItem.Position; touchItem.Position = inputTouchItem.position; touchItem.Phase = inputTouchItem.phase; } } if (EnableMouseEmulation) { if (Input.GetMouseButton(0)) { TouchBank[BankSize - 1].Phase = TouchPhase.Stationary; TouchBank[BankSize - 1].PositionDelta.x = Input.mousePosition.x - TouchBank[BankSize - 1].Position.x; TouchBank[BankSize - 1].PositionDelta.y = Input.mousePosition.y - TouchBank[BankSize - 1].Position.y; TouchBank[BankSize - 1].Position = new Vector2(Input.mousePosition.x, Input.mousePosition.y); TouchBank[BankSize - 1].Checked = true; } } foreach (TouchItemData touchItem in TouchBank) { if (!touchItem.Checked) { touchItem.ResetState(); } else { touchItem.Checked = false; } } }
/// <summary> /// Update /// </summary> void Update() { sH = Screen.height; sW = Screen.width; this.AlignLeft = Mathf.Clamp(transform.position.x, 0, 1) * (sW - WheelSize.x / 2); this.AlignTop = (sH - WheelSize.y) - (Mathf.Clamp(transform.position.y, -1, 1) * (sH - WheelSize.y / 2)); if (touchDriveManager == null) { return; } if (CenterSpeed <= 1) { CenterSpeed = 1; } if (AlphaValue < 0) { AlphaValue = 0; } if (string.IsNullOrEmpty(TurnRotation)) { this.CurrentAngle = Mathf.Lerp(CurrentAngle, 0, CenterSpeed * Time.deltaTime); } if (Mathf.Abs(CurrentAngle) < 0.05) { CurrentAngle = 0; } float oX = WheelSize.x; float oY = WheelSize.y; rectPivot = new Rect(AlignLeft, rectWheel.y, oX, oY); WheelPivot = new Vector2(rectPivot.width / 2, rectPivot.height / 2); if (touchDriveManager.TouchBank != null) { foreach (TouchItemData touch in touchDriveManager.TouchBank) { ntPos = new Vector2(touch.Position.x, touch.Position.y); if (((ntPos.x > 0) && (ntPos.x < oX + AlignLeft)) && ((ntPos.y > 0) && (ntPos.y < oY + (sH - AlignTop)))) { TouchData = touch; break; } } } if (TouchData != null) { mtPos = new Vector2(TouchData.Position.x - AlignLeft, sH - TouchData.Position.y - AlignTop); //if (((myTouch.Position.x > 0) && (myTouch.Position.x < oX)) && ((Screen.height - myTouch.Position.y > 0) && (Screen.height - myTouch.Position.y < oY))) if (((mtPos.x > 0) && (mtPos.x < oX)) && ((mtPos.y > 0) && (mtPos.y < oY))) { mtPos = new Vector2(mtPos.x, WheelSize.y - mtPos.y); if (mtPos.x <= WheelPivot.x) { this.CurrentAngle = -Vector2.Angle(new Vector2((float)0, (float)1), mtPos - this.WheelPivot); } else { this.CurrentAngle = Vector2.Angle(new Vector2((float)0, (float)1), mtPos - this.WheelPivot); } ChangeAlpha(true); } else { ChangeAlpha(false); } } else { ChangeAlpha(false); } if (CurrentAngle >= MaxAngle) { CurrentAngle = MaxAngle; } if (CurrentAngle <= -MaxAngle) { CurrentAngle = -MaxAngle; } if (!UseSensitivityCurve) { CurrentFloat = Mathf.Clamp((1 / MaxAngle) * CurrentAngle, -1, 1); } else { CurrentFloat = SensitivityCurve.Evaluate(Mathf.Abs(CurrentAngle) / MaxAngle); if (CurrentAngle < 0) { CurrentFloat *= -1; } } if (CurrentFloat > 0) { CurrentInt = 1; } else if (CurrentFloat < 0) { CurrentInt = -1; } else { CurrentInt = 0; } }