void OnTouch(TouchStruct touchStruct) { float currVelocity = cRigidbody.velocity.y; Vector2 newVelocity = new Vector2(0, Mathf.Clamp(currVelocity + PUSH_FORCE, -Mathf.Infinity, MAX_VELOCITY)); cRigidbody.velocity = newVelocity; Achievements.instance.UpgradeJump(); }
public ScreenTouch(TouchStruct touchStruct) { touchId = touchStruct.touchId; frame = touchStruct.frame; touchPosition = new Vector2(touchStruct.touchPosition.x * Screen.width, touchStruct.touchPosition.y * Screen.height); touchState = touchStruct.touchState; }
private void rawDeserialize(byte[] rawdatas) { int handIndex = 0; int fingerIndex = 0; int touchIndex = 0; int startIndex = 0; int frameCount = 0; int dataSize = rawdatas.Length; bool stop = false; while (startIndex < dataSize - 1) { byte[] typeByte = new byte[4]; Array.Copy(rawdatas, startIndex, typeByte, 0, 4); int type = BitConverter.ToInt32(typeByte, 0); switch (type) { case 1: HandStruct handStruct = new HandStruct(); getHandStruct(ref handStruct, rawdatas, startIndex); startIndex += handStructSize; handsData [handIndex] = handStruct; handIndex++; break; case 2: FingerStruct fingerStruct = new FingerStruct(); getFingerStruct(ref fingerStruct, rawdatas, startIndex); startIndex += fingerStructSize; fingersData [fingerIndex] = fingerStruct; fingerIndex++; break; case 4: TouchStruct touchStruct = new TouchStruct(); getTouchStruct(ref touchStruct, rawdatas, startIndex); startIndex += touchStructSize; touchesData [touchIndex] = touchStruct; touchIndex++; break; default: stop = true; break; } if (stop == true) { break; } } }
TouchStruct CreateTouchStructure(Touch touch) { TouchStruct tStruct = new TouchStruct(); tStruct.info = touch; tStruct.isDown = false; tStruct.isPending = false; tStruct.cooler = DOUBLE_TOUCH_COOLER; tStruct.previousPosition = touch.position; return(tStruct); }
void SwipeAction(TouchStruct touch, Vector2 direction) { if (!_enabled) { return; } Vector2 swipeDirection = ToolBox.instance.ClosestDirection(direction); Slide((int)swipeDirection.x); }
void StayTouch(Touch touch, TouchStruct touchStruct) { if (OnStayTouch != null) { OnStayTouch(touchStruct); } if (OnDownTouch != null) { OnDownTouch(touchStruct); } }
void MoveTouch(Touch touch, TouchStruct touchStruct) { if (OnMoveTouch != null) { OnMoveTouch(touchStruct); } if (OnDownTouch != null) { OnDownTouch(touchStruct); } }
public static void getTouchStruct(ref TouchStruct touchStruct, byte[] rawdatas, int startIndex) { touchStruct.structType = DataStruct.ScreenTouch; byte[] touchByte = new byte[touchStructSize]; Array.Copy(rawdatas, startIndex, touchByte, 0, touchStructSize); byte[] validByte = new byte[1]; Array.Copy(touchByte, 4, validByte, 0, 1); touchStruct.valid = BitConverter.ToBoolean(validByte, 0); byte[] touchIdByte = new byte[4]; Array.Copy(touchByte, 5, touchIdByte, 0, 4); touchStruct.touchId = BitConverter.ToInt32(touchIdByte, 0); byte[] frameByte = new byte[4]; Array.Copy(touchByte, 9, frameByte, 0, 4); touchStruct.frame = BitConverter.ToInt32(frameByte, 0); byte[] positionXByte = new byte[4]; byte[] positionYByte = new byte[4]; Array.Copy(touchByte, 13, positionXByte, 0, 4); Array.Copy(touchByte, 17, positionYByte, 0, 4); touchStruct.touchPosition.x = BitConverter.ToSingle(positionXByte, 0); touchStruct.touchPosition.y = BitConverter.ToSingle(positionYByte, 0); byte [] stateByte = new byte[4]; Array.Copy(touchByte, 21, stateByte, 0, 4); int stateNumber = BitConverter.ToInt32(stateByte, 0); switch (stateNumber) { case 1: touchStruct.touchState = TouchState.Down; // print ("Down"); break; case 2: touchStruct.touchState = TouchState.Move; // print ("Move"); break; case 3: touchStruct.touchState = TouchState.Up; // print ("Up"); break; default: break; } }
/// <summary> /// Do the calculation for the next player movement /// /// Calculate the swipe direction /// Calculate the next position if we move /// Check if the move is not out of bound /// Apply the movement /// </summary> /// <param name="touch"></param> /// <param name="direction"></param> void Movement(TouchStruct touch, Vector2 direction) { Vector3 swipeDirection = ToolBox.instance.ClosestDirection(direction); float angle = ToolBox.instance.ClosestAngle2D(-swipeDirection, lastDirection); body.Rotate(new Vector3(0, 0, angle), Space.Self); float nextPosX = currentGridIndex.x + swipeDirection.x; float nextPosY = currentGridIndex.y + swipeDirection.y; lastDirection = -swipeDirection; targetGridIndex = movementGrid.ClampIndexOnGrid((int)nextPosX, (int)nextPosY); StartCoroutine(MoveAnimation(movementGrid.GetPosition((int)targetGridIndex.x, (int)targetGridIndex.y))); }
void CheckIfIsSwipe(Touch touch, TouchStruct touchStruct) { Vector2 heading = touchStruct.info.position - touchStruct.startPosition; float distance = heading.magnitude; if (distance < SWIPE_DISTANCE_DETECTION) { return; } Vector2 direction = heading / distance; if (OnSwipe != null) { OnSwipe(touchStruct, direction); } }
void EndTouch(Touch touch, TouchStruct touchStruct) { CheckIfIsSwipe(touch, touchStruct); if (!touchStruct.isDown) { return; } if (OnEndTouch != null) { OnEndTouch(touchStruct); } touchStruct.isDown = false; touchStruct.isPending = true; touchStruct.cooler = DOUBLE_TOUCH_COOLER; }
void StartTouch(Touch touch, TouchStruct touchStruct) { touchStruct.startPosition = touch.position; if (touchStruct.isPending) { if (OnDoubleTouch != null) { OnDoubleTouch(touchStruct); } } else { if (OnStartTouch != null) { OnStartTouch(touchStruct); } } touchStruct.isDown = true; }
void StartStage(TouchStruct touch, Vector2 direction) { GameManager.instance.StartGame(); MusicPlayer.instance.Play(); }