|
@ -8,7 +8,7 @@ using UnityEngine.UI; |
|
|
|
|
|
|
|
|
public class TrackballInputManager : MonoBehaviour |
|
|
public class TrackballInputManager : MonoBehaviour |
|
|
{ |
|
|
{ |
|
|
const float defaultMiceSensitivity = 1f; |
|
|
const float defaultMiceSensitivity = 2f; |
|
|
const float upMultiplier = .5f; |
|
|
const float upMultiplier = .5f; |
|
|
const float accelerationThreshold = 40; |
|
|
const float accelerationThreshold = 40; |
|
|
const float accelerationMultiplier = 2; |
|
|
const float accelerationMultiplier = 2; |
|
@ -26,6 +26,8 @@ public class TrackballInputManager : MonoBehaviour |
|
|
public const byte RE_MOUSE = 2; |
|
|
public const byte RE_MOUSE = 2; |
|
|
public const byte RE_DEVICE_DISCONNECT = 1; |
|
|
public const byte RE_DEVICE_DISCONNECT = 1; |
|
|
|
|
|
|
|
|
|
|
|
List<int> _ignoredDevices = new List<int>(); |
|
|
|
|
|
|
|
|
[StructLayout(LayoutKind.Sequential)] |
|
|
[StructLayout(LayoutKind.Sequential)] |
|
|
public struct RawInputEvent |
|
|
public struct RawInputEvent |
|
|
{ |
|
|
{ |
|
@ -44,29 +46,37 @@ public class TrackballInputManager : MonoBehaviour |
|
|
public int playerID; |
|
|
public int playerID; |
|
|
public float sensitivity; |
|
|
public float sensitivity; |
|
|
} |
|
|
} |
|
|
public static TrackballInputManager instance; |
|
|
//public static TrackballInputManager instance;
|
|
|
|
|
|
|
|
|
[SerializeField] List<Player> _players; |
|
|
[SerializeField] List<Player> _players; |
|
|
// Start is called before the first frame update
|
|
|
// Start is called before the first frame update
|
|
|
void Start() |
|
|
void Start() |
|
|
{ |
|
|
{ |
|
|
instance = this; |
|
|
//instance = this;
|
|
|
|
|
|
if (isInit == false) |
|
|
|
|
|
{ |
|
|
bool res = init(); |
|
|
bool res = init(); |
|
|
Debug.Log("Init() ==> " + res); |
|
|
Debug.Log("Init() ==> " + res); |
|
|
|
|
|
isInit = true; |
|
|
|
|
|
} |
|
|
//Debug.Log(Marshal.SizeOf(typeof(RawInputEvent)));
|
|
|
//Debug.Log(Marshal.SizeOf(typeof(RawInputEvent)));
|
|
|
//canvas = GetComponent<Canvas>();
|
|
|
//canvas = GetComponent<Canvas>();
|
|
|
//canvasRect = GetComponent<RectTransform>();
|
|
|
//canvasRect = GetComponent<RectTransform>();
|
|
|
Cursor.lockState = CursorLockMode.Locked; |
|
|
Cursor.lockState = CursorLockMode.Locked; |
|
|
Cursor.visible = false; |
|
|
Cursor.visible = false; |
|
|
|
|
|
|
|
|
|
|
|
_ignoredDevices.Add(4468289); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public void OnDestroy() |
|
|
public void OnDestroy() |
|
|
{ |
|
|
{ |
|
|
instance = null; |
|
|
//instance = null;
|
|
|
|
|
|
kill(); |
|
|
|
|
|
isInit = false; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
int lastEvents = 0; |
|
|
int lastEvents = 0; |
|
|
bool isInit = true; |
|
|
static bool isInit = false; |
|
|
|
|
|
|
|
|
void Update() |
|
|
void Update() |
|
|
{ |
|
|
{ |
|
@ -111,12 +121,15 @@ public class TrackballInputManager : MonoBehaviour |
|
|
player._rigidbody.velocity += new Vector2(dx, -dy); |
|
|
player._rigidbody.velocity += new Vector2(dx, -dy); |
|
|
} |
|
|
} |
|
|
else |
|
|
else |
|
|
|
|
|
{ |
|
|
|
|
|
if (_ignoredDevices.Contains(ev.devHandle) == false) |
|
|
{ |
|
|
{ |
|
|
Debug.Log("Unknown device found"); |
|
|
Debug.Log("Unknown device found"); |
|
|
AddPlayer(ev.devHandle); |
|
|
AddPlayer(ev.devHandle); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
} |
|
|
Marshal.FreeCoTaskMem(data); |
|
|
Marshal.FreeCoTaskMem(data); |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
@ -133,6 +146,9 @@ public class TrackballInputManager : MonoBehaviour |
|
|
int AddPlayer(int deviceId) |
|
|
int AddPlayer(int deviceId) |
|
|
{ |
|
|
{ |
|
|
|
|
|
|
|
|
|
|
|
if (_ignoredDevices.Contains(deviceId)) |
|
|
|
|
|
return -1; |
|
|
|
|
|
|
|
|
if (!isInit) |
|
|
if (!isInit) |
|
|
{ |
|
|
{ |
|
|
Debug.LogError("Not initialized"); |
|
|
Debug.LogError("Not initialized"); |
|
|