protected override void OnTouch(TouchType type) { var mouseWorldPosition = Camera.main.ScreenToWorldPoint(Input.mousePosition); var localPosition = this._armatureComp.transform.localPosition; var progress = (mouseWorldPosition.x - localPosition.x + 3.0f) / 6.0f; progress = Mathf.Min(Mathf.Max(progress, 0.0f), 1.0f); switch (type) { case TouchType.TOUCH_BEGIN: { this._armatureComp.animation.GotoAndStopByProgress("idle", progress); } break; case TouchType.TOUCH_END: { this._armatureComp.animation.Play(); } break; case TouchType.TOUCH_MOVE: { var animationState = this._armatureComp.animation.GetState("idle"); if (animationState != null) { animationState.currentTime = animationState.totalTime * progress; } } break; } }
protected override void TouchGestureMessage(object sender, TouchType type, float force, ref bool handled) { if (Children == null) { return; } if (type == TouchType.GestureRight) { int newSel = _selIndex - 1; if (newSel < 0) { newSel = Children.Length - 1; } SelectedIndex = newSel; } else if (type == TouchType.GestureLeft) { int newSel = _selIndex + 1; if (newSel > Children.Length - 1) { newSel = 0; } SelectedIndex = newSel; } if (ActiveChild != null) { handled = true; ActiveChild.SendTouchGesture(sender, type, force); } }
/// <summary> /// Fires the TouchGesture event /// </summary> /// <param name="sender">>Object sending the event</param> /// <param name="type">Type of gesture being sent</param> /// <param name="force">Force associated with gesture (0.0 to 1.0)</param> public virtual void OnTouchGesture(object sender, TouchType type, float force) { if (TouchGesture != null) { TouchGesture(sender, type, force); } }
void angleRotateChangeComplete() { touchType = TouchType.none_t; STLevel.CheckForSolution(); STLevel.CalcTreeRects(); STLevel.HandleOverlayedNodes(); }
public void ProcessTouchEvent(TouchType touchType, int x, int y) { switch (touchType) { case TouchType.TouchUp: foreach (var clickRect in this.touchRects.ToArray()) { clickRect.EventToTrigger(touchType, clickRect, x - clickRect.X, y - clickRect.Y, clickRect.Collides(x, y)); //ignore result for mouseup } break; case TouchType.TouchDown: case TouchType.TouchMove: foreach (var clickRect in this.touchRects.ToArray()) { if (!clickRect.Collides(x, y)) { continue; } if (clickRect.EventToTrigger(touchType, clickRect, x - clickRect.X, y - clickRect.Y, true)) { break; } } break; } }
private bool closeBox(TouchType eventtype, TouchRect touchbox, int x, int y, bool collide) { if (eventtype == TouchType.TouchDown) { if (State.ShowingTutorial > 0) { State.ShowingTutorial++; Client.PlaySoundEffect(Assets.Sounds.Click); if (State.ShowingTutorial > 2) { State.ShowingTutorial = 0; } return(false); } if (State.AboutState == AboutState.Opened) { Client.PlaySoundEffect(Assets.Sounds.Click); State.AboutState = AboutState.Closing; AboutCloseAnimation.Restart(); AboutCloseDialogAnimation.Restart(); return(false); } return(true); } return(true); }
private bool startGame(TouchType eventtype, TouchRect touchbox, int x, int y, bool collide) { if (State.ShowingTutorial != 0) { return(true); } switch (eventtype) { case TouchType.TouchDown: if (State.StartClicked) { return(false); } Client.PlaySoundEffect(Assets.Sounds.Click); State.StartClicked = true; IImage logoImage = Assets.Images.Layouts.PenguinLogo; IImage shuffleImage = Assets.Images.Layouts.ShuffleLogo; PenguinLogoAnimation = MotionManager.StartMotion(Positions.PenguinLogoLocation) .Motion(new AnimationMotion(Layout.Width + 1000, Positions.PenguinLogoLocation.Y, 1000, AnimationEasing.SineEaseIn)) .Motion(new WaitMotion(5000)) .OnRender((layer, posX, posY, animationIndex, percentDone) => { mainLayer.DrawImage(logoImage, posX, posY, true); }) .OnComplete(() => { }); ShuffleLogoAnimation = MotionManager.StartMotion(Positions.ShuffleLogoLocation) .Motion(new AnimationMotion(Layout.Width + 1000, Positions.ShuffleLogoLocation.Y, 1400, AnimationEasing.SineEaseIn)) .Motion(new WaitMotion(5000)) .OnRender((layer, posX, posY, animationIndex, percentDone) => { mainLayer.DrawImage(shuffleImage, posX, posY, true); }) .OnComplete(() => { }); return(true); } return(false); }
public void Input(Collision other, TouchType touchType) { if (filter.RequestActivate(other, touchType)) { response.Invoke(other); } }
public bool toggleOpening(TouchType eventtype, TouchRect touchbox, int x, int y, bool collide) { if (State.StartClicked) { return(false); } if (eventtype == TouchType.TouchDown) { if (State.AboutState == AboutState.Opened) { Client.PlaySoundEffect(Assets.Sounds.Click); State.AboutState = AboutState.Closing; AboutCloseAnimation.Restart(); AboutCloseDialogAnimation.Restart(); } else if (State.AboutState == AboutState.Closed) { Client.PlaySoundEffect(Assets.Sounds.Click); State.AboutState = AboutState.Opening; AboutOpenAnimation.Restart(); AboutOpenDialogAnimation.Restart(); } return(true); } return(false); }
void GetMouseInput() { if (Input.GetMouseButton(0)) { if (!isTouching) { isTouching = true; touchStart = new Vector2(Input.mousePosition.x, Input.mousePosition.y); touchEnd = touchStart; } touchEnd = new Vector2(Input.mousePosition.x, Input.mousePosition.y); } else if (isTouching) { isTouching = false; touchEnd = new Vector2(Input.mousePosition.x, Input.mousePosition.y); touchType = TouchType.NULL; if (touchTime < 0.3f) { touchType = TouchType.TAP; } touchTime = 0.0f; } }
public void SwitchTouch(TouchType kind) { if (touchType == kind) { return; } touchType = kind; if (kind == TouchType.Empty) { scrollRect.enabled = true; image.enabled = true; pinchTool.ActiveRaycast(false); } else if (kind == TouchType.Node) { scrollRect.enabled = false; image.enabled = false; pinchTool.ActiveRaycast(false); } else if (kind == TouchType.Pinch) { scrollRect.enabled = false; image.enabled = false; pinchTool.ActiveRaycast(true); } else if (kind == TouchType.Drag) { scrollRect.enabled = true; image.enabled = true; pinchTool.ActiveRaycast(false); } }
// タッチイベントの設定(重複は削除) void RegisterEvent(UnityAction f, TouchType type) { switch (type) { case TouchType.Touch: TouchEvent -= f; TouchEvent += f; break; case TouchType.Click: ClickEvent -= f; ClickEvent += f; break; case TouchType.RollOver: RollOverEvent -= f; RollOverEvent += f; break; case TouchType.RollOut: RollOutEvent -= f; RollOutEvent += f; break; } }
public void RemoveTouchEvent(TouchType touchType, System.Action ev) { switch (touchType) { case TouchType.TouchIn: if (TouchInEvents.Contains(ev)) { TouchInEvents.Remove(ev); } break; case TouchType.TouchUp: if (TouchUpEvents.Contains(ev)) { TouchUpEvents.Remove(ev); } break; case TouchType.Touching: if (TouchingEvents.Contains(ev)) { TouchingEvents.Remove(ev); } break; } }
private void HandleTouch() { if (m_touchCount < 1) { m_touchType = TouchType.None; return; } // 一个touch if (m_touchCount == 1) { if (m_touchInfo[0].deltaPos.sqrMagnitude <= 10) { if (m_touchType == TouchType.None) { m_touchType = TouchType.Click; } } else { m_touchType = TouchType.Drag; } return; } else { m_touchType = TouchType.Zoom; } }
#pragma warning restore 0649 public void RequestActivate(Collision other, TouchType touchType) { if (this.touchType == touchType) { Output.Invoke(other); } }
void InputCollision(Collision other, TouchType touchType) { foreach (var item in collisionEvents) { item.RequestActivate(other, touchType); } }
/// <summary> /// スワイプ /// </summary> /// <param name="fingerId"></param> /// <param name="position"></param> public void SetTouchMove(int fingerId, Vector2 position, float maximumPossiblePressure = 1.0f, float pressure = 1.0f, float radius = 0f, float radiusVariance = 0f, TouchType type = TouchType.Direct, int tapCount = 1) { for (var i = 0; i < m_touchEvents.Count; i++) { if (m_touchEvents[i].touch.fingerId == fingerId) { m_touchEvents[i].touch.maximumPossiblePressure = maximumPossiblePressure; m_touchEvents[i].touch.pressure = pressure; m_touchEvents[i].touch.radius = radius; m_touchEvents[i].touch.radiusVariance = radiusVariance; m_touchEvents[i].touch.deltaPosition = position - m_touchEvents[i].touch.position; m_touchEvents[i].touch.position = position; m_touchEvents[i].touch.deltaTime += Time.deltaTime; m_touchEvents[i].touch.phase = TouchPhase.Moved; return; } } }
static GuiFrameworkCamerasInterface() { CameraTransitionTime = 0.5f; PanKey = KeyboardButtonCode.KC_LCONTROL; DefaultCameraButton = MouseButtonCode.MB_BUTTON1; TouchType = TouchType.None; }
public TileLayer(Size fullSize) { this.fullSize = fullSize; tiles = new MapTile[fullSize.Width * 2 - 1, fullSize.Height]; GridTouched = new TouchType[fullSize.Width * 2 - 1, fullSize.Height]; GridTouchedBy = new MapTile[fullSize.Width * 2 - 1, fullSize.Height]; }
public void Input(Collision other, TouchType touchType) { if (touchFilter.RequestActivate(other, touchType) && tagFilter.Input(other.collider)) { response.Invoke(other); } }
public override void TouchEvent(TouchType touchType, int x, int y) { var matrix = Renderer.GetScaleMatrix(); var screenSize = Renderer.GetScreenSize(); var point = Renderer.GetOffset(); if (y < point.Y) { return; } if (y > screenSize.Y + point.Y) { return; } if (x < point.X) { return; } if (x > screenSize.X + point.X) { return; } x -= point.X; y -= point.Y; x = (int)(x / matrix.Right.Length()); y = (int)(y / matrix.Down.Length()); ScreenManager.TouchEvent(touchType, x, y); }
protected override void InputTrigger(Collider other, TouchType touchType, CollisionType collisionType) { foreach (var item in triggerBindings) { item.Input(other, touchType, collisionType); } }
public TouchTracker(int id) { _id = id; _detectedTouches = new List<TouchPoint>(); _type = TouchType.NotSet; _available = true; }
private bool wholeBoardClick(TouchType eventtype, TouchRect touchbox, int x, int y, bool collide) { switch (eventtype) { case TouchType.TouchMove: if (State.BackDialogVisible) { return(true); } if (State.NSDragMouseDownPosition != null) { int i1 = Positions.NumberSelectionBoxPosition.Y - Positions.NumberSelectionBoxSize.Y / 2; State.CurrentNumber = Math.Max(Math.Min(State.NSDragMouseDownStartingNumber - ((y - i1) - State.NSDragMouseDownPosition.Y) / 50, 60), 1); } break; case TouchType.TouchDown: if (State.BackDialogVisible) { Client.PlaySoundEffect(Assets.Sounds.Click); State.BackDialogVisible = false; return(true); } closeNumberSelect(); break; } return(true); }
private bool numberSelectionDrag(TouchType eventtype, TouchRect touchbox, int x, int y, bool collide) { if (State.BackDialogVisible) { return(true); } if (GameService.ClassicGameState.GameState == GameSelectionState.ChooseNumber) { switch (eventtype) { case TouchType.TouchUp: State.NSDragMouseDownPosition = null; break; case TouchType.TouchDown: Client.PlaySoundEffect(Assets.Sounds.Click); State.SwipeDistance = 0; State.NSDragMouseDownPosition = new Point(x, y); State.NSDragMouseDownStartingNumber = State.CurrentNumber; break; case TouchType.TouchMove: if (State.NSDragMouseDownPosition != null) { State.CurrentNumber = Math.Max(Math.Min(State.NSDragMouseDownStartingNumber - (y - State.NSDragMouseDownPosition.Y) / 50, 60), 1); } break; } return(false); } return(true); }
private bool wholeBoardClick(TouchType eventtype, TouchRect touchbox, int x, int y, bool collide) { switch (eventtype) { case TouchType.TouchUp: if (collide) { if (State.ShowingTutorial > 2) { State.ShowingTutorial = 0; return(false); } } break; case TouchType.TouchDown: if (collide) { if (State.ShowingTutorial == 1 || State.ShowingTutorial == 2) { State.ShowingTutorial++; Client.PlaySoundEffect(Assets.Sounds.Click); return(false); } } break; } return(true); }
public void ProcessTouchEvent(TouchType touchType, int x, int y) { var touchCache = new TouchCache(DateTime.Now.AddMilliseconds(MaxSwipeLengthMS), touchType, x, y, touchRects); touchCache.Process(); touchCaches.Add(touchCache); //ignore result for mouseup }
public TouchEventArgs(long id, TouchType type, Point location, bool isInContact) { Id = id; Type = type; Location = location; IsInContact = isInContact; }
public bool numberOfPlayersClick(TouchType eventType, TouchRect touchBox, int x, int y, bool collide) { if (State.StartClicked) { return(false); } switch (eventType) { case TouchType.TouchDown: if (State.MenuAnimation.Completed) { Client.PlaySoundEffect(Assets.Sounds.Click); var selectedNumberOfPlayers = (int)touchBox.State; if (selectedNumberOfPlayers == 1) { State.SelectedNumberOfPlayers = selectedNumberOfPlayers; } else { if (HasMultiplayer) { State.SelectedNumberOfPlayers = selectedNumberOfPlayers; } else { // Client.ClientSettings.PurchaseProduct(GameService.Products[0]); } } } break; } return(false); }
/// <summary> /// Initializes a new instance of the <see cref="Paint.TouchPoint"/> class. /// </summary> /// <param name='position'>The position on screen that the user touched.</param> /// <param name='touchType'>Touch type (FreeFrag, Tap etc)</param> /// <param name='color'>The color for this point</param> /// <param name='size'>The size of the point</param> public TouchPointSizeColour(Vector2 position, TouchType touchType, Color color, Rectangle size) { this.Position = position; this.TouchType = touchType; this.Color = color; this.Size = size; }
protected override void InputCollision(Collision other, TouchType touchType) { foreach (var item in collisionBindings) { item.Input(other, touchType); } }
private void EventCage() { if (touchType != TouchType.NONE) { return; } for (int i = 0; i < cageList.Count; i++) { var pushDownPbject = cageList[i].GetComponent <PushDownObject>(); if (pushDownPbject.isPushed) { changeCageID = i; touchType = TouchType.TOUCH; pushDownPbject.isPushed = false; var notActiveAnimals_ = Instantiate(notActiveAnimals); notActiveAnimals_.transform.SetParent(GameObject.Find("Canvas").transform); notActiveAnimals_.GetComponent <RectTransform>().localPosition = Vector3.zero; notActiveAnimals_.GetComponent <RectTransform>().localScale = Vector3.one; } if (pushDownPbject.isPressed) { touchType = TouchType.PRESS; } } }
private void ChangeAnimal() { if (touchType != TouchType.TOUCH) { return; } if (!GameObject.Find(notActiveAnimals.name + "(Clone)").GetComponent <NotActiveAnimals>().is_select) { return; } var selectNotActiveAnimalID = GameObject.Find(notActiveAnimals.name + "(Clone)").GetComponent <NotActiveAnimals>().selectID; if (selectNotActiveAnimalID != int.MaxValue) { AnimalSwap(changeCageID, selectNotActiveAnimalID); } Destroy(GameObject.Find(notActiveAnimals.name + "(Clone)")); touchType = TouchType.NONE; int[] idList = new int[9]; for (int i = 0; i < 9; i++) { idList[i] = cageList[i].GetComponent <CageManager>().animalID; } combManager.CheckCombo(idList); }
// Update is called once per frame void Update() { touchType = touchController.ReturnTouchType(); Debug.Log(touchType.ToString()); fingerList = touchController.GetFingerPositions(); Vector3 fingerPosition1 = new Vector3(); Vector3 fingerPosition2 = new Vector3(); Vector3 avgFingerPos = new Vector3(); if(fingerList.Count == 2){ fingerPosition1 = Camera.main.ScreenToWorldPoint(fingerList[0]); fingerPosition2 = Camera.main.ScreenToWorldPoint(fingerList[1]); avgFingerPos.x = (fingerPosition1.x+fingerPosition2.x)/2; avgFingerPos.y = (fingerPosition1.y+fingerPosition2.y)/2; avgFingerPos.z = -1; /*Debug.Log(" 1 X: " + fingerPosition1.x + " 1 Y: " + fingerPosition1.y+ " 1 Z: " + fingerPosition1.z); Debug.Log(" 2 X: " + fingerPosition2.x + " 2 Y: " + fingerPosition2.y + " 2 Z: " + fingerPosition2.z); Debug.Log(" avg X: " + avgFingerPos.x + " avg Y: " + avgFingerPos.y + " avg Z: " + avgFingerPos.z);*/ } if(touchType == TouchType.NONE) { firstTouch = false; if(prevTouchType == TouchType.MULTITOUCH_2){ stop++; } } else if(touchType == TouchType.MULTITOUCH_2 && stop < 1){ if(!firstTouch) { this.transform.position = originalPosition; foreach(Transform child in transform) { originX = avgFingerPos.x; originY = avgFingerPos.y; } firstTouch = true; } float fingerPosX = avgFingerPos.x - originX; float fingerPosY = avgFingerPos.y - originY; if (fingerPosX == 0 && fingerPosY == 0) { return; } DoFoldTransforms(fingerPosX, fingerPosY, originX, originY); } else if(stop == 1){ DoTear(); Instantiate(prefab, originalPosition, originalRotation); stop++; GlobalVariables.zFoldLayer -= 0.2f; } prevTouchType = touchType; }
// Update is called once per frame void Update() { touchType = touchController.ReturnTouchType(); fingerList = touchController.GetFingerPositions(); Vector3 fingerPosition1 = new Vector3(); Vector3 fingerPosition2 = new Vector3(); Vector3 avgFingerPos = new Vector3(); if(fingerList.Count == 2){ fingerPosition1 = Camera.main.ScreenToWorldPoint(fingerList[0]); fingerPosition2 = Camera.main.ScreenToWorldPoint(fingerList[1]); avgFingerPos.x = (fingerPosition1.x+fingerPosition2.x)/2; avgFingerPos.y = (fingerPosition1.y+fingerPosition2.y)/2; avgFingerPos.z = -3; } if(touchType == TouchType.NONE) { firstTouch = false; if(prevTouchType == TouchType.MULTITOUCH_2){ stop++; } } else if(touchType == TouchType.MULTITOUCH_2 && stop < 1){ if(!firstTouch) { this.transform.position = originalPosition; foreach(Transform child in transform) { originX = avgFingerPos.x; originY = avgFingerPos.y; } firstTouch = true; } float mouseX = avgFingerPos.x - originX; float mouseY = avgFingerPos.y - originY; if (mouseX == 0 && mouseY == 0) { return; } this.transform.rotation = originalRotation; float angleInDegrees = Mathf.Rad2Deg * Mathf.Atan2(mouseY, mouseX); this.transform.position = new Vector3(originX + mouseX/2, originY + mouseY/2, GlobalVariables.zCoverLayer); this.transform.Rotate(Vector3.forward, angleInDegrees); } else if(stop == 1){ Instantiate(prefab, new Vector3(originalPosition.x, originalPosition.y, originalPosition.z + 0.1f), originalRotation); stop++; GlobalVariables.zCoverLayer -= 0.2f; } prevTouchType = touchType; }
// Update is called once per frame void Update() { touchType = touchController.ReturnTouchType(); fingerList = touchController.GetFingerPositions(); Vector3 fingerPosition1 = new Vector3(); Vector3 fingerPosition2 = new Vector3(); Vector3 avgFingerPos = new Vector3(); if(fingerList.Count == 2){ fingerPosition1 = Camera.main.ScreenToWorldPoint(fingerList[0]); fingerPosition2 = Camera.main.ScreenToWorldPoint(fingerList[1]); avgFingerPos.x = (fingerPosition1.x+fingerPosition2.x)/2; avgFingerPos.y = (fingerPosition1.y+fingerPosition2.y)/2; avgFingerPos.z = (fingerPosition1.z+fingerPosition2.z)/2; Debug.Log(" 1 X: " + fingerPosition1.x + " 1 Y: " + fingerPosition1.y+ " 1 Z: " + fingerPosition1.z); Debug.Log(" 2 X: " + fingerPosition2.x + " 2 Y: " + fingerPosition2.y + " 2 Z: " + fingerPosition2.z); Debug.Log(" avg X: " + avgFingerPos.x + " avg Y: " + avgFingerPos.y + " avg Z: " + avgFingerPos.z); } if(touchType == TouchType.NONE) { firstTouch = false; } else if(touchType == TouchType.MULTITOUCH_2){ if(!firstTouch) { foreach(Transform child in transform) { originX = avgFingerPos.x; originY = avgFingerPos.y; } firstTouch = true; } float mouseX = avgFingerPos.x - originX; float mouseY = avgFingerPos.y - originY; if (mouseX == 0 && mouseY == 0) { return; } this.transform.rotation = originalRotation; float angleInDegrees = Mathf.Rad2Deg * (2 * Mathf.Atan2(mouseY, mouseX)); this.transform.position = (new Vector3(mouseX + originX, mouseY + originY, 0)); this.transform.Rotate(Vector3.forward, angleInDegrees); this.transform.Translate(new Vector3(-2, 0, 0)); this.transform.Translate (new Vector3(originX, -originY, 0)); } }
public NodeTouchEvent(MotionEvent motion, VelocityTracker velocity) { this.velocity = velocity; velocity.AddMovement (motion); point = new Point (motion.GetX (), motion.GetY ()); if (motion.Action == MotionEventActions.Move) { type = TouchType.Move; } else if (motion.Action == MotionEventActions.Down) { type = TouchType.Down; } else if (motion.Action == MotionEventActions.Up) { type = TouchType.Up; } }
public NodeTouchEvent(NodeUIView parent, UIPanGestureRecognizer pan) { switch (pan.State) { case UIGestureRecognizerState.Began: type = TouchType.Down; break; case UIGestureRecognizerState.Changed: type = TouchType.Move; break; case UIGestureRecognizerState.Ended: type = TouchType.Up; break; case UIGestureRecognizerState.Possible: case UIGestureRecognizerState.Cancelled: case UIGestureRecognizerState.Failed: break; } var p = pan.LocationInView (parent); point = new Point (p.X, p.Y); var velo = pan.VelocityInView (parent); velocity = new Vec2 (velo.X / 1000, velo.Y / 1000); }
/// <summary> /// Initializes a new instance of the <see cref="Paint.TouchPoint"/> class. /// </summary> /// <param name='position'>The position on screen that the user touched.</param> /// <param name='touchType'>Touch type (FreeFrag, Tap etc)</param> public TouchPoint(Vector2 position, TouchType touchType) { this.Position = position; this.TouchType = touchType; }
// Update is called once per frame void Update() { bool inputFound = false; if(Input.GetMouseButton(1) && GameObject.FindGameObjectWithTag("TearManager").GetComponent<TearManager>().PlayerMovingPlatformState && inputFound) { inputFound = false; } else if(Input.GetMouseButton(1) && !GameObject.FindGameObjectWithTag("TearManager").GetComponent<TearManager>().PlayerMovingPlatformState && !inputFound) { inputFound = true; } touchType = touchController.ReturnTouchType(); fingerList = touchController.GetFingerPositions(); Vector3 fingerPosition1 = new Vector3(); Vector3 fingerPosition2 = new Vector3(); Vector3 avgFingerPos = new Vector3(); if(fingerList.Count == 2){ fingerPosition1 = Camera.main.ScreenToWorldPoint(fingerList[0]); fingerPosition2 = Camera.main.ScreenToWorldPoint(fingerList[1]); avgFingerPos.x = (fingerPosition1.x+fingerPosition2.x)/2; avgFingerPos.y = (fingerPosition1.y+fingerPosition2.y)/2; avgFingerPos.z = -3; } else if(inputFound){ avgFingerPos = Camera.main.ScreenToWorldPoint(Input.mousePosition); avgFingerPos.z = -1; currMouseState = true; //Debug.Log ("mouse down: " + avgFingerPos.ToString()); } if(!inputFound){ currMouseState = false; //Debug.Log("mouse up"); } if(touchType == TouchType.NONE && !inputFound) { //firstTouch = false; if((prevTouchType == TouchType.MULTITOUCH_2|| prevMouseState) && firstTouch){ script.ChangeMesh(reference3.GetComponent<MeshFilter>().mesh.vertices, reference3.transform, .15f, .15f); this.transform.position = new Vector3(this.transform.position.x, this.transform.position.y, zLayerTmp + 1); firstTouch = false; isFolded = true; } } else if((touchType == TouchType.MULTITOUCH_2 || inputFound)){ if(!firstTouch) { if(foldReference.onFoldBorder(avgFingerPos) && !isFolded) { this.transform.position = originalPosition; foreach(Transform child in transform) { originX = avgFingerPos.x; originY = avgFingerPos.y; } firstTouch = true; } else if(foldReference.onUnfoldBorder(avgFingerPos) && isFolded) { firstTouch = true; } } if(firstTouch){ float mouseX = avgFingerPos.x - originX; float mouseY = avgFingerPos.y - originY; if (mouseX == 0 && mouseY == 0) { return; } if(!foldCollide.getHitting()) { this.transform.rotation = originalRotation; float angleInDegrees = Mathf.Rad2Deg * Mathf.Atan2(mouseY, mouseX); this.transform.position = new Vector3(originX + mouseX/2, originY + mouseY/2, zLayerTmp); this.transform.Rotate(Vector3.forward, angleInDegrees); } } } /*else if(stop == 1){ //Instantiate(prefab, new Vector3(originalPosition.x, originalPosition.y, originalPosition.z + 0.1f), originalRotation); stop++; //GVariables.zCoverLayer -= 0.1f; }*/ prevTouchType = touchType; prevMouseState = currMouseState; }
void Update() { if (isTouching) touchTime += Time.deltaTime; if (deviceType == DeviceType.Handheld) GetTouchInput(); else if (deviceType == DeviceType.Desktop) GetMouseInput(); if (isTouching) { if ((touchEnd - touchStart).magnitude > 0.2f && touchType == TouchType.NULL) { touchType = TouchType.DRAG; } if (touchType == TouchType.DRAG) { Vector2 delta = touchStart - touchEnd; plane.transform.position += new Vector3(0, -delta.y, 0) / 50; touchStart = touchEnd; } } if (touchType == TouchType.TAP) { int layermask = 1 << 5; //raycast for collision with planet Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hit; if (Physics.Raycast(ray, out hit, 1000, layermask)) { GameObject gameObject = hit.collider.gameObject; MenuLevel script = gameObject.GetComponent<MenuLevel>(); script.Hit(); } touchType = TouchType.NULL; } }
/// <summary> /// Converts a MonoGame.GestureType into our TouchType representation /// </summary> /// <returns> /// The converted TouchType /// </returns> /// <param name='gestureType'> /// The monogame gesture type. /// </param> protected TouchType ConvertGestureType(GestureType gestureType) { /* If the user taps the screen then we get a single Tap * If the user touches the screen and drags then we get several FreeDrag events and a final DragComplete event. * We keep track of the previous GestureType so that we can characterise the first FreeDrag as a StartDrag. This * allows the Canvas control to track where the drag started - I've decided that while a drag continues then all input * should be handled by the control where the drag started, even if the user accidentally moves outside that control. * Makes for a better user experience. */ TouchType returnValue; switch (gestureType) { case GestureType.Tap: returnValue = TouchType.Tap; break; case GestureType.FreeDrag: if (this.previousTouchType != TouchType.FreeDrag && this.previousTouchType != TouchType.StartDrag) { returnValue = TouchType.StartDrag; } else { returnValue = TouchType.FreeDrag; } break; case GestureType.DragComplete: default: returnValue = TouchType.DragComplete; break; } this.previousTouchType = returnValue; return returnValue; }
public TouchMessage(TouchType touchType, Vector2 pos, float time = -1f) { if(time == -1) this.time = MyTime.GlobalTimer.realtimeSinceStartup; else this.time = time; this.touchType = touchType; this.pos = pos; }
void GetTouchInput() { if (Input.touchCount > 0) { if (Input.touches[0].phase == TouchPhase.Began) { isTouching = true; touchStart = Input.touches[0].position; touchEnd = touchStart; } if (Input.touches[0].phase == TouchPhase.Moved) { touchEnd = Input.touches[0].position; } if (Input.touches[0].phase == TouchPhase.Ended) { isTouching = false; touchEnd = Input.touches[0].position; touchType = TouchType.NULL; if (touchTime < 0.3f) { touchType = TouchType.TAP; } touchTime = 0.0f; } } }
// Update is called once per frame void Update() { bool inputFound = false; if(Input.GetMouseButton(1) && GameObject.FindGameObjectWithTag("TearManager").GetComponent<TearManager>().PlayerMovingPlatformState) { inputFound = false; } else if(Input.GetMouseButton(1) && !GameObject.FindGameObjectWithTag("TearManager").GetComponent<TearManager>().PlayerMovingPlatformState) { inputFound = true; } touchType = touchController.ReturnTouchType(); //Debug.Log(touchType.ToString()); fingerList = touchController.GetFingerPositions(); Vector3 fingerPosition1 = new Vector3(); Vector3 fingerPosition2 = new Vector3(); avgFingerPos = new Vector3(); if(fingerList.Count == 2) { fingerPosition1 = Camera.main.ScreenToWorldPoint(fingerList[0]); fingerPosition2 = Camera.main.ScreenToWorldPoint(fingerList[1]); avgFingerPos.x = (fingerPosition1.x+fingerPosition2.x)/2; avgFingerPos.y = (fingerPosition1.y+fingerPosition2.y)/2; avgFingerPos.z = -1; /*Debug.Log(" 1 X: " + fingerPosition1.x + " 1 Y: " + fingerPosition1.y+ " 1 Z: " + fingerPosition1.z); Debug.Log(" 2 X: " + fingerPosition2.x + " 2 Y: " + fingerPosition2.y + " 2 Z: " + fingerPosition2.z); Debug.Log(" avg X: " + avgFingerPos.x + " avg Y: " + avgFingerPos.y + " avg Z: " + avgFingerPos.z);*/ } else if(inputFound){ avgFingerPos = Camera.main.ScreenToWorldPoint(Input.mousePosition); avgFingerPos.z = -1; currMouseState = true; //Debug.Log ("mouse down: " + avgFingerPos.ToString()); } if(!inputFound){ currMouseState = false; //Debug.Log("mouse up"); } if(touchType == TouchType.NONE && !inputFound) { //firstTouch = false; if((prevTouchType == TouchType.MULTITOUCH_2 || prevMousestate) && firstTouch) { Debug.Log("mouse up and prev mouse state"); //stop++; //tearPoints = calcTearPoints(); script.ChangeMesh(backsideReference.GetComponent<MeshFilter>().mesh.vertices, backsideReference.transform, 0.15f, 0.15f); this.transform.position = new Vector3(this.transform.position.x, this.transform.position.y, .8f); foreach(GameObject iterate in backsideCollisionReference) { iterate.transform.Translate (new Vector3(0,0,0.8f)); //iterate.transform.position = new Vector3(this.transform.position.x, this.transform.position.y, 0); } firstTouch = false; isFolded = true; } } else if((touchType == TouchType.MULTITOUCH_2 || inputFound)/*&& stop < 1*/) { //if(!firstTouch && ((onFoldBorder(avgFingerPos) && !isFolded)|| (onUnfoldBorder(avgFingerPos) && isFolded))) if(!firstTouch) { if(onFoldBorder(avgFingerPos) && !isFolded) { this.transform.position = originalPosition; foreach(Transform child in transform) { originX = avgFingerPos.x; originY = avgFingerPos.y; } firstTouch = true; } else if(onUnfoldBorder(avgFingerPos) && isFolded) { firstTouch = true; script.RevertChanges(); } } if(firstTouch) { fingerPosX = avgFingerPos.x - originX; fingerPosY = avgFingerPos.y - originY; if (fingerPosX == 0 && fingerPosY == 0) { return; } DoFoldTransforms(fingerPosX, fingerPosY, originX, originY); } //script.ChangeMesh(backsideReference.GetComponent<MeshFilter>().mesh.vertices, backsideReference.transform); } /*else if(stop == 1) { //Instantiate(prefab, originalPosition, originalRotation); stop++; //Debug.Log("Does this happen?"); //GVariables.zFoldLayer -= 0.1f; }*/ prevTouchType = touchType; prevMousestate = currMouseState; }
/// <summary> /// Returns the type of the touch. /// How to use: /// Call in an update function that is used every frame to get /// data for the touch input. /// /// Reurn types: /// TAP: Happens when the player touches the screen and holds finger in same place /// Every touch starts as a tap but can be changed to something else. /// SWIPE: if player moves finger on the screen for less than .2 seconds /// DRAG: if player moves finger on the screen for more than or equal to .2 seconds /// NONE: if the player has not touched or has just ended a touch /// MULTITOUCH #: the number after the MULTITOUCH represents how many fingers have been put down /// MULTITOUCH OTHER: if the number of fingers is not 2-5 /// /// </summary> /// <returns> /// The touch type. /// </returns> public TouchType ReturnTouchType() { touchCount = 0; //resets the touchCount back to zero so it will be accurate. if (fingerPositions == null) fingerPositions = new List<Vector2>(); if (fingerPositions.Count > 0) fingerPositions.Clear(); //Clears the List of finger positions. //Begin loop for checking touches //touchType = TouchType.NONE; foreach(Touch touch in Input.touches) { //touchType = TouchType.NONE; fingerPositions.Add(touch.position); switch(touch.phase) { case TouchPhase.Began: startTime = Time.time; //isMultiTouch = false; if(Input.touchCount > 1) { //isMultiTouch = true; // switch statement for checking how many fingers on screen for multitouch switch(Input.touchCount) { case 2: touchType = TouchType.MULTITOUCH_2; break; case 3: touchType = TouchType.MULTITOUCH_3; break; case 4: touchType = TouchType.MULTITOUCH_4; break; case 5: touchType = TouchType.MULTITOUCH_5; break; default: touchType = TouchType.MULTITOUCH_OTHER; break; } } // if it's not a multitouch it becomes a tap else if (Input.touchCount == 1) { touchType = TouchType.TAP; } else { touchType = TouchType.NONE; } //Debug.Log("touch count begin: " + Input.touchCount); break; //if finger moved, check how long the finger has been on the screen to determine if it is a drag or swipe case TouchPhase.Moved: currentTime = Time.time - startTime; //Debug.Log(Input.touchCount); //dist = Mathf.Sqrt(Mathf.Pow((touch.position.x - prevTouch.x),2f)+Mathf.Pow((touch.position.y - prevTouch.y),2f)); Vector2 delta = touch.position - touch.deltaPosition; displacement = delta.magnitude - touch.position.magnitude; dist = Mathf.Abs(delta.magnitude - touch.position.magnitude); if(Input.touchCount == 1) { //Debug.Log ("dist: " + dist + " delta: " + delta.ToString() + " prevtouch: " + prevTouch.ToString()); if(dist >= SWIPE_DIST ){ touchType = TouchType.SWIPE; } else if( dist < SWIPE_DIST){ touchType = TouchType.DRAG; } } else if(Input.touchCount == 2) { touchType = TouchType.MULTITOUCH_2; } //Debug.Log("touch count moved: " + Input.touchCount); break; // if finger moved and becomes stationary it becomes a drag instead case TouchPhase.Stationary: if (touchType == TouchType.SWIPE) { touchType = TouchType.DRAG; } //Debug.Log("touch count stationary: " + Input.touchCount); break; // when finger is lifted from screen it becomes NONE again case TouchPhase.Ended: if(Input.touchCount == 1){ //isMultiTouch = false; touchType = TouchType.DRAG; //Debug.Log("1"); } else if(Input.touchCount > 1){ //isMultiTouch = true; switch(Input.touchCount) { case 2: touchType = TouchType.MULTITOUCH_2; break; case 3: touchType = TouchType.MULTITOUCH_3; break; case 4: touchType = TouchType.MULTITOUCH_4; break; case 5: touchType = TouchType.MULTITOUCH_5; break; default: touchType = TouchType.MULTITOUCH_OTHER; break; } //Debug.Log("2"); } else{ //Debug.Log("ended: " + Input.touchCount); touchType = TouchType.NONE; //Debug.Log("none"); } //Debug.Log("touch count ended: " + Input.touchCount); break; // if program force quits or is facepalm then it becomes NONE case TouchPhase.Canceled: touchType = TouchType.NONE; break; } touchCount++; //Debug.Log(touchType.ToString()); // debug line for testing purposes } if(Input.touchCount == 0){ touchType = TouchType.NONE; } //Debug.Log(touchType.ToString()); //Debug.Log(Input.touchCount); if(touchType != TouchType.NONE){ prevTouch = fingerPositions[0]; } return touchType; }
// Update is called once per frame void Update() { // Added by Dom // Ensures my own boolean for currently folding // is set false accordinly if (currentlyFolding && ((!Input.GetMouseButton(1) && !gameStateManagerRef.OnMobileDevice()) || ((gameStateManagerRef.GetInputManager().GetcurrPressState().Equals(InputManager.PressState.UP) || gameStateManagerRef.GetInputManager().GetcurrPressState().Equals(InputManager.PressState.JUST_RELEASED)) && gameStateManagerRef.OnMobileDevice()))) { currentlyFolding = false; } if(Input.GetKey(KeyCode.P) || (gameStateManagerRef.OnMobileDevice())){ guiEnable = true; } else{ guiEnable = false; } // if (GVariables.TearPieceCoveringFold) // { // backsideReference.GetComponent<MeshRenderer>().material.color = Color.gray; // } // else // { // backsideReference.GetComponent<MeshRenderer>().material.color = backSideInitialColor; // } //foldInput = false; if (tearReference.HaveTornOnce && !backsideIsInstantiated) { GameObject[] tempBackgroundObjs; tornPieceReference = GameObject.Find("paper_CuttPieceOfPaper"); tempBackgroundObjs = GameObject.FindGameObjectsWithTag("background"); foreach(GameObject temp in tempBackgroundObjs){ if(temp.name == "paper_LargerPiece"){ // missingTriangles = changeMeshScript.DeletePlatformsFromMissingTriangles(backsideTriangles, // temp.GetComponent<MeshFilter>().mesh.triangles, backsideReference.transform, "FoldPlatform"); tornBackground = temp; tearPaperMesh = temp.GetComponent<MeshFilter>().mesh; // changeMeshScript.GrabPlatformsInWorld("FoldPlatform"); // changeMeshScript.GrabPlatformsInWorld("Platform"); } else if( temp.name == "paper_CuttPieceOfPaper") { deletedTri = temp.GetComponent<MeshFilter>().mesh.triangles; } } //changeMeshScript.DeletePlatformsFromMissingTriangles(deletedTri, // backsideReference.transform ,"FoldPlatform"); //changeMeshScript.UpdateAfterTear("FoldPlatform"); //changeMeshScript.UpdateAfterTear("Platform"); backsideIsInstantiated = true; backsideReference.GetComponent<MeshFilter>().mesh = tearPaperMesh; backsideReference.GetComponent<MeshCollider>().sharedMesh = tearPaperMesh; shadowReference.GetComponent<MeshCollider>().sharedMesh = tearPaperMesh; rayTraceBlockRef.GetComponent<MeshCollider>().sharedMesh = tearPaperMesh; shadowReference.GetComponent<MeshFilter>().mesh = tearPaperMesh; rayTraceBlockRef.GetComponent<MeshFilter>().mesh = tearPaperMesh; paperBorderInsideRef.GetComponent<MeshCollider>().sharedMesh = tearPaperMesh; paperBorderInsideRef.GetComponent<MeshFilter>().mesh = tearPaperMesh; paperBorderOutsideRef.GetComponent<MeshCollider>().sharedMesh = tearPaperMesh; paperBorderOutsideRef.GetComponent<MeshFilter>().mesh = tearPaperMesh; backsideTriangles = tearPaperMesh.triangles; tornBacksidePieceReference.GetComponent<MeshFilter>().mesh = tornPieceReference.GetComponent<MeshFilter>().mesh; // tornBacksidePieceReference.GetComponent<MeshCollider>().sharedMesh = // tornPieceReference.GetComponent<MeshFilter>().mesh; tearInitialColor = new Color(0.8f, 0.8f, 0.8f, 1.0f); firstFoldAfterTear = true; foldEdge = Edge.BuildManifoldEdges(tearPaperMesh); // changeMeshScript.PrintColliderEnabled(); // changeMeshScript.ReapplyChanges(); // changeMeshScript.PrintColliderEnabled(); } //Try to set logic accordingly when on a tearing level try { if(((Input.GetMouseButton(1) || (gameStateManagerRef.GetInputManager().GetFingerGesture().Equals(InputManager.FingerGesture.FOLD) && touchController.ReturnTouchType() != TouchType.NONE)) && !tearReference.GetComponent<TearManager>().PlayerMovingPlatformState) && ( prevFoldInput || (!playerReference.GetComponent<TWCharacterController>().qDown && !playerReference.GetComponent<TWCharacterController>().eDown && !playerReference.GetComponent<TWCharacterController>().getFalling() ))) { foldInput = true; } else { foldInput = false; } } catch { //This logic will be hit on NON - Tearing levels if(Input.GetMouseButton(1)) { foldInput = true; } } //gets the current touch type from the touch controller touchType = touchController.ReturnTouchType(); //gets the current finger positions from the touch controller fingerList = touchController.GetFingerPositions(); //initializes three new vectors, one for each of the two fingers needed for folding, //and one for the average finger position. Vector3 fingerPosition1 = new Vector3(); Vector3 fingerPosition2 = new Vector3(); avgFingerPos = new Vector3(); //if there are 2 fingers on the screen, //set the finger positions to the corresponding world positions, //then finds the average of the two positions. /*if(fingerList.Count == 2) { fingerPosition1 = Camera.main.ScreenToWorldPoint(fingerList[0]); fingerPosition2 = Camera.main.ScreenToWorldPoint(fingerList[1]); avgFingerPos.x = (fingerPosition1.x+fingerPosition2.x)/2; avgFingerPos.y = (fingerPosition1.y+fingerPosition2.y)/2; avgFingerPos.z = -1; lastFingerPosition = avgFingerPos; }*/ //or if the right mouse button is down, //sets the average finger position to the world coordinates of the mouse position, //also sets currMouse state to true, so we know if the mouse is pressed down. if(foldInput){ avgFingerPos = Camera.main.ScreenToWorldPoint(Input.mousePosition); avgFingerPos.z = -1; currMouseState = true; lastFingerPosition = avgFingerPos; } //if the right mouse button is not pressed, set currMouseState to false, //so we know we arn't using the mouse. if(!foldInput){ currMouseState = false; } //if we are not touching the screen, and not clicking the right mouse button... if(touchType == TouchType.NONE && !foldInput) { //if the last state was a 2 finger touch, or the right mouse button was pressed, and had just been folding, if((prevFoldInput || prevMousestate) && firstTouch) { //set firstTouch back to false so we know we are done folding, and can now unfold or refold firstTouch = false; currentQuadrant = Quadrant.NONE; //if the fold is over the player, unfold. if(unfoldCollisionReference.getOverPlayer()) { blah = true; needsToUnfold = true; foldSmoothPosition = new Vector3(lastFingerPosition.x -origin.x + posModifier.x, lastFingerPosition.y - origin.y + posModifier.y, foldTmpZLayer); startDampTime = Time.time; coverupSmoothPosition = lastFingerPosition - origin + posModifier; coverupSmoothPosition.z = coverupTmpZLayer; } //if the fold is not over the player... else{ setDownFold(); } } } //if there are two fingers on the screen or right mouse button is pressed... else if(foldInput && !needsToUnfold) { //if this is the first touch to start a fold.. if(!firstTouch) { HandleScreenChanges(); if(!unfoldCollisionReference.getOverPlayer() && !GVariables.TearPieceCoveringFold) { //if the paper is not already folded and the user's fingers are on the fold border... if(onFoldBorder(avgFingerPos) && !isFolded) { //set the position to its original position, so the transforms work properly backsidePivotReference.transform.position = foldOriginalPosition; foreach(Transform child in transform) { origin = avgFingerPos; origin.z = 0; } //sets first touch to true so we know we are now folding. firstTouch = true; //brings back and removed triangles in platforms. changeMeshScript.RevertChanges(); //set the unfold position using where the fold started, so we know where to unfold to if the fold is invalid. foldUnfoldPosition = findUnfoldPosition(avgFingerPos, unfoldReference) - origin; //set the coverup unfold position using where the fold started, so we know where to unfold to if the fold is invalid. coverupUnfoldPosition = findUnfoldPosition(avgFingerPos, unfoldReference); coverupUnfoldPosition = new Vector3(coverupUnfoldPosition.x - origin.x, coverupUnfoldPosition.y - origin.y, coverupTmpZLayer); posModifier = Vector3.zero; firstTouchPosition = avgFingerPos; justUnfolded = false; startingQuadrant = ReturnSidePressed(avgFingerPos); currentQuadrant = startingQuadrant; } //else if the paper is folded, and the user's fingers are on the edge of the fold... else if(onUnfoldBorder(avgFingerPos) && isFolded) { isUnfoldingOnPaper = true; //sets first touch to true so we know we are folding. firstTouch = true; //brings back and removed triangles in platforms. changeMeshScript.RevertChanges(); //sets the unfold position to the last valid position (the last fold position) so it will unfold to the proper position if the fold is invalid foldUnfoldPosition = foldLastValidPos; //sets the unfold position to the last valid position (the last fold position) so it will unfold to the proper position if the fold is invalid coverupUnfoldPosition = coverupLastValidPos; posModifier = findPositionOffset(); justUnfolded = false; } //gets the position of the user's fingers when they first start the fold. } } //if the first touch of the fold already happened and we are folding... if(firstTouch && (!gameStateManagerRef.OnMobileDevice() || gameStateManagerRef.GetInputManager().GetFingerGesture().Equals(InputManager.FingerGesture.FOLD))) { //sets the finger position as the average finger position offset by the origin, //so we can get a position relative to the origin of the fold. currentQuadrant = ReturnSidePressed(avgFingerPos); fingerPos = avgFingerPos - origin+ posModifier - unfoldPosModifier; //if the finger positions are 0, return becuase it can mess up calculations if (fingerPos.x == 0 && fingerPos.y == 0) { return; } //if the user's fingers are on the paper background, do the transforms normally, //and set the isOffPaper bool to false so we know it is on the paper //float distance = Mathf.Sqrt(Mathf.Pow((firstTouchPosition.x - avgFingerPos.x),2f)+Mathf.Pow((firstTouchPosition.y-avgFingerPos.y),2f)); if(!offPaper(avgFingerPos) || currentQuadrant != startingQuadrant){ currentlyFolding = true; DoFoldTransforms(); DoCoverupTransforms(); isOffPaper = false; //if (!soundManagerRef.IsAudioPlaying("paperFold1", "SFX")) //{ // soundManagerRef.PlayAudio("paperFold1", "SFX"); //} //else soundManagerRef.StopSound("paperFold1", "SFX"); } //else if te user's fingers are off the paper, set the position and rotation back to defaults, //to give the illusion of completely unfolding. Also sets the isOffPaper bool to true, //so we know they are off the paper. else{ currentlyFolding = false; isUnfoldingOnPaper = false; backsidePivotReference.transform.position = foldOriginalPosition; backsidePivotReference.transform.rotation = foldOriginalRotation; coverupPivotReference.transform.position = coverupStartingPosition; coverupPivotReference.transform.rotation = coverupOriginalRotation; isOffPaper = true; isFolded = false; firstTouch = false; //prevTouchType = TouchType.NONE; prevMousestate = false; currentQuadrant = Quadrant.NONE; prevFoldInput = false; } } } // Debug.Log("FoldSmooth: " + foldSmoothPosition); // Debug.Log("FoldUnfold: " + foldUnfoldPosition); //If we need to unfold the paper... if(needsToUnfold) { //use smooth damp to get a smooth unfold for fold. foldSmoothPosition = Vector3.SmoothDamp(foldSmoothPosition, foldUnfoldPosition, ref velocity, .3f); //Do the transforms on the smooth position, which is the DoFoldTransforms function without the rotations backsidePivotReference.transform.position = (new Vector3(foldSmoothPosition.x + origin.x, foldSmoothPosition.y+ origin.y, 0)); //use smooth damp to get a smooth unfold for coverup. coverupSmoothPosition = Vector3.SmoothDamp(coverupSmoothPosition, coverupUnfoldPosition, ref velocity, .3f); //Do the transforms on the smooth position for coverup coverupPivotReference.transform.position = coverupOriginalPosition; coverupPivotReference.transform.position = new Vector3(origin.x + (coverupSmoothPosition.x)/2, origin.y + (coverupSmoothPosition.y)/2, coverupTmpZLayer); // if (isUnfoldingOnPaper) // { // backsidePivotReference.transform.rotation = foldOriginalRotation; // float angleInDegrees = Mathf.Rad2Deg * (2 * Mathf.Atan2(foldSmoothPosition.y, foldSmoothPosition.x)); // backsidePivotReference.transform.Rotate(Vector3.forward, angleInDegrees); // // coverupPivotReference.transform.rotation = coverupOriginalRotation; // angleInDegrees = Mathf.Rad2Deg * Mathf.Atan2(coverupSmoothPosition.y, coverupSmoothPosition.x); // coverupPivotReference.transform.Rotate(Vector3.forward, angleInDegrees); // } backsidePivotReference.transform.Translate(new Vector3(0, 0, 0)); backsidePivotReference.transform.Translate (new Vector3(origin.x, -origin.y, foldTmpZLayer)); // do the transformations on the smooth rotation for backside and coverup backsidePivotReference.transform.rotation = foldOriginalRotation; float angleInDegrees2 = Mathf.Rad2Deg * (2 * Mathf.Atan2(foldSmoothPosition.y, foldSmoothPosition.x)); backsidePivotReference.transform.Rotate(Vector3.forward, angleInDegrees2); coverupPivotReference.transform.rotation = coverupOriginalRotation; angleInDegrees2 = Mathf.Rad2Deg * Mathf.Atan2(coverupSmoothPosition.y, coverupSmoothPosition.x); coverupPivotReference.transform.Rotate(Vector3.forward, angleInDegrees2); //if the smooth position is off the paper, set needsToUnfold to false so we know we no longer need to unfold, //and set the position and rotation back to dafault positions. since it is off the paper, set isFolded to false. //if(foldSmoothPosition.x <= -6 -origin.x ||foldSmoothPosition.x >= 6 -origin.x || foldSmoothPosition.y <=-4 -origin.y|| foldSmoothPosition.y >=4-origin.y){ //float dist = Mathf.Sqrt(Mathf.Pow((foldUnfoldPosition.x - foldSmoothPosition.x),2f)+Mathf.Pow((foldUnfoldPosition.y-foldSmoothPosition.y),2f)); if(offPaper(foldSmoothPosition + origin) && currentQuadrant == startingQuadrant){ needsToUnfold = false; backsidePivotReference.transform.position = foldOriginalPosition; backsidePivotReference.transform.rotation = foldOriginalRotation; coverupPivotReference.transform.position = coverupStartingPosition; coverupPivotReference.transform.rotation = coverupOriginalRotation; isFolded = false; isUnfoldingOnPaper = false; justUnfolded = true; } //if the smooth damp doesn't bring it off the paper (bringing back to a folded position), have the smooth damp end when the time //runs out. Check if the fold is on the paper or not so we know if it is folded. else if(Time.time - startDampTime > 0.8F){ isUnfoldingOnPaper = false; needsToUnfold = false; justUnfolded = true; Vector3 tempVec = foldSmoothPosition + origin; //Debug.Log("When is this called?"); if(!offPaper(tempVec)){ isOffPaper = false; lastFingerPosition = tempVec; setDownFold(); } else{ //Debug.Log("This one too?"); // failsafe for if/when the fold never completely makes it back off the paper backsidePivotReference.transform.position = foldOriginalPosition; backsidePivotReference.transform.rotation = foldOriginalRotation; coverupPivotReference.transform.position = coverupStartingPosition; coverupPivotReference.transform.rotation = coverupOriginalRotation; isOffPaper = true; isFolded = false; } } } //sets the previous touch and mouse states to the current ones. // // PLEASE DO NOT TOUCH TORN PIECE MATERIAL HERE -> J.C. // //prevTouchType = touchType; prevMousestate = currMouseState; prevFoldInput = foldInput; if(unfoldCollisionReference.getOverPlayer()){ backsideReference.GetComponent<MeshRenderer>().material.color = Color.gray; } else if(tearReference.HaveTornOnce){ if(GVariables.TearPieceCoveringFold){ //tornPieceReference.GetComponent<MeshRenderer>().material.color = tearInitialColor; backsideReference.GetComponent<MeshRenderer>().material.color = Color.gray; } else if(GVariables.FoldPieceCoveringTear){ backsideReference.GetComponent<MeshRenderer>().material.color = backSideInitialColor; //tornPieceReference.GetComponent<MeshRenderer>().material.color = Color.gray; } else{ //tornPieceReference.GetComponent<MeshRenderer>().material.color = tearInitialColor; backsideReference.GetComponent<MeshRenderer>().material.color = backSideInitialColor; } } else{ backsideReference.GetComponent<MeshRenderer>().material.color = backSideInitialColor; } }
// Update is called once per frame void Update() { bool inputFound = false; if(Input.GetMouseButton(1) && GameObject.FindGameObjectWithTag("TearManager").GetComponent<TearManager>().PlayerMovingPlatformState) { inputFound = false; } else if(Input.GetMouseButton(1) && !GameObject.FindGameObjectWithTag("TearManager").GetComponent<TearManager>().PlayerMovingPlatformState) { inputFound = true; } touchType = touchController.ReturnTouchType(); //Debug.Log(touchType.ToString()); fingerList = touchController.GetFingerPositions(); Vector3 fingerPosition1 = new Vector3(); Vector3 fingerPosition2 = new Vector3(); avgFingerPos = new Vector3(); if(fingerList.Count == 2) { fingerPosition1 = Camera.main.ScreenToWorldPoint(fingerList[0]); fingerPosition2 = Camera.main.ScreenToWorldPoint(fingerList[1]); avgFingerPos.x = (fingerPosition1.x+fingerPosition2.x)/2; avgFingerPos.y = (fingerPosition1.y+fingerPosition2.y)/2; avgFingerPos.z = -1; /*Debug.Log(" 1 X: " + fingerPosition1.x + " 1 Y: " + fingerPosition1.y+ " 1 Z: " + fingerPosition1.z); Debug.Log(" 2 X: " + fingerPosition2.x + " 2 Y: " + fingerPosition2.y + " 2 Z: " + fingerPosition2.z); Debug.Log(" avg X: " + avgFingerPos.x + " avg Y: " + avgFingerPos.y + " avg Z: " + avgFingerPos.z);*/ } else if(inputFound){ avgFingerPos = Camera.main.ScreenToWorldPoint(Input.mousePosition); avgFingerPos.z = -1; currMouseState = true; //Debug.Log ("mouse down: " + avgFingerPos.ToString()); } if(!inputFound){ currMouseState = false; //Debug.Log("mouse up"); } if(touchType == TouchType.NONE && !inputFound) { //firstTouch = false; if((prevTouchType == TouchType.MULTITOUCH_2 || prevMousestate) && firstTouch) { Debug.Log("mouse up and prev mouse state"); this.transform.position = new Vector3(this.transform.position.x, this.transform.position.y, zLayerTmp + 1); //GameObject.Find("Collision").collider.enabled = false; //Destroy(gameObject); collisionReference.collider.enabled = false; firstTouch = false; isFolded = true; } } else if(touchType == TouchType.MULTITOUCH_2 || inputFound) { if(!firstTouch) { if(foldReference.onFoldBorder(avgFingerPos) && !isFolded) { this.transform.position = originalPosition; foreach(Transform child in transform) { originX = avgFingerPos.x; originY = avgFingerPos.y; } firstTouch = true; } else if(foldReference.onUnfoldBorder(avgFingerPos) && isFolded) { firstTouch = true; collisionReference.collider.enabled = true; } } if(firstTouch){ fingerPosX = avgFingerPos.x - originX; fingerPosY = avgFingerPos.y - originY; if (fingerPosX == 0 && fingerPosY == 0) { return; } DoFoldTransforms(fingerPosX, fingerPosY, originX, originY); } } // else if(stop == 1) // { // Instantiate(prefab, originalPosition, originalRotation); // stop++; // Debug.Log("you are stupid"); // GVariables.zFoldLayer -= 0.1f; // // // } prevTouchType = touchType; prevMousestate = currMouseState; }
public TouchInfo() { Type = TouchType.BEGIN; FingerId = 0; Position = new Vector2(); BeginDeltaPosition = new Vector2(); PrevDeltaPosition = new Vector2(); }
private void CalcDir(Point e) { TouchType sw = TouchType.NoGesture; int d; d = (e.Y - _ptDownAt.Y); if (d > 50) sw = TouchType.GestureDown; else if (d < -50) sw = TouchType.GestureUp; d = (e.X - _ptDownAt.X); if (d > 50) { if (sw == TouchType.GestureUp) sw = TouchType.GestureUpRight; else if (sw == TouchType.GestureDown) sw = TouchType.GestureDownRight; else sw = TouchType.GestureRight; } else if (d < -50) { if (sw == TouchType.GestureUp) sw = TouchType.GestureUpLeft; else if (sw == TouchType.GestureDown) sw = TouchType.GestureDownLeft; else sw = TouchType.GestureLeft; } if (_tt == TouchType.NoGesture) _tt = sw; else if (_tt != sw) _cancelSwipe = true; }
void SetTouchType() { touchType = TouchType.None; // Track a single touch as a direction control. if (Input.touchCount > 0) { var touch = Input.GetTouch (0); // Handle finger movements based on touch phase. switch (touch.phase) { // Record initial touch position. case TouchPhase.Began: this.startPos = touch.position; this.direction = Vector3.zero; directionChosen = false; break; // Determine direction by comparing the current touch // position with the initial one. case TouchPhase.Moved: this.direction = touch.position - this.startPos; break; // Report that a direction has been chosen when the finger is lifted. case TouchPhase.Ended: directionChosen = true; break; } } if (directionChosen) { directionChosen = false; if (direction.magnitude > this.minMovement) { if (Mathf.Abs (direction.x) > Mathf.Abs (direction.y)) { if (direction.x > 0) { touchType = TouchType.SweepRight; } else { touchType = TouchType.SweepLeft; } } } else { touchType = TouchType.Click; } } }
/// <summary> /// Returns the type of the touch. /// How to use: /// Call in an update function that is used every frame to get /// data for the touch input. /// /// Reurn types: /// TAP: Happens when the player touches the screen and holds finger in same place /// Every touch starts as a tap but can be changed to something else. /// SWIPE: if player moves finger on the screen for less than .2 seconds /// DRAG: if player moves finger on the screen for more than or equal to .2 seconds /// NONE: if the player has not touched or has just ended a touch /// MULTITOUCH #: the number after the MULTITOUCH represents how many fingers have been put down /// MULTITOUCH OTHER: if the number of fingers is not 2-5 /// /// </summary> /// <returns> /// The touch type. /// </returns> public TouchType ReturnTouchType() { touchCount = 0; //resets the touchCount back to zero so it will be accurate. if (fingerPositions == null) fingerPositions = new List<Vector2>(); if (fingerPositions.Count > 0) fingerPositions.Clear(); //Clears the List of finger positions. //Begin loop for checking touches //touchType = TouchType.NONE; foreach(Touch touch in Input.touches) { //touchType = TouchType.NONE; fingerPositions.Add(touch.position); switch(touch.phase) { case TouchPhase.Began: startTime = Time.time; isMultiTouch = false; if(Input.touchCount > 1) { isMultiTouch = true; // switch statement for checking how many fingers on screen for multitouch switch(Input.touchCount) { case 2: touchType = TouchType.MULTITOUCH_2; break; case 3: touchType = TouchType.MULTITOUCH_3; break; case 4: touchType = TouchType.MULTITOUCH_4; break; case 5: touchType = TouchType.MULTITOUCH_5; break; default: touchType = TouchType.MULTITOUCH_OTHER; break; } } // if it's not a multitouch it becomes a tap else if (Input.touchCount == 1) { touchType = TouchType.TAP; } else { touchType = TouchType.NONE; } break; //if finger moved, check how long the finger has been on the screen to determine if it is a drag or swipe case TouchPhase.Moved: currentTime = Time.time - startTime; if(currentTime > .2 && !isMultiTouch) { touchType = TouchType.DRAG; } else if(!isMultiTouch) { touchType = TouchType.SWIPE; } break; // if finger moved and becomes stationary it becomes a drag instead case TouchPhase.Stationary: if (touchType == TouchType.SWIPE) { touchType = TouchType.DRAG; } break; // when finger is lifted from screen it becomes NONE again case TouchPhase.Ended: touchType = TouchType.NONE; break; // if program force quits or is facepalm then it becomes NONE case TouchPhase.Canceled: touchType = TouchType.NONE; break; } touchCount++; //Debug.Log(touchType.ToString()); // debug line for testing purposes } //Debug.Log(touchType.ToString()); return touchType; }
private void display_CP7_ScreenPressed(Display_CP7 sender, Display_CP7.TouchStatus touchStatus) { ptLast = new Point(touchStatus.touchPos[0].xPos, touchStatus.touchPos[0].yPos); if (ptLast.X < 800) { if (!_tDown) { _tDown = true; _tt = TouchType.NoGesture; _cancelSwipe = false; _ptDownAt = ptLast; _lgDownAt = DateTime.Now.Ticks; TinkrCore.Instance.RaiseTouchEvent(TouchType.TouchDown, ptLast); } else { if (!_cancelSwipe) CalcDir(ptLast); TinkrCore.Instance.RaiseTouchEvent(TouchType.TouchMove, ptLast); } } }