I have a pause camera that rotates around a closeup of my character while showing the options on the right. For controller support on PC I went ahead an faked a mouse pointer that is controlled with the left stick. It was a bigger pain than I thought getting it working but I did about 90%. So here is my code.
protected override MouseState GetMousePointerEventData(int id)
{
MouseState m = new MouseState();
var screenSpaceCursorPosition = pauseCamera.WorldToScreenPoint(m_VirtualCursor.position);
// Populate the left button...
PointerEventData leftData;
var created = GetPointerData(kMouseLeftId, out leftData, true);
leftData.Reset();
if (created)
leftData.position = screenSpaceCursorPosition;
//leftData.position = Input.mousePosition;
//Vector2 pos = Input.mousePosition;
Vector2 pos = screenSpaceCursorPosition;
leftData.delta = pos - leftData.position;
leftData.position = pos;
leftData.scrollDelta = Input.mouseScrollDelta;
//leftData.button = PointerEventData.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
PointerEventData rightData;
GetPointerData(kMouseRightId, out rightData, true);
CopyFromTo(leftData, rightData);
rightData.button = PointerEventData.InputButton.Right;
PointerEventData middleData;
GetPointerData(kMouseMiddleId, out middleData, true);
CopyFromTo(leftData, middleData);
middleData.button = PointerEventData.InputButton.Middle;
PointerEventData.FramePressState selectState = PointerEventData.FramePressState.NotChanged;
if (Input.GetButtonDown("JoySubmit"))
selectState = PointerEventData.FramePressState.Pressed;
else if (Input.GetButtonUp("JoySubmit"))
selectState = PointerEventData.FramePressState.Released;
m_MouseState.SetButtonState(PointerEventData.InputButton.Left, selectState, leftData);
m_MouseState.SetButtonState(PointerEventData.InputButton.Right, StateForMouseButton(1), rightData);
m_MouseState.SetButtonState(PointerEventData.InputButton.Middle, StateForMouseButton(2), middleData);
return m_MouseState;
}
The issue seems to be the world space calculation. Using this code while the camera or player was moving makes the mouse over blink in and out as well as making them have odd and unpredictable location updates at times. If you stand perfectly still and I disable the code that spins the camera around the player it works great. Any thoughts on how I can counter this issue?
-Alexander