/// <summary> /// Callback to draw gizmos that are pickable and always drawn. /// </summary> void OnDrawGizmos() { if (fingerID != 0) { Gizmos.DrawWireSphere(transform.position, TouchHelper.GetTouchByFingerID(fingerID).radius); } }
// Update is called once per frame void Update() { Vector2 pos = Input.mousePosition; if (!TouchHelper.NotInRects(rects, pos)) { return; } Ray ray = cam.ScreenPointToRay(pos); RaycastHit hit; if (Physics.Raycast(ray, out hit, 5000f)) { string name = hit.transform.gameObject.name; if (name == "Floor") { //print (hit.point); Move(curActive.transform, hit.point); } /*else if(name=="curChair"){ * curActive = goChair; * }else if(name=="curLamp"){ * * }*/ } }
private async void LessonContainer_TouchDown(object sender, TouchEventArgs e) { // Forward touch events to container //FrameworkElement control = sender as FrameworkElement; //control.CaptureTouch(e.TouchDevice); if (LayerStackDC.CurrentState.FingerInkingEnabled) { LessonContainer.IsContentManipulationEnabled = false; return; } // Saves current touch information //touchDevices.Add(e.TouchDevice); touchOrigin = e.GetTouchPoint(LessonContainer).Position; // Disable manipulation/drawing //LessonContainer.IsContentManipulationEnabled = false; LayerStackDC.ContainerTouchDown(); // If touch-and-hold (within 10px radius circle, over 500ms) if (await TouchHelper.TouchHold(e, LessonContainer, 500, 10)) { // Opens RadialMenu LessonContainer.IsContentManipulationEnabled = false; LayerStackDC.OpenRadialMenu(LayerStackDC.Viewport.GetViewport(), e.GetTouchPoint(LessonContainer).Position, RadialMenuState.Levels.Main); // Un-forward touch events to container //control.ReleaseAllTouchCaptures(); } }
private void LessonContainer_TouchMove(object sender, TouchEventArgs e) { if (LayerStackDC.CurrentState.FingerInkingEnabled) { LessonContainer.IsContentManipulationEnabled = false; return; } // Verification to triggers this only one time if (!LessonContainer.IsContentManipulationEnabled && !LayerStackDC.RadialMenuState.IsOpen) { // If the manipulation is more than 10px expansion var touchCurrent = e.GetTouchPoint(LessonContainer).Position; if (TouchHelper.Distance(touchOrigin, touchCurrent) > 10) { // Re-enable manipulation/drawing //LayerStackDC.ContainerTouchMove(); LessonContainer.IsContentManipulationEnabled = true; // Un-forward touch events to container //foreach (var device in touchDevices) //{ // LessonContainer.ContentCaptureTouch(device); //} } } }
private void input() { int moveIndex = -1; if (Input.GetKeyDown(KeyCode.LeftArrow) || TouchHelper.getTouchInput() == TouchHelper.Direction.left) { moveIndex = 0; } else if (Input.GetKeyDown(KeyCode.RightArrow) || TouchHelper.getTouchInput() == TouchHelper.Direction.right) { moveIndex = 2; } else if (Input.GetKeyDown(KeyCode.UpArrow) || TouchHelper.getTouchInput() == TouchHelper.Direction.up) { moveIndex = 1; } else if (Input.GetKeyDown(KeyCode.DownArrow) || TouchHelper.getTouchInput() == TouchHelper.Direction.down) { moveIndex = 3; } if (moveIndex != -1) { makeMove(moveIndex); } }
/// <summary> /// Occurs when a touchPoint is Released /// </summary> private void OnTouchUp(object sender, TouchEventArgs e) { #if WINDOWS_PHONE //Workaround for the Touch.FrameReported issue in WP7 not releasing Touch Points TouchHelper.ResetTouchPoints(); #endif if (AreFingersVisible) { #if WINDOWS_PHONE //Workaround: Remove all the Markers in the WP7 version if (_touchPointsMarkers != null) { foreach (var touchPointsMarker in _touchPointsMarkers .Where(touchPointsMarker => touchPointsMarker.Value != null)) { touchPointsMarker.Value.IsOpen = false; } } #else //Hide the TouchPoint if (_touchPointsMarkers.ContainsKey(e.TouchPoint.TouchDevice.Id)) { _touchPointsMarkers[e.TouchPoint.TouchDevice.Id].IsOpen = false; _touchPointsMarkers[e.TouchPoint.TouchDevice.Id] = null; _touchPointsMarkers.Remove(e.TouchPoint.TouchDevice.Id); } #endif } #if DEBUG Debug.WriteLine("TouchPoint Up: Id {0} at ({1})", e.TouchPoint.TouchDevice.Id, e.TouchPoint.Position); #endif }
public void SetState(States state) { this.state = state; switch (state) { default: case States.Bringing: // Reset everything touchHelper = new TouchHelper(); var op = operatorLibrary.GetRandomOperator(); lockerController.currentRarity = op.rarity; operatorView.SetInfo(op); audioController.SetInfo(op); break; case States.Touching: playableDirector.Pause(); break; case States.Opening: playableDirector.Resume(); break; case States.AfterOpening: playableDirector.Pause(); break; } }
void Update() { List <Touch> touches = TouchHelper.GetTouches(); if (touches.Count > 0) { var touch = touches[0]; if (touch.phase == TouchPhase.Began) { var ray = Camera.main.ScreenPointToRay(touch.position); RaycastHit hit; if (Physics.Raycast(ray, out hit, 100)) { ARObject arObj = hit.collider.GetComponent <ARObject>(); if (arObj == null) { arObj = hit.collider.GetComponentInParent <ARObject>(); } if (arObj != null) { SelectObject(arObj); } } } } }
// Update is called once per frame void Update() { List <Touch> Touches = TouchHelper.GetTouches(); if (Touches.Count <= 0) { return; } foreach (Touch touch in Touches) { Vector2 touchPosition = Camera.main.ScreenToWorldPoint(touch.position); switch (touch.phase) { case TouchPhase.Began: foreach (GameObject fruitPiece in godObject.GetComponent <PieceGenerator>().ActiveFruitList) { if (fruitPiece.GetComponent <BoxCollider2D>().OverlapPoint(touchPosition)) { // fruit is grabbed by the touch fruitPiece.GetComponent <SimpleGravity>().velocity = Vector3.zero; fruitPiece.GetComponent <SimpleGravity>().gravity = 0.0f; fruitPiece.GetComponent <FruitBase>().GrabBy(touch.fingerId); } } break; case TouchPhase.Moved: foreach (GameObject fruitPiece in godObject.GetComponent <PieceGenerator>().ActiveFruitList) { if (fruitPiece.GetComponent <FruitBase>().IsGrabbedBy(touch.fingerId)) { fruitPiece.transform.position = new Vector3(touchPosition.x, touchPosition.y, 0); } } break; case TouchPhase.Ended: foreach (GameObject fruitPiece in godObject.GetComponent <PieceGenerator>().ActiveFruitList) { if (fruitPiece.GetComponent <FruitBase>().IsGrabbedBy(touch.fingerId)) { fruitPiece.GetComponent <FruitBase>().Release(); // Calculate releasing velocity. Vector2 previousPos = Camera.main.ScreenToWorldPoint(touch.position - touch.deltaPosition); Vector3 deltaPos = touchPosition - previousPos; float multiplier = 0.5f / touch.deltaTime; Debug.Log("Delta screen position: x " + deltaPos.x + ",y " + deltaPos.y); Debug.Log("Delta screen time: " + Time.deltaTime); fruitPiece.GetComponent <SimpleGravity>().velocity = new Vector3(deltaPos.x * multiplier, deltaPos.y * multiplier, 0); fruitPiece.GetComponent <SimpleGravity>().gravity = SimpleGravity.GRAVITY; } } break; } } }
void OnNewFinger(FingerObj newFinger) { if (TouchHelper.IsObjectUnderTouch(newFinger.originTouch, tapToMoveTarget.transform, .5f)) { fingerOfInterest = newFinger; fingerOfInterest.OnStatusChange += FingerStatusChange; } }
private async void LessonContainer_StylusDown(object sender, StylusDownEventArgs e) { // If touch-and-hold (within 9px radius circle, over 700ms) if (await TouchHelper.StylusHold(e, LessonContainer, 700, 9)) { // Opens RadialMenu LayerStackDC.OpenRadialMenu(LayerStackDC.Viewport.GetViewport(), e.GetPosition(LessonContainer), RadialMenuState.Levels.Main); } }
void Update() { List <Touch> touches = TouchHelper.GetTouches(); if (touches.Count > 0) { var touch = touches[0]; if (touch.phase == TouchPhase.Moved) { targetObject.Rotate(targetObject.up * touch.deltaPosition.x * speed * Time.deltaTime); } } }
static int RemoveDragListener(IntPtr L) { try { ToLua.CheckArgsCount(L, 1); UnityEngine.GameObject arg0 = (UnityEngine.GameObject)ToLua.CheckObject(L, 1, typeof(UnityEngine.GameObject)); TouchHelper.RemoveDragListener(arg0); return(0); } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e)); } }
protected override void OnElementChanged(ElementChangedEventArgs <Button> e) { if (this.Control != null) { this.touchHelper?.Dispose(); } base.OnElementChanged(e); if (e.NewElement != null) { this.touchHelper = new TouchHelper(this.Element.TouchManager, this); } }
void Update() { List <Touch> touches = TouchHelper.GetTouches(); if (touches.Count > 0) { var touch = touches[0]; if (touch.phase == TouchPhase.Began) { float closestDot = -1f; foreach (Transform axis in axes) { Ray ray = Camera.main.ScreenPointToRay(new Vector3(touch.position.x, touch.position.y, 0)); Vector3 vectorToAxis = (axis.position - Camera.main.transform.position).normalized; float currentDot = Vector3.Dot(ray.direction, vectorToAxis); if (currentDot > closestDot) { closestDot = currentDot; activeAxis = axis; } } } if (touch.phase == TouchPhase.Moved) { Vector3 offset = activeAxis.forward; offset.x *= touch.deltaPosition.x; offset.y *= touch.deltaPosition.y; offset.z *= touch.deltaPosition.x; if (widgetType == WidgetType.TranslateWidget) { targetObject.position += offset * speed * Time.deltaTime; } else if (widgetType == WidgetType.ScaleWidget) { targetObject.localScale += offset * speed * Time.deltaTime; } } if (touch.phase == TouchPhase.Ended) { activeAxis = null; } } }
/// <summary> /// Reset the Touch handlers for the AssociatedObject /// </summary> private void ResetAssociatedObject(FrameworkElement associatedObject) { if (associatedObject == null) { return; } associatedObject.MouseLeftButtonUp -= OnMouseUp; associatedObject.MouseLeftButtonDown -= OnMouseDown; associatedObject.MouseMove -= OnMouseMove; associatedObject.LostMouseCapture -= OnLostMouseCapture; associatedObject.Loaded -= AssociatedObjectLoaded; TouchHelper.RemoveHandlers(associatedObject); // Better to not disable the TouchHelper here otherwise touch events will be disabled for all other elements using the Behavior // TouchHelper.EnableInput(false); }
static int AddDragListener(IntPtr L) { try { ToLua.CheckArgsCount(L, 2); UnityEngine.GameObject arg0 = (UnityEngine.GameObject)ToLua.CheckObject(L, 1, typeof(UnityEngine.GameObject)); UIDragEventHandlerDetail arg1 = (UIDragEventHandlerDetail)ToLua.CheckDelegate <UIDragEventHandlerDetail>(L, 2); TouchHelper.AddDragListener(arg0, arg1); return(0); } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e)); } }
private void OnCapturedTouchReported(object sender, TouchReportedEventArgs e) { UIElement parent = this.AssociatedObject.Parent as UIElement; if (parent == null) { return; } //Find the root element UIElement root = TouchHelper.GetRootElement(parent); if (root == null) { return; } // get transformation to convert positions to the parent's coordinate system GeneralTransform transform = root.TransformToVisual(parent); List <Manipulator2D> manipulators = null; foreach (TouchPoint touchPoint in e.TouchPoints) { Point position = touchPoint.Position; // convert to the parent's coordinate system position = transform.Transform(position); // create a manipulator Manipulator2D manipulator = new Manipulator2D( touchPoint.TouchDevice.Id, (float)(position.X), (float)(position.Y)); if (manipulators == null) { // lazy initialization manipulators = new List <Manipulator2D>(); } manipulators.Add(manipulator); } // process manipulations this.manipulationProcessor.ProcessManipulators( Timestamp, manipulators); }
// Update is called once per frame void Update() { foreach (Touch thisTouch in Input.touches) { if (thisTouch.phase == TouchPhase.Began) { // we must have a new baby finger! FingerObj newFinger = Instantiate(fingerPrefab, TouchHelper.GetTouchWorldPosition(thisTouch), Quaternion.identity); // Instantiate all member variables the ugly way! newFinger.fingerID = thisTouch.fingerId; newFinger.transform.position = TouchHelper.GetTouchWorldPosition(thisTouch); newFinger.touchLastFrame = newFinger.touch = newFinger.originTouch = thisTouch; currentFingers.Add(newFinger); if (OnNewFinger != null) { OnNewFinger(newFinger); } } } if (Input.mousePresent) { if (Input.GetMouseButtonDown(0)) { // Debug.Log( "we got a mouse click"); // Create a new baby mouse finger 🐁 Touch thisTouch = TouchHelper.GetFakeMouseTouch(); FingerObj newFinger = Instantiate(fingerPrefab, TouchHelper.GetTouchWorldPosition(thisTouch), Quaternion.identity); // Instantiate all member variables the ugly way! newFinger.fingerID = thisTouch.fingerId; newFinger.transform.position = TouchHelper.GetTouchWorldPosition(thisTouch); newFinger.touchLastFrame = newFinger.touch = newFinger.originTouch = thisTouch; currentFingers.Add(newFinger); if (OnNewFinger != null) { OnNewFinger(newFinger); } } } foreach (FingerObj thisFinger in currentFingers) { thisFinger.UpdateFinger(); if (FingersDoneUpdating != null) { FingersDoneUpdating(); } } }
/// <summary> /// Gets the first object in the direction of wherever the user tapped. /// </summary> /// <returns>Returns the raycast collision itself so that the position of contact can be preserved. Returns an empty `RaycastHit2D` if the object hit does not contain a `<see cref="StickInteractable" />`. You can evaluate a `RaycastHit2D` as a boolean to determine if this function succeeded or failed.</returns> RaycastHit2D GetFirstObjHitByStick(Touch finger) { Vector2 tapLocation = TouchHelper.GetTouchWorldPosition(finger); float radius = finger.radius + expandTouchRadiusBy; Vector2 direction = tapLocation - (Vector2)transform.position; RaycastHit2D hit = Physics2D.CircleCast(tapLocation, radius, direction.normalized, Mathf.Max(maxTapDistance, direction.magnitude)); // just play the hits 💿 ayy lmao if (hit && hit.collider.GetComponent <StickInteractable>() != null) { return(hit); } else { return(new RaycastHit2D()); } }
/// <summary> /// Occurs when detaching the behavior /// </summary> protected override void OnDetaching() { base.OnDetaching(); this.manipulationProcessor.Started -= OnManipulationStarted; this.manipulationProcessor.Delta -= OnManipulationDelta; this.manipulationProcessor.Completed -= OnManipulationCompleted; this.inertiaProcessor.Delta -= OnManipulationDelta; this.inertiaProcessor.Completed -= OnInertiaCompleted; this.inertiaTimer.Tick -= OnTimerTick; this.AssociatedObject.MouseLeftButtonUp -= OnMouseUp; this.AssociatedObject.MouseLeftButtonDown -= OnMouseDown; this.AssociatedObject.MouseMove -= OnMouseMove; this.AssociatedObject.LostMouseCapture -= OnLostMouseCapture; TouchHelper.EnableInput(false); this.AssociatedObject.Loaded -= (s1, e1) => { }; }
// Use this for initialization public void UpdateFinger() { if (!calledThisFrameYet) { gameObject.name = "Finger - " + fingerID; calledThisFrameYet = true; touchLastFrame = touch; touch = TouchHelper.GetTouchByFingerID(fingerID); Vector3 newPos = TouchHelper.GetTouchWorldPosition(touch); newPos.z = 0f; transform.position = newPos; // determine the 🗾 state if (currentState == TouchState.Tap) { // are we a drag 👑 yet? Vector2 distance = touch.position - originTouch.position; if (distance.magnitude > TouchManager.inst.dragDetectionDistPixels) { currentState = TouchState.Dragging; if (OnStatusChange != null) { OnStatusChange(this); } } } // or are we to 💀 die if (IsFingerLeaving(this)) { currentState = TouchState.Ending; if (OnStatusChange != null) { OnStatusChange(this); } Destroy(this.gameObject); } if (OnFingerUpdated != null) { OnFingerUpdated(this); } } }
/// <summary> /// Initialize the behavior /// </summary> protected override void OnAttached() { base.OnAttached(); this.manipulationProcessor = new ManipulationProcessor2D(SupportedManipulations); this.manipulationProcessor.Started += OnManipulationStarted; this.manipulationProcessor.Delta += OnManipulationDelta; this.manipulationProcessor.Completed += OnManipulationCompleted; this.inertiaProcessor = new InertiaProcessor2D(); this.inertiaProcessor.TranslationBehavior.DesiredDeceleration = Deceleration; this.inertiaProcessor.RotationBehavior.DesiredDeceleration = AngularDeceleration; this.inertiaProcessor.ExpansionBehavior.DesiredDeceleration = ExpansionDeceleration; this.inertiaProcessor.Delta += OnManipulationDelta; this.inertiaProcessor.Completed += OnInertiaCompleted; this.inertiaTimer = new DispatcherTimer(); this.inertiaTimer.Interval = TimeSpan.FromMilliseconds(30); this.inertiaTimer.Tick += OnTimerTick; this.AssociatedObject.RenderTransformOrigin = new Point(0.5, 0.5); Move(new Point(0, 0), 0, 100); IsPivotActive = true; this.AssociatedObject.MouseLeftButtonUp += OnMouseUp; this.AssociatedObject.MouseLeftButtonDown += OnMouseDown; this.AssociatedObject.MouseMove += OnMouseMove; this.AssociatedObject.LostMouseCapture += OnLostMouseCapture; TouchHelper.AddHandlers(this.AssociatedObject, new TouchHandlers { TouchDown = OnTouchDown, CapturedTouchReported = OnCapturedTouchReported, }); TouchHelper.EnableInput(true); this.AssociatedObject.Loaded += (s1, e1) => { TouchHelper.SetRootElement(TouchHelper.GetRootElement(this.AssociatedObject)); }; }
static int _CreateTouchHelper(IntPtr L) { try { int count = LuaDLL.lua_gettop(L); if (count == 0) { TouchHelper obj = new TouchHelper(); ToLua.PushObject(L, obj); return(1); } else { return(LuaDLL.luaL_throw(L, "invalid arguments to ctor method: TouchHelper.New")); } } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e)); } }
/// <summary> /// Initialize Touch handlers for the AssociatedObject /// </summary> private void InitializeAssociatedObject(FrameworkElement associatedObject) { if (associatedObject == null) { return; } associatedObject.MouseLeftButtonUp += OnMouseUp; associatedObject.MouseLeftButtonDown += OnMouseDown; associatedObject.MouseMove += OnMouseMove; associatedObject.LostMouseCapture += OnLostMouseCapture; TouchHelper.AddHandlers(associatedObject, new TouchHandlers { TouchDown = OnTouchDown, CapturedTouchReported = OnCapturedTouchReported, CapturedTouchUp = OnTouchUp }); TouchHelper.EnableInput(true); associatedObject.Loaded += AssociatedObjectLoaded; }
protected override void OnDestroy() { TouchHelper.Unlock(_lockId); base.OnDestroy(); }
protected virtual void Start() { _lockId = TouchHelper.Lock(); }
public static void HandleMainCameraEvent(GameObject fullMask) { TouchHelper.AddDragListener(fullMask, GUIHelper.MainCameraOnDrag); TouchHelper.AddEndDragListener(fullMask, GUIHelper.MainCameraOnEndDrag); }
/// <summary> /// Occurs when Touch points are reported: handles manipulations /// </summary> private void OnCapturedTouchReported(object sender, TouchReportedEventArgs e) { var parent = AssociatedObject.Parent as UIElement; if (parent == null) { return; } //Find the root element var root = TouchHelper.GetRootElement(parent); if (root == null) { return; } //Multi-Page support: verify if the collection of Touch points is null var touchPoints = e.TouchPoints; List <Manipulator2D> manipulators = null; if (touchPoints.FirstOrDefault() != null) { // get transformation to convert positions to the parent's coordinate system var transform = root.TransformToVisual(parent); foreach (var touchPoint in touchPoints) { var position = touchPoint.Position; // convert to the parent's coordinate system position = transform.Transform(position); // create a manipulator var manipulator = new Manipulator2D( touchPoint.TouchDevice.Id, (float)(position.X), (float)(position.Y)); if (manipulators == null) { // lazy initialization manipulators = new List <Manipulator2D>(); } manipulators.Add(manipulator); //Change the visualization of the touchPoint if (_touchPointsMarkers.ContainsKey(touchPoint.TouchDevice.Id)) { if (AreFingersVisible) { _touchPointsMarkers[touchPoint.TouchDevice.Id].HorizontalOffset = touchPoint.Position.X - (EllipseWidth / 2); _touchPointsMarkers[touchPoint.TouchDevice.Id].VerticalOffset = touchPoint.Position.Y - (EllipseWidth / 2); } #if DEBUG Debug.WriteLine("TouchPoint Reported: Id {0} at ({1} - Total Touch Points: {2})", touchPoint.TouchDevice.Id, touchPoint.Position, touchPoints.Count()); #endif } } } // process manipulations _manipulationProcessor.ProcessManipulators(Timestamp, manipulators); }
/// <summary> /// Initialize the TouchHelper /// </summary> void AssociatedObjectLoaded(object sender, RoutedEventArgs e) { TouchHelper.SetRootElement(TouchHelper.GetRootElement(AssociatedObject)); }