示例#1
0
        public UserInputManager(int maxFingers)
        {
            Service.Set <UserInputManager>(this);
            int num = 4;

            this.observers = new List <IUserInputObserver> [num];
            for (UserInputLayer userInputLayer = UserInputLayer.InternalLowest; userInputLayer <= UserInputLayer.Screen; userInputLayer++)
            {
                int num2 = userInputLayer - UserInputLayer.InternalLowest;
                this.observers[num2] = new List <IUserInputObserver>();
            }
            this.miter              = new MutableIterator();
            this.niter              = new MutableIterator();
            this.fingerIds          = new int[maxFingers];
            this.lastIsPressed      = new bool[maxFingers];
            this.lastScreenPosition = new Vector2[maxFingers];
            this.lastLayer          = new UserInputLayer[maxFingers];
            this.lastEntity         = new Entity[maxFingers];
            this.lastPlanet         = new Planet[maxFingers];
            for (int i = 0; i < maxFingers; i++)
            {
                this.ResetTouch(i);
            }
            this.clickThrough = new HashSet <GameObject>();
            this.inited       = false;
            this.enabled      = false;
        }
示例#2
0
        protected bool Raycast(UserInputLayer layer, Vector3 screenPosition, ref GameObject gameObjectHit, ref Vector3 groundPosition)
        {
            bool flag = false;

            switch (layer)
            {
            case UserInputLayer.InternalLowest:
                flag = this.activeWorldCamera.GetGroundPosition(screenPosition, ref groundPosition);
                break;

            case UserInputLayer.World:
                flag = this.RaycastHelper(this.activeWorldCamera, screenPosition, ref gameObjectHit);
                flag = (this.activeWorldCamera.GetGroundPosition(screenPosition, ref groundPosition) | flag);
                break;

            case UserInputLayer.UX:
            {
                GameObject gameObject = gameObjectHit;
                flag = this.RaycastHelper(this.uxCamera, screenPosition, ref gameObject);
                if (flag && this.clickThrough.Contains(gameObject))
                {
                    return(false);
                }
                if (flag && UnityUtils.ShouldIgnoreUIGameObjectInRaycast(gameObject))
                {
                    return(false);
                }
                gameObjectHit = gameObject;
                break;
            }
            }
            return(flag);
        }
示例#3
0
        private void HandleMouseChanges()
        {
            bool           mouseButton    = Input.GetMouseButton(0);
            Vector3        mousePosition  = Input.mousePosition;
            Vector2        vector         = new Vector2(mousePosition.x, mousePosition.y);
            UserInputLayer userInputLayer = UserInputLayer.InternalNone;
            GameObject     gameObject     = null;
            Vector3        zero           = Vector3.zero;
            bool           flag           = this.lastIsPressed[0] != mouseButton;
            bool           flag2          = this.lastScreenPosition[0] != vector;

            if (mouseButton | flag2)
            {
                if (mouseButton && !flag)
                {
                    if (this.lastLayer[0] != UserInputLayer.UX)
                    {
                        base.Raycast(UserInputLayer.World, vector, ref gameObject, ref zero);
                    }
                    userInputLayer = this.lastLayer[0];
                    gameObject     = base.GetLastGameObject(0);
                }
                else if (base.Raycast(UserInputLayer.UX, vector, ref gameObject, ref zero))
                {
                    userInputLayer = UserInputLayer.UX;
                }
                else if (base.Raycast(UserInputLayer.World, vector, ref gameObject, ref zero))
                {
                    userInputLayer = ((gameObject == null) ? UserInputLayer.InternalLowest : UserInputLayer.World);
                }
            }
            else
            {
                userInputLayer = this.lastLayer[0];
            }
            this.lastIsPressed[0]      = mouseButton;
            this.lastScreenPosition[0] = vector;
            this.lastLayer[0]          = userInputLayer;
            base.SetLastGameObject(0, gameObject);
            UserInputLayer lowestLayer = (userInputLayer == UserInputLayer.UX) ? UserInputLayer.Screen : UserInputLayer.InternalLowest;

            if (flag)
            {
                if (mouseButton)
                {
                    base.SendOnPress(0, gameObject, vector, zero, lowestLayer);
                }
                else
                {
                    base.SendOnRelease(0, lowestLayer);
                }
            }
            if (mouseButton)
            {
                base.SendOnDrag(0, gameObject, vector, zero, lowestLayer);
            }
        }
示例#4
0
        protected UserInputLayer GetLowestLayer(UserInputLayer thisLayer)
        {
            UserInputLayer result = UserInputLayer.InternalLowest;

            if (thisLayer == UserInputLayer.UX)
            {
                result = thisLayer + 1;
            }
            return(result);
        }
示例#5
0
 public void UnregisterAll()
 {
     this.Enable(false);
     for (UserInputLayer userInputLayer = UserInputLayer.InternalLowest; userInputLayer <= UserInputLayer.Screen; userInputLayer++)
     {
         int num = userInputLayer - UserInputLayer.InternalLowest;
         this.observers[num] = new List <IUserInputObserver>();
     }
     this.miter.Reset();
     this.niter.Reset();
     this.clickThrough.Clear();
 }
示例#6
0
        public void UnregisterObserver(IUserInputObserver observer, UserInputLayer layer)
        {
            int num  = layer - UserInputLayer.InternalLowest;
            int num2 = this.observers[num].IndexOf(observer);

            if (num2 >= 0)
            {
                this.observers[num].RemoveAt(num2);
                this.miter.OnRemove(num2);
                this.niter.OnRemove(num2);
            }
        }
示例#7
0
        public void RegisterObserver(IUserInputObserver observer, UserInputLayer layer)
        {
            if (observer == null)
            {
                return;
            }
            int num = layer - UserInputLayer.InternalLowest;

            if (this.observers[num].IndexOf(observer) < 0)
            {
                this.observers[num].Add(observer);
            }
        }
示例#8
0
 protected void SendOnScroll(float delta, Vector2 screenPosition, UserInputLayer lowestLayer)
 {
     for (UserInputLayer userInputLayer = UserInputLayer.Screen; userInputLayer >= lowestLayer; userInputLayer--)
     {
         int num = userInputLayer - UserInputLayer.InternalLowest;
         this.miter.Init(this.observers[num]);
         while (this.miter.Active())
         {
             IUserInputObserver userInputObserver = this.observers[num][this.miter.Index];
             if (userInputObserver.OnScroll(delta, screenPosition) == EatResponse.Eaten)
             {
                 this.miter.Reset();
                 return;
             }
             this.miter.Next();
         }
         this.miter.Reset();
     }
 }
示例#9
0
 protected void SendOnRelease(int touchIndex, UserInputLayer lowestLayer)
 {
     for (UserInputLayer userInputLayer = UserInputLayer.Screen; userInputLayer >= lowestLayer; userInputLayer--)
     {
         int num = userInputLayer - UserInputLayer.InternalLowest;
         this.miter.Init(this.observers[num]);
         while (this.miter.Active())
         {
             IUserInputObserver userInputObserver = this.observers[num][this.miter.Index];
             if (userInputObserver.OnRelease(touchIndex) == EatResponse.Eaten)
             {
                 this.miter.Reset();
                 return;
             }
             this.miter.Next();
         }
         this.miter.Reset();
     }
 }
示例#10
0
 protected void SendOnDrag(int touchIndex, GameObject target, Vector2 screenPosition, Vector3 groundPosition, UserInputLayer lowestLayer)
 {
     for (UserInputLayer userInputLayer = UserInputLayer.Screen; userInputLayer >= lowestLayer; userInputLayer--)
     {
         int num = userInputLayer - UserInputLayer.InternalLowest;
         this.miter.Init(this.observers[num]);
         while (this.miter.Active())
         {
             IUserInputObserver userInputObserver = this.observers[num][this.miter.Index];
             if (userInputObserver.OnDrag(touchIndex, target, screenPosition, groundPosition) == EatResponse.Eaten)
             {
                 this.miter.Reset();
                 return;
             }
             this.miter.Next();
         }
         this.miter.Reset();
     }
 }
示例#11
0
        public void ReleaseSubordinates(IUserInputObserver observer, UserInputLayer layer, int id)
        {
            int num  = layer - UserInputLayer.InternalLowest;
            int num2 = this.observers[num].IndexOf(observer);

            if (num2 >= 0)
            {
                bool flag = false;
                this.niter.Init(this.observers[num]);
                this.niter.Index = num2 + 1;
                while (this.niter.Active())
                {
                    observer = this.observers[num][this.niter.Index];
                    if (observer.OnRelease(id) == EatResponse.Eaten)
                    {
                        flag = true;
                        break;
                    }
                    this.niter.Next();
                }
                this.niter.Reset();
                num--;
                while (num >= 0 && !flag)
                {
                    this.niter.Init(this.observers[num]);
                    while (this.niter.Active())
                    {
                        observer = this.observers[num][this.niter.Index];
                        if (observer.OnRelease(id) == EatResponse.Eaten)
                        {
                            flag = true;
                            break;
                        }
                        this.niter.Next();
                    }
                    this.niter.Reset();
                    num--;
                }
            }
        }
示例#12
0
        private void HandleTouchChanges()
        {
            int i   = 0;
            int num = Input.touches.Length;

            while (i < num)
            {
                Touch touch    = Input.touches[i];
                int   fingerId = touch.fingerId;
                int   num2     = this.FindTouch(fingerId);
                switch (touch.phase)
                {
                case TouchPhase.Began:
                    if (num2 < 0)
                    {
                        num2 = this.FindTouch(-1);
                        if (num2 >= 0)
                        {
                            Vector2        position       = touch.position;
                            UserInputLayer userInputLayer = UserInputLayer.InternalNone;
                            GameObject     gameObject     = null;
                            Vector3        zero           = Vector3.zero;
                            if (base.Raycast(UserInputLayer.UX, position, ref gameObject, ref zero))
                            {
                                userInputLayer = UserInputLayer.UX;
                            }
                            else if (base.Raycast(UserInputLayer.World, position, ref gameObject, ref zero))
                            {
                                userInputLayer = ((gameObject == null) ? UserInputLayer.InternalLowest : UserInputLayer.World);
                            }
                            this.fingerIds[num2]          = fingerId;
                            this.lastIsPressed[num2]      = true;
                            this.lastScreenPosition[num2] = position;
                            this.lastLayer[num2]          = userInputLayer;
                            base.SetLastGameObject(num2, gameObject);
                            UserInputLayer lowestLayer = (userInputLayer == UserInputLayer.UX) ? UserInputLayer.Screen : UserInputLayer.InternalLowest;
                            base.SendOnPress(num2, gameObject, position, zero, lowestLayer);
                        }
                    }
                    break;

                case TouchPhase.Moved:
                case TouchPhase.Stationary:
                    if (num2 >= 0)
                    {
                        Vector2    position2 = touch.position;
                        GameObject target    = null;
                        Vector3    zero2     = Vector3.zero;
                        base.Raycast(UserInputLayer.InternalLowest, position2, ref target, ref zero2);
                        target = base.GetLastGameObject(num2);
                        this.lastScreenPosition[num2] = position2;
                        UserInputLayer lowestLayer2 = (this.lastLayer[num2] == UserInputLayer.UX) ? UserInputLayer.Screen : UserInputLayer.InternalLowest;
                        base.SendOnDrag(num2, target, position2, zero2, lowestLayer2);
                    }
                    break;

                case TouchPhase.Ended:
                case TouchPhase.Canceled:
                    if (num2 >= 0)
                    {
                        UserInputLayer lowestLayer3 = (this.lastLayer[num2] == UserInputLayer.UX) ? UserInputLayer.Screen : UserInputLayer.InternalLowest;
                        base.ResetTouch(num2);
                        base.SendOnRelease(num2, lowestLayer3);
                    }
                    break;
                }
                i++;
            }
        }