Esempio n. 1
0
        // --------------
        private SystemTouch StartNewTouch(SystemTouchEventData data)
        {
            SystemTouch newTouch = null;

            for (int i = 0; i < this.touchList.Count; ++i)
            {
                SystemTouch t = this.touchList[i];
                if (!t.touch.IsOn())
                {
                    newTouch = t;
                }
                else if (t.hwId == data.id)
                {
#if UNITY_EDITOR
                    //		Debug.LogWarning("[" + Time.frameCount + "] System tries to start a duplicate touch (" + data.id + ")! Ending the old one (started at frame: " + t.startFrame + ").");
#endif
                    t.touch.End(true);
                }
            }


            if (newTouch != null)
            {
                newTouch.elapsedSinceLastAction = 0;
                newTouch.hwId       = data.id;
                newTouch.startFrame = Time.frameCount;

                newTouch.touch.Start(data.pos, data.pos, data.cam, data.isMouseEvent);

                return(newTouch);
            }

            return(null);
        }
Esempio n. 2
0
        // -------------------
        public void OnSystemTouchStart(SystemTouchEventData data)
        {
            if (!this.IsInitialized)
            {
                return;
            }


            if (this.rig != null)
            {
                this.rig.WakeTouchControlsUp();
            }

            SystemTouch t = this.StartNewTouch(data);

            if (t == null)
            {
                return;
            }


            this.Prepare();

            if (this.hitPool.HitTest(this.controls, data.pos, data.cam, MAX_RAYCAST_HITS, this.fingerRadInPx,
                                     t.touch.DirectTouchControlFilter) > 0)
            {
                for (int i = 0; i < this.hitPool.GetList().Count; ++i)
                {
                    TouchControl.Hit hit = this.hitPool.GetList()[i];
                    if ((hit == null) || (hit.c == null))
                    {
                        continue;
                    }


                    // If this touch is already shared by other controls...

                    if (hit.c.dontAcceptSharedTouches && (t.touch.GetControlCount() > 0))
                    {
                        continue;
                    }

                    if (hit.c.OnTouchStart(t.touch, null, TouchControl.TouchStartType.DirectPress))
                    {
                        // Stop sharing this touch if a control doesn't allow it...

                        if (!hit.c.shareTouch)
                        {
                            break;
                        }
                    }
                    else
                    {
                    }
                }
            }
            else
            {
            }
        }
        // --------------
        private SystemTouch FindTouch(int hwId)
        {
            for (int i = 0; i < this.touchList.Count; ++i)
            {
                SystemTouch t = this.touchList[i];
                if (t.touch.IsOn() && (t.hwId == hwId))
                {
                    return(t);
                }
            }

            return(null);
        }
        // -----------------
        public TouchControlPanel() : base()
        {
            this.controls = new List <TouchControl>(16);

            this.hitPool = new TouchControl.HitPool();
            this.hitPool.EnsureCapacity(MAX_RAYCAST_HITS);

            // Init system touch list...

            this.touchList = new List <SystemTouch>(MAX_SYSTEM_TOUCHES);

            for (int i = 0; i < MAX_SYSTEM_TOUCHES; ++i)
            {
                SystemTouch t = new SystemTouch(this);

                this.touchList.Add(t);
            }
        }
        // ----------------------
        public void OnSystemTouchEnd(SystemTouchEventData data)
        {
            if (!this.IsInitialized)
            {
                return;
            }

            if (this.rig != null)
            {
                this.rig.WakeTouchControlsUp();
            }


            SystemTouch t = this.FindTouch(data.id);

            if (t == null)
            {
                return;
            }

            t.touch.End(false);
        }
        // ---------------
        private void UpdateTouchPressure()
        {
#if !UNITY_PRE_5_3
            if (UnityEngine.Input.touchPressureSupported)
            {
                for (int i = 0; i < UnityEngine.Input.touchCount; ++i)
                {
                    UnityEngine.Touch t = UnityEngine.Input.GetTouch(i);
                    if ((t.phase == TouchPhase.Canceled) || (t.phase == TouchPhase.Ended))
                    {
                        continue;
                    }

                    SystemTouch st = this.FindTouch(t.fingerId);
                    if (st == null)
                    {
                        continue;
                    }

                    st.touch.SetPressure(t.pressure, t.maximumPossiblePressure);
                }
            }
#endif
        }
        // ----------------------
        public void OnSystemTouchMove(SystemTouchEventData data)
        {
            if (!this.IsInitialized)
            {
                return;
            }

            if (this.rig != null)
            {
                this.rig.WakeTouchControlsUp();
            }

            SystemTouch t = this.FindTouch(data.id);

            if (t == null)
            {
                return;
            }


            t.WakeUp();

            Vector2 pos = data.pos;

#if UNITY_EDITOR
            mSkipTouchScreenPixels = Mathf.Clamp(mSkipTouchScreenPixels, 0, 10);
            if (mSkipTouchScreenPixels > 0)
            {
                pos.x = (float)((mSkipTouchScreenPixels + 1) * (Mathf.RoundToInt(pos.x) / (mSkipTouchScreenPixels + 1)));
                pos.y = (float)((mSkipTouchScreenPixels + 1) * (Mathf.RoundToInt(pos.y) / (mSkipTouchScreenPixels + 1)));
            }
#endif

            t.touch.Move(pos, data.cam);



            // Handle swipe over...

            List <TouchControl>
            restrictedSwipeOverTargetList = t.touch.GetRestrictedSwipeOverTargetList();
            List <TouchControl>
            swipeOverTargetList = ((restrictedSwipeOverTargetList != null) ? restrictedSwipeOverTargetList : this.controls);



            if ((swipeOverTargetList.Count > 0) &&
                (this.hitPool.HitTest(swipeOverTargetList, t.touch.screenPosCur, t.touch.cam, MAX_RAYCAST_HITS, 0) > 0))
            {
                for (int ci = 0; ci < this.hitPool.GetList().Count; ++ci)
                {
                    TouchControl c = this.hitPool.GetList()[ci].c;
                    if (!c.IsActive())
                    {
                        continue;
                    }

                    if ((restrictedSwipeOverTargetList == null) ? c.CanBeSwipedOverFromNothing(t.touch) : c.CanBeSwipedOverFromRestrictedList(t.touch))
                    {
                        if (c.OnTouchStart(t.touch, null, TouchControl.TouchStartType.SwipeOver))
                        {
                            if (!c.shareTouch)
                            {
                                break;
                            }
                        }
                    }
                }
            }
        }