Browse Source

trackball movement

combinedRaceAndNameDropper
Josh 2 years ago
parent
commit
63c2ed54b3
  1. 84
      namedropper/Assets/Scenes/Game.unity
  2. 4
      namedropper/Assets/Scenes/MouseInputManager.cs
  3. 62
      namedropper/Assets/Scenes/TopicSelect.unity
  4. 3
      namedropper/Assets/Scripts/Player.cs
  5. 166
      namedropper/Assets/TrackballInputManager.cs
  6. 11
      namedropper/Assets/TrackballInputManager.cs.meta

84
namedropper/Assets/Scenes/Game.unity

@ -224,6 +224,17 @@ GameObject:
m_CorrespondingSourceObject: {fileID: 9049015333349338381, guid: 56b5ab1b6ee02794ab9664e282d1930a, type: 3} m_CorrespondingSourceObject: {fileID: 9049015333349338381, guid: 56b5ab1b6ee02794ab9664e282d1930a, type: 3}
m_PrefabInstance: {fileID: 76032778} m_PrefabInstance: {fileID: 76032778}
m_PrefabAsset: {fileID: 0} m_PrefabAsset: {fileID: 0}
--- !u!114 &23812154 stripped
MonoBehaviour:
m_CorrespondingSourceObject: {fileID: 9049015333349338377, guid: 56b5ab1b6ee02794ab9664e282d1930a, type: 3}
m_PrefabInstance: {fileID: 76032778}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 23812149}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 27913ac4da04ed24db893ba625314f05, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!1 &64627487 --- !u!1 &64627487
GameObject: GameObject:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -1037,6 +1048,17 @@ GameObject:
m_CorrespondingSourceObject: {fileID: 9049015333349338381, guid: 56b5ab1b6ee02794ab9664e282d1930a, type: 3} m_CorrespondingSourceObject: {fileID: 9049015333349338381, guid: 56b5ab1b6ee02794ab9664e282d1930a, type: 3}
m_PrefabInstance: {fileID: 2050475643} m_PrefabInstance: {fileID: 2050475643}
m_PrefabAsset: {fileID: 0} m_PrefabAsset: {fileID: 0}
--- !u!114 &707823890 stripped
MonoBehaviour:
m_CorrespondingSourceObject: {fileID: 9049015333349338377, guid: 56b5ab1b6ee02794ab9664e282d1930a, type: 3}
m_PrefabInstance: {fileID: 2050475643}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 707823885}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 27913ac4da04ed24db893ba625314f05, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!1001 &714773755 --- !u!1001 &714773755
PrefabInstance: PrefabInstance:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -3557,6 +3579,7 @@ GameObject:
- component: {fileID: 1641253473} - component: {fileID: 1641253473}
- component: {fileID: 1641253472} - component: {fileID: 1641253472}
- component: {fileID: 1641253474} - component: {fileID: 1641253474}
- component: {fileID: 1641253475}
m_Layer: 0 m_Layer: 0
m_Name: Game m_Name: Game
m_TagString: Untagged m_TagString: Untagged
@ -3617,6 +3640,26 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: d9f0573f6651ecd4b900ae5fee7f7cb6, type: 3} m_Script: {fileID: 11500000, guid: d9f0573f6651ecd4b900ae5fee7f7cb6, type: 3}
m_Name: m_Name:
m_EditorClassIdentifier: m_EditorClassIdentifier:
--- !u!114 &1641253475
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1641253471}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 70de4eb8e48bea54b864b5d20448ee50, type: 3}
m_Name:
m_EditorClassIdentifier:
defaultMiceSensitivity: 1
accelerationThreshold: 40
accelerationMultiplier: 2
_players:
- {fileID: 1791992025}
- {fileID: 23812154}
- {fileID: 707823890}
- {fileID: 1777639907}
--- !u!1 &1666960087 --- !u!1 &1666960087
GameObject: GameObject:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -3629,7 +3672,6 @@ GameObject:
- component: {fileID: 1666960091} - component: {fileID: 1666960091}
- component: {fileID: 1666960090} - component: {fileID: 1666960090}
- component: {fileID: 1666960089} - component: {fileID: 1666960089}
- component: {fileID: 1666960092}
m_Layer: 5 m_Layer: 5
m_Name: Canvas m_Name: Canvas
m_TagString: Untagged m_TagString: Untagged
@ -3724,24 +3766,6 @@ Canvas:
m_SortingLayerID: 0 m_SortingLayerID: 0
m_SortingOrder: 0 m_SortingOrder: 0
m_TargetDisplay: 0 m_TargetDisplay: 0
--- !u!114 &1666960092
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1666960087}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: c1935701df9467a4697e65458c3ecd11, type: 3}
m_Name:
m_EditorClassIdentifier:
cursor: {fileID: 23812149}
colors: []
defaultMiceSensitivity: 1
accelerationThreshold: 40
accelerationMultiplier: 2
screenBorderPixels: 16
--- !u!1001 &1680381204 --- !u!1001 &1680381204
PrefabInstance: PrefabInstance:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -4114,11 +4138,33 @@ GameObject:
m_CorrespondingSourceObject: {fileID: 9049015333349338381, guid: 56b5ab1b6ee02794ab9664e282d1930a, type: 3} m_CorrespondingSourceObject: {fileID: 9049015333349338381, guid: 56b5ab1b6ee02794ab9664e282d1930a, type: 3}
m_PrefabInstance: {fileID: 881809258} m_PrefabInstance: {fileID: 881809258}
m_PrefabAsset: {fileID: 0} m_PrefabAsset: {fileID: 0}
--- !u!114 &1777639907 stripped
MonoBehaviour:
m_CorrespondingSourceObject: {fileID: 9049015333349338377, guid: 56b5ab1b6ee02794ab9664e282d1930a, type: 3}
m_PrefabInstance: {fileID: 881809258}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1777639902}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 27913ac4da04ed24db893ba625314f05, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!1 &1791992020 stripped --- !u!1 &1791992020 stripped
GameObject: GameObject:
m_CorrespondingSourceObject: {fileID: 9049015333349338381, guid: 56b5ab1b6ee02794ab9664e282d1930a, type: 3} m_CorrespondingSourceObject: {fileID: 9049015333349338381, guid: 56b5ab1b6ee02794ab9664e282d1930a, type: 3}
m_PrefabInstance: {fileID: 9049015332794659158} m_PrefabInstance: {fileID: 9049015332794659158}
m_PrefabAsset: {fileID: 0} m_PrefabAsset: {fileID: 0}
--- !u!114 &1791992025 stripped
MonoBehaviour:
m_CorrespondingSourceObject: {fileID: 9049015333349338377, guid: 56b5ab1b6ee02794ab9664e282d1930a, type: 3}
m_PrefabInstance: {fileID: 9049015332794659158}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1791992020}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 27913ac4da04ed24db893ba625314f05, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!1001 &1801753663 --- !u!1001 &1801753663
PrefabInstance: PrefabInstance:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0

4
namedropper/Assets/Scenes/MouseInputManager.cs

@ -11,8 +11,6 @@ using UnityEngine.UI;
public class MouseInputManager : MonoBehaviour public class MouseInputManager : MonoBehaviour
{ {
public static MouseInputManager instance;
[DllImport("LibRawInput")] [DllImport("LibRawInput")]
private static extern bool init(); private static extern bool init();
@ -72,7 +70,6 @@ public class MouseInputManager : MonoBehaviour
void Start() void Start()
{ {
instance = this;
bool res = init(); bool res = init();
Debug.Log("Init() ==> " + res); Debug.Log("Init() ==> " + res);
Debug.Log(Marshal.SizeOf(typeof(RawInputEvent))); Debug.Log(Marshal.SizeOf(typeof(RawInputEvent)));
@ -83,7 +80,6 @@ public class MouseInputManager : MonoBehaviour
public void OnDestroy() public void OnDestroy()
{ {
instance = null;
} }
int addCursor(int deviceId) int addCursor(int deviceId)

62
namedropper/Assets/Scenes/TopicSelect.unity

@ -359,6 +359,17 @@ GameObject:
m_CorrespondingSourceObject: {fileID: 9049015333349338381, guid: 56b5ab1b6ee02794ab9664e282d1930a, type: 3} m_CorrespondingSourceObject: {fileID: 9049015333349338381, guid: 56b5ab1b6ee02794ab9664e282d1930a, type: 3}
m_PrefabInstance: {fileID: 261236785} m_PrefabInstance: {fileID: 261236785}
m_PrefabAsset: {fileID: 0} m_PrefabAsset: {fileID: 0}
--- !u!114 &261236788 stripped
MonoBehaviour:
m_CorrespondingSourceObject: {fileID: 9049015333349338377, guid: 56b5ab1b6ee02794ab9664e282d1930a, type: 3}
m_PrefabInstance: {fileID: 261236785}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 261236787}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 27913ac4da04ed24db893ba625314f05, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!1 &277092716 --- !u!1 &277092716
GameObject: GameObject:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -676,6 +687,17 @@ GameObject:
m_CorrespondingSourceObject: {fileID: 9049015333349338381, guid: 56b5ab1b6ee02794ab9664e282d1930a, type: 3} m_CorrespondingSourceObject: {fileID: 9049015333349338381, guid: 56b5ab1b6ee02794ab9664e282d1930a, type: 3}
m_PrefabInstance: {fileID: 1003872900} m_PrefabInstance: {fileID: 1003872900}
m_PrefabAsset: {fileID: 0} m_PrefabAsset: {fileID: 0}
--- !u!114 &1003872903 stripped
MonoBehaviour:
m_CorrespondingSourceObject: {fileID: 9049015333349338377, guid: 56b5ab1b6ee02794ab9664e282d1930a, type: 3}
m_PrefabInstance: {fileID: 1003872900}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1003872902}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 27913ac4da04ed24db893ba625314f05, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!1001 &1192266242 --- !u!1001 &1192266242
PrefabInstance: PrefabInstance:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -871,6 +893,17 @@ GameObject:
m_CorrespondingSourceObject: {fileID: 9049015333349338381, guid: 56b5ab1b6ee02794ab9664e282d1930a, type: 3} m_CorrespondingSourceObject: {fileID: 9049015333349338381, guid: 56b5ab1b6ee02794ab9664e282d1930a, type: 3}
m_PrefabInstance: {fileID: 1192266242} m_PrefabInstance: {fileID: 1192266242}
m_PrefabAsset: {fileID: 0} m_PrefabAsset: {fileID: 0}
--- !u!114 &1192266245 stripped
MonoBehaviour:
m_CorrespondingSourceObject: {fileID: 9049015333349338377, guid: 56b5ab1b6ee02794ab9664e282d1930a, type: 3}
m_PrefabInstance: {fileID: 1192266242}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1192266244}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 27913ac4da04ed24db893ba625314f05, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!1 &1225785571 --- !u!1 &1225785571
GameObject: GameObject:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -1211,6 +1244,17 @@ GameObject:
m_CorrespondingSourceObject: {fileID: 9049015333349338381, guid: 56b5ab1b6ee02794ab9664e282d1930a, type: 3} m_CorrespondingSourceObject: {fileID: 9049015333349338381, guid: 56b5ab1b6ee02794ab9664e282d1930a, type: 3}
m_PrefabInstance: {fileID: 1272407093} m_PrefabInstance: {fileID: 1272407093}
m_PrefabAsset: {fileID: 0} m_PrefabAsset: {fileID: 0}
--- !u!114 &1272407096 stripped
MonoBehaviour:
m_CorrespondingSourceObject: {fileID: 9049015333349338377, guid: 56b5ab1b6ee02794ab9664e282d1930a, type: 3}
m_PrefabInstance: {fileID: 1272407093}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1272407095}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 27913ac4da04ed24db893ba625314f05, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!1 &1439945299 --- !u!1 &1439945299
GameObject: GameObject:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -1321,6 +1365,7 @@ GameObject:
- component: {fileID: 1641253473} - component: {fileID: 1641253473}
- component: {fileID: 1641253472} - component: {fileID: 1641253472}
- component: {fileID: 1641253474} - component: {fileID: 1641253474}
- component: {fileID: 1641253475}
m_Layer: 0 m_Layer: 0
m_Name: TopicSelect m_Name: TopicSelect
m_TagString: Untagged m_TagString: Untagged
@ -1375,6 +1420,23 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: d9f0573f6651ecd4b900ae5fee7f7cb6, type: 3} m_Script: {fileID: 11500000, guid: d9f0573f6651ecd4b900ae5fee7f7cb6, type: 3}
m_Name: m_Name:
m_EditorClassIdentifier: m_EditorClassIdentifier:
--- !u!114 &1641253475
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1641253471}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 70de4eb8e48bea54b864b5d20448ee50, type: 3}
m_Name:
m_EditorClassIdentifier:
_players:
- {fileID: 261236788}
- {fileID: 1272407096}
- {fileID: 1192266245}
- {fileID: 1003872903}
--- !u!1 &1666960087 --- !u!1 &1666960087
GameObject: GameObject:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0

3
namedropper/Assets/Scripts/Player.cs

@ -29,6 +29,7 @@ public class Player : MonoBehaviour
Vector3 _originalScale; Vector3 _originalScale;
Vector3 _originalTextScale; Vector3 _originalTextScale;
string _categoryName; string _categoryName;
public int? DeviceId = null;
public enum Team public enum Team
{ {
@ -36,7 +37,7 @@ public class Player : MonoBehaviour
BLUE BLUE
} }
Rigidbody2D _rigidbody; public Rigidbody2D _rigidbody;
private void Awake() private void Awake()
{ {

166
namedropper/Assets/TrackballInputManager.cs

@ -0,0 +1,166 @@
using UnityEngine;
using System.Collections;
using System.Runtime.InteropServices;
using System;
using System.Collections.Generic;
using UnityEngine.UI;
public class TrackballInputManager : MonoBehaviour
{
const float defaultMiceSensitivity = 1f;
const float upMultiplier = .5f;
const float accelerationThreshold = 40;
const float accelerationMultiplier = 2;
[DllImport("LibRawInput")]
private static extern bool init();
[DllImport("LibRawInput")]
private static extern bool kill();
[DllImport("LibRawInput")]
private static extern IntPtr poll();
public const byte RE_DEVICE_CONNECT = 0;
public const byte RE_MOUSE = 2;
public const byte RE_DEVICE_DISCONNECT = 1;
[StructLayout(LayoutKind.Sequential)]
public struct RawInputEvent
{
public int devHandle;
public int x, y, wheel;
public byte press;
public byte release;
public byte type;
}
public class MousePointer
{
public GameObject obj;
public Vector2 position;
public int deviceID;
public int playerID;
public float sensitivity;
}
public static TrackballInputManager instance;
[SerializeField] List<Player> _players;
// Start is called before the first frame update
void Start()
{
instance = this;
bool res = init();
Debug.Log("Init() ==> " + res);
//Debug.Log(Marshal.SizeOf(typeof(RawInputEvent)));
//canvas = GetComponent<Canvas>();
//canvasRect = GetComponent<RectTransform>();
Cursor.lockState = CursorLockMode.Locked;
Cursor.visible = false;
}
public void OnDestroy()
{
instance = null;
}
int lastEvents = 0;
bool isInit = true;
void Update()
{
// Poll the events and properly update whatever we need
IntPtr data = poll();
int numEvents = Marshal.ReadInt32(data);
if (numEvents > 0) lastEvents = numEvents;
for (int i = 0; i < numEvents; ++i)
{
var ev = new RawInputEvent();
long offset = data.ToInt64() + sizeof(int) + i * Marshal.SizeOf(ev);
ev.devHandle = Marshal.ReadInt32(new IntPtr(offset + 0));
ev.x = Marshal.ReadInt32(new IntPtr(offset + 4));
ev.y = Marshal.ReadInt32(new IntPtr(offset + 8));
ev.wheel = Marshal.ReadInt32(new IntPtr(offset + 12));
ev.press = Marshal.ReadByte(new IntPtr(offset + 16));
ev.release = Marshal.ReadByte(new IntPtr(offset + 17));
ev.type = Marshal.ReadByte(new IntPtr(offset + 18));
//Debug.Log(getEventName(ev.type) + ": H=" + ev.devHandle + "; (" + ev.x + ";" + ev.y + ") Down=" + ev.press + " Up=" + ev.release);
if (ev.type == RE_DEVICE_CONNECT) AddPlayer(ev.devHandle);
else if (ev.type == RE_DEVICE_DISCONNECT) RemovePlayer(ev.devHandle);
else if (ev.type == RE_MOUSE)
{
Player player = null;
if (_playersByDeviceId.TryGetValue(ev.devHandle, out player))
{
float dx = ev.x * defaultMiceSensitivity;
float dy = ev.y * defaultMiceSensitivity;
if (Mathf.Abs(dx) > accelerationThreshold) dx *= accelerationMultiplier;
if (Mathf.Abs(dy) > accelerationThreshold) dy *= accelerationMultiplier;
if (dy < 0)
dy *= upMultiplier;
//use this method to move using position
//player.transform.position = new Vector2(player.transform.position.x + dx, player.transform.position.y - dy);
//use this method to move using velocity
player._rigidbody.velocity += new Vector2(dx, -dy);
}
else
{
Debug.Log("Unknown device found");
AddPlayer(ev.devHandle);
}
}
}
Marshal.FreeCoTaskMem(data);
}
void RemovePlayer(int deviceId)
{
Debug.Log("Removing DeviceID " + deviceId);
_playersByDeviceId[deviceId].DeviceId = null;
_playersByDeviceId.Remove(deviceId);
}
Dictionary<int, Player> _playersByDeviceId = new Dictionary<int, Player>();
int AddPlayer(int deviceId)
{
if (!isInit)
{
Debug.LogError("Not initialized");
return -1;
}
Player player = null;
_playersByDeviceId.TryGetValue(deviceId, out player);
if (player != null)
{
Debug.LogError("This device already has a player");
return -1;
}
Debug.Log("Adding DeviceID " + deviceId);
foreach (Player p in _players)
{
if (p.DeviceId == null)
{
p.DeviceId = deviceId;
_playersByDeviceId.Add(deviceId, p);
return deviceId;
}
}
Debug.Log("no players left to add");
return -1;
}
}

11
namedropper/Assets/TrackballInputManager.cs.meta

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 70de4eb8e48bea54b864b5d20448ee50
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
Loading…
Cancel
Save