示例#1
0
        //tracker
        IEnumerator TrackPointer()
        {
            var _raycaster = GetComponentInParent <GraphicRaycaster>();
            var _input     = FindObjectOfType <StandaloneInputModule>();

            if (_raycaster != null && _input != null && _mainEngine.Initialized)
            {
                while (Application.isPlaying)
                {
                    Vector2 localPos = GetScreenCoords(_raycaster, _input);

                    int px = (int)localPos.x;
                    int py = (int)localPos.y;

                    ProcessScrollInput(px, py);


                    if (posX != px || posY != py)
                    {
                        MouseMessage msg = new MouseMessage
                        {
                            Type        = MouseEventType.Move,
                            X           = px,
                            Y           = py,
                            GenericType = MessageLibrary.BrowserEventType.Mouse,
                            // Delta = e.Delta,
                            Button = MouseButton.None
                        };


                        if (Input.GetMouseButton(0))
                        {
                            msg.Button = MouseButton.Left;
                        }
                        if (Input.GetMouseButton(1))
                        {
                            msg.Button = MouseButton.Right;
                        }
                        if (Input.GetMouseButton(2))
                        {
                            msg.Button = MouseButton.Middle;
                        }

                        posX = px;
                        posY = py;
                        _mainEngine.SendMouseEvent(msg);
                    }

                    yield return(0);
                }
            }
            //  else
            //      UnityEngine.Debug.LogWarning("Could not find GraphicRaycaster and/or StandaloneInputModule");
        }
        private void OnMouseOver()
        {
            if (_mainEngine.Initialized)
            {
                var pixelUV = GetScreenCoords();

                if (pixelUV.x > 0)
                {
                    var px = (int)pixelUV.x;
                    var py = (int)pixelUV.y;

                    ProcessScrollInput(px, py);

                    if (posX != px || posY != py)
                    {
                        var msg = new MouseMessage {
                            Type        = MouseEventType.Move,
                            X           = px,
                            Y           = py,
                            GenericType = BrowserEventType.Mouse,
                            // Delta = e.Delta,
                            Button = MouseButton.None
                        };

                        if (Input.GetMouseButton(0))
                        {
                            msg.Button = MouseButton.Left;
                        }
                        if (Input.GetMouseButton(1))
                        {
                            msg.Button = MouseButton.Right;
                        }
                        if (Input.GetMouseButton(1))
                        {
                            msg.Button = MouseButton.Middle;
                        }

                        posX = px;
                        posY = py;
                        _mainEngine.SendMouseEvent(msg);
                    }

                    //check other buttons...
                    if (Input.GetMouseButtonDown(1))
                    {
                        SendMouseButtonEvent(px, py, MouseButton.Right, MouseEventType.ButtonDown);
                    }
                    if (Input.GetMouseButtonUp(1))
                    {
                        SendMouseButtonEvent(px, py, MouseButton.Right, MouseEventType.ButtonUp);
                    }
                    if (Input.GetMouseButtonDown(2))
                    {
                        SendMouseButtonEvent(px, py, MouseButton.Middle, MouseEventType.ButtonDown);
                    }
                    if (Input.GetMouseButtonUp(2))
                    {
                        SendMouseButtonEvent(px, py, MouseButton.Middle, MouseEventType.ButtonUp);
                    }
                }
            }

            // Debug.Log(pixelUV);
        }