From a05aec9b28d255659f0cf22609f13d87ccdcd7a1 Mon Sep 17 00:00:00 2001 From: Josh Date: Wed, 29 Mar 2023 19:09:24 -0400 Subject: [PATCH] calibration --- namedropper/Assets/Calibration.cs | 2 +- namedropper/Assets/CalibrationBox.cs | 7 ++++++- namedropper/Assets/Scenes/Calibration.unity | 10 ++++----- namedropper/Assets/Scripts/Game.cs | 16 +++++++------- namedropper/Assets/TrackballInputManager.cs | 23 ++++++++++++++++++--- 5 files changed, 40 insertions(+), 18 deletions(-) diff --git a/namedropper/Assets/Calibration.cs b/namedropper/Assets/Calibration.cs index 5e7a3d6..2d89cdd 100644 --- a/namedropper/Assets/Calibration.cs +++ b/namedropper/Assets/Calibration.cs @@ -14,7 +14,7 @@ public class Calibration : MonoBehaviour // Update is called once per frame void Update() { - if (FindObjectsOfType() == null) + if (FindObjectsOfType().Length == 0) { SceneManager.LoadScene("Title"); } diff --git a/namedropper/Assets/CalibrationBox.cs b/namedropper/Assets/CalibrationBox.cs index 7578830..3e8cbe9 100644 --- a/namedropper/Assets/CalibrationBox.cs +++ b/namedropper/Assets/CalibrationBox.cs @@ -21,8 +21,13 @@ public class CalibrationBox : MonoBehaviour { if (DeviceId != null) { TrackballInputManager.Calibrate(_playerNumber,(int)DeviceId); - GameObject.Destroy(this.gameObject); } + else + { + Debug.LogError("deviceID is null, couldn't calibrate"); + } + + GameObject.Destroy(this.gameObject); } } diff --git a/namedropper/Assets/Scenes/Calibration.unity b/namedropper/Assets/Scenes/Calibration.unity index 1cf7a84..5dc5e28 100644 --- a/namedropper/Assets/Scenes/Calibration.unity +++ b/namedropper/Assets/Scenes/Calibration.unity @@ -762,7 +762,7 @@ GameObject: - component: {fileID: 443893162} - component: {fileID: 443893161} m_Layer: 0 - m_Name: Light Right + m_Name: Light Red m_TagString: Untagged m_Icon: {fileID: 0} m_NavMeshLayer: 0 @@ -896,7 +896,7 @@ MonoBehaviour: m_HorizontalOverflow: 0 m_VerticalOverflow: 1 m_LineSpacing: 1 - m_Text: Dark Red + m_Text: Far Right --- !u!222 &477423984 CanvasRenderer: m_ObjectHideFlags: 0 @@ -1014,7 +1014,7 @@ MonoBehaviour: m_HorizontalOverflow: 0 m_VerticalOverflow: 1 m_LineSpacing: 1 - m_Text: Light Blue + m_Text: Inner Left --- !u!222 &913169058 CanvasRenderer: m_ObjectHideFlags: 0 @@ -2875,7 +2875,7 @@ MonoBehaviour: m_HorizontalOverflow: 0 m_VerticalOverflow: 1 m_LineSpacing: 1 - m_Text: Light Red + m_Text: Inner Right --- !u!222 &2073580014 CanvasRenderer: m_ObjectHideFlags: 0 @@ -3216,7 +3216,7 @@ MonoBehaviour: m_HorizontalOverflow: 0 m_VerticalOverflow: 1 m_LineSpacing: 1 - m_Text: Dark Blue + m_Text: Far Left --- !u!4 &1499098758326845050 Transform: m_ObjectHideFlags: 0 diff --git a/namedropper/Assets/Scripts/Game.cs b/namedropper/Assets/Scripts/Game.cs index 6a31a6c..101d87f 100644 --- a/namedropper/Assets/Scripts/Game.cs +++ b/namedropper/Assets/Scripts/Game.cs @@ -191,24 +191,24 @@ public class Game : Level public void AddScore(int amount = 1, int player = 1) { - if (player == 1) + if (player == 0) { 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; } - else if (player == 3) + else if (player == 2) { - _redScoreStack.AddChecker(amount / 10, true); + _redScoreStack.AddChecker(amount / 10, false); 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; } diff --git a/namedropper/Assets/TrackballInputManager.cs b/namedropper/Assets/TrackballInputManager.cs index 7636356..cd9f99f 100644 --- a/namedropper/Assets/TrackballInputManager.cs +++ b/namedropper/Assets/TrackballInputManager.cs @@ -4,7 +4,7 @@ using System.Runtime.InteropServices; using System; using System.Collections.Generic; using UnityEngine.UI; - +using UnityEditor; public class TrackballInputManager : MonoBehaviour { @@ -32,7 +32,11 @@ public class TrackballInputManager : MonoBehaviour public static void Calibrate(int playerNumber, int DeviceId) { + Debug.Log("calibration player " + playerNumber + " to deviceID: " + DeviceId); Calibration[playerNumber] = DeviceId; + + PlayerPrefs.SetInt("Player" + playerNumber + "Device", DeviceId); + PlayerPrefs.Save(); } public struct RawInputEvent @@ -55,9 +59,19 @@ public class TrackballInputManager : MonoBehaviour //public static TrackballInputManager instance; [SerializeField] List _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() { + LoadCalibration(); Debug.Log("starting trackballs"); //instance = this; if (isInit == false) @@ -87,6 +101,9 @@ public class TrackballInputManager : MonoBehaviour _ignoredDevices.Add(381291525); _ignoredDevices.Add(254348147); _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++) { if (Calibration[i] == deviceId) { - return 0; + return i; } }