From 2e24da55b56d66627b7326a27d601220c2d5780f Mon Sep 17 00:00:00 2001 From: Reid Faistl Date: Sun, 29 Jun 2025 22:49:27 -0500 Subject: [PATCH 1/2] Working Scene References Code --- .../POINT/InputAssets/SceneController.cs | 43 ++++++++++++++++++- .../POINT/InputAssets/StartMenuManager.cs | 10 ++++- 2 files changed, 49 insertions(+), 4 deletions(-) diff --git a/POINT-VR-Chapter-1/Assets/POINT/InputAssets/SceneController.cs b/POINT-VR-Chapter-1/Assets/POINT/InputAssets/SceneController.cs index 8a001932..35902845 100644 --- a/POINT-VR-Chapter-1/Assets/POINT/InputAssets/SceneController.cs +++ b/POINT-VR-Chapter-1/Assets/POINT/InputAssets/SceneController.cs @@ -1,6 +1,24 @@ using UnityEngine; using UnityEngine.SceneManagement; using UnityEngine.UI; +using System.Collections.Generic; + +/// +/// Stores integer values under scene names. Do not change these intergers (you should be changing the SceneDict dictionary below). Integers are linked to build settings scene integers in the dictionary SceneDict (defined in SceneController). +/// There are two layers of this (enum here, and the dict down below) because the Unity Editor stores the value of the enum, not its name. So if the build settings change and you change the enum in the code then what the editor stores +/// won't actually change. +/// +public enum SceneNumEnum +{ + StartMenu = 900, + Tutorial = 901, + Ch1_Scene1 = 902, + Conf_Demo_P1 = 903, + Conf_Demo_P2 = 904, + Conf_Demo_P3 = 905, + EndCredits = 906 +} + /// /// This script should be on the player prefab. It communicates the player's setting to the GameManager before switching scenes and then retrieves this information upon being instantiated. /// @@ -50,6 +68,21 @@ public class SceneController : MonoBehaviour /// /// When Instantiated: Get the player data. Communicate this data to all component arguments. /// + + /// + /// Relates the shown enum (left) to scene numbers in build settings. If the scene numbers in build settings change you should update + /// the right side of the dictionary (the values) with the new numbers. + /// + private Dictionary SceneDict = new Dictionary + { + { (int) SceneNumEnum.StartMenu, 0 }, + { (int) SceneNumEnum.Tutorial, 1 }, + { (int) SceneNumEnum.Ch1_Scene1, 2 }, + { (int) SceneNumEnum.Conf_Demo_P1, 3 }, + { (int) SceneNumEnum.Conf_Demo_P2, 4 }, + { (int) SceneNumEnum.Conf_Demo_P3, 5 }, + { (int) SceneNumEnum.EndCredits, 6 } + }; private void Start() { GameManager.PlayerData data = GameManager.Instance.GetData(); @@ -58,7 +91,7 @@ private void Start() functional.value = data.functionalVolume; aesthetic.value = data.aestheticVolume; uiManager.Language = (int)data.language; - uiManager.SubtitleLanguage = (int) data.subtitleLanguage; + uiManager.SubtitleLanguage = (int)data.subtitleLanguage; music.mute = false; floorToggle.IsOn = data.isFloorVisible; hapticToggle.IsOn = data.isHapticsEnabled; @@ -81,10 +114,16 @@ public void ChangeScene(int scene) isHapticsEnabled = hapticToggle.IsOn, isControllerHighlighted = highlightsToggle.IsOn, language = (GameManager.Language)uiManager.Language, - subtitleLanguage = (GameManager.Language) uiManager.SubtitleLanguage + subtitleLanguage = (GameManager.Language)uiManager.SubtitleLanguage }; GameManager.Instance.SetData(data); pause.Unpause(); SceneManager.LoadScene(scene); } + + // Using a function here so the dictionary can't be modified and we don't have to bother passing larger object (I lack C# knowledge; there may be a better way to do this) + public int OperateSceneDict(int SceneNumEnum_number) + { + return SceneDict[SceneNumEnum_number]; + } } \ No newline at end of file diff --git a/POINT-VR-Chapter-1/Assets/POINT/InputAssets/StartMenuManager.cs b/POINT-VR-Chapter-1/Assets/POINT/InputAssets/StartMenuManager.cs index d05001ad..510a91b6 100644 --- a/POINT-VR-Chapter-1/Assets/POINT/InputAssets/StartMenuManager.cs +++ b/POINT-VR-Chapter-1/Assets/POINT/InputAssets/StartMenuManager.cs @@ -1,4 +1,5 @@ using System.Collections; +using System.Collections.Generic; using TMPro; using UnityEngine; using UnityEngine.UI; @@ -24,6 +25,11 @@ public class StartMenuManager : MonoBehaviour [Tooltip("Default localized string that appears under current objective in the UI menu")] [SerializeField] private LocalizedString defaultObjective; + [SerializeField] SceneNumEnum Tutorial_Enum; + + [SerializeField] SceneNumEnum End_Credits_Enum; + + /// /// A reference to the player GameObject /// @@ -242,7 +248,7 @@ public void StartGame() SceneController sceneController = player.GetComponentInChildren(); if (sceneController != null) { - sceneController.ChangeScene(1); + sceneController.ChangeScene(sceneController.OperateSceneDict((int) Tutorial_Enum)); } } } @@ -271,7 +277,7 @@ public void StartCredits() SceneController sceneController = player.GetComponentInChildren(); if (sceneController != null) { - sceneController.ChangeScene(6); + sceneController.ChangeScene(sceneController.OperateSceneDict((int) End_Credits_Enum)); } } } From e73e438796ce5f36ae0b2ae12280f08967de0855 Mon Sep 17 00:00:00 2001 From: Reid Faistl <44991327+faisr9@users.noreply.github.com> Date: Mon, 30 Jun 2025 18:51:58 -0500 Subject: [PATCH 2/2] Formatting --- .../Assets/POINT/InputAssets/SceneController.cs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/POINT-VR-Chapter-1/Assets/POINT/InputAssets/SceneController.cs b/POINT-VR-Chapter-1/Assets/POINT/InputAssets/SceneController.cs index 35902845..6d0e9f5c 100644 --- a/POINT-VR-Chapter-1/Assets/POINT/InputAssets/SceneController.cs +++ b/POINT-VR-Chapter-1/Assets/POINT/InputAssets/SceneController.cs @@ -10,13 +10,13 @@ /// public enum SceneNumEnum { - StartMenu = 900, - Tutorial = 901, - Ch1_Scene1 = 902, - Conf_Demo_P1 = 903, - Conf_Demo_P2 = 904, - Conf_Demo_P3 = 905, - EndCredits = 906 + StartMenu = 114, + Tutorial = 97, + Ch1_Scene1 = 115, + Conf_Demo_P1 = 116, + Conf_Demo_P2 = 108, + Conf_Demo_P3 = 101, + EndCredits = 121 } /// @@ -126,4 +126,4 @@ public int OperateSceneDict(int SceneNumEnum_number) { return SceneDict[SceneNumEnum_number]; } -} \ No newline at end of file +}