bool CheckInteractionType(InteractableComponent.INTERACTION_TYPE _interactionType)
 {
     if (_interactionType == InteractableComponent.INTERACTION_TYPE.ON_CLICK)
     {
         TouchTracker tm = TouchInputManager.GetInstance().m_TouchTracker[0];
         if (tm.GetTouchBegan())
         {
             return(true);
         }
     }
     else if (_interactionType == InteractableComponent.INTERACTION_TYPE.ON_LONG_PRESS)
     {
         TouchTracker tm = TouchInputManager.GetInstance().m_TouchTracker[0];
         if (tm.m_TouchDidBegin && !tm.m_TouchDidMove && tm.GetTimeSinceTouchBegan() > 0.5f)
         {
             return(true);
         }
     }
     else if (_interactionType == InteractableComponent.INTERACTION_TYPE.ON_CLICK_UP)
     {
         TouchTracker tm = TouchInputManager.GetInstance().m_TouchTracker[0];
         if (tm.GetTouchEnded())
         {
             return(true);
         }
     }
     return(false);
 }
Example #2
0
    /**
     * Clear a tracker from being updated, tell it to stop
     */
    public void EndTracking(TouchTracker tracker)
    {
        tracker.End();

        trackers.Remove(tracker);
        trackerLookup[tracker.fingerId] = null;
    }
Example #3
0
    private void OnTrackerCreated()
    {
        if (moveTracker == null)
        {
            moveTracker         = theTouchManager.GetNewTouchTracker("move");
            moveTracker.OnBegan = (Touch touch, ref Player player) =>
            {
                player.SetupTouchOffset(touch);
            };

            moveTracker.OnStationary = moveTracker.OnMoved = (Touch touch, ref Player player) =>
            {
                player.CalculateDestination(touch.position);
            };

            moveTracker.OnFrame = (Touch touch, ref Player player) =>
            {
                player.Move();
            };
        }
        else if (shotTracker == null)
        {
            shotTracker         = theTouchManager.GetNewTouchTracker("shot");
            shotTracker.OnBegan = (Touch touch, ref Player player) =>
            {
                player.StartShooting();
            };
            shotTracker.OnEnded = (Touch touch, ref Player player) =>
            {
                player.StopShooting();
            };
        }
    }
Example #4
0
 private void DoTrackingBegin(TouchTracker tracker, TouchWrapper touch)
 {
     tracker.BeginTracking(touch);
     if (OnTouchBegin != null)
     {
         OnTouchBegin(touch);
     }
 }
Example #5
0
 private void DoTrackingEnd(TouchTracker tracker)
 {
     if (OnTouchEnd != null)
     {
         OnTouchEnd(tracker.FingerId, tracker.LastPosition);
     }
     tracker.EndTracking();
 }
Example #6
0
    public TouchTracker BeginTracking(iPhoneTouch touch)
    {
        TouchTracker tracker = new TouchTracker(touch);
        trackers.Add(tracker);
        trackerLookup[touch.fingerId] = tracker;

        return tracker;
    }
Example #7
0
 private void DoTrackingUpdate(TouchTracker tracker, TouchWrapper touch)
 {
     tracker.Update(touch);
     if (OnTouchUpdate != null)
     {
         OnTouchUpdate(touch);
     }
 }
Example #8
0
    /**
     * Start up a tracker for a fingerid
     */
    public TouchTracker BeginTracking(Touch touch)
    {
        TouchTracker tracker = new TouchTracker(touch);

        // remember our tracker
        trackers.Add(tracker);
        trackerLookup[touch.fingerId] = tracker;
        return(tracker);
    }
 public override void Disable()
 {
     m_TrackLeft  = null;
     m_TrackRight = null;
     m_leftDelta  = Vector2.zero;
     m_rightDelta = Vector2.zero;
     OnLeftDelta?.Invoke(m_leftDelta);
     OnRightDelta?.Invoke(m_rightDelta);
     UIT_JoyStick.Instance.OnDeactivate();
 }
Example #10
0
 /// <summary>
 /// Manually clear all currently active touches.
 /// </summary>
 public void ClearTouches()
 {
     for (int i = 0; i < _trackers.Length; i++)
     {
         TouchTracker tracker = _trackers [i];
         if (tracker.IsActive)
         {
             DoTrackingEnd(tracker);
         }
     }
 }
Example #11
0
        /// <summary>
        /// Creates a new TouchObserver.
        /// maxTouchCount # of touches will be monitored.
        /// Any touches over this number will be ignored.
        /// </summary>
        public TouchObserver(int maxTouchCount)
        {
            MAX_TOUCH_TRACKER_COUNT = maxTouchCount;

            // Allocate.
            {
                _trackers = new TouchTracker[MAX_TOUCH_TRACKER_COUNT];
                for (int i = 0; i < MAX_TOUCH_TRACKER_COUNT; i++) {
                    _trackers [i] = new TouchTracker ();
                }
            }
        }
Example #12
0
 private int CompareByTime(TouchTracker a, TouchTracker b)
 {
     if (a.timeCreated > b.timeCreated)
     {
         return(-1);
     }
     if (a.timeCreated < b.timeCreated)
     {
         return(1);
     }
     return(0);
 }
Example #13
0
        /// <summary>
        /// Creates a new TouchObserver.
        /// maxTouchCount # of touches will be monitored.
        /// Any touches over this number will be ignored.
        /// </summary>
        public TouchObserver(int maxTouchCount)
        {
            MAX_TOUCH_TRACKER_COUNT = maxTouchCount;

            // Allocate.
            {
                _trackers = new TouchTracker[MAX_TOUCH_TRACKER_COUNT];
                for (int i = 0; i < MAX_TOUCH_TRACKER_COUNT; i++)
                {
                    _trackers [i] = new TouchTracker();
                }
            }
        }
Example #14
0
        private TouchTracker GetNewTracker()
        {
            for (int i = 0; i < _trackers.Length; i++)
            {
                TouchTracker tracker = _trackers [i];
                if (!tracker.IsActive)
                {
                    return(tracker);
                }
            }

            return(null);
        }
Example #15
0
        private TouchTracker GetExistingTracker(int fingerId)
        {
            for (int i = 0; i < _trackers.Length; i++)
            {
                TouchTracker tracker = _trackers [i];
                if (tracker.IsActive && tracker.FingerId == fingerId)
                {
                    return(tracker);
                }
            }

            return(null);
        }
Example #16
0
    private void OnTrackerLost(string trackerName)
    {
        switch (trackerName)
        {
        case "move":
            moveTracker = null;
            break;

        case "shot":
            shotTracker = null;
            break;
        }
    }
Example #17
0
    TouchTracker GetTouchTracker(Touch t)
    {
        TouchTracker ret;

        if (!touchTrackers.TryGetValue(t.fingerId, out ret))
        {
            ret = new TouchTracker(t);
            touchTrackers.Add(t.fingerId, ret);
        }
        if (t.phase == TouchPhase.Began)
        {
            ret.Reset(t);
        }
        return(ret);
    }
Example #18
0
    /**
     * Update all of our trackers
     */
    public void Update()
    {
        // clean all touches (so they know if they aren't updated after we pull info)
        foreach (TouchTracker tracker in trackers)
        {
            tracker.Clean();
        }

        // process our touches
        foreach (Touch touch in Input.touches)
        {
            // try to get our tracker for this finger id
            TouchTracker tracker = (TouchTracker)trackerLookup[touch.fingerId];

            if (tracker != null)
            {
                tracker.UpdateTouch(touch, 1);
            }
            else
            {
                tracker = BeginTracking(touch);
            }

            // iPhoneTouchPhase.Ended isn't very reliable (especially with the remote)

            /*
             * if(touch.phase == iPhoneTouchPhase.Ended)
             *      EndTracking(tracker);
             */
        }

        // track which events vanished (without using iPhoneTouchPhase.Ended)
        List <TouchTracker> ended = new List <TouchTracker>();

        // use an intermediate list because EndTracking removes from trackers arraylist
        foreach (TouchTracker tracker in trackers)
        {
            if (!tracker.isDirty)
            {
                ended.Add(tracker);
            }
        }

        foreach (TouchTracker tracker in ended)
        {
            EndTracking(tracker);
        }
    }
Example #19
0
    public TouchTracker GetNewTouchTracker(string name)
    {
        List <TouchTracker> notUsedTouchTrackers = touchTrackers.FindAll((TouchTracker el) => el.name == "default");

        if (notUsedTouchTrackers.Count > 0)
        {
            notUsedTouchTrackers.Sort(CompareByTime);
            TouchTracker chosen = notUsedTouchTrackers[notUsedTouchTrackers.Count - 1];
            chosen.name = name;
            return(chosen);
        }
        else
        {
            return(null);
        }
    }
Example #20
0
    private void HandleMultipleTouch()
    {
        for (int index = 0; index < Input.touchCount; index++)
        {
            Touch        currentTouch = Input.GetTouch(index);
            TouchTracker tracker      = null;

            if (currentTouch.phase == TouchPhase.Began)
            {
                tracker = new TouchTracker(currentTouch.fingerId, Time.time);
                touchTrackers.Add(tracker);

                OnTrackerCreated?.Invoke();

                tracker.OnBegan?.Invoke(currentTouch, ref thePlayer);
            }
            else if (currentTouch.phase == TouchPhase.Stationary)
            {
                tracker = touchTrackers.Find((TouchTracker touchTracker) => touchTracker.fingerID == currentTouch.fingerId);

                tracker.OnStationary?.Invoke(currentTouch, ref thePlayer);
            }
            else if (currentTouch.phase == TouchPhase.Moved)
            {
                tracker = touchTrackers.Find((TouchTracker touchTracker) => touchTracker.fingerID == currentTouch.fingerId);

                tracker.OnMoved?.Invoke(currentTouch, ref thePlayer);
            }
            else if (currentTouch.phase == TouchPhase.Ended)
            {
                tracker = touchTrackers.Find((TouchTracker touchTracker) => touchTracker.fingerID == currentTouch.fingerId);

                tracker.OnEnded?.Invoke(currentTouch, ref thePlayer);

                touchTrackers.Remove(tracker);
                OnTrackerLost?.Invoke(tracker.name);
            }
            tracker.OnFrame?.Invoke(currentTouch, ref thePlayer);
        }
    }
Example #21
0
        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);
                }
            }
        }
Example #22
0
 private void DoTrackingBegin(TouchTracker tracker, TouchWrapper touch)
 {
     tracker.BeginTracking (touch);
     if (OnTouchBegin != null) {
         OnTouchBegin (touch);
     }
 }
Example #23
0
        /// <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);
                }
            }
        }
Example #24
0
 void EndTracking(TouchTracker tracker)
 {
     tracker.End();
     trackers.Remove(tracker);
     trackerLookup[tracker.fingerId] = null;
 }
Example #25
0
 private void DoTrackingUpdate(TouchTracker tracker, TouchWrapper touch)
 {
     tracker.Update (touch);
     if (OnTouchUpdate != null) {
         OnTouchUpdate (touch);
     }
 }
Example #26
0
    void TouchControl()
    {
        foreach (var t in touchTrackers)
        {
            t.Value.isValid = false;
        }
        if (Input.touchCount > 0)
        {
            for (int i = 0; i < Input.touchCount; ++i)
            {
                Touch        t     = Input.GetTouch(i);
                TouchTracker tt    = GetTouchTracker(t);
                var          trail = Instantiate(Resources.Load <GameObject>("Trail"), GameObject.Find("Canvas").transform);
                (trail.transform as RectTransform).anchoredPosition = ScreenToCanvasPos(t.position);
                (trail.transform as RectTransform).localScale       = 30 * Vector3.one;
                tt.isValid  = true;
                tt.velocity = t.position - tt.lastPos;

                // start
                float cpos = GetCordPos();
                if (t.position.x > cpos)
                {
                    float right = t.position.x - cpos;
                    if (right > tt.rightMax)
                    {
                        tt.rightMax = right;
                    }
                }
                if (t.position.x < cpos)
                {
                    float left = cpos - t.position.x;
                    if (left > tt.leftMax)
                    {
                        tt.leftMax = left;
                    }
                }
                if (t.position.x > cpos && tt.lastPos.x < cpos)
                {
                    tt.rightToLeftCount++;

                    if (tt.leftToRightCount == tt.rightToLeftCount)
                    {
                        float newTime   = Time.time;
                        float deltaTime = newTime - tt.time;
                        if (tt.leftMax > 0 && tt.rightMax > 0)
                        {
                            tt.cordLength      = tt.leftMax + tt.rightMax;
                            tt.cordLengthComps = tt.leftMax + "+" + tt.rightMax;
                            tt.speed           = tt.cordLength / deltaTime;
                        }
                        tt.time    = newTime;
                        tt.leftMax = tt.rightMax = -1;
                    }

                    tt.speed = tt.velocity.magnitude;
                }
                if (t.position.x < cpos && tt.lastPos.x > cpos)
                {
                    tt.leftToRightCount++;

                    if (tt.leftToRightCount == tt.rightToLeftCount)
                    {
                        float newTime   = Time.time;
                        float deltaTime = newTime - tt.time;
                        if (tt.leftMax > 0 && tt.rightMax > 0)
                        {
                            tt.cordLength      = tt.leftMax + tt.rightMax;
                            tt.cordLengthComps = tt.leftMax + "+" + tt.rightMax;
                            tt.speed           = tt.cordLength / deltaTime;
                        }
                        tt.time    = newTime;
                        tt.leftMax = tt.rightMax = -1;
                    }
                }
                // end

                tt.lastPos = t.position;
            }
        }
    }
    public override void Tick(float deltaTime)
    {
        if (UIT_JoyStick.Instance == null)
        {
            return;
        }

        m_rightDelta = Vector2.zero;
        int touchCount = Input.touchCount;

        for (int i = 0; i < touchCount; i++)
        {
            Touch t = Input.GetTouch(i);
            if (t.phase == TouchPhase.Began)
            {
                TouchTracker track = new TouchTracker(t);
                if (m_TrackLeft == null && track.isLeft && track.isDown)
                {
                    m_TrackLeft = track;
                    UIT_JoyStick.Instance.OnActivate(m_TrackLeft.v2_startPos);
                    m_leftDelta = Vector2.zero;
                }
                else if (m_TrackRight == null && !track.isLeft)
                {
                    m_TrackRight = track;
                }
            }
            else if (t.phase == TouchPhase.Ended || t.phase == TouchPhase.Canceled)
            {
                if (m_TrackLeft != null && t.fingerId == m_TrackLeft.m_Touch.fingerId)
                {
                    m_TrackLeft = null;
                    UIT_JoyStick.Instance.OnDeactivate();
                    m_leftDelta = Vector2.zero;
                }
                if (m_TrackRight != null && t.fingerId == m_TrackRight.m_Touch.fingerId)
                {
                    m_TrackRight = null;
                }
            }
            else if (t.phase == TouchPhase.Moved)
            {
                if (m_TrackRight != null && t.fingerId == m_TrackRight.m_Touch.fingerId)
                {
                    m_TrackRight.Record(t);
                    m_rightDelta = t.deltaPosition;
                }
                else if (m_TrackLeft != null && t.fingerId == m_TrackLeft.m_Touch.fingerId)
                {
                    m_TrackLeft.Record(t);
                    m_leftDelta = UIT_JoyStick.Instance.OnMoved(t.position);
                }
            }
        }

#if UNITY_EDITOR
        m_leftDelta  = new Vector2(Input.GetAxis("Horizontal"), Input.GetAxis("Vertical"));
        m_rightDelta = new Vector2(Input.GetAxis("Mouse X"), Input.GetAxis("Mouse Y"));
#endif

        if (OnCanSendDelta != null && !OnCanSendDelta())
        {
            m_leftDelta  = Vector2.zero;
            m_rightDelta = Vector2.zero;
        }

        OnLeftDelta?.Invoke(m_leftDelta);
        OnRightDelta?.Invoke(m_rightDelta);
    }
Example #28
0
 private void DoTrackingEnd(TouchTracker tracker)
 {
     if (OnTouchEnd != null) {
         OnTouchEnd (tracker.FingerId, tracker.LastPosition);
     }
     tracker.EndTracking ();
 }