Browse Source

calibration

combinedRaceAndNameDropper
Josh 2 years ago
parent
commit
a05aec9b28
  1. 2
      namedropper/Assets/Calibration.cs
  2. 7
      namedropper/Assets/CalibrationBox.cs
  3. 10
      namedropper/Assets/Scenes/Calibration.unity
  4. 16
      namedropper/Assets/Scripts/Game.cs
  5. 23
      namedropper/Assets/TrackballInputManager.cs

2
namedropper/Assets/Calibration.cs

@ -14,7 +14,7 @@ public class Calibration : MonoBehaviour
// Update is called once per frame // Update is called once per frame
void Update() void Update()
{ {
if (FindObjectsOfType<CalibrationBox>() == null) if (FindObjectsOfType<CalibrationBox>().Length == 0)
{ {
SceneManager.LoadScene("Title"); SceneManager.LoadScene("Title");
} }

7
namedropper/Assets/CalibrationBox.cs

@ -21,8 +21,13 @@ public class CalibrationBox : MonoBehaviour
{ {
if (DeviceId != null) { if (DeviceId != null) {
TrackballInputManager.Calibrate(_playerNumber,(int)DeviceId); TrackballInputManager.Calibrate(_playerNumber,(int)DeviceId);
GameObject.Destroy(this.gameObject);
} }
else
{
Debug.LogError("deviceID is null, couldn't calibrate");
}
GameObject.Destroy(this.gameObject);
} }
} }

10
namedropper/Assets/Scenes/Calibration.unity

@ -762,7 +762,7 @@ GameObject:
- component: {fileID: 443893162} - component: {fileID: 443893162}
- component: {fileID: 443893161} - component: {fileID: 443893161}
m_Layer: 0 m_Layer: 0
m_Name: Light Right m_Name: Light Red
m_TagString: Untagged m_TagString: Untagged
m_Icon: {fileID: 0} m_Icon: {fileID: 0}
m_NavMeshLayer: 0 m_NavMeshLayer: 0
@ -896,7 +896,7 @@ MonoBehaviour:
m_HorizontalOverflow: 0 m_HorizontalOverflow: 0
m_VerticalOverflow: 1 m_VerticalOverflow: 1
m_LineSpacing: 1 m_LineSpacing: 1
m_Text: Dark Red m_Text: Far Right
--- !u!222 &477423984 --- !u!222 &477423984
CanvasRenderer: CanvasRenderer:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -1014,7 +1014,7 @@ MonoBehaviour:
m_HorizontalOverflow: 0 m_HorizontalOverflow: 0
m_VerticalOverflow: 1 m_VerticalOverflow: 1
m_LineSpacing: 1 m_LineSpacing: 1
m_Text: Light Blue m_Text: Inner Left
--- !u!222 &913169058 --- !u!222 &913169058
CanvasRenderer: CanvasRenderer:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -2875,7 +2875,7 @@ MonoBehaviour:
m_HorizontalOverflow: 0 m_HorizontalOverflow: 0
m_VerticalOverflow: 1 m_VerticalOverflow: 1
m_LineSpacing: 1 m_LineSpacing: 1
m_Text: Light Red m_Text: Inner Right
--- !u!222 &2073580014 --- !u!222 &2073580014
CanvasRenderer: CanvasRenderer:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -3216,7 +3216,7 @@ MonoBehaviour:
m_HorizontalOverflow: 0 m_HorizontalOverflow: 0
m_VerticalOverflow: 1 m_VerticalOverflow: 1
m_LineSpacing: 1 m_LineSpacing: 1
m_Text: Dark Blue m_Text: Far Left
--- !u!4 &1499098758326845050 --- !u!4 &1499098758326845050
Transform: Transform:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0

16
namedropper/Assets/Scripts/Game.cs

@ -191,24 +191,24 @@ public class Game : Level
public void AddScore(int amount = 1, int player = 1) public void AddScore(int amount = 1, int player = 1)
{ {
if (player == 1) if (player == 0)
{ {
GameManager.Instance.Score1 += amount; GameManager.Instance.Score1 += amount;
_blueScoreStack.AddChecker(amount/10, false); _blueScoreStack.AddChecker(amount/10, true);
} }
else if (player == 2) else if (player == 1)
{ {
_blueScoreStack.AddChecker(amount / 10, true); _blueScoreStack.AddChecker(amount / 10, false);
GameManager.Instance.Score2 += amount; GameManager.Instance.Score2 += amount;
} }
else if (player == 3) else if (player == 2)
{ {
_redScoreStack.AddChecker(amount / 10, true); _redScoreStack.AddChecker(amount / 10, false);
GameManager.Instance.Score3 += amount; GameManager.Instance.Score3 += amount;
} }
else if (player == 4) else if (player == 3)
{ {
_redScoreStack.AddChecker(amount / 10, false); _redScoreStack.AddChecker(amount / 10, true);
GameManager.Instance.Score4 += amount; GameManager.Instance.Score4 += amount;
} }

23
namedropper/Assets/TrackballInputManager.cs

@ -4,7 +4,7 @@ using System.Runtime.InteropServices;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using UnityEngine.UI; using UnityEngine.UI;
using UnityEditor;
public class TrackballInputManager : MonoBehaviour public class TrackballInputManager : MonoBehaviour
{ {
@ -32,7 +32,11 @@ public class TrackballInputManager : MonoBehaviour
public static void Calibrate(int playerNumber, int DeviceId) public static void Calibrate(int playerNumber, int DeviceId)
{ {
Debug.Log("calibration player " + playerNumber + " to deviceID: " + DeviceId);
Calibration[playerNumber] = DeviceId; Calibration[playerNumber] = DeviceId;
PlayerPrefs.SetInt("Player" + playerNumber + "Device", DeviceId);
PlayerPrefs.Save();
} }
public struct RawInputEvent public struct RawInputEvent
@ -55,9 +59,19 @@ public class TrackballInputManager : MonoBehaviour
//public static TrackballInputManager instance; //public static TrackballInputManager instance;
[SerializeField] List<Player> _players; [SerializeField] List<Player> _players;
// Start is called before the first frame update
void LoadCalibration()
{
for (int i=0; i<4; ++i)
{
Calibration[i] = PlayerPrefs.GetInt("Player" + i + "Device", 0);
}
}
void Start() void Start()
{ {
LoadCalibration();
Debug.Log("starting trackballs"); Debug.Log("starting trackballs");
//instance = this; //instance = this;
if (isInit == false) if (isInit == false)
@ -87,6 +101,9 @@ public class TrackballInputManager : MonoBehaviour
_ignoredDevices.Add(381291525); _ignoredDevices.Add(381291525);
_ignoredDevices.Add(254348147); _ignoredDevices.Add(254348147);
_ignoredDevices.Add(254282139); _ignoredDevices.Add(254282139);
_ignoredDevices.Add(65595);
_ignoredDevices.Add(65599);
_ignoredDevices.Add(1250497353);
@ -222,7 +239,7 @@ public class TrackballInputManager : MonoBehaviour
for (int i = 0; i < _players.Count; i++) { for (int i = 0; i < _players.Count; i++) {
if (Calibration[i] == deviceId) if (Calibration[i] == deviceId)
{ {
return 0; return i;
} }
} }

Loading…
Cancel
Save