private static void setPosition(Vector2 position) { // Convert position from "screen coordinates" to "gui coordinates" position = _panel.GetManager().ScreenToGui(position); // Center the control on the mouse/touch _panel.RelativePosition = position - _cursorOffset; }
void Update() { if (mIsDragging) { Vector2 aPosition = mScreenPanel.GetManager().ScreenToGui(new Vector2(Input.mousePosition.x, Input.mousePosition.y)); aPosition = new Vector2(aPosition.x, 0 - aPosition.y); // TODO: these numbers are hardcoded - copied from the unity gui - figure out how to get this programatically Vector2 relativePosition = new Vector2(aPosition.x - 183, aPosition.y + 123); mSprite.Position = new Vector2(relativePosition.x - mXOffset, relativePosition.y - mYOffset); // Left = 183 // Top = 123 if (!Input.GetMouseButton(0)) { StopDragging(); } mSprite.BringToFront(); } }