// Update is called once per frame void Update() { if (Application.platform == RuntimePlatform.WindowsEditor || Application.platform == RuntimePlatform.OSXEditor) { if (Input.GetAxis("Vertical") > 0) { if (keyUp) { inputMap.FireInputEvents(MultiPlatformInputs.UpArrow); keyUp = false; } } else if (Input.GetAxis("Vertical") < 0) { if (keyUp) { inputMap.FireInputEvents(MultiPlatformInputs.DownArrow); keyUp = false; } } else if (Input.GetAxis("Horizontal") > 0) { if (keyUp) { inputMap.FireInputEvents(MultiPlatformInputs.RightArrow); keyUp = false; } } else if (Input.GetKeyDown("space")) { if (keyUp) { inputMap.FireInputEvents(MultiPlatformInputs.SpaceBar); keyUp = false; } } else if (Input.GetKeyDown(KeyCode.RightShift) || Input.GetKeyDown(KeyCode.LeftShift)) { if (keyUp) { inputMap.FireInputEvents(MultiPlatformInputs.Shift); keyUp = false; } } else if (Input.GetKeyDown(KeyCode.Return)) { if (keyUp) { inputMap.FireInputEvents(MultiPlatformInputs.Return); keyUp = false; } } else { keyUp = true; } } }
/** * Update is called once per frame * Builds list of Swipes */ void Update() { if (Application.platform == RuntimePlatform.Android) { if (UnityEngine.Input.acceleration.x > accelerationThreshold || UnityEngine.Input.acceleration.y > accelerationThreshold || UnityEngine.Input.acceleration.z > accelerationThreshold) { inputMap.FireInputEvents(MultiPlatformInputs.Shake); } if (Input.touchCount > 0) { Touch touch = Input.touches [0]; switch (touch.phase) { //Clears all data when swipe begins case TouchPhase.Began: directionList.Clear(); currentDist = 0; break; //Builds list of directions swiped case TouchPhase.Moved: //Right swiping if (Math.Abs(touch.deltaPosition.x) > Math.Abs(touch.deltaPosition.y) && touch.deltaPosition.x > 0) { if (currentDir != CurrentDir.right) { if (currentDist > minSwipeDist) { directionList.Add(currentDir); } currentDir = CurrentDir.right; currentDist = 0; } currentDist += touch.deltaPosition.x; } //Up swiping if (Math.Abs(touch.deltaPosition.y) > Math.Abs(touch.deltaPosition.x) && touch.deltaPosition.y > 0) { if (currentDir != CurrentDir.up) { if (currentDist > minSwipeDist) { directionList.Add(currentDir); } currentDir = CurrentDir.up; currentDist = 0; } currentDist += touch.deltaPosition.y; } //Left swiping if (Math.Abs(touch.deltaPosition.x) > Math.Abs(touch.deltaPosition.y) && touch.deltaPosition.x < 0) { if (currentDir != CurrentDir.left) { if (currentDist > minSwipeDist) { directionList.Add(currentDir); } currentDir = CurrentDir.left; currentDist = 0; } currentDist += -touch.deltaPosition.x; } //Down swiping if (Math.Abs(touch.deltaPosition.y) > Math.Abs(touch.deltaPosition.x) && touch.deltaPosition.y < 0) { if (currentDir != CurrentDir.down) { if (currentDist > minSwipeDist) { directionList.Add(currentDir); } currentDir = CurrentDir.down; currentDist = 0; } currentDist += -touch.deltaPosition.y; } break; case TouchPhase.Ended: //Adds the last direction swiped to the list if (currentDist > minSwipeDist) { directionList.Add(currentDir); } this.FireSwipeEvents(); break; } } } }