private void TrocaToques() { agás++; isH = true; MyTouch tmp = User1.handRight.userTouch.touch; if (User2.handRight.userTouch.touch != null) { User1.handRight.userTouch.NewTouchStarts(User2.handRight.userTouch.touch.gameObject); } else { User1.handRight.userTouch.touch = null; } if (tmp != null) { User2.handRight.userTouch.NewTouchStarts(tmp.gameObject); } else { User2.handRight.userTouch.touch = null; } }
// Update is called once per frame void Update() { if (Input.touchCount > 0) { // print("Touch!"); foreach (Touch touch in Input.touches) { if (touch.phase == TouchPhase.Began) { MyTouch ourTouch = Hand1.GetComponent <UserHand>().userTouch.touch; //Nada esta a tocar ainda if (ourTouch == null)// && ourT3 == null && ourT4 == null) { //Se estah mais perto da hand1, associar a hand1. CC o oposto GameObject touchGO = Instantiate(TouchInput, Vector3.zero, Quaternion.identity); touchGO.GetComponent <MyTouch>().Init(touch); Vector3 hand1Pos = Hand1.transform.position; Vector3 touchPos = touchGO.transform.position; Hand1.GetComponent <UserHand>().userTouch.NewTouchStarts(touchGO); } } } } }
private void ReprocessTouches() { repro++; isRep = true; if (User1.handRight.userTouch.touch != null) { Destroy(User1.handRight.userTouch.touch.gameObject); } if (User2.handRight.userTouch.touch != null) { Destroy(User2.handRight.userTouch.touch.gameObject); } User1.handRight.userTouch.touch = User2.handRight.userTouch.touch = null; foreach (Touch touch in Input.touches) { MyTouch mt = ProcessNewTouch(touch); if (mt != null) { mt.setDrag(); } } }
public static TouchContent CreateFromTouch(MyTouch[] touch) { if (touch.Length == 2) { return new TouchContent (touch); } return null; }
private List<MyTouch> BuildTouch(MyTouch[] touch) { var list = new List<MyTouch> ( touch ); list.Sort ((MyTouch a, MyTouch b) => { return a.fingerId < b.fingerId ? -1 : 1; }); return list; }
// Update is called once per frame void Update() { if (Controller.bGame) { GameObject[] touchObj = MyTouch.TouchObject(); for (int i = 0; i < touchObj.Length; i++) { if (touchObj[i] == gameObject) { switch (gameObject.name) { case "Delete": if (Controller.Japan.Count != 0) { Controller.Japan.RemoveAt(Controller.Japan.Count - 1); } break; case "Shift": shift = !shift; break; case "Space": Controller.Japan.Add(" "); break; case "Complete": Controller.bComplete = true; //GameObject.Find("Result").GetComponent<Text>().text = Hangle.WriteHangle(string.Join("", Controller.Japan.ToArray())); break; default: shift = false; Controller.Japan.Add(gameObject.name); break; } GameObject.Find("Result").GetComponent <Text>().text = Hangle.WriteHangle(string.Join("", Controller.Japan.ToArray())); if (shift && GameObject.Find(originalKeys[0]) != null) { for (int j = 0; j < originalKeys.Length; j++) { GameObject.Find(originalKeys[j]).name = changeKeys[j]; } } else if (!shift && GameObject.Find(changeKeys[0]) != null) { for (int j = 0; j < originalKeys.Length; j++) { GameObject.Find(changeKeys[j]).name = originalKeys[j]; } } } } } }
private void TryReleaseMouseBlock() { if (_blockedMouse == null || _blockedMouse.State != TouchState.Relased) { return; } _blockedMouse.SetAsNotOwned(); _blockedMouse = null; }
private void Focusable_OnClick(MyTouch e) { if (IsFocused) { UnFocus(); } else { Focus(); } }
private MyTouch GetMouse() { MyTouch touch = null; var absPosition = GetAbsolutePosition(); if (GeneralOptions.UseMouse && !InputOptions.MyState.MouseTouch.HasOwner && InputOptions.MyState.MouseTouch.State == TouchState.JustPressed && (IsFullscreenButton || MyMath.CollisionPointAndRectangle(InputOptions.MyState.MouseTouch.Position, absPosition, GetAbsoluteRotation(), GetAbsoluteSize()))) { touch = InputOptions.MyState.MouseTouch; InputOptions.MyState.MouseTouch.SetAsOwned(); } return(touch); }
public bool Test(MyTouch[] touch) { if (touch.Length != 2) { return false; } var newTouchGroup = BuildTouch (touch); if (touchs [0].fingerId != newTouchGroup [0].fingerId || touchs [1].fingerId != newTouchGroup [1].fingerId) { return false; } touchs = newTouchGroup; return true; }
public virtual void Update() { #region Searching new touch if (_myTouch == null) { _myTouch = InputOptions.MyState.GetBrandNewTouch(false); if (_myTouch == null) { _myTouch = InputOptions.MyState.GetPressedMouse(false); } if (_myTouch != null) { //Just pressed FirstPosition = _myTouch.Position; } } #endregion #region Is here some touch if (_myTouch != null) { switch (_myTouch.State) { #region Continuing case TouchState.Continuing: if (_myTouch.HasOwner) { LooseTouch(); } break; #endregion #region Relased case TouchState.Relased: LooseTouch(); break; #endregion } } #endregion }
private void BlockTouches() { if (!IsTouchBlocking || Touch == null) { return; } MyTouch touch; do { touch = GetTouch(); } while (touch != null); if (_blockedMouse == null) { _blockedMouse = GetMouse(); } }
public static bool HandleDragAndDrop() { if (!GameContr.m_RunOnMac) { foreach (Touch touch in Input.touches) { if (HandleOneTouch(new MyTouch(touch))) { return(true); } } } else { MyTouch mouse_touch = new MyTouch(); if (Input.GetMouseButtonDown(0)) { mouse_touch.phase = TouchPhase.Began; mouse_touch.position = new Vector2(Input.mousePosition.x, Input.mousePosition.y); m_LastMousePos = Input.mousePosition; } else if (Input.GetMouseButton(0)) { mouse_touch.phase = TouchPhase.Moved; mouse_touch.position = new Vector2(Input.mousePosition.x, Input.mousePosition.y); Vector2 delta_p = Input.mousePosition - m_LastMousePos; mouse_touch.deltaPosition = delta_p; m_LastMousePos = Input.mousePosition; } else { return(false); } if (HandleOneTouch(mouse_touch)) { return(true); } } return(false); }
void Update() { currentTouchs = new MyTouch[Input.touches.Length]; for (int i = 0; i < currentTouchs.Length; ++i) { currentTouchs [i] = new MyTouch( Input.touches [i] ); } VirtualTouch (); if (m_content == null) { m_content = TouchContent.CreateFromTouch (currentTouchs); if (m_content != null) { Open (); Sync (); isMultiTouch = true; } } else { if (m_content.Test (currentTouchs)) { Sync (); } else { m_content = null; Close (); isMultiTouch = false; } } }
private void OnOnClick(MyTouch myTouch) { MenuScreenManager.GetScreen <ScreenLevelCreator>().CreatePixelRectangle(); }
public void NewTouchStarts(GameObject touchStart) { touch = touchStart.GetComponent <MyTouch>(); //Ponteiro para a classe MyTouch touch.hand = this; //O MyTouch vai saber que esta mao agora eh dele }
public void update() { myTouches_ = new MyTouch[Input.touchCount]; if (Input.touchCount != 0) { tmpSwypeCenter_ = Vector2.zero; for (int ii = 0; ii < Input.touchCount; ++ii) { Touch tw = Input.touches[ii]; myTouches_[ii] = new MyTouch(tw.fingerId, tw.position, tw.deltaPosition, tw.deltaTime, tw.tapCount, tw.phase); tmpSwypeCenter_ += tw.position; } tmpSwypeCenter_ /= Input.touchCount; } else { tmpSwypeCenter_ = Input.mousePosition; wheelMove_ = (Input.GetAxis("Mouse ScrollWheel") != 0.0f) ? Input.GetAxis("Mouse ScrollWheel") : wheelMove_ * 0.5f; if ((Mathf.Abs(wheelMove_) > 0.001f) || (Input.GetMouseButton(2))) { if (Input.GetMouseButton(2)) // swype,zoom,pinch { touchCkSize_ = Mathf.Clamp(touchCkSize_ + wheelMove_ * 0.5f, 0.1f, 0.9f); } else { touchCkAng_ += wheelMove_ * 0.5f; } myTouches_ = new MyTouch[2]; Vector2 tmpPos = new Vector2(-touchCkSize_ * 0.5f, 0.0f); tmpPos.y = Mathf.Sin(touchCkAng_) * tmpPos.x; tmpPos.x = Mathf.Cos(touchCkAng_) * tmpPos.x; myTouches_[0] = new MyTouch(0, new Vector2(moveMax * (0.5f + tmpPos.x), moveMax * (0.5f + tmpPos.y))); myTouches_[1] = new MyTouch(1, new Vector2(moveMax * (0.5f - tmpPos.x), moveMax * (0.5f - tmpPos.y))); } else { touchCkSize_ = 0.5f; touchCkAng_ = 0.0f; } } if (myTouches_.Length >= 2) { Vector2 vec = myTouches_[1].position - myTouches_[0].position; touchOldAng_ = touchAng_; touchAng_ = Mathf.Atan2(vec.y, vec.x); if (touchSttAng_ == float.MaxValue) { touchSttAng_ = touchAng_; touchOldAng_ = touchAng_; } touchOldSize_ = touchSize_; touchSize_ = vec.magnitude / moveMax; if (touchSttSize_ == float.MaxValue) { touchSttSize_ = touchSize_; touchOldSize_ = touchSize_; } swypeOldPos_ = swypePos_; swypePos_ = tmpSwypeCenter_; if (swypeSttPos_.x == float.MaxValue) { swypeSttPos_ = swypePos_; swypeOldPos_ = swypePos_; } // for debug if (myTouches_.Length >= 2) { Vector3 v0 = Camera.main.ScreenToWorldPoint(new Vector3(myTouches_[0].position.x, myTouches_[0].position.y, -Camera.main.transform.position.z)); Vector3 v1 = Camera.main.ScreenToWorldPoint(new Vector3(myTouches_[1].position.x, myTouches_[1].position.y, -Camera.main.transform.position.z)); Debug.DrawLine(v0, v1, ((deltaSize < 0.0f) ? Color.red : ((deltaSize > 0.0f) ? Color.blue : Color.white))); } } else { touchSttSize_ = float.MaxValue; touchOldSize_ = float.MaxValue; touchSttAng_ = float.MaxValue; touchOldAng_ = float.MaxValue; swypeSttPos_ = new Vector2(float.MaxValue, float.MaxValue); swypeOldPos_ = new Vector2(float.MaxValue, float.MaxValue); // tmpSwypeCenter_ = new Vector2(Screen.width*0.5f,Screen.height*0.5f); } isDoubleTap_ = doubleTapCheck(); }
private MyTouch ProcessNewTouch(Touch touch) { //Suportar multiplos toques MyTouch touchUser1 = User1.handRight.userTouch.touch; MyTouch touchUser2 = User2.handRight.userTouch.touch; Vector3 user1RightHPos = User1.handRight.transform.position; Vector3 user1LeftHPos = User1.handLeft.transform.position; Vector3 user2RightHPos = User2.handRight.transform.position; Vector3 user2LeftHPos = User2.handLeft.transform.position; Vector3 touchPos = MyTouch.GetTouchWorldPosition(touch); // distancias User 1 float dUser1 = Mathf.Min(Vector3.Distance(user1RightHPos, touchPos), Vector3.Distance(user1LeftHPos, touchPos)); // distancias User 2 float dUser2 = Mathf.Min(Vector3.Distance(user2RightHPos, touchPos), Vector3.Distance(user2LeftHPos, touchPos)); //Nada esta a tocar ainda if (touchUser1 == null && touchUser2 == null)// && ourT3 == null && ourT4 == null) { //Se estah mais perto da hand1, associar a hand1. CC o oposto GameObject touchGO = Instantiate(TouchInput, Vector3.zero, Quaternion.identity); touchGO.GetComponent <MyTouch>().Init(touch); // escolhe mao 1 if (dUser1 < dUser2) { User1.handRight.userTouch.NewTouchStarts(touchGO); //Hand3.GetComponent<UserHand>().userTouch.NewTouchStarts(touchGO); //print("entrei 1: A"); } else { User2.handRight.userTouch.NewTouchStarts(touchGO); //Hand4.GetComponent<UserHand>().userTouch.NewTouchStarts(touchGO); //print("entrei 2: A"); } return(touchGO.GetComponent <MyTouch>()); } // User 1 esta a tocar else if (touchUser1 != null && touchUser2 == null) { // sera o User 2 if (dUser2 < distanceThreshold) { GameObject touchGO = Instantiate(TouchInput, Vector3.zero, Quaternion.identity); touchGO.GetComponent <MyTouch>().Init(touch); User2.handRight.userTouch.NewTouchStarts(touchGO); //Hand4.GetComponent<UserHand>().userTouch.NewTouchStarts(touchGO); //print("entrei 2: B"); return(touchGO.GetComponent <MyTouch>()); } } // User 2 esta a tocar else if (touchUser1 == null && touchUser2 != null) { // sera o User 1 if (dUser1 < distanceThreshold) { GameObject touchGO = Instantiate(TouchInput, Vector3.zero, Quaternion.identity); touchGO.GetComponent <MyTouch>().Init(touch); User1.handRight.userTouch.NewTouchStarts(touchGO); // Hand3.GetComponent<UserHand>().userTouch.NewTouchStarts(touchGO); //print("entrei 1: C"); return(touchGO.GetComponent <MyTouch>()); } } return(null); }
public TouchContent(MyTouch[] touch) { touchs.AddRange( touch ); }
public void update() { myTouches_ = new MyTouch[Input.touchCount]; if( Input.touchCount != 0){ tmpSwypeCenter_ = Vector2.zero; for( int ii = 0; ii < Input.touchCount; ++ii ){ Touch tw = Input.touches[ii]; myTouches_[ii] = new MyTouch(tw.fingerId,tw.position,tw.deltaPosition,tw.deltaTime,tw.tapCount,tw.phase); tmpSwypeCenter_ += tw.position; } tmpSwypeCenter_ /= Input.touchCount; }else{ tmpSwypeCenter_ = Input.mousePosition; wheelMove_ = (Input.GetAxis("Mouse ScrollWheel")!=0.0f) ? Input.GetAxis("Mouse ScrollWheel") : wheelMove_*0.5f; if((Mathf.Abs(wheelMove_)>0.001f)||(Input.GetMouseButton(2))){ if(Input.GetMouseButton(2)){ // swype,zoom,pinch touchCkSize_ = Mathf.Clamp(touchCkSize_ + wheelMove_*0.5f,0.1f,0.9f); }else{ touchCkAng_ += wheelMove_*0.5f; } myTouches_ = new MyTouch[2]; Vector2 tmpPos = new Vector2(-touchCkSize_*0.5f,0.0f); tmpPos.y = Mathf.Sin(touchCkAng_)*tmpPos.x; tmpPos.x = Mathf.Cos(touchCkAng_)*tmpPos.x; myTouches_[0] = new MyTouch(0,new Vector2(moveMax*(0.5f + tmpPos.x),moveMax*(0.5f + tmpPos.y))); myTouches_[1] = new MyTouch(1,new Vector2(moveMax*(0.5f - tmpPos.x),moveMax*(0.5f - tmpPos.y))); }else{ touchCkSize_ = 0.5f; touchCkAng_ = 0.0f; } } if( myTouches_.Length >= 2){ Vector2 vec = myTouches_[1].position - myTouches_[0].position; touchOldAng_ = touchAng_; touchAng_ = Mathf.Atan2(vec.y,vec.x); if(touchSttAng_ == float.MaxValue){ touchSttAng_ = touchAng_; touchOldAng_ = touchAng_; } touchOldSize_ = touchSize_; touchSize_ = vec.magnitude / moveMax; if(touchSttSize_ == float.MaxValue){ touchSttSize_ = touchSize_; touchOldSize_ = touchSize_; } swypeOldPos_ = swypePos_; swypePos_ = tmpSwypeCenter_; if(swypeSttPos_.x == float.MaxValue){ swypeSttPos_ = swypePos_; swypeOldPos_ = swypePos_; } // for debug if(myTouches_.Length >= 2){ Vector3 v0 = Camera.main.ScreenToWorldPoint(new Vector3(myTouches_[0].position.x,myTouches_[0].position.y,-Camera.main.transform.position.z)); Vector3 v1 = Camera.main.ScreenToWorldPoint(new Vector3(myTouches_[1].position.x,myTouches_[1].position.y,-Camera.main.transform.position.z)); Debug.DrawLine(v0,v1,((deltaSize<0.0f) ? Color.red : ((deltaSize>0.0f) ? Color.blue : Color.white))); } }else{ touchSttSize_ = float.MaxValue; touchOldSize_ = float.MaxValue; touchSttAng_ = float.MaxValue; touchOldAng_ = float.MaxValue; swypeSttPos_ = new Vector2(float.MaxValue,float.MaxValue); swypeOldPos_ = new Vector2(float.MaxValue,float.MaxValue); // tmpSwypeCenter_ = new Vector2(Screen.width*0.5f,Screen.height*0.5f); } isDoubleTap_ = doubleTapCheck(); }
// Control player void OnTouch(MyTouch touch) { if (touch.startTime - lastTouchTime < 0.1) { return; } float laneWidth = Screen.width / m_PlayerObjects.Length; int player = (int)(touch.startLoc.x / laneWidth); lastTouchTime = touch.startTime; switch (touch.type) { // Move left case TouchType.SwipeLeft: SwapLeft(player); break; // Move right case TouchType.SwipeRight: SwapRight(player); break; // Change shape case TouchType.Tap: if (LoadSceneOnClick.stageNum == 3 || LoadSceneOnClick.stageNum == 5) { m_PlayerObjects[player].ChangeShape(); } break; // Fuse colors case TouchType.PinchIn: if (LoadSceneOnClick.stageNum == 2 || LoadSceneOnClick.stageNum == 5) { int player2 = (int)(touch.endLoc.x / laneWidth); Player p1 = m_PlayerObjects[player]; Player p2 = m_PlayerObjects[player2]; if (player == 0 && player2 == 2 || player == 2 && player2 == 0) { return; } if (!p1.isFused && !p2.isFused) { FuseColors(p1, p2); } } break; // Unfuse colors case TouchType.PinchOut: if (LoadSceneOnClick.stageNum == 2 || LoadSceneOnClick.stageNum == 5) { int player2 = (int)(touch.endLoc.x / laneWidth); Player p1 = m_PlayerObjects[player]; Player p2 = m_PlayerObjects[player2]; if (player == 0 && player2 == 2 || player == 2 && player2 == 0) { return; } if (p1.isFused && p2.isFused) { UnFuseColors(p1, p2); } } break; } }
private void LooseTouch2() { _myTouch2?.SetAsNotOwned(); _myTouch2 = null; }
private void LooseTouch1() { _myTouch1?.SetAsNotOwned(); _myTouch1 = null; }
private void RemoveTouch() { Touch?.SetAsNotOwned(); Touch = null; }
public void Update() { if (!Enabled) { return; } //Check touches if they are still active if (_myTouch1 != null) { if (_myTouch1.IsRelased()) { LooseTouch1(); } } if (_myTouch2 != null) { if (_myTouch2.IsRelased()) { LooseTouch2(); } } //If second touch is active but first is not, then lets move second to first if (_myTouch2 != null && _myTouch1 == null) { _myTouch1 = _myTouch2; _myTouch2 = null; } //Get new touches if (_myTouch1 == null) { if ((_myTouch1 = InputOptions.MyState.GetBrandNewTouch(false)) != null) { _firstTouchMoved = false; _firstTouchPosition = _myTouch1.Position; _isMyTouch1Mouse = false; } else { //Try get mouse if ((_myTouch1 = InputOptions.MyState.GetPressedMouse(true)) != null) { _firstTouchMoved = false; _firstTouchPosition = _myTouch1.Position; _isMyTouch1Mouse = true; } } } if (_myTouch2 == null && _myTouch1 != null && !_isMyTouch1Mouse) { if ((_myTouch2 = InputOptions.MyState.GetBrandNewTouchBut(_myTouch1)) != null) { //Ready for zooming _zoomTouchesAveragePosition = (_myTouch1.Position + _myTouch2.Position) / 2; _myTouch1.SetAsOwned(); _firstTouchMoved = true; } } if (_myTouch1 != null) { if (_myTouch2 == null) { if (!_firstTouchMoved) { if (Vector2.Distance(_myTouch1.Position, _firstTouchPosition) > _firstTouchMoveDist) { //Start dragging _firstTouchMoved = true; HardAdjustFocusPosition(_myTouch1.Position - _firstTouchPosition); _myTouch1.SetAsOwned(); } } else { // There is only one touch - dragging! HardAdjustFocusPosition(_myTouch1.Move); } } else { // There are two touches - finger zooming! #region Fingerzooming! Vector2 previousDiff = _myTouch1.PreviousTouch.Position - _myTouch2.PreviousTouch.Position; float previousDist = previousDiff.Length(); Vector2 currDiff = _myTouch1.Position - _myTouch2.Position; float currDist = currDiff.Length(); FingerZoom *= currDist / previousDist; if (FingerZoom < CameraOptions.MinZoom) { FingerZoom = CameraOptions.MinZoom; } if (FingerZoom > CameraOptions.MaxZoom) { FingerZoom = CameraOptions.MaxZoom; } Vector2 newAveragePosition = (_myTouch1.Position + _myTouch2.Position) / 2; HardAdjustFocusPosition(newAveragePosition - _zoomTouchesAveragePosition); _zoomTouchesAveragePosition = newAveragePosition; #endregion } } }
// private members static bool HandleOneTouch(MyTouch touch) { // Debug.Log("Touching at: " + touch.position); if (touch.phase == TouchPhase.Began) { // Debug.Log("Touch phase began at: " + touch.position); // don't catch the vase all the time! RaycastHit2D hit = Physics2D.Raycast(Camera.main.ScreenToWorldPoint(touch.position), Vector2.zero, 10.0f, 1 << LayerMask.NameToLayer("MovingByFingerObjects")); if (hit.collider != null) { m_PickedObject = hit.transform; // Debug.Log("catch object" + m_PickedObject.gameObject.name); } else { m_PickedObject = null; // Debug.Log("no object"); return(false); } return(true); } else if (m_PickedObject && touch.phase == TouchPhase.Moved) { // Debug.Log("Touch phase Moved"); Vector2 screen_delta = touch.deltaPosition; Vector2 world_delta = Utils.ScreenDeltaToWorld(screen_delta); Vector3 world_delta_3d = new Vector3(world_delta.x, world_delta.y, 0.0f); if (m_PickedObject.gameObject.tag == "FallingBomb") { FallingBomb fb = Utils.GetTheClassFromGO <FallingBomb>(m_PickedObject.gameObject); fb.MoveByFinger(world_delta_3d); } else if (m_PickedObject.gameObject.tag == "Vase") { FallingObject fo = Utils.GetTheClassFromGO <FallingObject>(m_PickedObject.gameObject); fo.MoveByFinger(world_delta_3d); } // if (m_PickedObject.CompareTag("FallingBomb")) { // // } else { // m_PickedObject.position += world_delta_3d; // } return(true); } else if (m_PickedObject && touch.phase == TouchPhase.Ended) { // Debug.Log("Touch phase Ended"); if (m_PickedObject.CompareTag("FallingBomb")) { FallingBomb fb = Utils.GetTheClassFromGO <FallingBomb>(m_PickedObject.gameObject); fb.EndMovingByFinger(); } if (m_PickedObject.CompareTag("Vase")) { FallingObject fo = Utils.GetTheClassFromGO <FallingObject>(m_PickedObject.gameObject); fo.EndMovingByFinger(); } m_PickedObject = null; return(true); } return(false); }
// Update is called once per frame void Update() { if (Input.GetKeyDown(KeyCode.Space)) { ReprocessTouches(); } if (Input.GetKeyDown(KeyCode.H)) { TrocaToques(); } if (Input.GetKeyUp(KeyCode.Space)) { isRep = false; } if (Input.GetKeyUp(KeyCode.H)) { isH = false; } Vector3 user1RightHPos = User1.handRight.transform.position; Vector3 user1LeftHPos = User1.handLeft.transform.position; Vector3 user2RightHPos = User2.handRight.transform.position; Vector3 user2LeftHPos = User2.handLeft.transform.position; float distUserHands = Mathf.Min( Vector3.Distance(user1RightHPos, user2RightHPos), Vector3.Distance(user1RightHPos, user2LeftHPos), Vector3.Distance(user1LeftHPos, user2RightHPos), Vector3.Distance(user1LeftHPos, user2LeftHPos) ); if (!(distUserHands < (distanceThreshold))) { handsTooCloseLuci = false; } if (Input.touchCount > 0) { // print("Touch!"); foreach (Touch touch in Input.touches) { if (touch.phase == TouchPhase.Began) { MyTouch touchUser1 = User1.handRight.userTouch.touch; MyTouch touchUser2 = User2.handRight.userTouch.touch; if (touchUser1 == null || touchUser2 == null) { if (distUserHands < (distanceThreshold)) { handsTooCloseLuci = true; } } ProcessNewTouch(touch); } } if (reprocessInterval >= 0) { if ((DateTime.Now - lastReprocess).TotalMilliseconds > reprocessInterval) { if ( ((User1.handRight.userTouch.touch == null && !User1.handRight.userTouch.possibleDoubleTap) || (User1.handRight.userTouch.touch != null && User1.handRight.userTouch.touch.isDrag)) && ((User2.handRight.userTouch.touch == null && !User2.handRight.userTouch.possibleDoubleTap) || (User2.handRight.userTouch.touch != null && User2.handRight.userTouch.touch.isDrag)) ) { if (Vector3.Distance(User1.handRight.transform.position, User2.handRight.transform.position) > distanceThreshold && Vector3.Distance(User1.handLeft.transform.position, User2.handRight.transform.position) > distanceThreshold && Vector3.Distance(User1.handRight.transform.position, User2.handLeft.transform.position) > distanceThreshold && Vector3.Distance(User1.handLeft.transform.position, User2.handLeft.transform.position) > distanceThreshold ) { lastReprocess = DateTime.Now; ReprocessTouches(); } } } } if (distUserHands > distanceThreshold) { handsTooClose = false; foreach (Touch t in Input.touches) { // descobrir qual o user com a mao mais proxima Vector3 touchPos = MyTouch.GetTouchWorldPosition(t); // distancias User 1 float dUser1 = Mathf.Min(Vector3.Distance(user1RightHPos, touchPos), Vector3.Distance(user1LeftHPos, touchPos)); // distancias User 2 float dUser2 = Mathf.Min(Vector3.Distance(user2RightHPos, touchPos), Vector3.Distance(user2LeftHPos, touchPos)); // toques dos users MyTouch touchUser1 = User1.handRight.userTouch.touch; MyTouch touchUser2 = User2.handRight.userTouch.touch; if (dUser1 < dUser2) { if (dUser1 < distanceThreshold) { if (touchUser1 == null) { ReprocessTouches(); break; } else { Vector3 currentTouchPos = touchUser1.transform.position; float currentDUser = Mathf.Min(Vector3.Distance(user1RightHPos, currentTouchPos), Vector3.Distance(user1LeftHPos, currentTouchPos)); if (currentDUser > distanceThreshold) { ReprocessTouches(); break; } } } } else if (dUser2 < dUser1) { if (dUser2 < distanceThreshold) { if (touchUser2 == null) { ReprocessTouches(); break; } else { Vector3 currentTouchPos = touchUser2.transform.position; float currentDUser = Mathf.Min(Vector3.Distance(user2RightHPos, currentTouchPos), Vector3.Distance(user2LeftHPos, currentTouchPos)); if (currentDUser > distanceThreshold) { ReprocessTouches(); break; } } } } } } else { handsTooClose = true; // Se estiverem ainda mais perto: Luci mode } } if (reprocessInterval >= 0) { if ((DateTime.Now - lastReprocess).TotalMilliseconds > reprocessInterval) { if ( ((User1.handRight.userTouch.touch == null && !User1.handRight.userTouch.possibleDoubleTap) || (User1.handRight.userTouch.touch != null && User1.handRight.userTouch.touch.isDrag)) && ((User2.handRight.userTouch.touch == null && !User2.handRight.userTouch.possibleDoubleTap) || (User2.handRight.userTouch.touch != null && User2.handRight.userTouch.touch.isDrag)) ) { if (Vector3.Distance(User1.handRight.transform.position, User2.handRight.transform.position) > distanceThreshold && Vector3.Distance(User1.handLeft.transform.position, User2.handRight.transform.position) > distanceThreshold && Vector3.Distance(User1.handRight.transform.position, User2.handLeft.transform.position) > distanceThreshold && Vector3.Distance(User1.handLeft.transform.position, User2.handLeft.transform.position) > distanceThreshold ) { lastReprocess = DateTime.Now; ReprocessTouches(); } } } } }
private void VirtualTouch() { if (Input.GetMouseButtonDown (1)) { Debug.Log ("MouseButtonDown"); m_beginPosition = Input.mousePosition; m_touched = true; } if (Input.GetMouseButtonUp (1)) { m_touched = false; currentTouchs = new MyTouch[0]; } if (m_touched) { currentTouchs = new MyTouch[2]; Vector3 dir = Input.mousePosition - m_beginPosition; currentTouchs [0] = new MyTouch (); currentTouchs [0].fingerId = 0; currentTouchs [0].position = m_beginPosition + dir; currentTouchs [1] = new MyTouch (); currentTouchs [1].fingerId = 1; currentTouchs [1].position = m_beginPosition - dir; } }
public void LooseTouch() { _myTouch.SetAsNotOwned(); _myTouch = null; }
public override void Update() { base.Update(); TryReleaseMouseBlock(); #region Getting touch if (CanBeTouched()) { if (Touch == null) { Touch = GetMouse() ?? GetTouch(); } BlockTouches(); } #endregion #region Has touch if (Touch != null) { switch (Touch.State) { #region JustPressed case TouchState.JustPressed: { if (IsClickable) { Press(); } } break; #endregion #region Continuing case TouchState.Continuing: { #region Dragging if (IsDraggingAllowed) { if (!IsDragging) { #region Drag start Vector2 mouseStartDragMove = Touch.Position - _startDragPosition; if (!IsClickable || mouseStartDragMove.Length() >= _dragStartDistance) { StartDragging(); Drag(mouseStartDragMove); } #endregion } else { Drag(Touch.Move); } } #endregion if (IsClickable) { OnClickContinues?.Invoke(Touch); } } break; #endregion #region Relased case TouchState.Relased: { ReleaseTouch(); } break; #endregion } } #endregion }