public void Initialized(NotesController gameCont, int Id, Vector3 sPosition, Vector3 tPosition, Vector3 dir, int nTime, int dTime, slideVector aimDir) //初始化方法 { gameController = gameCont; ID = Id; selfTransform.position = sPosition; targetPosition = tPosition; direction = dir; noteTime = nTime; delayTime = dTime; aimDirection = aimDir; if (aimDirection == slideVector.up) { GetComponent <Image>().sprite = filpNoteRenderSprites[0]; } else if (aimDirection == slideVector.down) { GetComponent <Image>().sprite = filpNoteRenderSprites[1]; } }
private void HandleEnd(Touch myTouch) { _currentVector = slideVector.nullVector; //判断是否需要页码回归,只有横向滑动时才需要页码回归 if (_isCheckPage) { float tempVal = myTouch.position.x - clickPos.x; //判断手指抬起时和按下时 间距超过50则直接回归到下一页,否则回归到本页 if (Mathf.Abs(tempVal) >= 50) { int newIndex; if (tempVal >= 0) { //往左滑 newIndex = _horizontalIndex - 1; _horizontalIndex = newIndex < 0 ? 0 : newIndex; } else { //往右滑 newIndex = _horizontalIndex + 1; _horizontalIndex = newIndex >= _pageArray.Count ? _pageArray.Count - 1 : newIndex; } } } //根据滑动条的位置判断是否回归到本页 //_horizontalIndex = GetPageIndex(_scrollRect.horizontalNormalizedPosition); //将回归的页码值赋给目标值 _targetHorizontalPosition = _pageArray[_horizontalIndex]; //开始页码回归缓动效果 _isEndDrag = true; }
void OnGUI() // 滑动方法02 { if (Event.current.type == EventType.MouseDown) //判断当前手指是按下事件 { touchFirst = Event.current.mousePosition;//记录开始按下的位置 } if (Event.current.type == EventType.MouseDrag) //判断当前手指是拖动事件 { touchSecond = Event.current.mousePosition; timer += Time.deltaTime; //计时器 if (timer > offsetTime) { touchSecond = Event.current.mousePosition; //记录结束下的位置 Vector2 slideDirection = touchFirst - touchSecond; float x = slideDirection.x; float y = slideDirection.y; if (y + SlidingDistance < x && y > -x - SlidingDistance) { if (currentVector == slideVector.left) { return; } Debug.Log("right"); currentVector = slideVector.left; } else if (y > x + SlidingDistance && y < -x - SlidingDistance) { if (currentVector == slideVector.right) { return; } Debug.Log("left"); currentVector = slideVector.right; } else if (y > x + SlidingDistance && y - SlidingDistance > -x) { if (currentVector == slideVector.up) { return; } Debug.Log("up"); currentVector = slideVector.up; } else if (y + SlidingDistance < x && y < -x - SlidingDistance) { if (currentVector == slideVector.down) { return; } Debug.Log("Down"); currentVector = slideVector.down; } timer = 0; touchFirst = touchSecond; } if (Event.current.type == EventType.MouseUp) {//滑动结束 currentVector = slideVector.nullVector; } } // 滑动方法 }
private void LateUpdate() { Vector3 movement = new Vector3(0f, 0f, 2f); Vector3 left = new Vector3(-5f, 0f, 5f); Vector3 right = new Vector3(5f, 0f, 5f); rigidbodyPlayer.AddForce(movement * 1f); if (Input.GetButtonDown("Jump") || currentVector == slideVector.up) { if (ground == true) { GetComponent <Rigidbody>().velocity = new Vector3(0, 5, 0); GetComponent <Rigidbody>().AddForce(Vector3.up * mJumpSpeed); ground = false; currentVector = slideVector.nullVector; Debug.Log("Jump"); } else { currentVector = slideVector.nullVector; } } timeRemaining += Time.deltaTime; if (Input.GetKeyDown(KeyCode.A) || currentVector == slideVector.left) { if (x == -1) { x = x; currentVector = slideVector.nullVector; } else { x--; rigidbodyPlayer.AddForce(left * 20f); currentVector = slideVector.nullVector; } } if (Input.GetKeyDown(KeyCode.D) || currentVector == slideVector.right) { if (x == 1) { x = x; currentVector = slideVector.nullVector; } else { x++; rigidbodyPlayer.AddForce(right * 20f); currentVector = slideVector.nullVector; } } if (x == -1) { gameObject.transform.localPosition = Vector3.MoveTowards(gameObject.transform.localPosition, new Vector3(-2.4f, gameObject.transform.localPosition.y, gameObject.transform.localPosition.z), 4f * Time.deltaTime); } if (x == 0) { gameObject.transform.localPosition = Vector3.MoveTowards(gameObject.transform.localPosition, new Vector3(0, gameObject.transform.localPosition.y, gameObject.transform.localPosition.z), 4f * Time.deltaTime); } if (x == 1) { gameObject.transform.localPosition = Vector3.MoveTowards(gameObject.transform.localPosition, new Vector3(2.4f, gameObject.transform.localPosition.y, gameObject.transform.localPosition.z), 4f * Time.deltaTime); } PickupCategories(); }
public float offsetTime = 0.1f; //判断的时间间隔 void OnGUI() { if (Event.current.type == EventType.MouseDown) //判断当前手指是按下事件 { st = Event.current.mousePosition; //记录开始按下的位置 } if (Event.current.type == EventType.MouseDrag) //判断当前手指是拖动事件 { timer += Time.deltaTime; //计时器 if (timer > offsetTime) { end = Event.current.mousePosition; //记录结束下的位置 Vector2 slideDirection = st - end; float x = slideDirection.x; float y = slideDirection.y; if (y < x && y > -x) { if (currentVector == slideVector.right) //判断当前方向 { return; } Debug.Log("right"); currentVector = slideVector.right; //设置方向 } else if (y > x && y < -x) { if (currentVector == slideVector.left) { return; } Debug.Log("left"); currentVector = slideVector.right; } else if (y > x && y > -x) { if (currentVector == slideVector.up) { return; } Debug.Log("up"); currentVector = slideVector.up; } else if (y < x && y < -x) { if (currentVector == slideVector.down) { return; } Debug.Log("down"); currentVector = slideVector.down; } timer = 0; st = end;//初始化位置 } } if (Event.current.type == EventType.MouseUp) { currentVector = slideVector.nullVector; //初始化方向 } }
void OnGUI() { if (Event.current.type == EventType.MouseDown) //判断当前手指是按下事件 { st = Event.current.mousePosition; //记录开始按下的位置 fingerDown = true; } if (Event.current.type == EventType.MouseDrag)//判断当前手指是拖动事件 { timer += Time.deltaTime; //计时器 if (timer > offsetTime && fingerDown) { end = Event.current.mousePosition; //记录结束下的位置 Vector2 slideDirection = end - st; float x = slideDirection.x; float y = slideDirection.y; if (x > 0 && x > Mathf.Abs(y)) { if (currentVector == slideVector.right) //判断当前方向 { return; } boxManager.mergeBoxWithRight(); if (boxManager.createNewBoxIsAllowed) { Invoke("findALocationAndAddABox", 0.3f); } currentVector = slideVector.right; //设置方向 } else if (x < 0 && Mathf.Abs(y) < -x) { if (currentVector == slideVector.left) { return; } boxManager.mergeBoxWithLeft(); if (boxManager.createNewBoxIsAllowed) { Invoke("findALocationAndAddABox", 0.3f); } currentVector = slideVector.left; } else if (y < 0 && Mathf.Abs(x) < -y) { if (currentVector == slideVector.up) { return; } boxManager.mergeBoxWithUp(); if (boxManager.createNewBoxIsAllowed) { Invoke("findALocationAndAddABox", 0.3f); } currentVector = slideVector.up; } else if (y > 0 && y > Mathf.Abs(x)) { if (currentVector == slideVector.down) { return; } boxManager.mergeBoxWithDown(); if (boxManager.createNewBoxIsAllowed) { Invoke("findALocationAndAddABox", 0.3f); } currentVector = slideVector.down; } timer = 0; st = end;//初始化位置 fingerDown = false; } } if (Event.current.type == EventType.MouseUp) { currentVector = slideVector.nullVector; //初始化方向 fingerDown = false; } }
private void CheckFlip(Touch eachTouch, RaycastHit2D targetHit) { if (eachTouch.phase == TouchPhase.Moved) //判断当前手指是拖动事件 { touchSecond = eachTouch.position; timer += Time.deltaTime; //计时器 if (timer > offsetTime) { touchSecond = eachTouch.position; //记录结束下的位置 Vector2 slideDirection = touchFirst - touchSecond; float x = slideDirection.x; float y = slideDirection.y; // if (y + SlidingDistance < x && y > -x - SlidingDistance && !ifEnd) // { // Debug.Log("left"); // // currentVector = slideVector.left; // ifEnd = true; // } // else if (y > x + SlidingDistance && y < -x - SlidingDistance && !ifEnd) // { // Debug.Log("right"); // // currentVector = slideVector.right; // ifEnd = true; // } if (y > x + SlidingDistance && y - SlidingDistance > -x && !ifEnd) { // Debug.Log("Down"); currentVector = slideVector.down; ifEnd = true; } else if (y + SlidingDistance < x && y < -x - SlidingDistance && !ifEnd) { // Debug.Log("Up"); currentVector = slideVector.up; ifEnd = true; } timer = 0; touchFirst = touchSecond; } } // 滑动方法 if (ifEnd || (eachTouch.phase == TouchPhase.Ended && ifEnd)) { if (targetHit) { if (targetHit.collider.GetComponent <FlipNote>().aimDirection == currentVector) { targetHit.collider.GetComponent <FlipNote>().Onhit(); } else { targetHit.collider.GetComponent <FlipNote>().WrongDirInput(); } targetMovingHit = new RaycastHit2D(); currentVector = slideVector.nullVector; ifEnd = false; } } }
private void HandleMove(Touch myTouch) { _isEndDrag = false; var currentPos = myTouch.position; _moveTimer += Time.deltaTime; if (_moveTimer > offsetTime) { if (currentPos.x < lastPos.x) { _currentVector = slideVector.left; //Debug.Log("Turn left"); } if (currentPos.x > lastPos.x) { _currentVector = slideVector.right; //Debug.Log("Turn right"); } lastPos = currentPos; _moveTimer = 0; } //判断是否需要检测,如果不需要则说明手指已经检测出是向左右滑动还是向上下滑动 if (_isNeedCheck) { _horizontalSpace = Mathf.Abs(currentPos.x - clickPos.x); _verticalSpace = Mathf.Abs(currentPos.y - clickPos.y); } //实时横向滑动 if (_horizontalSpace >= InoutThreshold || _verticalSpace >= InoutThreshold) { //比较手指横向滑动的距离与竖向滑动的距离用来判断是横向滑动还是竖向滑动 if (_horizontalSpace > _verticalSpace) { SetVertical(false); var tempValue = _boarderSpace / HorizontalSpeed; switch (_currentVector) { case slideVector.nullVector: break; case slideVector.left: _scrollRect.horizontalNormalizedPosition += tempValue; break; case slideVector.right: _scrollRect.horizontalNormalizedPosition -= tempValue; break; } //标记滑动结束需要页码回归 _isCheckPage = true; } else { SetVertical(true); //标记滑动结束不需要页码回归 _isCheckPage = false; } //判断成功,则标记为不再需要检测 _isNeedCheck = false; } }
void Update() { if (Input.GetMouseButtonDown(0)) { lastPos = Input.mousePosition; currentPos = Input.mousePosition; startPos = Input.mousePosition; startCameraEuler = mainCameraTrans.transform.localEulerAngles; timer = 0; delta_slider = 0; } if (Input.GetMouseButton(0)) { currentPos = Input.mousePosition; timer += Time.deltaTime; if (timer > offsetTime) { if (currentPos.x < lastPos.x) { if (currentVector == slideVector.left) { return; } //TODO trun Left event lastVector = slideVector.left; currentVector = slideVector.left; // if (player != null) { // player.AttackLeft (); // } //Debug.Log ("Turn left"); } if (currentPos.x > lastPos.x) { if (currentVector == slideVector.right) { return; } //TODO trun right event lastVector = slideVector.right; currentVector = slideVector.right; // if (player != null) { // player.AttackRight (); // } //Debug.Log ("Turn right"); } delta_slider = delta_slider + (currentPos.x - lastPos.x) / 2; lastPos = currentPos; timer = 0; } } if (Input.GetMouseButtonUp(0)) { if (lastVector != slideVector.nullVector && currentVector == slideVector.nullVector) { if (lastVector == slideVector.left) { //TODO trun Left event //Debug.Log("click attack left++++++++++++"); // player.AttackLeft(); } else { //Debug.Log("click attack right++++++++++++"); // player.AttackRight(); } } currentVector = slideVector.nullVector; } }
private void CheckMove() { if (Input.GetMouseButtonDown(0)) { lastPos = Input.mousePosition; currentPos = Input.mousePosition; timer = 0; } if (Input.GetMouseButton(0) && isMovingTo == false) { currentPos = Input.mousePosition; timer += Time.deltaTime; if (timer > offsetTime) { float offsetY = currentPos.y - lastPos.y; float offsetX = currentPos.x - lastPos.x; if (Mathf.Abs(offsetX) < Mathf.Abs(offsetY)) { if (offsetY >= slideDelicacy) // UP向上跳跃 { if (currentVector == slideVector.up) { return; } currentVector = slideVector.up; Jump(); isMovingTo = true; } else if (offsetY <= -slideDelicacy) { if (currentVector == slideVector.up) { QuickDown(); } else { SliderDown(); } currentVector = slideVector.down; isMovingTo = true; } } else { if (offsetX <= -slideDelicacy) { if (playerPos == EplayerPos._left) { return; } currentVector = slideVector.left; if (playerPos != EplayerPos._left) { } if (playerPos == EplayerPos._center) { playerPos = EplayerPos._left; } else if (playerPos == EplayerPos._right) { playerPos = EplayerPos._center; } isMovingTo = true; MoveLeft(); } else if (offsetX >= slideDelicacy) { if (playerPos == EplayerPos._right) { return; } //TODO trun right event currentVector = slideVector.right; if (playerPos == EplayerPos._center) { playerPos = EplayerPos._right; } else if (playerPos == EplayerPos._left) { playerPos = EplayerPos._center; } isMovingTo = true; MoveRight(); } } lastPos = currentPos; timer = 0; } } if (Input.GetMouseButtonUp(0)) { isMovingTo = false; } Vector3 vSpeed = new Vector3(this.transform.forward.x, this.transform.forward.y, this.transform.forward.z) * mMoveSpeed; // Vector3 jumpSpeed = new Vector3( this.transform.up.x, this.transform.up.y, this.transform.up.z ) * jumpHeight * m_jumpState; //让角色开始奔跑 //transform.Translate( Vector3.forward * mMoveSpeed * Time.deltaTime ); transform.position += (vSpeed) * Time.deltaTime; //移动摄像机 mCamera.Translate(Vector3.forward * mMoveSpeed * Time.deltaTime); }
IEnumerator RestJumpState() { yield return(new WaitForSeconds(0.5f)); currentVector = slideVector.nullVector; }
void OnGUI() // 滑动方法02 { if (Event.current.type == EventType.MouseDown) //判断当前手指是按下事件 { touchFirst = Event.current.mousePosition; //记录开始按下的位置 } if (Event.current.type == EventType.MouseDrag) //判断当前手指是拖动事件 { touchSecond = Event.current.mousePosition; timer += Time.deltaTime; //计时器 if (timer > offsetTime) { touchSecond = Event.current.mousePosition; //记录结束下的位置 Vector2 slideDirection = touchFirst - touchSecond; float x = slideDirection.x; float y = slideDirection.y; if (y + SlidingDistance < x && y > -x - SlidingDistance) { if (currentVector == slideVector.left) { return; } Debug.Log("right"); currentVector = slideVector.left; } else if (y > x + SlidingDistance && y < -x - SlidingDistance) { if (currentVector == slideVector.right) { return; } Debug.Log("left"); currentVector = slideVector.right; } else if (y > x + SlidingDistance && y - SlidingDistance > -x) { if (currentVector == slideVector.up) { return; } Debug.Log("up"); currentVector = slideVector.up; TopPanel.GetComponent <CanvasGroup>().alpha = 0; TopPanel.GetComponent <CanvasGroup>().interactable = false; TopPanel.GetComponent <CanvasGroup>().blocksRaycasts = false; BottomPanel.GetComponent <CanvasGroup>().alpha = 0; BottomPanel.GetComponent <CanvasGroup>().interactable = false; BottomPanel.GetComponent <CanvasGroup>().blocksRaycasts = false; } else if (y + SlidingDistance < x && y < -x - SlidingDistance) { if (currentVector == slideVector.down) { return; } Debug.Log("Down"); currentVector = slideVector.down; TopPanel.GetComponent <CanvasGroup>().alpha = 1; TopPanel.GetComponent <CanvasGroup>().interactable = true; TopPanel.GetComponent <CanvasGroup>().blocksRaycasts = true; BottomPanel.GetComponent <CanvasGroup>().alpha = 1; BottomPanel.GetComponent <CanvasGroup>().interactable = true; BottomPanel.GetComponent <CanvasGroup>().blocksRaycasts = true; } timer = 0; touchFirst = touchSecond; } if (Event.current.type == EventType.MouseUp) //滑动结束 { currentVector = slideVector.nullVector; } } // 滑动方法 }
int Slide() // 滑动方法 { if (Input.touchCount == 1) //判断当前手指是按下事件 { touchFirst = Input.GetTouch(0).position;//记录开始按下的位置 } else { return(0); } if (Input.GetTouch(0).phase == TouchPhase.Moved) //判断当前手指是拖动事件 { touchSecond = Input.GetTouch(0).position; timeCount += Time.deltaTime; //计时器 if (timeCount > offsetTime) { touchSecond = Input.GetTouch(0).position; //记录结束下的位置 Vector2 slideDirection = touchFirst - touchSecond; float x = slideDirection.x; float y = slideDirection.y; if (y + SlidingDistance < x && y > -x - SlidingDistance) { if (currentVector == slideVector.left) { return(0); } Debug.Log("right"); return(2); } else if (y > x + SlidingDistance && y < -x - SlidingDistance) { if (currentVector == slideVector.right) { return(0); } Debug.Log("left"); return(1); } else if (y > x + SlidingDistance && y - SlidingDistance > -x) { if (currentVector == slideVector.up) { return(0); } Debug.Log("up"); return(3); } else if (y + SlidingDistance < x && y < -x - SlidingDistance) { if (currentVector == slideVector.down) { return(0); } Debug.Log("Down"); return(4); } timeCount = 0; touchFirst = touchSecond; } if (Input.touchCount == 0) { //滑动结束 currentVector = slideVector.nullVector; } } return(0); }