public IMouseInputSource GetMouseInputSource(int playerId, int mouseIndex)
        {
            if (mouseIndex < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(mouseIndex));
            }
            if (this.m_MouseInputSourcesList.Count == 0 && this.IsDefaultPlayer(playerId))
            {
                return(this.defaultMouseInputSource);
            }
            int count = this.m_MouseInputSourcesList.Count;
            int num   = 0;

            for (int index = 0; index < count; ++index)
            {
                IMouseInputSource mouseInputSources = this.m_MouseInputSourcesList[index];
                if (!UnityTools.IsNullOrDestroyed <IMouseInputSource>((M0)mouseInputSources) && mouseInputSources.get_playerId() == playerId)
                {
                    if (mouseIndex == num)
                    {
                        return(mouseInputSources);
                    }
                    ++num;
                }
            }
            return((IMouseInputSource)null);
        }
        protected PointerEventData.FramePressState StateForMouseButton(int playerId, int mouseIndex, int buttonId)
        {
            IMouseInputSource mouseInputSource = GetMouseInputSource(playerId, mouseIndex);

            if (mouseInputSource == null)
            {
                return(PointerEventData.FramePressState.NotChanged);
            }
            var pressed  = mouseInputSource.GetButtonDown(buttonId);
            var released = mouseInputSource.GetButtonUp(buttonId);

            if (pressed && released)
            {
                return(PointerEventData.FramePressState.PressedAndReleased);
            }
            if (pressed)
            {
                return(PointerEventData.FramePressState.Pressed);
            }
            if (released)
            {
                return(PointerEventData.FramePressState.Released);
            }
            return(PointerEventData.FramePressState.NotChanged);
        }
Пример #3
0
            public void UpdateFromSource(IMouseInputSource source)
            {
                this.IsAvailable = source != null ? source.IsAvailable : false;
                if (source == null)
                {
                    return;
                }

                this.WindowPos = source.Pos;
                this.Wheel     = source.Wheel;
                for (int i = 0; i < this.ButtonPressed.Length; i++)
                {
                    this.ButtonPressed[i] = source[(MouseButton)i];
                }

                // Map window position to game view position
                Rect    viewportRect;
                Vector2 gameViewSize;

                DualityApp.CalculateGameViewport(DualityApp.WindowSize, out viewportRect, out gameViewSize);
                Vector2 relativePos = new Vector2(
                    MathF.Clamp((this.WindowPos.X - viewportRect.X) / viewportRect.W, 0.0f, 1.0f),
                    MathF.Clamp((this.WindowPos.Y - viewportRect.Y) / viewportRect.H, 0.0f, 1.0f));

                this.ViewPos = relativePos * gameViewSize;
            }
        /// <summary>
        /// Gets or sets the input source used for mouse input.
        /// </summary>
        /// <param name="playerId">The Player Id that owns the mouse input source.</param>
        /// <param name="mouseIndex">The index of the mouse input source. If a Player owns more than one mouse input source, set this to the index. See <see cref="GetMouseInputSourceCount"/> to determine the number of mouse input sources that exist for a Player.</param>
        public IMouseInputSource GetMouseInputSource(int playerId, int mouseIndex)
        {
            if (mouseIndex < 0)
            {
                throw new ArgumentOutOfRangeException("mouseIndex");
            }
            if (m_MouseInputSourcesList.Count == 0 && IsDefaultPlayer(playerId))
            {
                return(defaultMouseInputSource);                                                                // fall back to default if nothing set
            }
            int count        = m_MouseInputSourcesList.Count;
            int pointerCount = 0;

            for (int i = 0; i < count; i++)
            {
                IMouseInputSource source = m_MouseInputSourcesList[i];
                if (Utils.UnityTools.IsNullOrDestroyed(source))
                {
                    continue;
                }
                if (source.playerId != playerId)
                {
                    continue;
                }
                if (mouseIndex == pointerCount)
                {
                    return(source);
                }
                pointerCount++;
            }
            return(null);
        }
        // Token: 0x06002D4A RID: 11594 RVA: 0x0013AEE4 File Offset: 0x001390E4
        protected PointerEventData.FramePressState StateForMouseButton(int playerId, int mouseIndex, int buttonId)
        {
            IMouseInputSource mouseInputSource = this.GetMouseInputSource(playerId, mouseIndex);

            if (mouseInputSource == null)
            {
                return(PointerEventData.FramePressState.NotChanged);
            }
            bool buttonDown = mouseInputSource.GetButtonDown(buttonId);
            bool buttonUp   = mouseInputSource.GetButtonUp(buttonId);

            if (buttonDown && buttonUp)
            {
                return(PointerEventData.FramePressState.PressedAndReleased);
            }
            if (buttonDown)
            {
                return(PointerEventData.FramePressState.Pressed);
            }
            if (buttonUp)
            {
                return(PointerEventData.FramePressState.Released);
            }
            return(PointerEventData.FramePressState.NotChanged);
        }
        // Token: 0x06002D31 RID: 11569 RVA: 0x0013A4A8 File Offset: 0x001386A8
        public IMouseInputSource GetMouseInputSource(int playerId, int mouseIndex)
        {
            if (mouseIndex < 0)
            {
                throw new ArgumentOutOfRangeException("mouseIndex");
            }
            if (this.m_MouseInputSourcesList.Count == 0 && this.IsDefaultPlayer(playerId))
            {
                return(this.defaultMouseInputSource);
            }
            int count = this.m_MouseInputSourcesList.Count;
            int num   = 0;

            for (int i = 0; i < count; i++)
            {
                IMouseInputSource mouseInputSource = this.m_MouseInputSourcesList[i];
                if (!UnityTools.IsNullOrDestroyed <IMouseInputSource>(mouseInputSource) && mouseInputSource.playerId == playerId)
                {
                    if (mouseIndex == num)
                    {
                        return(mouseInputSource);
                    }
                    num++;
                }
            }
            return(null);
        }
        protected virtual void ProcessMove(PlayerPointerEventData pointerEvent)
        {
            GameObject targetGO;

            if (pointerEvent.sourceType == PointerEventType.Mouse)
            {
                IMouseInputSource source = GetMouseInputSource(pointerEvent.playerId, pointerEvent.inputSourceIndex);
                if (source != null)
                {
                    targetGO = !source.enabled || source.locked ? null : pointerEvent.pointerCurrentRaycast.gameObject;
                }
                else
                {
                    targetGO = null;
                }
            }
            else if (pointerEvent.sourceType == PointerEventType.Touch)
            {
                targetGO = pointerEvent.pointerCurrentRaycast.gameObject;
            }
            else
            {
                throw new NotImplementedException();
            }
            HandlePointerExitAndEnter(pointerEvent, targetGO);
        }
 public void AddMouseInputSource(IMouseInputSource source)
 {
     if (UnityTools.IsNullOrDestroyed <IMouseInputSource>((M0)source))
     {
         throw new ArgumentNullException(nameof(source));
     }
     this.m_MouseInputSourcesList.Add(source);
 }
 /// <summary>
 /// Removes the mouse input source.
 /// </summary>
 /// <param name="source">The mouse input source.</param>
 public void RemoveMouseInputSource(IMouseInputSource source)
 {
     if (source == null)
     {
         throw new ArgumentNullException("source");                // do not check if destroyed here so removal works on destroyed objects
     }
     m_MouseInputSourcesList.Remove(source);
 }
 public void RemoveMouseInputSource(IMouseInputSource source)
 {
     if (source == null)
     {
         throw new ArgumentNullException(nameof(source));
     }
     this.m_MouseInputSourcesList.Remove(source);
 }
 /// <summary>
 /// Adds the mouse input source.
 /// </summary>
 /// <param name="source">The mouse input source.</param>
 public void AddMouseInputSource(IMouseInputSource source)
 {
     if (Utils.UnityTools.IsNullOrDestroyed(source))
     {
         throw new ArgumentNullException("source");
     }
     m_MouseInputSourcesList.Add(source);
 }
Пример #12
0
			public void UpdateFromSource(IMouseInputSource source)
			{
				if (source == null) return;
				this.X = source.X;
				this.Y = source.Y;
				this.Wheel = source.Wheel;
				this.CursorInView = source.CursorInView;
				for (int i = 0; i < this.ButtonPressed.Length; i++)
				{
					this.ButtonPressed[i] = source[(MouseButton)i];
				}
			}
Пример #13
0
			public void UpdateFromSource(IMouseInputSource source)
			{
				this.IsAvailable = source != null ? source.IsAvailable : false;
				if (source == null) return;

				this.X = source.X;
				this.Y = source.Y;
				this.Wheel = source.Wheel;
				for (int i = 0; i < this.ButtonPressed.Length; i++)
				{
					this.ButtonPressed[i] = source[(MouseButton)i];
				}
			}
Пример #14
0
 public void UpdateFromSource(IMouseInputSource source)
 {
     if (source == null)
     {
         return;
     }
     this.X            = source.X;
     this.Y            = source.Y;
     this.Wheel        = source.Wheel;
     this.CursorInView = source.CursorInView;
     for (int i = 0; i < this.ButtonPressed.Length; i++)
     {
         this.ButtonPressed[i] = source[(MouseButton)i];
     }
 }
Пример #15
0
            public void UpdateFromSource(IMouseInputSource source)
            {
                this.IsAvailable = source != null ? source.IsAvailable : false;
                if (source == null)
                {
                    return;
                }

                this.X     = source.X;
                this.Y     = source.Y;
                this.Wheel = source.Wheel;
                for (int i = 0; i < this.ButtonPressed.Length; i++)
                {
                    this.ButtonPressed[i] = source[(MouseButton)i];
                }
            }
        public int GetMouseInputSourceCount(int playerId)
        {
            if (this.m_MouseInputSourcesList.Count == 0 && this.IsDefaultPlayer(playerId))
            {
                return(1);
            }
            int count = this.m_MouseInputSourcesList.Count;
            int num   = 0;

            for (int index = 0; index < count; ++index)
            {
                IMouseInputSource mouseInputSources = this.m_MouseInputSourcesList[index];
                if (!UnityTools.IsNullOrDestroyed <IMouseInputSource>((M0)mouseInputSources) && mouseInputSources.get_playerId() == playerId)
                {
                    ++num;
                }
            }
            return(num);
        }
        // Token: 0x06002D34 RID: 11572 RVA: 0x0013A528 File Offset: 0x00138728
        public int GetMouseInputSourceCount(int playerId)
        {
            if (this.m_MouseInputSourcesList.Count == 0 && this.IsDefaultPlayer(playerId))
            {
                return(1);
            }
            int count = this.m_MouseInputSourcesList.Count;
            int num   = 0;

            for (int i = 0; i < count; i++)
            {
                IMouseInputSource mouseInputSource = this.m_MouseInputSourcesList[i];
                if (!UnityTools.IsNullOrDestroyed <IMouseInputSource>(mouseInputSource) && mouseInputSource.playerId == playerId)
                {
                    num++;
                }
            }
            return(num);
        }
        protected virtual void ProcessDrag(PlayerPointerEventData pointerEvent)
        {
            if (!pointerEvent.IsPointerMoving() || pointerEvent.pointerDrag == null)
            {
                return;
            }
            if (pointerEvent.sourceType == PointerEventType.Mouse)
            {
                IMouseInputSource source = GetMouseInputSource(pointerEvent.playerId, pointerEvent.inputSourceIndex);
                if (source == null || source.locked || !source.enabled)
                {
                    return;
                }
            }

            if (!pointerEvent.dragging &&
                ShouldStartDrag(pointerEvent.pressPosition, pointerEvent.position, eventSystem.pixelDragThreshold, pointerEvent.useDragThreshold))
            {
                ExecuteEvents.Execute(pointerEvent.pointerDrag, pointerEvent, ExecuteEvents.beginDragHandler);
                pointerEvent.dragging = true;
            }

            // Drag notification
            if (pointerEvent.dragging)
            {
                // Before doing drag we should cancel any pointer down state
                // And clear selection!
                if (pointerEvent.pointerPress != pointerEvent.pointerDrag)
                {
                    ExecuteEvents.Execute(pointerEvent.pointerPress, pointerEvent, ExecuteEvents.pointerUpHandler);

                    pointerEvent.eligibleForClick = false;
                    pointerEvent.pointerPress     = null;
                    pointerEvent.rawPointerPress  = null;
                }
                ExecuteEvents.Execute(pointerEvent.pointerDrag, pointerEvent, ExecuteEvents.dragHandler);
            }
        }
        /// <summary>
        /// Returns the number of possible pointers.
        /// Does not count the number actually assigned.
        /// </summary>
        public int GetMouseInputSourceCount(int playerId)
        {
            if (m_MouseInputSourcesList.Count == 0 && IsDefaultPlayer(playerId))
            {
                return(1);                                                                // fall back to default if nothing set
            }
            int count        = m_MouseInputSourcesList.Count;
            int pointerCount = 0;

            for (int i = 0; i < count; i++)
            {
                IMouseInputSource source = m_MouseInputSourcesList[i];
                if (Utils.UnityTools.IsNullOrDestroyed(source))
                {
                    continue;
                }
                if (source.playerId != playerId)
                {
                    continue;
                }
                pointerCount++;
            }
            return(pointerCount);
        }
        protected PointerEventData.FramePressState StateForMouseButton(
            int playerId,
            int mouseIndex,
            int buttonId)
        {
            IMouseInputSource mouseInputSource = this.GetMouseInputSource(playerId, mouseIndex);

            if (mouseInputSource == null)
            {
                return((PointerEventData.FramePressState) 3);
            }
            bool buttonDown = mouseInputSource.GetButtonDown(buttonId);
            bool buttonUp   = mouseInputSource.GetButtonUp(buttonId);

            if (buttonDown && buttonUp)
            {
                return((PointerEventData.FramePressState) 2);
            }
            if (buttonDown)
            {
                return((PointerEventData.FramePressState) 0);
            }
            return(buttonUp ? (PointerEventData.FramePressState) 1 : (PointerEventData.FramePressState) 3);
        }
        // Token: 0x060022EA RID: 8938 RVA: 0x000A49A8 File Offset: 0x000A2BA8
        protected override RewiredPointerInputModule.MouseState GetMousePointerEventData(int playerId, int mouseIndex)
        {
            IMouseInputSource mouseInputSource = base.GetMouseInputSource(playerId, mouseIndex);

            if (mouseInputSource == null)
            {
                return(null);
            }
            PlayerPointerEventData playerPointerEventData;
            bool pointerData = base.GetPointerData(playerId, mouseIndex, -1, out playerPointerEventData, true, PointerEventType.Mouse);

            playerPointerEventData.Reset();
            if (pointerData)
            {
                playerPointerEventData.position = base.input.mousePosition;
            }
            Vector2 mousePosition = base.input.mousePosition;

            if (mouseInputSource.locked)
            {
                playerPointerEventData.position = new Vector2(-1f, -1f);
                playerPointerEventData.delta    = Vector2.zero;
            }
            else
            {
                playerPointerEventData.delta    = mousePosition - playerPointerEventData.position;
                playerPointerEventData.position = mousePosition;
            }
            playerPointerEventData.scrollDelta = mouseInputSource.wheelDelta;
            playerPointerEventData.button      = PointerEventData.InputButton.Left;
            base.eventSystem.RaycastAll(playerPointerEventData, this.m_RaycastResultCache);
            RaycastResult pointerCurrentRaycast = BaseInputModule.FindFirstRaycast(this.m_RaycastResultCache);

            playerPointerEventData.pointerCurrentRaycast = pointerCurrentRaycast;
            this.UpdateHover(this.m_RaycastResultCache);
            this.m_RaycastResultCache.Clear();
            PlayerPointerEventData playerPointerEventData2;

            base.GetPointerData(playerId, mouseIndex, -2, out playerPointerEventData2, true, PointerEventType.Mouse);
            base.CopyFromTo(playerPointerEventData, playerPointerEventData2);
            playerPointerEventData2.button = PointerEventData.InputButton.Right;
            PlayerPointerEventData playerPointerEventData3;

            base.GetPointerData(playerId, mouseIndex, -3, out playerPointerEventData3, true, PointerEventType.Mouse);
            base.CopyFromTo(playerPointerEventData, playerPointerEventData3);
            playerPointerEventData3.button = PointerEventData.InputButton.Middle;
            for (int i = 3; i < mouseInputSource.buttonCount; i++)
            {
                PlayerPointerEventData playerPointerEventData4;
                base.GetPointerData(playerId, mouseIndex, -2147483520 + i, out playerPointerEventData4, true, PointerEventType.Mouse);
                base.CopyFromTo(playerPointerEventData, playerPointerEventData4);
                playerPointerEventData4.button = (PointerEventData.InputButton)(-1);
            }
            this.m_MouseState.SetButtonState(0, base.StateForMouseButton(playerId, mouseIndex, 0), playerPointerEventData);
            this.m_MouseState.SetButtonState(1, base.StateForMouseButton(playerId, mouseIndex, 1), playerPointerEventData2);
            this.m_MouseState.SetButtonState(2, base.StateForMouseButton(playerId, mouseIndex, 2), playerPointerEventData3);
            for (int j = 3; j < mouseInputSource.buttonCount; j++)
            {
                PlayerPointerEventData data;
                base.GetPointerData(playerId, mouseIndex, -2147483520 + j, out data, false, PointerEventType.Mouse);
                this.m_MouseState.SetButtonState(j, base.StateForMouseButton(playerId, mouseIndex, j), data);
            }
            return(this.m_MouseState);
        }
Пример #22
0
		/// <summary>
		/// Assigns a new input source for mouse input.
		/// </summary>
		/// <param name="source"></param>
		public static void SetInputSource(IMouseInputSource source)
		{
			mouse.Source = source;
		}
 protected bool IsDefaultMouse(IMouseInputSource mouse)
 {
     return(this.defaultMouseInputSource == mouse);
 }
        protected virtual RewiredPointerInputModule.MouseState GetMousePointerEventData(
            int playerId,
            int mouseIndex)
        {
            IMouseInputSource mouseInputSource = this.GetMouseInputSource(playerId, mouseIndex);

            if (mouseInputSource == null)
            {
                return((RewiredPointerInputModule.MouseState)null);
            }
            PlayerPointerEventData data1;
            bool pointerData = this.GetPointerData(playerId, mouseIndex, -1, out data1, true, PointerEventType.Mouse);

            ((AbstractEventData)data1).Reset();
            if (pointerData)
            {
                data1.set_position(mouseInputSource.get_screenPosition());
            }
            Vector2 screenPosition = mouseInputSource.get_screenPosition();

            if (mouseInputSource.get_locked())
            {
                data1.set_position(new Vector2(-1f, -1f));
                data1.set_delta(Vector2.get_zero());
            }
            else
            {
                data1.set_delta(Vector2.op_Subtraction(screenPosition, data1.get_position()));
                data1.set_position(screenPosition);
            }
            data1.set_scrollDelta(mouseInputSource.get_wheelDelta());
            data1.set_button((PointerEventData.InputButton) 0);
            this.get_eventSystem().RaycastAll((PointerEventData)data1, (List <RaycastResult>) this.m_RaycastResultCache);
            RaycastResult firstRaycast = BaseInputModule.FindFirstRaycast((List <RaycastResult>) this.m_RaycastResultCache);

            data1.set_pointerCurrentRaycast(firstRaycast);
            ((List <RaycastResult>) this.m_RaycastResultCache).Clear();
            PlayerPointerEventData data2;

            this.GetPointerData(playerId, mouseIndex, -2, out data2, true, PointerEventType.Mouse);
            this.CopyFromTo((PointerEventData)data1, (PointerEventData)data2);
            data2.set_button((PointerEventData.InputButton) 1);
            PlayerPointerEventData data3;

            this.GetPointerData(playerId, mouseIndex, -3, out data3, true, PointerEventType.Mouse);
            this.CopyFromTo((PointerEventData)data1, (PointerEventData)data3);
            data3.set_button((PointerEventData.InputButton) 2);
            for (int index = 3; index < mouseInputSource.get_buttonCount(); ++index)
            {
                PlayerPointerEventData data4;
                this.GetPointerData(playerId, mouseIndex, index - 2147483520, out data4, true, PointerEventType.Mouse);
                this.CopyFromTo((PointerEventData)data1, (PointerEventData)data4);
                data4.set_button((PointerEventData.InputButton) - 1);
            }
            this.m_MouseState.SetButtonState(0, this.StateForMouseButton(playerId, mouseIndex, 0), data1);
            this.m_MouseState.SetButtonState(1, this.StateForMouseButton(playerId, mouseIndex, 1), data2);
            this.m_MouseState.SetButtonState(2, this.StateForMouseButton(playerId, mouseIndex, 2), data3);
            for (int index = 3; index < mouseInputSource.get_buttonCount(); ++index)
            {
                PlayerPointerEventData data4;
                this.GetPointerData(playerId, mouseIndex, index - 2147483520, out data4, false, PointerEventType.Mouse);
                this.m_MouseState.SetButtonState(index, this.StateForMouseButton(playerId, mouseIndex, index), data4);
            }
            return(this.m_MouseState);
        }
        protected virtual MouseState GetMousePointerEventData(int playerId, int mouseIndex)
        {
            IMouseInputSource mouseInputSource = GetMouseInputSource(playerId, mouseIndex);

            if (mouseInputSource == null)
            {
                return(null);
            }

            // Populate the left button...
            PlayerPointerEventData leftData;
            var created = GetPointerData(playerId, mouseIndex, kMouseLeftId, out leftData, true, PointerEventType.Mouse);

            leftData.Reset();

            if (created)
            {
                leftData.position = mouseInputSource.screenPosition;
            }

            Vector2 pos = mouseInputSource.screenPosition;

            if (mouseInputSource.locked || !mouseInputSource.enabled)
            {
                // We don't want to do ANY cursor-based interaction when the mouse is locked
                leftData.position = new Vector2(-1.0f, -1.0f);
                leftData.delta    = Vector2.zero;
            }
            else
            {
                leftData.delta    = pos - leftData.position;
                leftData.position = pos;
            }

            leftData.scrollDelta = mouseInputSource.wheelDelta;
            leftData.button      = PlayerPointerEventData.InputButton.Left;
            eventSystem.RaycastAll(leftData, m_RaycastResultCache);
            var raycast = FindFirstRaycast(m_RaycastResultCache);

            leftData.pointerCurrentRaycast = raycast;
            m_RaycastResultCache.Clear();

            // copy the apropriate data into right and middle slots
            PlayerPointerEventData rightData;

            GetPointerData(playerId, mouseIndex, kMouseRightId, out rightData, true, PointerEventType.Mouse);
            CopyFromTo(leftData, rightData);
            rightData.button = PlayerPointerEventData.InputButton.Right;

            PlayerPointerEventData middleData;

            GetPointerData(playerId, mouseIndex, kMouseMiddleId, out middleData, true, PointerEventType.Mouse);
            CopyFromTo(leftData, middleData);
            middleData.button = PlayerPointerEventData.InputButton.Middle;

            // Do remaining buttons
            for (int i = 3; i < mouseInputSource.buttonCount; i++)
            {
                PlayerPointerEventData data;
                GetPointerData(playerId, mouseIndex, customButtonsStartingId + i, out data, true, PointerEventType.Mouse);
                CopyFromTo(leftData, data);
                data.button = (PlayerPointerEventData.InputButton)(-1);
            }

            m_MouseState.SetButtonState(0, StateForMouseButton(playerId, mouseIndex, 0), leftData);
            m_MouseState.SetButtonState(1, StateForMouseButton(playerId, mouseIndex, 1), rightData);
            m_MouseState.SetButtonState(2, StateForMouseButton(playerId, mouseIndex, 2), middleData);
            // Do remaining buttons
            for (int i = 3; i < mouseInputSource.buttonCount; i++)
            {
                PlayerPointerEventData data;
                GetPointerData(playerId, mouseIndex, customButtonsStartingId + i, out data, false, PointerEventType.Mouse);
                m_MouseState.SetButtonState(i, StateForMouseButton(playerId, mouseIndex, i), data);
            }

            return(m_MouseState);
        }