public void BeginTracking(TouchWrapper touch) { _isActive = true; _isDirty = true; _fingerId = touch.touchId; _lastPosition = touch.position; }
private void DoTrackingUpdate(TouchTracker tracker, TouchWrapper touch) { tracker.Update(touch); if (OnTouchUpdate != null) { OnTouchUpdate(touch); } }
private void DoTrackingBegin(TouchTracker tracker, TouchWrapper touch) { tracker.BeginTracking(touch); if (OnTouchBegin != null) { OnTouchBegin(touch); } }
private static TouchWrapper RMBToTouchWrapper() { TouchWrapper touch = new TouchWrapper(); touch.position = Input.mousePosition; touch.touchId = RMB_TOUCH_ID; touch.deltaTime = Time.time - _RMBDownStartTime; return(touch); }
private static TouchWrapper TouchToTouchWrapper(Touch t) { TouchWrapper touch = new TouchWrapper(); touch.position = t.position; touch.touchId = t.fingerId; touch.deltaTime = t.deltaTime; return(touch); }
public InputWrapper() { #if UNITY_EDITOR _mouse = new MouseWrapper(); _device = _mouse; #else _touch = new TouchWrapper(); _device = _touch; #endif }
private void OnClick(TouchWrapper wrapper, bool isOverGameObjects) { var touch = wrapper.GetTouch(); if (touch.phase != TouchPhase.Began || IsBlocked || !_canFlip) { return; } _canFlip = false; Invoke(nameof(AllowFlipping), FlipInterruption); FlipEvent?.Invoke(); }
private void StartDoubleTouch(TouchWrapper firstTouch, TouchWrapper secondTouch, Transform target1, Vector3 position1, Vector3 direction1, Vector3 groundPosition1, bool isFindFirstTarget, Transform target2, Vector3 position2, Vector3 direction2, Vector3 groundPosition2, bool isFindSecondTarget) { TwoFingerTouchStartEvent evt = new TwoFingerTouchStartEvent(firstTouch.position, secondTouch.position); if (isFindFirstTarget) { if (target1 != null) { evt.target1 = target1; evt.position1 = target1.position; } else { evt.position1 = position1; } } if (isFindSecondTarget) { if (target2 != null) { evt.target2 = target2; evt.position2 = target2.position; } else { evt.position2 = position2; } } evt.direction1 = direction1; evt.direction2 = direction2; evt.groundPosition1 = groundPosition1; evt.groundPosition2 = groundPosition2; RaiseEvent(evt); }
void Update() { _activeTouches.Clear(); #if UNITY_EDITOR || UNITY_STANDALONE if (Input.GetMouseButtonDown(0)) { _mouseTouch = new TouchWrapper(1, TouchPhase.Began, Input.mousePosition); } else if (Input.GetMouseButton(0) && _mouseTouch.isActive) { Vector2 delta = (Vector2)Input.mousePosition - _mouseTouch.position; if (Vector2.SqrMagnitude(delta) > _stationaryThreshold * _stationaryThreshold) { _mouseTouch = new TouchWrapper(1, TouchPhase.Moved, Input.mousePosition, delta); } else { _mouseTouch = new TouchWrapper(1, TouchPhase.Stationary, Input.mousePosition, delta); } } else if (Input.GetMouseButtonUp(0) && _mouseTouch.isActive) { _mouseTouch = new TouchWrapper(1, TouchPhase.Ended, Input.mousePosition, (Vector2)Input.mousePosition - _mouseTouch.position); } else { _mouseTouch = new TouchWrapper(); } if (_mouseTouch.isActive) { _activeTouches.Add(_mouseTouch); } #else for (int i = 0; i < Input.touchCount; ++i) { _activeTouches.Add(new TouchWrapper(Input.GetTouch(i))); } #endif }
private void DoMouseProcessing(int buttonIndex, int touchId, ref float downStartTime, System.Func <TouchWrapper> touchWrapperFunc) { if (Input.GetMouseButtonDown(buttonIndex)) { TouchTracker tracker = GetExistingTracker(touchId); if (tracker != null) { Debug.LogWarning("Mouse button [" + buttonIndex + "] pressed down twice without an up!?"); DoTrackingEnd(tracker); } tracker = GetNewTracker(); if (tracker != null) { downStartTime = Time.time; TouchWrapper touch = touchWrapperFunc(); DoTrackingBegin(tracker, touch); } } else if (Input.GetMouseButtonUp(buttonIndex)) { TouchTracker tracker = GetExistingTracker(touchId); if (tracker != null) { DoTrackingEnd(tracker); } } else if (Input.GetMouseButton(buttonIndex)) { TouchTracker tracker = GetExistingTracker(touchId); if (tracker != null) { TouchWrapper touch = touchWrapperFunc(); DoTrackingUpdate(tracker, touch); } } }
private void DoTrackingBegin(TouchTracker tracker, TouchWrapper touch) { tracker.BeginTracking (touch); if (OnTouchBegin != null) { OnTouchBegin (touch); } }
private void EndSingleTouch(TouchWrapper touch, Transform target, Vector3 location, Vector3 direction, Vector3 groundPosition, bool hasValidNavPoint) { float singleTouchDuration = Time.time - _singleTouchStartTime; if (singleTouchDuration < TapLength) { if (Time.time - _lastTapTime > DoubleTapLength) { TapEvent tapEvent = (null != target) ? new TapEvent(touch.position, target, location) : new TapEvent(touch.position, location); tapEvent.direction = direction; tapEvent.groundPosition = groundPosition; tapEvent.hasValidNavPoint = hasValidNavPoint; #if BUFFER_SINGLE_TAPS StartCoroutine(QueueSingleTap(tapEvent)); #else _lastTapTime = Time.time; _didDoubleTap = false; RaiseEvent(tapEvent); #endif } else { DoubleTapEvent doubleTapEvent = (null != target) ? new DoubleTapEvent(touch.position, target, location) : new DoubleTapEvent(touch.position, location); doubleTapEvent.direction = direction; DoDoubleTap(doubleTapEvent); } } else if (_touchStartedOnPlayer) { DragFromPlayerGestureEndEvent evt = null; if (target) { evt = new DragFromPlayerGestureEndEvent(touch.position, target); } else { evt = new DragFromPlayerGestureEndEvent(touch.position, location); } evt.direction = direction; evt.groundPosition = groundPosition; RaiseEvent(evt); _touchStartedOnPlayer = false; } TouchEndEvent endEvent = (TouchEndEvent)CodeObjectManager.GetEventManager(typeof(TouchEndEvent)).GetNext();; if (target != null) { endEvent.Initialize(touch.position, target, location); } else { endEvent.Initialize(touch.position, location); } endEvent.direction = direction; endEvent.groundPosition = groundPosition; RaiseEvent(endEvent); CodeObjectManager.GetEventManager(typeof(TouchEndEvent)).Destroy(endEvent); //check for flick gesture float flick_history_check = 1.5f; float time_look_back = 0.0f; int i = 0; int touch_index = m_touch_history_index - 1 > 0 ? m_touch_history_index - 1: TOUCH_HISTORY_LENGTH - 1; Vector3 flick_vel = Vector3.zero; float last_time = _touchHistory[touch_index]._time; Vector3 last_flick = touch.position; while (time_look_back < flick_history_check && i < TOUCH_HISTORY_LENGTH - 1) { if (_touchHistory[touch_index]._time == 0.0f) { break; } float time = last_time - _touchHistory[touch_index]._time; last_time = _touchHistory[touch_index]._time; time_look_back += time; flick_vel += _touchHistory[touch_index]._position - last_flick; last_flick = _touchHistory[touch_index]._position; i++; touch_index = touch_index - 1 > 0 ? touch_index - 1 : TOUCH_HISTORY_LENGTH - 1; } //EB.Debug.Log (i); if (time_look_back > 0.0f) { flick_vel *= time_look_back; if (flick_vel.magnitude > 0.2f) { FlickEvent flickEvent = new FlickEvent(); flickEvent.Initialize(touch.position, flick_vel); RaiseEvent(flickEvent); } else { //EB.Debug.Log ("VEL FAIL"); } } else { //EB.Debug.Log ("TIME FAIL"); } ResetTouchHistory(); }
private void UpdateSingleTouch(TouchWrapper touch, Transform target, Vector3 location, Vector3 direction, Vector3 groundPosition, bool hasValidNavPoint) { float touchDuration = Time.time - _singleTouchStartTime; float selfSelectRadiusSq = GlobalBalanceData.Instance.selfSelectRadius; selfSelectRadiusSq *= selfSelectRadiusSq; if (touchDuration < TapLength) { // Do nothing yet } else if (!_longPressStarted) { // This press is longer than a tap _longPressStarted = true; TouchStartEvent startEvent = (TouchStartEvent)CodeObjectManager.GetEventManager(typeof(TouchStartEvent)).GetNext(); if (target) { startEvent.Initialize(touch.position, target, location); } else { startEvent.Initialize(touch.position, location); } startEvent.direction = direction; startEvent.groundPosition = groundPosition; startEvent.deltaPosition = touch.deltaPosition; RaiseEvent(startEvent); CodeObjectManager.GetEventManager(typeof(TouchStartEvent)).Destroy(startEvent); } else if (_touchStartedOnPlayer) { if (!_playerLongPressStarted) { if (GameUtils.GetDistSqXZ(groundPosition, _playerTransform.position) > selfSelectRadiusSq) { DragFromPlayerGestureStartEvent evt = null; if (target) { evt = new DragFromPlayerGestureStartEvent(touch.position, target); } else { evt = new DragFromPlayerGestureStartEvent(touch.position, location); } evt.direction = direction; evt.groundPosition = groundPosition; RaiseEvent(evt); _playerLongPressStarted = true; } } else { DragFromPlayerGestureUpdateEvent evt = null; if (target) { evt = new DragFromPlayerGestureUpdateEvent(touch.position, target); } else { evt = new DragFromPlayerGestureUpdateEvent(touch.position, location); } evt.direction = direction; evt.groundPosition = groundPosition; RaiseEvent(evt); } } else { TouchUpdateEvent updateEvent = (TouchUpdateEvent)CodeObjectManager.GetEventManager(typeof(TouchUpdateEvent)).GetNext();; if (target != null) { updateEvent.Initialize(touch.position, target, location); } else { updateEvent.Initialize(touch.position, location); } updateEvent.direction = direction; updateEvent.groundPosition = groundPosition; updateEvent.hasValidNavPoint = hasValidNavPoint; RaiseEvent(updateEvent); CodeObjectManager.GetEventManager(typeof(TouchUpdateEvent)).Destroy(updateEvent); } //add the touch to the touch history for gesture checking on end _touchHistory[m_touch_history_index]._time = Time.realtimeSinceStartup; _touchHistory[m_touch_history_index]._position = touch.position; m_touch_history_index = (m_touch_history_index + 1) % TOUCH_HISTORY_LENGTH; }
void Update() { if (!GameEngine.Instance.IsTimeToRootScene) { return; } //如果是副本中则不能进入rvo /*if (LTInstanceMapModel.Instance.IsInstanceMap()) * { * return; * }*/ if (!AreControlsEnabled) { return; } if (GameVars.paused || TouchController.Instance == null) { return; } int numTouches = System.Math.Min(TouchController.Instance.ActiveTouches.Count, MaxTouches); if (_touchStartOverUI) { for (int i = 0; i < numTouches; i++) { TouchWrapper touch = TouchController.Instance.ActiveTouches[i]; if (touch.phase == TouchPhase.Ended || touch.phase == TouchPhase.Canceled) { _touchStartOverUI = false; } } return; } // make sure our events aren't being handled by NGUI if (UICamera.IsOverUIByRoot(mRoot)) { for (int i = 0; i < numTouches; i++) { if (TouchController.Instance.ActiveTouches[i].phase == TouchPhase.Began) { _touchStartOverUI = true; return; } } } if (numTouches == 1) { if (!_areSingleTouchEnabled) { return; } TouchWrapper touch = TouchController.Instance.ActiveTouches[0]; Transform target = null; Vector3 location = Vector3.zero; Vector3 groundPosition = Vector3.zero; Vector3 direction = Vector3.zero; bool isFindTarget = false; if (IsShowJoystick) { isFindTarget = true; } else { isFindTarget = FindTargetAndLocation(touch, out target, out location, out groundPosition, out direction); } if (touch.phase == TouchPhase.Began) { _firstFingerID = touch.fingerId; StartSingleTouch(groundPosition, isFindTarget); } if (touch.phase == TouchPhase.Began || (touch.fingerId == _firstFingerID && touch.phase != TouchPhase.Ended && touch.phase != TouchPhase.Canceled)) { UpdateSingleTouch(touch, target, location, direction, groundPosition, isFindTarget); } if (touch.phase == TouchPhase.Ended || touch.phase == TouchPhase.Canceled) { EndSingleTouch(touch, target, location, direction, groundPosition, isFindTarget); _touchStartOverUI = false; } } else if (numTouches > 1) { TouchWrapper firstTouch = TouchController.Instance.ActiveTouches[0]; TouchWrapper secondTouch = TouchController.Instance.ActiveTouches[1]; Transform target1 = null; Vector3 position1 = Vector3.zero; Vector3 direction1 = Vector3.zero; Vector3 groundPosition1 = Vector3.zero; bool isFindFirstTarget = false; if (IsShowJoystick) { isFindFirstTarget = true; } else { isFindFirstTarget = FindTargetAndLocation(firstTouch, out target1, out position1, out groundPosition1, out direction1); } Transform target2 = null; Vector3 position2 = Vector3.zero; Vector3 direction2 = Vector3.zero; Vector3 groundPosition2 = Vector3.zero; bool isFindSecondTarget = false; if (IsShowJoystick) { isFindSecondTarget = true; } else { isFindSecondTarget = FindTargetAndLocation(secondTouch, out target2, out position2, out groundPosition2, out direction2); } Transform targetCenter = null; Vector3 positionCenter = Vector3.zero; Vector3 directionCenter = Vector3.zero; Vector3 groundPositionCenter = Vector3.zero; TwoFingerTouchUpdateEvent evt = new TwoFingerTouchUpdateEvent(firstTouch.position, secondTouch.position); bool isFindCenterTarget = false; if (IsShowJoystick) { isFindCenterTarget = true; } else { isFindCenterTarget = FindTargetAndLocation(new TouchWrapper(0, TouchPhase.Moved, evt.screenPositionCenter), out targetCenter, out positionCenter, out groundPositionCenter, out directionCenter); } if (firstTouch.phase == TouchPhase.Began || secondTouch.phase == TouchPhase.Began) { StartDoubleTouch(firstTouch, secondTouch, target1, position1, direction1, groundPosition1, isFindFirstTarget, target2, position2, direction2, groundPosition2, isFindSecondTarget); } if (firstTouch.phase != TouchPhase.Ended && firstTouch.phase != TouchPhase.Canceled && secondTouch.phase != TouchPhase.Ended && secondTouch.phase != TouchPhase.Canceled) { UpdateDoubleTouch(firstTouch, secondTouch, target1, position1, direction1, groundPosition1, isFindFirstTarget, target2, position2, direction2, groundPosition2, isFindSecondTarget, evt, isFindCenterTarget, targetCenter, positionCenter, directionCenter, groundPositionCenter); } if (firstTouch.phase == TouchPhase.Ended || secondTouch.phase == TouchPhase.Ended || firstTouch.phase == TouchPhase.Canceled || secondTouch.phase == TouchPhase.Canceled) { EndDoubleTouch(firstTouch, secondTouch, target1, position1, direction1, groundPosition1, isFindFirstTarget, target2, position2, direction2, groundPosition2, isFindSecondTarget, evt, isFindCenterTarget, targetCenter, positionCenter, directionCenter, groundPositionCenter); _touchStartOverUI = false; } } }
public static SkillResponse CreateAPL() { Container upperTextContainer = new Container(new Text("Welcome to ASMR Video")); upperTextContainer.Height = "10vh"; upperTextContainer.Width = "10vw"; Container footerContainer = new Container(new Text("Try: \"Alexa, play Video 1.\"")); footerContainer.Height = "10vh"; footerContainer.Width = "10vw"; TouchWrapper[] tr = new TouchWrapper[names.Length]; for (int i = 0; i < names.Length; i++) { tr[i] = new TouchWrapper( //Touchwrapper for each list item new Container( // Containner for each list item with Video Thumbnail and Video name new APLComponent[] { new Image(imgUrls[i]) { Height = "50vh", Width = "50vh" }, new Text(names[i]) { MaxLines = 2, Spacing = 12 } }) { MaxWidth = 528, MinWidth = 312, PaddingLeft = 16, PaddingRight = 16, Height = "100%" }) { Id = ID[i], OnPress = new SendEvent() }; } Sequence seq = new Sequence(tr); seq.ScrollDirection = "horizontal"; seq.Height = "70vh"; seq.Width = "100%"; seq.Numbered = true; Container mainContainer = new Container(seq); mainContainer.Height = "80vh"; mainContainer.Width = "80vw"; Container outerContainer = new Container(upperTextContainer, mainContainer, footerContainer); outerContainer.Direction = "row"; response.Response.Directives.Add(new RenderDocumentDirective { Token = "MainDocument", Document = new Response.APL.APLDocument { MainTemplate = new Response.APL.Layout(outerContainer) } }); Log.Output("APL Response Started Building"); Reprompt reprompt = new Reprompt("Which video do you want to play? "); response.Response.OutputSpeech = new PlainTextOutputSpeech { Text = "Welcome to ASMR Video. Select a video to start playing or ask for help." }; Log.Output(JsonConvert.SerializeObject(response)); return(response); }
public void Update(TouchWrapper touch) { _isDirty = true; _lastPosition = touch.position; }
private static APLComponent GetTouchWrappedItem(MediaItem mediaItem) { bool isSpot = Core.Device.IsRound; Container empty = new Container(); // touch input interface TouchWrapper touchWrapper = new TouchWrapper() { AlignSelf = "center", OnPress = new SendEvent { Arguments = new List <string> { mediaItem.Title, mediaItem.VideoSource } } }; // component container Container container = new Container() { Direction = "column", AlignItems = "center", Width = isSpot ? DisplayHelper.GetWidth(1f) : DisplayHelper.GetWidth(0.3f), Height = isSpot ? DisplayHelper.GetHeight(0.8f) : DisplayHelper.GetHeight(0.4f), Spacing = isSpot ? DisplayHelper.GetHeight(0) : DisplayHelper.GetHeight(0.01f) }; // thumbnail image Image thumbnail = new Image(mediaItem.Thumbnail) { AlignSelf = "center", Width = isSpot ? DisplayHelper.GetWidth(0.7f) : DisplayHelper.GetWidth(0.22f), Height = isSpot ? DisplayHelper.GetHeight(0.4f) : DisplayHelper.GetHeight(0.2f), Spacing = isSpot ? DisplayHelper.GetHeight(0.03f) : DisplayHelper.GetHeight(0.05f), BorderRadius = new APLDimensionValue("10px") }; // name of the media Text mediaName = new Text(mediaItem.Title) { MaxLines = 2, Color = TextColor, FontWeight = FontWeight, FontSize = isSpot ? "28dp" : "24dp", TextAlign = isSpot ? "center" : "left", PaddingLeft = isSpot ? new APLDimensionValue("0px") : new APLDimensionValue("20px"), //Left = isSpot ? new AbsoluteDimension(0, "px") : new AbsoluteDimension(25, "px"), Width = isSpot ? DisplayHelper.GetWidth(0.8f) : DisplayHelper.GetWidth(0.25f), Height = isSpot ? DisplayHelper.GetHeight(0.15f) : DisplayHelper.GetHeight(0.09f), Spacing = isSpot ? DisplayHelper.GetHeight(0.02f) : DisplayHelper.GetHeight(0.02f) }; // view count Text views = new Text($"{mediaItem.Views} plays") { Color = TextColor, FontWeight = FontWeight, FontSize = isSpot ? "20dp" : "20dp", TextAlign = isSpot ? "center" : "left", PaddingLeft = isSpot ? new APLDimensionValue("0px") : new APLDimensionValue("20px"), Height = DisplayHelper.GetHeight(0.08f), // this does nothing Width = isSpot ? DisplayHelper.GetWidth(0.6f) : DisplayHelper.GetWidth(0.25f), }; // show index if spot Text index = new Text($"{mediaItem.Id} of {MediaItems.GetMediaItems().Count}") { Color = TextColor, TextAlign = "center", FontSize = "18dp", Height = DisplayHelper.GetHeight(0.1f), // this does nothing }; // set components container.Items = isSpot ? new List <APLComponent> { thumbnail, mediaName, views, index } : new List <APLComponent> { empty, thumbnail, mediaName, views }; touchWrapper.Item = new List <APLComponent> { container }; return(touchWrapper); }
private static TouchWrapper RMBToTouchWrapper() { TouchWrapper touch = new TouchWrapper (); touch.position = Input.mousePosition; touch.touchId = RMB_TOUCH_ID; touch.deltaTime = Time.time - _RMBDownStartTime; return touch; }
public void Update(TouchWrapper touch) { _isDirty = true; _lastPosition = touch.position; }
public void BeginTracking(TouchWrapper touch) { _isActive = true; _isDirty = true; _fingerId = touch.touchId; _lastPosition = touch.position; }
private void EndDoubleTouch(TouchWrapper firstTouch, TouchWrapper secondTouch, Transform target1, Vector3 position1, Vector3 direction1, Vector3 groundPosition1, bool isFindFirstTarget, Transform target2, Vector3 position2, Vector3 direction2, Vector3 groundPosition2, bool isFindSecondTarget, TwoFingerTouchUpdateEvent evt, bool isFindCenterTarget, Transform targetCenter, Vector3 positionCenter, Vector3 directionCenter, Vector3 groundPositionCenter) { if (isFindFirstTarget) { if (target1 != null) { evt.target1 = target1; evt.position1 = target1.position; } else { evt.position1 = position1; } } evt.direction1 = direction1; evt.groundPosition1 = groundPosition1; if (isFindSecondTarget) { if (target2 != null) { evt.target2 = target2; evt.position2 = target2.position; } else { evt.position2 = position2; } } evt.direction2 = direction2; evt.groundPosition2 = groundPosition2; if (isFindCenterTarget) { if (targetCenter != null) { evt.targetCenter = targetCenter; evt.positionCenter = targetCenter.position; } else { evt.positionCenter = positionCenter; } } evt.direction2 = direction2; evt.groundPosition2 = groundPosition2; RaiseEvent(evt); }
private static TouchWrapper TouchToTouchWrapper(Touch t) { TouchWrapper touch = new TouchWrapper (); touch.position = t.position; touch.touchId = t.fingerId; touch.deltaTime = t.deltaTime; return touch; }
/// <summary> /// Updates the states of all touches. /// Call once per frame. /// </summary> public void Update() { // Clear all active trackers dirty state. for (int i = 0; i < _trackers.Length; i++) { TouchTracker tracker = _trackers [i]; if (tracker.IsActive) { tracker.IsDirty = false; } } // Process all touches... int touchCount = Input.touches.Length; for (int i = 0; i < touchCount; i++) { Touch touch = Input.touches [i]; TouchWrapper touchWrapper = TouchToTouchWrapper(touch); // Are we already tracking this finger? TouchTracker tracker = GetExistingTracker(touch.fingerId); if (touch.phase == TouchPhase.Began) { // If the tracker for this finger is already existing, // but the touch phase is just beginning, then this is // a different touch event. End the previous event, and detect // a new event. if (tracker != null) { DoTrackingEnd(tracker); tracker = null; } // New finger detected - start tracking if possible. if (tracker == null) { tracker = GetNewTracker(); if (tracker != null) { DoTrackingBegin(tracker, touchWrapper); } } } else { // Update the tracker. if (tracker != null) { DoTrackingUpdate(tracker, touchWrapper); } } } #if UNITY_EDITOR || UNITY_STANDALONE || UNITY_WEBPLAYER // Mouse. { DoMouseProcessing(0, LMB_TOUCH_ID, ref _LMBDownStartTime, LMBToTouchWrapper); DoMouseProcessing(1, RMB_TOUCH_ID, ref _RMBDownStartTime, RMBToTouchWrapper); } #endif // Deactivate all active trackers that weren't updated this frame so they can be re-used. // Ideally, TouchPhase.Ended could be used to do this, but it is not reliable. for (int i = 0; i < _trackers.Length; i++) { TouchTracker tracker = _trackers [i]; if (tracker.IsActive && !tracker.IsDirty) { DoTrackingEnd(tracker); } } }
private bool FindTargetAndLocation(TouchWrapper touch, out Transform target, out Vector3 location, out Vector3 groundPosition, out Vector3 direction) { target = null; if (Camera.main == null) { location = default(Vector3); groundPosition = default(Vector3); direction = default(Vector3); return(false); } if (mMainCamera == null) { mMainCamera = Camera.main; } Ray ray = mMainCamera.ScreenPointToRay(new Vector3(Mathf.Clamp(touch.position.x, 0, Screen.width), Mathf.Clamp(touch.position.y, 0, Screen.height), 0.0f)); RaycastHit rayHit; groundPosition = default(Vector3); direction = default(Vector3); location = default(Vector3); if (Physics.Raycast(ray, out rayHit, 200, _groundLayer)) { groundPosition = rayHit.point; } //Check raycast first for best precision if (Physics.Raycast(ray, out rayHit, 200, _characterLayers | _groundLayer)) { if (PlayerManager.IsPlayer(rayHit.transform.gameObject)) { target = rayHit.transform; } else if (rayHit.transform.gameObject.layer != LayerMask.NameToLayer("Ground")) { Selectable selectable = rayHit.transform.GetComponent <Selectable>(); if (selectable == null) { //If raycast couldn't find a selectable widen to an overlap sphere cast and pick closest selectable Collider[] colliders = Physics.OverlapSphere(rayHit.point, fingerRadius, 1 << LayerMask.NameToLayer("Enemy")); if (colliders.Length > 0) { float minSqDistance = float.MaxValue; Collider closestCollider = colliders[0]; foreach (Collider collider in colliders) { float sqrDistance = Vector3.SqrMagnitude(collider.transform.position - rayHit.point); if (sqrDistance < minSqDistance) { minSqDistance = sqrDistance; closestCollider = collider; } } selectable = closestCollider.gameObject.GetComponent <Selectable>(); } } //Move or target selectable if (selectable != null) { target = selectable.transform; } else { target = null; } } //if the object has a ServerCallback then call it!! if (rayHit.transform.gameObject != null) { MeshClick callback = rayHit.transform.gameObject.GetComponent <MeshClick>(); if (callback != null) { target = callback.transform; } } if (target != null) { location = target.transform.position; } else { location = groundPosition; } if (_playerTransform != null && _muzzleTransform != null) { Vector3 muzzleYOffset = new Vector3(0, _muzzleTransform.position.y - _playerTransform.position.y, 0); location += muzzleYOffset; direction = (groundPosition - _playerTransform.position).normalized; } // todo: FindTargetAndLocation called many times //Debug.LogFormat("FindTargetAndLocation: location = {0}", location.ToString()); if (!AStarPathfindingUtils.IsPointOnNavMeshOptimized(location)) { return(false); } return(true); } else if (_playerTransform != null) { Plane playerPlane = new Plane(Vector3.up, _playerTransform.position); float enter = 0; if (playerPlane.Raycast(ray, out enter)) { Vector3 hitPoint = ray.GetPoint(enter); direction = (hitPoint - _playerTransform.position).normalized; groundPosition = hitPoint; } } target = null; location = default(Vector3); return(false); }
private void DoTrackingUpdate(TouchTracker tracker, TouchWrapper touch) { tracker.Update (touch); if (OnTouchUpdate != null) { OnTouchUpdate (touch); } }