private void GetClickedItem(Point p) { p.Y += Convert.ToInt32(_scrollAmount); for (int i = 0; i < _items.Count; i++) { if (new Rectangle(_areaCurrent.X, _areaCurrent.Y + i * _spacing, _areaCurrent.Width, _spacing).Contains(p)) { _hilightedItem = (short)i; if (MouseTouch.LButtonClick) { _selectedItem = (short)i; MouseTouch.Reset(); if (OnItemSelected != null) //if a function is attached { OnItemSelected(_items[_selectedItem], i); //run the function } if (OnItemClick != null) { OnItemClick(_items[_selectedItem].Contents[0].Text, i); } _lastItemSelected = i; return; } for (int c = 0; c < _items[_hilightedItem].Contents.Count; c++) { HilightedItem.Add(_items[_hilightedItem].Contents[c].Text); } break; } } _isScrolable = false; }
public Action IdleUpdate = () => { }; //Event when there is no input //#if UNITY_EDITOR // public void UpdateMethod() { // noInput = true; // bool mouseUp = Input.GetMouseButtonUp(0); // // if(handleInput == true && (Input.GetMouseButton(0) || mouseUp)) { // // //If the mouse was just clicked assign current values to the variables // if (Input.GetMouseButtonDown(0)) { // previousMouse = Input.mousePosition; // previousTime = Time.time; // } // // MouseTouch t = MouseTouch.TransformMouse(Input.mousePosition, previousMouse, previousTime, mouseUp); // // previousTime = Time.time; //Set the values ready for next frame // previousMouse = Input.mousePosition; //Set the value ready for next frame // // noInput = false; // // //Decide which event to trigger // switch (t.phase) { // case TouchPhase.Began: // TouchStart(t); // break; // case TouchPhase.Moved: // InputUpdate(t); // break; // case TouchPhase.Ended: // TouchEnd(t); // break; // } // } // if (noInput == true) // IdleUpdate(); // } //#elif UNITY_ANDROID || UNITY_IPHONE public void UpdateMethod() { noInput = true; if (handleInput == true) { foreach (Touch touch in Input.touches) { noInput = false; MouseTouch t = MouseTouch.TransformTouch(touch); //Transform the unity touch to mouse touch //Decide which event to trigger switch (t.phase) { case TouchPhase.Began: TouchStart(t); break; case TouchPhase.Moved: InputUpdate(t); break; case TouchPhase.Ended: TouchEnd(t); break; } } } if (noInput == true) { IdleUpdate(); } }
public static MouseTouch fromInput(MouseState mouseState, ref Vector2?lastMousePosition) { MouseTouch result = default(MouseTouch); result.fingerId = 2; if (lastMousePosition != null) { result.deltaPosition = Input.mousePosition - ((lastMousePosition == null) ? default(Vector3) : lastMousePosition.GetValueOrDefault()); } if (mouseState == MouseState.DownThisFrame) { result.phase = TouchPhase.Began; lastMousePosition = new Vector2?(Input.mousePosition); } else if (mouseState == MouseState.UpThisFrame) { result.phase = TouchPhase.Ended; lastMousePosition = null; } else { result.phase = TouchPhase.Moved; lastMousePosition = new Vector2?(Input.mousePosition); } result.position = new Vector2(Input.mousePosition.x, Input.mousePosition.y); return(result); }
public static MouseTouch TransformMouse(Vector3 currentPos, Vector3 previousPos, float previousTime, bool mouseUp) { MouseTouch m = new MouseTouch(); //Set the phase for the mousetouch if (Input.GetMouseButton(0)) { if (Input.GetMouseButtonDown(0)) { m.phase = TouchPhase.Began; } else { m.phase = TouchPhase.Moved; } } else if (mouseUp) { m.phase = TouchPhase.Ended; } m.position = currentPos; m.deltaPosition = currentPos - previousPos; m.deltaTime = Time.time - previousTime; return(m); }
public static MouseTouch TransformTouch(Touch touch) { MouseTouch m = new MouseTouch(); m.phase = touch.phase; m.position = touch.position; m.deltaTime = touch.deltaTime; m.deltaPosition = touch.deltaPosition; return(m); }
public override void InputUpdate(MouseTouch touch) { if (buttonRectangle.Contains(touch.position)) { pressingButton = true; } else { pressingButton = false; } }
// Logic based on http://stackoverflow.com/questions/25323389/camera-2d-movement-android-unity void Update() { updatedPosition = false; if (Input.touchCount > 0) { if (Input.GetTouch(0).phase == TouchPhase.Moved && !isTouchCanceled) { Vector2 touchDeltaPosition = Input.GetTouch(0).deltaPosition; transform.Translate(-touchDeltaPosition.x * Speed * Time.deltaTime, -touchDeltaPosition.y * Speed * Time.deltaTime, 0); updatedPosition = true; } else if (Input.GetTouch(0).phase == TouchPhase.Ended || Input.GetTouch(0).phase == TouchPhase.Canceled) { isTouchCanceled = false; } } else { isTouchCanceled = false; } MouseTouch.Touch?mouseTouch = MouseTouch.GetTouch(0); if (mouseTouch.HasValue && !UnityEngine.EventSystems.EventSystem.current.IsPointerOverGameObject()) { if (mouseTouch.Value.Phase == MouseTouch.TouchPhase.Moved && !isMouseCanceled) { Vector2 touchDeltaPosition = mouseTouch.Value.DeltaPosition; transform.Translate(-touchDeltaPosition.x * Speed * Time.deltaTime, -touchDeltaPosition.y * Speed * Time.deltaTime, 0); updatedPosition = true; } else if (mouseTouch.Value.Phase == MouseTouch.TouchPhase.Canceled || mouseTouch.Value.Phase == MouseTouch.TouchPhase.Ended) { isMouseCanceled = false; } } else { isMouseCanceled = false; } if (updatedPosition && BoundingBox != null) { Vector3 pos = transform.position; pos.x = Mathf.Clamp(pos.x, BoundingBox.transform.position.x - (BoundingBox.size.x / 2.0f), BoundingBox.transform.position.x + (BoundingBox.size.x / 2.0f)); pos.y = Mathf.Clamp(pos.y, BoundingBox.transform.position.y - (BoundingBox.size.y / 2.0f), BoundingBox.transform.position.y + (BoundingBox.size.y / 2.0f)); transform.position = pos; } }
public override void TouchStart(MouseTouch touch) { if (playerRb.GetComponent <Collider2D>() == Physics2D.OverlapPoint(Camera.main.ScreenToWorldPoint(touch.position))) { hookOut = !hookOut; if (hookOut == true) //Actions to take when hook is thrown { ThrowHook(); } else //Actions to take when hook is summoned back in { UpdateDelegate = ReelInUpdate; } } }
private void HandlePower(MouseTouch touch) { if (currentPower <= maxPower && currentPower >= minPower) { if (touch.deltaTime != 0f) { currentPower += (((touch.deltaPosition.y / Screen.height) * (maxPower - minPower)) * powerSensitivity) * (Time.deltaTime / touch.deltaTime); } else { currentPower += (((touch.deltaPosition.y / Screen.height) * (maxPower - minPower)) * powerSensitivity); } } if (currentPower < minPower) { currentPower = minPower; } if (currentPower > maxPower) { currentPower = maxPower; } }
public void SetData(Hashtable ht) { if(ht.ContainsKey("mouseclick")) { this.useClick = true; this.mouseClick = int.Parse((string)ht["mouseclick"]); } else this.useClick = false; if(ht.ContainsKey("touchcount")) { this.useTouch = true; this.touchCount = int.Parse((string)ht["touchcount"]); } else this.useTouch = false; if(ht.ContainsKey("clickcount")) { this.clickCount = int.Parse((string)ht["clickcount"]); } if(ht.ContainsKey("mode")) { this.mode = (MouseTouch)System.Enum.Parse(typeof(MouseTouch), (string)ht["mode"]); } }
private MouseTouch GetTouch(UnityEngine.Touch t) { MouseTouch touch = new MouseTouch(); touch.position = t.position; touch.deltaPosition = t.deltaPosition; touch.deltaTime = t.deltaTime; touch.Time = Time.time; touch.phase = t.phase; touch.buttonID = t.fingerId; return touch; }
private MouseTouch GetDeltaTouch() { MouseTouch touch = new MouseTouch(); touch.position = Input.mousePosition; touch.deltaPosition = touch.position-_pos; touch.Time = Time.time; touch.deltaTime = touch.Time - _time; touch.phase = TouchPhase.Moved; touch.buttonID = 0; _time = touch.Time; _pos = touch.position; return touch; }
void FixedMouseUpdate() { if (_pressed) if (v3tov2(Input.mousePosition) != _pos) _lg.AddTouch(GetDeltaTouch()); if (Input.GetMouseButton(0) && !_pressed) { _pressed = true; _pos = Input.mousePosition; _time = Time.time; // on start gesture _lg = new Gesture(); MouseTouch touch = new MouseTouch(); touch.position = _pos; touch.deltaTime = 0; touch.deltaPosition = Vector2.zero; touch.phase = TouchPhase.Began; touch.buttonID = 0; touch.Time = Time.time; _lg.AddTouch(touch); OnGestureStart(_lg); } if (!Input.GetMouseButton(0) && _pressed) { _pressed = false; // on finish gesture MouseTouch touch = GetDeltaTouch(); touch.phase = TouchPhase.Ended; _lg.AddTouch(touch); OnGestureEnd(_lg); } }
public void AddTouch(MouseTouch touch) { Frames.Add(touch); OnAddingTouch(this); }
public override void TouchStart(MouseTouch touch) { currentAngle = copterAngle; hasInput = true; }
public Touch toTouch() { return(MouseTouch.createTouch(this.fingerId, 0, this.position, this.deltaPosition, this.deltaTime, this.phase)); }
//Update when the touchphase is Ended public virtual void TouchEnd(MouseTouch touch) { }
//Update when the touchphase is Began public virtual void TouchStart(MouseTouch touch) { }
//Update every frame when the player holds his finger on the screen public virtual void InputUpdate(MouseTouch touch) { }
public override void TouchEnd(MouseTouch touch) { tempHoldTime = 0; //Reset tempholdtime hasInput = false; }
public override void InputUpdate(MouseTouch touch) { HandleRotation(touch); HandlePower(touch); }
private void HandleRotation(MouseTouch touch) { if ((currentAngle < maxTiltValue || touch.deltaPosition.x < 0f) || (currentAngle > 360f - maxTiltValue || touch.deltaPosition.x > 0f)) { currentAngle -= touch.deltaPosition.x * rotationSensitivity; } if (currentAngle < 0f) { currentAngle += 360f; } else if (currentAngle > 360f) { currentAngle -= 360f; } if (currentAngle > maxTiltValue && currentAngle < 180f) { currentAngle = maxTiltValue; } else if (currentAngle < 360f - maxTiltValue && currentAngle > 180f) { currentAngle = 360f - maxTiltValue; } Quaternion q = Quaternion.AngleAxis(currentAngle, Vector3.forward); copterTr.rotation = Quaternion.RotateTowards(copterTr.rotation, q, Time.deltaTime * maxTiltSpeed); // if (copterAngle != currentAngle) // { // Turn to currentAngle // if (currentAngle < 180f) // { // if (copterAngle > 180f) // { // // Rotate CCW // //copterTr.Rotate(new Vector3(0f, 0f, maxTiltSpeed * Time.deltaTime)); // } // else if (copterAngle < 180f) // { // if (copterAngle < currentAngle) // { // // Rotate CCW // //copterTr.Rotate(new Vector3(0f, 0f, maxTiltSpeed * Time.deltaTime)); // } // else if (copterAngle > currentAngle) // { // // Rotate CW // //copterTr.Rotate(new Vector3(0f, 0f, -maxTiltSpeed * Time.deltaTime)); // } // } // } // else if (currentAngle > 180f) // { // if (copterAngle < 180f) // { // // Rotate CW // //copterTr.Rotate(new Vector3(0f, 0f, -maxTiltSpeed * Time.deltaTime)); // } // else if (copterAngle > 180f) // { // if (copterAngle < currentAngle) // { // // Rotate CCW // //copterTr.Rotate(new Vector3(0f, 0f, maxTiltSpeed * Time.deltaTime)); // } // else if (copterAngle > currentAngle) // { // // Rotate CW // //copterTr.Rotate(new Vector3(0f, 0f, -maxTiltSpeed * Time.deltaTime)); // } // } // } // } }
public void AddTouch(MouseTouch touch) { Frames.Add(touch); OnGestureStay(this); }