/// <summary> /// Touch press down (only call manually, if you need to simulate a touch). SentFromChild is the UIItem child it was sent from. If sentFromChild is /// null that means it wasn't sent from a child /// </summary> /// /// <value> /// return true if newly pressed /// </value> public bool Press(tk2dUITouch touch, tk2dUIItem sentFromChild) //pressed down ontop of button { if (isPressed) { return(false); //already pressed } if (!isPressed) { this.touch = touch; //if orginal press (not sent from child), or resgieterPressFromChildren is enabled if (registerPressFromChildren || sentFromChild == null) { if (enabled) { isPressed = true; if (OnDown != null) { OnDown(); } if (OnDownUIItem != null) { OnDownUIItem(this); } DoSendMessage(SendMessageOnDownMethodName); } } if (parentUIItem != null) { parentUIItem.Press(touch, this); } } return(true); //newly touched }
/// <summary> /// Fired every frame this touch is still down, regardless if button is down. Only call manually if you need to simulate a touch /// </summary> public void UpdateTouch(tk2dUITouch touch) { this.touch = touch; if (parentUIItem != null) { parentUIItem.UpdateTouch(touch); } }
//raycasts to colliders and checks of UIItems based on a touch private tk2dUIItem GetHitUIItemFromTouch(tk2dUITouch touch) { ray = uiCamera.ScreenPointToRay(touch.position); if (Physics.Raycast(ray, out hit, uiCamera.farClipPlane, raycastLayerMask)) { return(hit.collider.GetComponent <tk2dUIItem>()); } return(null); }
/// <summary> /// Touch press down (only call manually, if you need to simulate a touch) /// </summary> public bool Press(tk2dUITouch touch) //pressed down ontop of button { return Press(touch, null); }
//checks for inputs (multi-touch) private void CheckMultiTouchInputs() { bool isAnyPressBeganRecorded = false; int prevFingerID = -1; bool wasPrevTouchFound = false; bool isNewlyPressed = false; touchCounter = 0; if (inputEnabled) { if (Input.touchCount > 0) { foreach (Touch touch in Input.touches) { if (touchCounter < MAX_MULTI_TOUCH_COUNT) { allTouches[touchCounter] = new tk2dUITouch(touch); touchCounter++; } else { break; } } } else { if (Input.GetMouseButtonDown(0)) { allTouches[touchCounter] = new tk2dUITouch(TouchPhase.Began, tk2dUITouch.MOUSE_POINTER_FINGER_ID, Input.mousePosition, Vector2.zero, 0); mouseDownFirstPos = Input.mousePosition; touchCounter++; } else if (Input.GetMouseButton(0) || Input.GetMouseButtonUp(0)) { Vector2 deltaPosition = mouseDownFirstPos - new Vector2(Input.mousePosition.x, Input.mousePosition.y); TouchPhase mousePhase = TouchPhase.Moved; if (Input.GetMouseButtonUp(0)) { mousePhase = TouchPhase.Ended; } else if (deltaPosition == Vector2.zero) { mousePhase = TouchPhase.Stationary; } allTouches[touchCounter] = new tk2dUITouch(mousePhase, tk2dUITouch.MOUSE_POINTER_FINGER_ID, Input.mousePosition, deltaPosition, tk2dUITime.deltaTime); touchCounter++; } } } for (int p = 0; p < touchCounter; p++) { pressedUIItems[p] = RaycastForUIItem(allTouches[p].position); } //deals with all the previous presses for (int f=0; f<prevPressedUIItemList.Count; f++) { prevPressedItem = prevPressedUIItemList[f]; if (prevPressedItem != null) { prevFingerID = prevPressedItem.Touch.fingerId; wasPrevTouchFound=false; for (int t = 0; t < touchCounter; t++) { currTouch = allTouches[t]; if (currTouch.fingerId == prevFingerID) { wasPrevTouchFound=true; currPressedItem = pressedUIItems[t]; if (currTouch.phase == TouchPhase.Began) { prevPressedItem.CurrentOverUIItem(currPressedItem); if (prevPressedItem != currPressedItem) { prevPressedItem.Release(); prevPressedUIItemList.RemoveAt(f); f--; } } else if (currTouch.phase == TouchPhase.Ended) { prevPressedItem.CurrentOverUIItem(currPressedItem); prevPressedItem.UpdateTouch(currTouch); prevPressedItem.Release(); prevPressedUIItemList.RemoveAt(f); f--; } else { prevPressedItem.CurrentOverUIItem(currPressedItem); prevPressedItem.UpdateTouch(currTouch); } break; } } if(!wasPrevTouchFound) { prevPressedItem.CurrentOverUIItem(null); prevPressedItem.Release(); prevPressedUIItemList.RemoveAt(f); f--; } } } for (int f = 0; f < touchCounter; f++) { currPressedItem = pressedUIItems[f]; currTouch = allTouches[f]; if (currTouch.phase == TouchPhase.Began) { if (currPressedItem != null) { isNewlyPressed = currPressedItem.Press(currTouch); if (isNewlyPressed) { prevPressedUIItemList.Add(currPressedItem); } } isAnyPressBeganRecorded = true; } } if (isAnyPressBeganRecorded) { if (OnAnyPress != null) { OnAnyPress(); } } }
//checks for inputs (non-multi-touch) private void CheckInputs() { bool isPrimaryTouchFound = false; bool isSecondaryTouchFound = false; bool isAnyPressBeganRecorded = false; primaryTouch = new tk2dUITouch(); secondaryTouch = new tk2dUITouch(); resultTouch = new tk2dUITouch(); hitUIItem = null; if (inputEnabled) { if (Input.touchCount > 0) { foreach (Touch touch in Input.touches) { if (touch.phase == TouchPhase.Began) { primaryTouch = new tk2dUITouch(touch); isPrimaryTouchFound = true; isAnyPressBeganRecorded = true; } else if (pressedUIItem != null && touch.fingerId == firstPressedUIItemTouch.fingerId) { secondaryTouch = new tk2dUITouch(touch); isSecondaryTouchFound = true; } } checkForHovers = false; } else { if (Input.GetMouseButtonDown(0)) { primaryTouch = new tk2dUITouch(TouchPhase.Began, tk2dUITouch.MOUSE_POINTER_FINGER_ID, Input.mousePosition, Vector2.zero, 0); isPrimaryTouchFound = true; isAnyPressBeganRecorded = true; } else if (Input.GetMouseButton(0) || Input.GetMouseButtonUp(0)) { Vector2 deltaPosition = Vector2.zero; TouchPhase mousePhase = TouchPhase.Moved; if (pressedUIItem != null) { deltaPosition = firstPressedUIItemTouch.position - new Vector2(Input.mousePosition.x, Input.mousePosition.y); } if (Input.GetMouseButtonUp(0)) { mousePhase = TouchPhase.Ended; } else if (deltaPosition == Vector2.zero) { mousePhase = TouchPhase.Stationary; } secondaryTouch = new tk2dUITouch(mousePhase, tk2dUITouch.MOUSE_POINTER_FINGER_ID, Input.mousePosition, deltaPosition, tk2dUITime.deltaTime); isSecondaryTouchFound = true; } } } if (isPrimaryTouchFound) { resultTouch = primaryTouch; } else if (isSecondaryTouchFound) { resultTouch = secondaryTouch; } if (isPrimaryTouchFound || isSecondaryTouchFound) //focus touch found { hitUIItem = RaycastForUIItem(resultTouch.position); if (resultTouch.phase == TouchPhase.Began) { if (pressedUIItem != null) { pressedUIItem.CurrentOverUIItem(hitUIItem); if (pressedUIItem != hitUIItem) { pressedUIItem.Release(); pressedUIItem = null; } else { firstPressedUIItemTouch = resultTouch; //just incase touch changed } } if (hitUIItem != null) { hitUIItem.Press(resultTouch); } pressedUIItem = hitUIItem; firstPressedUIItemTouch = resultTouch; } else if (resultTouch.phase == TouchPhase.Ended) { if (pressedUIItem != null) { pressedUIItem.CurrentOverUIItem(hitUIItem); pressedUIItem.UpdateTouch(resultTouch); pressedUIItem.Release(); pressedUIItem = null; } } else { if (pressedUIItem != null) { pressedUIItem.CurrentOverUIItem(hitUIItem); pressedUIItem.UpdateTouch(resultTouch); } } } else //no touches found { if (pressedUIItem != null) { pressedUIItem.CurrentOverUIItem(null); pressedUIItem.Release(); pressedUIItem = null; } } //only if hover events are enabled and only if no touch events have ever been recorded if (checkForHovers) { if (inputEnabled) //if input enabled and mouse button is not currently down { if (!isPrimaryTouchFound && !isSecondaryTouchFound && hitUIItem == null && !Input.GetMouseButton(0)) //if raycast for a button has not yet been done { hitUIItem = RaycastForUIItem( Input.mousePosition ); } else if (Input.GetMouseButton(0)) //if mouse button is down clear it { hitUIItem = null; } } if (hitUIItem != null) { if (hitUIItem.isHoverEnabled) { bool wasPrevOverFound = hitUIItem.HoverOver(overUIItem); if (!wasPrevOverFound && overUIItem != null) { overUIItem.HoverOut(hitUIItem); } overUIItem = hitUIItem; } else { if (overUIItem != null) { overUIItem.HoverOut(null); } } } else { if (overUIItem != null) { overUIItem.HoverOut(null); } } } if (isAnyPressBeganRecorded) { if (OnAnyPress != null) { OnAnyPress(); } } }
public bool Press(tk2dUITouch touch, tk2dUIItem sentFromChild) { if (this.isPressed) { this.updateMaxMoveDistanceWhenDown(touch); return false; } if (!this.isPressed) { this.touch = touch; if ((this.registerPressFromChildren || (sentFromChild == null)) && base.enabled) { this.isPressed = true; this.maxMoveDistanceInDown = 0f; this.startPressPoint = touch.position; if (this.OnDown != null) { this.OnDown(); } if (this.OnDownUIItem != null) { this.OnDownUIItem(this); } this.DoSendMessage(this.SendMessageOnDownMethodName); } if (this.parentUIItem != null) { this.parentUIItem.Press(touch, this); } } return true; }
//checks for inputs (non-multi-touch) private void CheckInputs() { bool isPrimaryTouchFound = false; bool isSecondaryTouchFound = false; bool isAnyPressBeganRecorded = false; primaryTouch = new tk2dUITouch(); secondaryTouch = new tk2dUITouch(); resultTouch = new tk2dUITouch(); hitUIItem = null; if (inputEnabled) { if (Input.touchCount > 0) { foreach (Touch touch in Input.touches) { if (touch.phase == TouchPhase.Began) { primaryTouch = new tk2dUITouch(touch); isPrimaryTouchFound = true; isAnyPressBeganRecorded = true; } else if (pressedUIItem != null && touch.fingerId == firstPressedUIItemTouch.fingerId) { secondaryTouch = new tk2dUITouch(touch); isSecondaryTouchFound = true; } } checkForHovers = false; } else { if (Input.GetMouseButtonDown(0)) { primaryTouch = new tk2dUITouch(TouchPhase.Began, tk2dUITouch.MOUSE_POINTER_FINGER_ID, Input.mousePosition, Vector2.zero, 0); isPrimaryTouchFound = true; isAnyPressBeganRecorded = true; } else if (Input.GetMouseButton(0) || Input.GetMouseButtonUp(0)) { Vector2 deltaPosition = Vector2.zero; TouchPhase mousePhase = TouchPhase.Moved; if (pressedUIItem != null) { deltaPosition = firstPressedUIItemTouch.position - new Vector2(Input.mousePosition.x, Input.mousePosition.y); } if (Input.GetMouseButtonUp(0)) { mousePhase = TouchPhase.Ended; } else if (deltaPosition == Vector2.zero) { mousePhase = TouchPhase.Stationary; } secondaryTouch = new tk2dUITouch(mousePhase, tk2dUITouch.MOUSE_POINTER_FINGER_ID, Input.mousePosition, deltaPosition, tk2dUITime.deltaTime); isSecondaryTouchFound = true; } } } if (isPrimaryTouchFound) { resultTouch = primaryTouch; } else if (isSecondaryTouchFound) { resultTouch = secondaryTouch; } if (isPrimaryTouchFound || isSecondaryTouchFound) //focus touch found { hitUIItem = RaycastForUIItem(resultTouch.position); if (resultTouch.phase == TouchPhase.Began) { if (pressedUIItem != null) { pressedUIItem.CurrentOverUIItem(hitUIItem); if (pressedUIItem != hitUIItem) { pressedUIItem.Release(); pressedUIItem = null; } else { firstPressedUIItemTouch = resultTouch; //just incase touch changed } } if (hitUIItem != null) { hitUIItem.Press(resultTouch); } pressedUIItem = hitUIItem; firstPressedUIItemTouch = resultTouch; } else if (resultTouch.phase == TouchPhase.Ended) { if (pressedUIItem != null) { pressedUIItem.CurrentOverUIItem(hitUIItem); pressedUIItem.UpdateTouch(resultTouch); pressedUIItem.Release(); pressedUIItem = null; } } else { if (pressedUIItem != null) { pressedUIItem.CurrentOverUIItem(hitUIItem); pressedUIItem.UpdateTouch(resultTouch); } } } else //no touches found { if (pressedUIItem != null) { pressedUIItem.CurrentOverUIItem(null); pressedUIItem.Release(); pressedUIItem = null; } } //only if hover events are enabled and only if no touch events have ever been recorded if (checkForHovers) { if (inputEnabled) //if input enabled and mouse button is not currently down { if (!isPrimaryTouchFound && !isSecondaryTouchFound && hitUIItem == null && !Input.GetMouseButton(0)) //if raycast for a button has not yet been done { hitUIItem = RaycastForUIItem(Input.mousePosition); } else if (Input.GetMouseButton(0)) //if mouse button is down clear it { hitUIItem = null; } } if (hitUIItem != null) { if (hitUIItem.isHoverEnabled) { bool wasPrevOverFound = hitUIItem.HoverOver(overUIItem); if (!wasPrevOverFound && overUIItem != null) { overUIItem.HoverOut(hitUIItem); } overUIItem = hitUIItem; } else { if (overUIItem != null) { overUIItem.HoverOut(null); } } } else { if (overUIItem != null) { overUIItem.HoverOut(null); } } } if (isAnyPressBeganRecorded) { if (OnAnyPress != null) { OnAnyPress(); } } }
//checks for inputs (multi-touch) private bool CheckMultiTouchInputs() { bool claimTouches = false; bool isAnyPressBeganRecorded = false; int prevFingerID = -1; bool wasPrevTouchFound = false; bool isNewlyPressed = false; touchCounter = 0; if (IsEnabledInputTouches) { if (Input.touchCount > 0) { foreach (Touch touch in Input.touches) { if (touchCounter < MAX_MULTI_TOUCH_COUNT) { allTouches[touchCounter] = new tk2dUITouch(touch); touchCounter++; } else { break; } } } else { if (Input.GetMouseButtonDown(0)) { allTouches[touchCounter] = new tk2dUITouch(TouchPhase.Began, tk2dUITouch.MOUSE_POINTER_FINGER_ID, Input.mousePosition, Vector2.zero, 0); mouseDownFirstPos = Input.mousePosition; touchCounter++; } else if (Input.GetMouseButton(0) || Input.GetMouseButtonUp(0)) { Vector2 deltaPosition = mouseDownFirstPos - new Vector2(Input.mousePosition.x, Input.mousePosition.y); TouchPhase mousePhase = TouchPhase.Moved; if (Input.GetMouseButtonUp(0)) { mousePhase = TouchPhase.Ended; } else if (deltaPosition == Vector2.zero) { mousePhase = TouchPhase.Stationary; } allTouches[touchCounter] = new tk2dUITouch(mousePhase, tk2dUITouch.MOUSE_POINTER_FINGER_ID, Input.mousePosition, deltaPosition, tk2dUITime.deltaTime); touchCounter++; } } } for (int p = 0; p < touchCounter; p++) { tk2dUITouch touch = allTouches[p]; pressedUIItems[p] = RaycastForUIItem(touch.position); } //deals with all the previous presses for (int f = prevPressedUIItemList.Count - 1; f >= 0; f--) { tk2dUIItem prevPressedItem = prevPressedUIItemList[f]; if ((prevPressedItem != null) && (prevPressedItem.isActiveAndEnabled)) { prevFingerID = prevPressedItem.Touch.fingerId; wasPrevTouchFound = false; for (int t = 0; t < touchCounter; t++) { currTouch = allTouches[t]; if (currTouch.fingerId == prevFingerID) { wasPrevTouchFound = true; currPressedItem = pressedUIItems[t]; if (currPressedItem != null && currPressedItem.isActiveAndEnabled && prevPressedItem != null) { /*if (currTouch.phase == TouchPhase.Began) * { * prevPressedItem.CurrentOverUIItem(currPressedItem); * * if (prevPressedItem != currPressedItem) * { * prevPressedItem.Release(); * * temp.Add(prevPressedItem); * // if (prevPressedUIItemList.Contains(prevPressedItem)) * // { * // prevPressedUIItemList.Remove(prevPressedItem); * // } * // prevPressedItem = null; * * if (touchCounter > 1) * { * CustomDebug.Log("Began!"); * } * } * } * else */if (currTouch.phase == TouchPhase.Ended) { prevPressedItem.CurrentOverUIItem(currPressedItem); prevPressedItem.UpdateTouch(currTouch); prevPressedItem.Release(); if (prevPressedUIItemList.Contains(prevPressedItem)) { prevPressedUIItemList.Remove(prevPressedItem); } // prevPressedItem = null; } else if (currTouch.phase == TouchPhase.Canceled) { prevPressedItem.CurrentOverUIItem(currPressedItem); prevPressedItem.UpdateTouch(currTouch); prevPressedItem.Release(); if (prevPressedUIItemList.Contains(prevPressedItem)) { prevPressedUIItemList.Remove(prevPressedItem); } // prevPressedItem = null; } else { prevPressedItem.CurrentOverUIItem(currPressedItem); prevPressedItem.UpdateTouch(currTouch); } } break; } } if (!wasPrevTouchFound && (prevPressedItem != null)) { prevPressedItem.CurrentOverUIItem(null); prevPressedItem.Release(); if (prevPressedUIItemList.Contains(prevPressedItem)) { prevPressedUIItemList.Remove(prevPressedItem); } } } else { prevPressedUIItemList.RemoveAt(f); } } for (int f = 0; f < touchCounter; f++) { currPressedItem = pressedUIItems[f]; currTouch = allTouches[f]; if (currTouch.phase == TouchPhase.Began) { if (currPressedItem != null && currPressedItem.isActiveAndEnabled) { claimTouches = true; isNewlyPressed = currPressedItem.Press(currTouch); if (isNewlyPressed && !prevPressedUIItemList.Contains(currPressedItem)) { prevPressedUIItemList.Add(currPressedItem); } } isAnyPressBeganRecorded = true; } } if (isAnyPressBeganRecorded) { if (OnAnyPress != null) { OnAnyPress(); } } return(claimTouches); }
private void CheckMultiTouchInputs() { bool flag = false; int fingerId = -1; bool flag2 = false; this.touchCounter = 0; if (this.inputEnabled) { if (Input.touchCount > 0) { foreach (Touch touch in Input.touches) { if (this.touchCounter >= 5) { break; } this.allTouches[this.touchCounter] = new tk2dUITouch(touch); this.touchCounter++; } } else if (Input.GetMouseButtonDown(0)) { this.allTouches[this.touchCounter] = new tk2dUITouch(TouchPhase.Began, 0x270f, Input.mousePosition, Vector2.zero, 0f); this.mouseDownFirstPos = Input.mousePosition; this.touchCounter++; } else if (Input.GetMouseButton(0) || Input.GetMouseButtonUp(0)) { Vector2 vector = this.mouseDownFirstPos - new Vector2(Input.mousePosition.x, Input.mousePosition.y); TouchPhase moved = TouchPhase.Moved; if (Input.GetMouseButtonUp(0)) { moved = TouchPhase.Ended; } else if (vector == Vector2.zero) { moved = TouchPhase.Stationary; } this.allTouches[this.touchCounter] = new tk2dUITouch(moved, 0x270f, Input.mousePosition, vector, tk2dUITime.deltaTime); this.touchCounter++; } } for (int i = 0; i < this.touchCounter; i++) { this.pressedUIItems[i] = this.RaycastForUIItem(this.allTouches[i].position); } for (int j = 0; j < this.prevPressedUIItemList.Count; j++) { this.prevPressedItem = this.prevPressedUIItemList[j]; if (this.prevPressedItem != null) { fingerId = this.prevPressedItem.Touch.fingerId; flag2 = false; for (int m = 0; m < this.touchCounter; m++) { this.currTouch = this.allTouches[m]; if (this.currTouch.fingerId == fingerId) { flag2 = true; this.currPressedItem = this.pressedUIItems[m]; if (this.currTouch.phase == TouchPhase.Began) { this.prevPressedItem.CurrentOverUIItem(this.currPressedItem); if (this.prevPressedItem != this.currPressedItem) { this.prevPressedItem.Release(); this.prevPressedUIItemList.RemoveAt(j); j--; } } else if (this.currTouch.phase == TouchPhase.Ended) { this.prevPressedItem.CurrentOverUIItem(this.currPressedItem); this.prevPressedItem.UpdateTouch(this.currTouch); this.prevPressedItem.Release(); this.prevPressedUIItemList.RemoveAt(j); j--; } else { this.prevPressedItem.CurrentOverUIItem(this.currPressedItem); this.prevPressedItem.UpdateTouch(this.currTouch); } break; } } if (!flag2) { this.prevPressedItem.CurrentOverUIItem(null); this.prevPressedItem.Release(); this.prevPressedUIItemList.RemoveAt(j); j--; } } } for (int k = 0; k < this.touchCounter; k++) { this.currPressedItem = this.pressedUIItems[k]; this.currTouch = this.allTouches[k]; if (this.currTouch.phase == TouchPhase.Began) { if ((this.currPressedItem != null) && this.currPressedItem.Press(this.currTouch)) { this.prevPressedUIItemList.Add(this.currPressedItem); } flag = true; } } if (flag && (this.OnAnyPress != null)) { this.OnAnyPress(); } }
private void CheckInputs() { bool flag = false; bool flag2 = false; bool flag3 = false; this.primaryTouch = new tk2dUITouch(); this.secondaryTouch = new tk2dUITouch(); this.resultTouch = new tk2dUITouch(); this.hitUIItem = null; if (this.inputEnabled) { if (Input.touchCount > 0) { foreach (Touch touch in Input.touches) { if (touch.phase == TouchPhase.Began) { this.primaryTouch = new tk2dUITouch(touch); flag = true; flag3 = true; } else if ((this.pressedUIItem != null) && (touch.fingerId == this.firstPressedUIItemTouch.fingerId)) { this.secondaryTouch = new tk2dUITouch(touch); flag2 = true; } } this.checkForHovers = false; } else if (Input.GetMouseButtonDown(0)) { this.primaryTouch = new tk2dUITouch(TouchPhase.Began, 0x270f, Input.mousePosition, Vector2.zero, 0f); flag = true; flag3 = true; } else if (Input.GetMouseButton(0) || Input.GetMouseButtonUp(0)) { Vector2 zero = Vector2.zero; TouchPhase moved = TouchPhase.Moved; if (this.pressedUIItem != null) { zero = this.firstPressedUIItemTouch.position - new Vector2(Input.mousePosition.x, Input.mousePosition.y); } if (Input.GetMouseButtonUp(0)) { moved = TouchPhase.Ended; } else if (zero == Vector2.zero) { moved = TouchPhase.Stationary; } this.secondaryTouch = new tk2dUITouch(moved, 0x270f, Input.mousePosition, zero, tk2dUITime.deltaTime); flag2 = true; } } if (flag) { this.resultTouch = this.primaryTouch; } else if (flag2) { this.resultTouch = this.secondaryTouch; } if (flag || flag2) { this.hitUIItem = this.RaycastForUIItem(this.resultTouch.position); if (this.resultTouch.phase == TouchPhase.Began) { if (this.pressedUIItem != null) { this.pressedUIItem.CurrentOverUIItem(this.hitUIItem); if (this.pressedUIItem != this.hitUIItem) { this.pressedUIItem.Release(); this.pressedUIItem = null; } else { this.firstPressedUIItemTouch = this.resultTouch; } } if (this.hitUIItem != null) { this.hitUIItem.Press(this.resultTouch); } this.pressedUIItem = this.hitUIItem; this.firstPressedUIItemTouch = this.resultTouch; } else if (this.resultTouch.phase == TouchPhase.Ended) { if (this.pressedUIItem != null) { this.pressedUIItem.CurrentOverUIItem(this.hitUIItem); this.pressedUIItem.UpdateTouch(this.resultTouch); this.pressedUIItem.Release(); this.pressedUIItem = null; } } else if (this.pressedUIItem != null) { this.pressedUIItem.CurrentOverUIItem(this.hitUIItem); this.pressedUIItem.UpdateTouch(this.resultTouch); } } else if (this.pressedUIItem != null) { this.pressedUIItem.CurrentOverUIItem(null); this.pressedUIItem.Release(); this.pressedUIItem = null; } if (this.checkForHovers) { if (this.inputEnabled) { if ((!flag && !flag2) && ((this.hitUIItem == null) && !Input.GetMouseButton(0))) { this.hitUIItem = this.RaycastForUIItem(Input.mousePosition); } else if (Input.GetMouseButton(0)) { this.hitUIItem = null; } } if (this.hitUIItem != null) { if (this.hitUIItem.isHoverEnabled) { if (!this.hitUIItem.HoverOver(this.overUIItem) && (this.overUIItem != null)) { this.overUIItem.HoverOut(this.hitUIItem); } this.overUIItem = this.hitUIItem; } else if (this.overUIItem != null) { this.overUIItem.HoverOut(null); } } else if (this.overUIItem != null) { this.overUIItem.HoverOut(null); } } if (flag3 && (this.OnAnyPress != null)) { this.OnAnyPress(); } }
//raycasts to colliders and checks of UIItems based on a touch private tk2dUIItem GetHitUIItemFromTouch(tk2dUITouch touch) { ray = uiCamera.ScreenPointToRay(touch.position); if (Physics.Raycast(ray, out hit, uiCamera.farClipPlane, raycastLayerMask)) { return hit.collider.GetComponent<tk2dUIItem>(); } return null; }
public void UpdateTouch(tk2dUITouch touch) { this.touch = touch; this.updateMaxMoveDistanceWhenDown(touch); if (this.parentUIItem != null) { this.parentUIItem.UpdateTouch(touch); } }
private void updateMaxMoveDistanceWhenDown(tk2dUITouch touch) { if (this.moveDistanceWhenPressedLimit) { this.maxMoveDistanceInDown = Mathf.Max(this.maxMoveDistanceInDown, Vector2.Distance(touch.position, this.startPressPoint)); } }
/// <summary> /// Touch press down (only call manually, if you need to simulate a touch). SentFromChild is the UIItem child it was sent from. If sentFromChild is /// null that means it wasn't sent from a child /// </summary> /// /// <value> /// return true if newly pressed /// </value> public bool Press(tk2dUITouch touch, tk2dUIItem sentFromChild) //pressed down ontop of button { if (isPressed) { return false; //already pressed } if (!isPressed) { this.touch = touch; //if orginal press (not sent from child), or resgieterPressFromChildren is enabled if (registerPressFromChildren || sentFromChild == null) { if (enabled) { isPressed = true; if (OnDown != null) { OnDown(); } if (OnDownUIItem != null) { OnDownUIItem(this); } if (SendMessageOnDownMethodName != "" && sendMessageTarget!=null) { sendMessageTarget.SendMessage(SendMessageOnDownMethodName, SendMessageOptions.RequireReceiver); } } } if (parentUIItem != null) { parentUIItem.Press(touch, this); } } return true; //newly touched }
//pressed down ontop of button /// <summary> /// Touch press down (only call manually, if you need to simulate a touch) /// </summary> public bool Press(tk2dUITouch touch) { return Press(touch, null); }
/// <summary> /// Touch press down (only call manually, if you need to simulate a touch) /// </summary> public bool Press(tk2dUITouch touch) //pressed down ontop of button { return(Press(touch, null)); }
//checks for inputs (multi-touch) private void CheckMultiTouchInputs() { bool isAnyPressBeganRecorded = false; int prevFingerID = -1; bool wasPrevTouchFound = false; bool isNewlyPressed = false; touchCounter = 0; if (inputEnabled) { if (Input.touchCount > 0) { foreach (Touch touch in Input.touches) { if (touchCounter < MAX_MULTI_TOUCH_COUNT) { allTouches[touchCounter] = new tk2dUITouch(touch); touchCounter++; } else { break; } } } else { if (Input.GetMouseButtonDown(0)) { allTouches[touchCounter] = new tk2dUITouch(TouchPhase.Began, tk2dUITouch.MOUSE_POINTER_FINGER_ID, Input.mousePosition, Vector2.zero, 0); mouseDownFirstPos = Input.mousePosition; touchCounter++; } else if (Input.GetMouseButton(0) || Input.GetMouseButtonUp(0)) { Vector2 deltaPosition = mouseDownFirstPos - new Vector2(Input.mousePosition.x, Input.mousePosition.y); TouchPhase mousePhase = TouchPhase.Moved; if (Input.GetMouseButtonUp(0)) { mousePhase = TouchPhase.Ended; } else if (deltaPosition == Vector2.zero) { mousePhase = TouchPhase.Stationary; } allTouches[touchCounter] = new tk2dUITouch(mousePhase, tk2dUITouch.MOUSE_POINTER_FINGER_ID, Input.mousePosition, deltaPosition, tk2dUITime.deltaTime); touchCounter++; } } } for (int p = 0; p < touchCounter; p++) { pressedUIItems[p] = RaycastForUIItem(allTouches[p].position); } //deals with all the previous presses for (int f = 0; f < prevPressedUIItemList.Count; f++) { prevPressedItem = prevPressedUIItemList[f]; if (prevPressedItem != null) { prevFingerID = prevPressedItem.Touch.fingerId; wasPrevTouchFound = false; for (int t = 0; t < touchCounter; t++) { currTouch = allTouches[t]; if (currTouch.fingerId == prevFingerID) { wasPrevTouchFound = true; currPressedItem = pressedUIItems[t]; if (currTouch.phase == TouchPhase.Began) { prevPressedItem.CurrentOverUIItem(currPressedItem); if (prevPressedItem != currPressedItem) { prevPressedItem.Release(); prevPressedUIItemList.RemoveAt(f); f--; } } else if (currTouch.phase == TouchPhase.Ended) { prevPressedItem.CurrentOverUIItem(currPressedItem); prevPressedItem.UpdateTouch(currTouch); prevPressedItem.Release(); prevPressedUIItemList.RemoveAt(f); f--; } else { prevPressedItem.CurrentOverUIItem(currPressedItem); prevPressedItem.UpdateTouch(currTouch); } break; } } if (!wasPrevTouchFound) { prevPressedItem.CurrentOverUIItem(null); prevPressedItem.Release(); prevPressedUIItemList.RemoveAt(f); f--; } } } for (int f = 0; f < touchCounter; f++) { currPressedItem = pressedUIItems[f]; currTouch = allTouches[f]; if (currTouch.phase == TouchPhase.Began) { if (currPressedItem != null) { isNewlyPressed = currPressedItem.Press(currTouch); if (isNewlyPressed) { prevPressedUIItemList.Add(currPressedItem); } } isAnyPressBeganRecorded = true; } } if (isAnyPressBeganRecorded) { if (OnAnyPress != null) { OnAnyPress(); } } }
//pressed down ontop of button /// <summary> /// Touch press down (only call manually, if you need to simulate a touch). SentFromChild is the UIItem child it was sent from. If sentFromChild is /// null that means it wasn't sent from a child /// </summary> /// /// <value> /// return true if newly pressed /// </value> public bool Press(tk2dUITouch touch, tk2dUIItem sentFromChild) { if (isPressed) { return false; //already pressed } if (!isPressed) { this.touch = touch; //if orginal press (not sent from child), or resgieterPressFromChildren is enabled if (registerPressFromChildren || sentFromChild == null) { if (enabled) { isPressed = true; if (OnDown != null) { OnDown(); } if (OnDownUIItem != null) { OnDownUIItem(this); } DoSendMessage( SendMessageOnDownMethodName ); } } if (parentUIItem != null) { parentUIItem.Press(touch, this); } } return true; //newly touched }