Skip to content

Commit

Permalink
Finished new features
Browse files Browse the repository at this point in the history
  • Loading branch information
noahzemlin committed Jul 27, 2022
1 parent db1757a commit ed52026
Show file tree
Hide file tree
Showing 14 changed files with 593 additions and 165 deletions.
336 changes: 311 additions & 25 deletions Unity/Assets/Scenes/Loading.unity

Large diffs are not rendered by default.

15 changes: 9 additions & 6 deletions Unity/Assets/Scenes/MainScene.unity
Original file line number Diff line number Diff line change
Expand Up @@ -1053,7 +1053,7 @@ MonoBehaviour:
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 829615084}
m_Enabled: 0
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 938611d5f671cfe4f9be87c66d865ae1, type: 3}
m_Name:
Expand Down Expand Up @@ -1082,7 +1082,7 @@ MonoBehaviour:
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 829615084}
m_Enabled: 0
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: f51320dc62f801a40b8ac30bb02afaef, type: 3}
m_Name:
Expand All @@ -1095,7 +1095,7 @@ MonoBehaviour:
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 829615084}
m_Enabled: 0
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: b44e1486d7dbdce40958f480202bf058, type: 3}
m_Name:
Expand All @@ -1109,7 +1109,7 @@ MonoBehaviour:
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 829615084}
m_Enabled: 0
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 5622a2e2753f1c14abdbf40795d4329b, type: 3}
m_Name:
Expand Down Expand Up @@ -1234,7 +1234,7 @@ MonoBehaviour:
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 829615084}
m_Enabled: 0
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 6754bb5aaed72614b8f93c1d3ff3a992, type: 3}
m_Name:
Expand Down Expand Up @@ -2514,11 +2514,14 @@ MonoBehaviour:
RecordMenu: {fileID: 2140772450}
Slider: {fileID: 1511870107}
SliderText: {fileID: 319283295}
RecordText: {fileID: 12193271}
paused: 0
targetFreq: 735
captureStartTime: -1
targetFreq: 750
minFreq: 735
maxFreq: 792
timeToTarget: 5
timeToComplete: 7
--- !u!1 &1868617787
GameObject:
m_ObjectHideFlags: 0
Expand Down
53 changes: 46 additions & 7 deletions Unity/Assets/Scripts/GameManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.IO;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;

[RequireComponent(typeof(RosConnector))]
Expand All @@ -13,6 +14,7 @@ public class GameManager : MonoBehaviour

public TextMeshProUGUI loadingText;
public TMP_InputField rootField;
public Button startButton;
public float maxTime = 300f;

public Transform robotTf;
Expand All @@ -31,12 +33,22 @@ public enum GameState
{
INIT,
WAITING_FOR_ROS,
READY,
PLAYING,
QUITTING
}

public GameState State { get; private set; } = GameState.INIT;

public enum CaptureState
{
NONE,
CAPTURING,
FINISHED
}

private CaptureState CapState = CaptureState.NONE;

// Start is called before the first frame update
void Start()
{
Expand Down Expand Up @@ -108,11 +120,20 @@ private void FixedUpdate() {
}
}

if (State == GameState.READY && !rosConnector.Connected)
{
ReloadSim();
}

if (State == GameState.WAITING_FOR_ROS && rosConnector.Connected)
{
State = GameState.PLAYING;
SceneManager.LoadScene(1);
AddBonusAdjustments();
if (ConfigLoader.simulator.CompetitionMode) {
RestartSim();
} else {
State = GameState.READY;
startButton.interactable = true;
loadingText.text = "Ready! Press Start to begin.";
}
}

// Time limit reached
Expand Down Expand Up @@ -172,10 +193,12 @@ public void ReloadSim()
// Restart the sim, basically just resetting the level
public void RestartSim()
{
State = GameState.PLAYING;
SceneManager.LoadScene(1);
adjustments = new List<ScoreAdjust>();
AddBonusAdjustments();
if (State == GameState.READY || State == GameState.PLAYING) {
State = GameState.PLAYING;
SceneManager.LoadScene(1);
adjustments = new List<ScoreAdjust>();
AddBonusAdjustments();
}
}

public void AddBonusAdjustments() {
Expand Down Expand Up @@ -262,6 +285,22 @@ public void StartSim()
startTime = Time.time;
}

public void StartCapture() {
CapState = CaptureState.CAPTURING;
}

public void EndCapture() {
CapState = CaptureState.NONE;
}

public void FinishCapture() {
CapState = CaptureState.FINISHED;
}

public CaptureState CaptureStatus() {
return CapState;
}

public class ScoreAdjust
{
public float adjustment;
Expand Down
32 changes: 29 additions & 3 deletions Unity/Assets/Scripts/UICanvas.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,54 @@ public class UICanvas : MonoBehaviour
public GameObject RecordMenu;
public GameObject Slider;
public GameObject SliderText;
public GameObject RecordText;

public bool paused = false;
public int targetFreq = 735;
public float captureStartTime = -1f;
public int targetFreq = 750;

// :)
public int minFreq = 735;
public int maxFreq = 792;

public float timeToTarget = 5f;
public float timeToComplete = 7f;

void Update() {
if (Input.GetKeyDown(KeyCode.Escape)) {
paused = !paused;
PauseMenu.SetActive(paused);
}

if (GameManager.instance.CaptureStatus() == GameManager.CaptureState.CAPTURING && captureStartTime < 0f) {
captureStartTime = Time.fixedTime;
targetFreq = Random.Range(minFreq, maxFreq+1);
RecordText.GetComponent<TMPro.TextMeshProUGUI>().text = string.Format("Recording RF...");
RecordMenu.SetActive(true);
}

if (GameManager.instance.CaptureStatus() == GameManager.CaptureState.NONE) {
captureStartTime = -1f;
RecordMenu.SetActive(false);
return;
}

float centerFreq = (maxFreq + minFreq) / 2f;

// :)
float scaledTime = Time.time % 7;
float scaledTime = Time.fixedTime - captureStartTime;

if (scaledTime > timeToComplete) {
GameManager.instance.EndCapture();
captureStartTime = -1f;
RecordMenu.SetActive(false);
return;
}

if (scaledTime > timeToTarget) {
scaledTime = timeToTarget;
RecordText.GetComponent<TMPro.TextMeshProUGUI>().text = string.Format("Peak RF detected at {0:0} MHz!", targetFreq);
}

float width = (maxFreq - minFreq) * (timeToTarget - scaledTime) / timeToTarget;
float center = ((timeToTarget - scaledTime) * centerFreq + scaledTime * targetFreq) / timeToTarget;
float freq = center + width * Mathf.Sin(Time.time * 3);
Expand Down
21 changes: 18 additions & 3 deletions Unity/Assets/Scripts/Waypoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ public class Waypoint : MonoBehaviour
{
public int index;
public float triggerDist = 1f;
public float captureTime = 5f;
private float captureStartTime = -1f;
private bool reached = false;

private void FixedUpdate() {
Expand All @@ -19,9 +21,22 @@ private void FixedUpdate() {
}

if (!reached && (robotTf.position - transform.position).sqrMagnitude < triggerDist * triggerDist) {
reached = true;
GameManager.instance.ReachWaypoint(index);
Destroy(this);
if (captureStartTime < 0) {
captureStartTime = Time.fixedTime;
GameManager.instance.StartCapture();
}

if (captureStartTime + captureTime < Time.fixedTime) {
reached = true;
GameManager.instance.FinishCapture();
GameManager.instance.ReachWaypoint(index);
Destroy(this);
}
} else {
if (captureStartTime > 0) {
captureStartTime = -1f;
GameManager.instance.EndCapture();
}
}
}
}
8 changes: 8 additions & 0 deletions Unity/Assets/StreamingAssets.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Unity/Packages/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"dependencies": {
"com.unity.collab-proxy": "1.15.18",
"com.unity.ide.rider": "3.0.14",
"com.unity.ide.visualstudio": "2.0.15",
"com.unity.ide.visualstudio": "2.0.16",
"com.unity.ide.vscode": "1.2.5",
"com.unity.probuilder": "5.0.3",
"com.unity.test-framework": "1.1.31",
Expand Down
2 changes: 1 addition & 1 deletion Unity/Packages/packages-lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"url": "https://packages.unity.com"
},
"com.unity.ide.visualstudio": {
"version": "2.0.15",
"version": "2.0.16",
"depth": 0,
"source": "registry",
"dependencies": {
Expand Down
16 changes: 11 additions & 5 deletions Unity/ProjectSettings/ProjectSettings.asset
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
--- !u!129 &1
PlayerSettings:
m_ObjectHideFlags: 0
serializedVersion: 22
serializedVersion: 23
productGUID: cf2004c16d40cfc46bbf0f0185d17595
AndroidProfiler: 0
AndroidFilterTouchesWhenObscured: 0
Expand Down Expand Up @@ -134,7 +134,7 @@ PlayerSettings:
16:10: 1
16:9: 1
Others: 1
bundleVersion: 1.0
bundleVersion: beta-v0.1
preloadedAssets: []
metroInputSource: 0
wsaTransparentSwapchain: 0
Expand All @@ -145,11 +145,13 @@ PlayerSettings:
enable360StereoCapture: 0
isWsaHolographicRemotingEnabled: 0
enableFrameTimingStats: 0
enableOpenGLProfilerGPURecorders: 1
useHDRDisplay: 0
D3DHDRBitDepth: 0
m_ColorGamuts: 00000000
targetPixelDensity: 30
resolutionScalingMode: 0
resetResolutionOnWindowResize: 0
androidSupportedAspectRatio: 1
androidMaxAspectRatio: 2.1
applicationIdentifier:
Expand All @@ -160,7 +162,7 @@ PlayerSettings:
tvOS: 0
overrideDefaultApplicationIdentifier: 0
AndroidBundleVersionCode: 1
AndroidMinSdkVersion: 19
AndroidMinSdkVersion: 22
AndroidTargetSdkVersion: 0
AndroidPreferredInstallLocation: 1
aotOptions:
Expand Down Expand Up @@ -216,6 +218,7 @@ PlayerSettings:
iOSLaunchScreeniPadCustomStoryboardPath:
iOSDeviceRequirements: []
iOSURLSchemes: []
macOSURLSchemes: []
iOSBackgroundModes: 0
iOSMetalForceHardShadows: 0
metalEditorSupport: 1
Expand Down Expand Up @@ -326,7 +329,7 @@ PlayerSettings:
m_BuildTargetGraphicsAPIs:
- m_BuildTarget: AndroidPlayer
m_APIs: 150000000b000000
m_Automatic: 0
m_Automatic: 1
- m_BuildTarget: iOSSupport
m_APIs: 10000000
m_Automatic: 1
Expand All @@ -353,6 +356,7 @@ PlayerSettings:
m_BuildTargetGroupLightmapEncodingQuality: []
m_BuildTargetGroupLightmapSettings: []
m_BuildTargetNormalMapEncoding: []
m_BuildTargetDefaultTextureCompressionFormat: []
playModeTestRunnerEnabled: 0
runPlayModeTestAsEditModeTest: 0
actionOnDotNetUnhandledException: 1
Expand All @@ -371,6 +375,7 @@ PlayerSettings:
switchScreenResolutionBehavior: 2
switchUseCPUProfiler: 0
switchUseGOLDLinker: 0
switchLTOSetting: 0
switchApplicationID: 0x01004b9000490000
switchNSODependencies:
switchTitleNames_0:
Expand Down Expand Up @@ -609,7 +614,6 @@ PlayerSettings:
suppressCommonWarnings: 1
allowUnsafeCode: 0
useDeterministicCompilation: 1
useReferenceAssemblies: 1
enableRoslynAnalyzers: 1
additionalIl2CppArgs:
scriptingRuntimeVersion: 1
Expand Down Expand Up @@ -698,4 +702,6 @@ PlayerSettings:
organizationId:
cloudEnabled: 0
legacyClampBlendShapeWeights: 0
playerDataPath:
forceSRGBBlit: 1
virtualTexturingSupportEnabled: 0
1 change: 1 addition & 0 deletions Unity/ProjectSettings/UnityConnectSettings.asset
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ UnityConnectSettings:
m_EventOldUrl: https://api.uca.cloud.unity3d.com/v1/events
m_EventUrl: https://cdp.cloud.unity3d.com/v1/events
m_ConfigUrl: https://config.uca.cloud.unity3d.com
m_DashboardUrl: https://dashboard.unity3d.com
m_TestInitMode: 0
CrashReportingSettings:
m_EventUrl: https://perf-events.cloud.unity3d.com
Expand Down
4 changes: 2 additions & 2 deletions Unity/UserSettings/EditorUserSettings.asset
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ EditorUserSettings:
serializedVersion: 4
m_ConfigSettings:
RecentlyUsedSceneGuid-0:
value: 5100055154025a0a5a5d5573427609441515402e792973332f7d4f67e7b16c3d
value: 5a5757560101590a5d0c0e24427b5d44434e4c7a7b7a23677f2b4565b7b5353a
flags: 0
RecentlyUsedSceneGuid-1:
value: 5a5757560101590a5d0c0e24427b5d44434e4c7a7b7a23677f2b4565b7b5353a
value: 5100055154025a0a5a5d5573427609441515402e792973332f7d4f67e7b16c3d
flags: 0
RecentlyUsedScenePath-0:
value: 22424703114646680e0b0227036c731f171311242b66333e243d04
Expand Down
Loading

0 comments on commit ed52026

Please sign in to comment.