Ejemplo n.º 1
0
 public void UnRegisterListener(SceneRaycastHitListener listener)
 {
     if (!transformToListenerDownState.TryGetValue(listener.transform, out var _))
     {
         throw new ArgumentException("Listener <" + listener.gameObject.name + "> was not registered.");
     }
     transformToListenerDownState.Remove(listener.transform);
 }
Ejemplo n.º 2
0
 public void RegisterListener(SceneRaycastHitListener listener)
 {
     if (transformToListenerDownState.TryGetValue(listener.transform, out var _))
     {
         throw new ArgumentException("Listener <" + listener.gameObject.name + "> has already been registered.");
     }
     transformToListenerDownState.Add(listener.transform, listener);
 }
Ejemplo n.º 3
0
        private void Update()
        {
            if (Camera.main == null)
            {
                return;
            }
            secElapsedBetweenRaycasts += Time.deltaTime;
            Vector2    touchPosition;
            TouchPhase touchPhaseAndPosition = GetTouchPhaseAndPosition(out touchPosition);
            int        num;

            switch (touchPhaseAndPosition)
            {
            case TouchPhase.Canceled:
                return;

            default:
                num = ((touchPhaseAndPosition == TouchPhase.Ended) ? 1 : 0);
                break;

            case TouchPhase.Began:
                num = 1;
                break;
            }
            bool flag = (byte)num != 0;

            if (secElapsedBetweenRaycasts > minSecBetweenRaycasts)
            {
                flag = true;
                secElapsedBetweenRaycasts -= minSecBetweenRaycasts;
            }
            if (!flag)
            {
                return;
            }
            Ray ray  = Camera.main.ScreenPointToRay(touchPosition);
            int num2 = Physics.RaycastNonAlloc(ray, raycastHits);

            Array.Sort(raycastHits, (RaycastHit a, RaycastHit b) => a.distance.CompareTo(b.distance));
            bool uiWasHit = EventSystem.current.IsPointerOverGameObject();

            for (int i = 0; i < num2; i++)
            {
                RaycastHit hit = raycastHits[i];
                if (transformToListenerDownState.TryGetValue(hit.transform, out var value))
                {
                    int num3;
                    switch (touchPhaseAndPosition)
                    {
                    case TouchPhase.Began:
                        value.DispatchTouchBegan(hit, i, uiWasHit);
                        continue;

                    case TouchPhase.Ended:
                        num3 = ((!value.IsTouchDown) ? 1 : 0);
                        break;

                    default:
                        num3 = 1;
                        break;
                    }
                    if (num3 == 0)
                    {
                        value.DispatchTouchEnded(hit, i, uiWasHit);
                        value.IsTouchDown = false;
                    }
                    else if (touchPhaseAndPosition == TouchPhase.Moved && value.IsTouchDown)
                    {
                        value.DispatchMoved(hit, i, uiWasHit);
                    }
                    else if (touchPhaseAndPosition == TouchPhase.Stationary && value.IsTouchDown)
                    {
                        value.DispatchStationary(hit, i, uiWasHit);
                    }
                }
            }
            if (touchPhaseAndPosition != TouchPhase.Ended)
            {
                return;
            }
            foreach (KeyValuePair <Transform, SceneRaycastHitListener> item in transformToListenerDownState)
            {
                SceneRaycastHitListener value2 = item.Value;
                value2.IsTouchDown = false;
            }
        }