private void AddNewPointer(PointerID id, Entity pressed, Entity hover)
 {
     Debugging.Assert.IsTrue(GetPointer(id) == null);
     pointers.Add(new PointerControlInteraction {
         id = id, pressed = pressed, hover = hover
     });
 }
Esempio n. 2
0
        private static void GetTouchState(InputSystem input, ref NativeList <PointerState> pointers)
        {
            int touchCount = input.TouchCount();

            for (int i = 0; i < touchCount; i++)
            {
                if (pointers.Length == MaxPointers)
                {
                    break;
                }

                var  touch          = input.GetTouch(i);
                var  worldPoint     = input.TranslateScreenToWorld(new float2(touch.x, touch.y));
                bool touchDown      = touch.phase == TouchState.Began;
                bool touchUp        = touch.phase == TouchState.Ended;
                bool touchCancelled = touch.phase == TouchState.Canceled;

                var          touchPointerId = new PointerID(PointerType.Touch, touch.fingerId);
                bool         willGone       = touchUp;
                PointerState touchPointer   = new PointerState()
                {
                    id        = touchPointerId,
                    pos       = worldPoint.xy,
                    down      = touchDown,
                    up        = touchUp,
                    willGone  = willGone,
                    cancelled = touchCancelled
                };

                pointers.Add(touchPointer);
            }
        }
        public Entity GetHoverControl(PointerID id)
        {
            var pointer = GetPointer(id);

            if (pointer == null)
            {
                return(Entity.Null);
            }

            return(pointer.hover);
        }
        public Entity GetPressedControl(PointerID id)
        {
            var pointer = GetPointer(id);

            if (pointer == null)
            {
                return(Entity.Null);
            }

            return(pointer.pressed);
        }
        private PointerControlInteraction GetPointer(PointerID id)
        {
            foreach (var item in pointers)
            {
                if (item.id.Equals(id))
                {
                    return(item);
                }
            }

            return(null);
        }
        public void SetHover(PointerID id, Entity control)
        {
            var pointer = GetPointer(id);

            if (pointer != null)
            {
                pointer.hover = control;
            }
            else if (control != Entity.Null)
            {
                AddNewPointer(id, Entity.Null, control);
            }
        }
        public void SetPressed(PointerID id, Entity control)
        {
            var pointer = GetPointer(id);

            if (pointer != null)
            {
                pointer.pressed = control;
            }
            else if (control != Entity.Null)
            {
                AddNewPointer(id, control, Entity.Null);
            }
        }
 public void ClearHover(PointerID id)
 {
     SetHover(id, Entity.Null);
 }
 public void ClearPressed(PointerID id)
 {
     SetPressed(id, Entity.Null);
 }