diff --git a/Assets/Localisation/UI elements_en.asset b/Assets/Localisation/UI elements_en.asset index 141fbad0c1cdbd92fe9dd339206cf600518f8a59..564b342fe99037d84463b751ae4464206860597e 100644 --- a/Assets/Localisation/UI elements_en.asset +++ b/Assets/Localisation/UI elements_en.asset @@ -69,7 +69,7 @@ MonoBehaviour: m_Metadata: m_Items: [] - m_Id: 7148552577024 - m_Localized: Experience in progress + m_Localized: VR Experience in Progress m_Metadata: m_Items: [] - m_Id: 7705266741248 @@ -105,7 +105,7 @@ MonoBehaviour: m_Metadata: m_Items: [] - m_Id: 10843914756096 - m_Localized: An error occurred + m_Localized: An Error Occurred m_Metadata: m_Items: [] - m_Id: 11108332068864 diff --git a/Assets/Scenes/AppOffline.unity b/Assets/Scenes/AppOffline.unity index ae121dea7b8cbecf015ef2ecf632eda641b53438..e55fa97092f750417b4989d3c04958856ca97dfa 100644 --- a/Assets/Scenes/AppOffline.unity +++ b/Assets/Scenes/AppOffline.unity @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:36400f4210fe88ef14cd95e6983765cee6c0ecc6793818116587d3482e9bd283 -size 448747 +oid sha256:ec7e00095b56c45e5392d188587bca1363d3d900d6b46930d40f450e70fefc63 +size 448894 diff --git a/Assets/Scenes/RuralSceneMobile.unity b/Assets/Scenes/RuralSceneMobile.unity index e407954e587da151c396cbe0ae1696fed0e94f0b..dd098a586b727678f81027b62804edd983138a02 100644 --- a/Assets/Scenes/RuralSceneMobile.unity +++ b/Assets/Scenes/RuralSceneMobile.unity @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:9c60d88995c4dd8f391818366b6467fb4fd1b54d664a65c0b7adccf96420f83d -size 665461 +oid sha256:8371735d2fde0cc1101fd611615d1d97ee10b96c551e0aceeafd58776dbd1c22 +size 674814 diff --git a/Assets/Scenes/VROffline.unity b/Assets/Scenes/VROffline.unity index 231f927a51a63062f7229ef213261002788f0549..55fd0c60a18d0fb4c3de1206e69175ae6205defa 100644 --- a/Assets/Scenes/VROffline.unity +++ b/Assets/Scenes/VROffline.unity @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:6de293025ba05b1d1ebd96900d46a39ec6f13e704a648baa4a6a2e158fe4eb7f +oid sha256:fdeffd6907007e9deb4ef664d748888541f685ccd7a64302400caa53011b9fc6 size 189781 diff --git a/Assets/Scripts/Animals/AnimalController.cs b/Assets/Scripts/Animals/AnimalController.cs index 01b75286e09a1c5dc61beae7693d514f8e918cac..83e0fa63c50138c48d302b86d9c32d7f7ba92f0b 100644 --- a/Assets/Scripts/Animals/AnimalController.cs +++ b/Assets/Scripts/Animals/AnimalController.cs @@ -50,7 +50,6 @@ public void TriggerSound() { if (_audioSource == null) { - Debug.Log("Audio source null " + name); return; } diff --git a/Assets/Scripts/Animals/AnimalSpawnPositions.cs b/Assets/Scripts/Animals/AnimalSpawnPositions.cs deleted file mode 100644 index fc97d5f68eab010e58e21f209068718b8cbd74c1..0000000000000000000000000000000000000000 --- a/Assets/Scripts/Animals/AnimalSpawnPositions.cs +++ /dev/null @@ -1,11 +0,0 @@ -using UnityEngine; -using Vector3 = UnityEngine.Vector3; - -namespace Animals -{ - public static class AnimalSpawnPositions - { - public static readonly Vector3 DeerSpawnPosition = new Vector3(205, 107, 207); - } - -} \ No newline at end of file diff --git a/Assets/Scripts/Animals/AnimalSpawnPositions.cs.meta b/Assets/Scripts/Animals/AnimalSpawnPositions.cs.meta deleted file mode 100644 index 3738c72e7cc9f2efeb078eb2d47a4da3e46b435f..0000000000000000000000000000000000000000 --- a/Assets/Scripts/Animals/AnimalSpawnPositions.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: 124fa713f1a846e8945148d161aa1020 -timeCreated: 1613302983 \ No newline at end of file diff --git a/Assets/Scripts/Animals/InstantiateAnimal.cs b/Assets/Scripts/Animals/InstantiateAnimal.cs index afe6b730c42a594efbc839903966037397040491..cc6fc5d6fb627bfa83e72ef1ce50e266f44eecb7 100644 --- a/Assets/Scripts/Animals/InstantiateAnimal.cs +++ b/Assets/Scripts/Animals/InstantiateAnimal.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using Colliders; +using Player; using UnityEngine; namespace Animals @@ -12,7 +13,7 @@ public class InstantiateAnimal : MonoBehaviour public void OnCollisionEnter(Collision collision) { - if (collision.gameObject.CompareTag("NetworkCamera") && collision.gameObject.name != "Terrain") + if (collision.gameObject.CompareTag(GameConstants.NetworkCamera) && collision.gameObject.name != GameConstants.Terrain) { for (int i = 0; i < prefabs.Length; i++) { diff --git a/Assets/Scripts/Cart/CartCreator.cs b/Assets/Scripts/Cart/CartCreator.cs index a072b4cacbc7e5bc1a9dc7df180ddb95499ed72c..51cfdc6abcaa9d4ed4426305cc16996470a8bcd2 100644 --- a/Assets/Scripts/Cart/CartCreator.cs +++ b/Assets/Scripts/Cart/CartCreator.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Numerics; +using Player; using TMPro; using UI; using UnityEngine; @@ -52,44 +53,14 @@ private void Awake() _rightHandSkeleton = rightHand.GetComponent<OVRSkeleton>(); } + /** + * Waits first for detecting the pinch gesture on right hand => instantiate cart at the indicated point, + * then for the left => rotates the cart to be in accordance with the left indicated point + * saves the indicated points in the _currenPointsPositionList + * + */ private void Update() { - //TODO remove - if (_interactable && debug) - { - var rightArrowPressed = Input.GetKeyDown(KeyCode.RightArrow); - var leftArrowPressed = Input.GetKeyDown(KeyCode.LeftArrow); - - if (rightArrowPressed || leftArrowPressed) - { - _interactable = false; - - if (rightArrowPressed && !_rightSideCreated) - { - _currentPointPositionList.Add(new Vector3(0.485f, 1.3903f, 0.163f)); - _rightSideCreated = true; - _lastPointPosition = _currentPointPositionList[_currentPointPositionList.Count - 1]; - CreateCart(_lastPointPosition); - } - - if (leftArrowPressed && !_leftSideCreated && _rightSideCreated) - { - _currentPointPositionList.Add(new Vector3(-0.2958f, 1.3903f, 0.4578f)); - _leftSideCreated = true; - RotateCart(_lastPointPosition, _currentPointPositionList[_currentPointPositionList.Count - 1]); - } - - - _interactable = true; - } - - if (Input.GetKeyDown(KeyCode.X)) - { - EndCalibration(); - } - } - - if (_interactable && !EventSystem.current.currentSelectedGameObject) { _isLeftIndexFingerPinching = _leftHand.GetFingerIsPinching(OVRHand.HandFinger.Index); @@ -121,6 +92,10 @@ private void Update() } } + /** + * instantiate cart at the given position + * displays UI step 2 + */ private void CreateCart(Vector3 pointPosition) { _cart = Instantiate(cartPrefab, pointPosition, cartPrefab.transform.rotation); @@ -128,6 +103,14 @@ private void CreateCart(Vector3 pointPosition) uiController.DisplayCalibrationStep2(); } + /** + * rotates the cart in a following way: + * 1. compute the distance between the indicated points in 2D space (plain from the x-axis and z-axis) + * (y position is fixed with the first indicated point) + * 2. computes the angle by which the newly created cart has to be rotated around the y-axis + * 3. rotates cart by the angle about the y-axis + * displays UI step 3 + */ private void RotateCart(Vector3 pos1, Vector3 pos2) { Vector3 pointsDifferenceVector = new Vector3(pos2.x - pos1.x, 0, pos2.z - pos1.z); @@ -137,6 +120,7 @@ private void RotateCart(Vector3 pos1, Vector3 pos2) uiController.DisplayCalibrationStep3(); } + public void Reset() { Destroy(_cart); @@ -164,26 +148,26 @@ public void SkipCalibration() EndCalibration(); } + /** + * 1. disables detecting of pinch gestures + * 2. rotates cart and the player in order to face the UI + * 3. sets cart the children of player + * 4. invokes calibration complete event + */ public void EndCalibration() { _interactable = false; ColorCart(); - var networkCamera = GameObject.FindWithTag("NetworkCamera"); + var networkCamera = GameObject.FindWithTag(GameConstants.NetworkCamera); - // var cartRotation = _cart.transform.parent.eulerAngles - _cart.transform.eulerAngles; var cartRotation = _cart.transform.eulerAngles; - Debug.Log(cartRotation); _cart.transform.Rotate(-cartRotation); - // networkCamera.transform.Rotate(cartRotation); var children = networkCamera.GetComponentsInChildren<Transform>(); foreach (var child in children) { - Debug.Log(child); - // var rotation = child.transform.rotation; - // rotation = Quaternion.Euler(rotation.x, cartRotation.y, rotation.z); child.transform.Rotate(-cartRotation); } networkCamera.transform.Rotate(cartRotation); @@ -191,12 +175,5 @@ public void EndCalibration() OnCartCreatorCalibrationComplete?.Invoke(); } - - private void RotatePlayer(GameObject networkCamera) - { - networkCamera.transform.Rotate(Vector3.up, _cart.transform.rotation.y); - - - } } } \ No newline at end of file diff --git a/Assets/Scripts/Colliders/AnimalCollider.cs b/Assets/Scripts/Colliders/AnimalCollider.cs index e37a6b8d9cf688753d4889916c2a7a7debc33077..726c1f78957e857159c511cf127388f267c40785 100644 --- a/Assets/Scripts/Colliders/AnimalCollider.cs +++ b/Assets/Scripts/Colliders/AnimalCollider.cs @@ -1,5 +1,6 @@  using Animals; +using Player; using UnityEngine; namespace Colliders @@ -12,8 +13,7 @@ public class AnimalCollider : MonoBehaviour public void OnCollisionEnter(Collision collision) { _controller = animal.GetComponentInChildren<AnimalController>(); - Debug.Log(_controller); - if (collision.gameObject.CompareTag("NetworkCamera") && collision.gameObject.name != "Terrain") + if (collision.gameObject.CompareTag(GameConstants.NetworkCamera) && collision.gameObject.name != GameConstants.Terrain) { if (_controller.GetMoving()) { diff --git a/Assets/Scripts/Colliders/DestroyObjectCollider.cs b/Assets/Scripts/Colliders/DestroyObjectCollider.cs index 9fe74ee722a308e74dd129e2776d738c6f795510..cd0a0741bd372bdfe97b2e92b935f94ad7a56153 100644 --- a/Assets/Scripts/Colliders/DestroyObjectCollider.cs +++ b/Assets/Scripts/Colliders/DestroyObjectCollider.cs @@ -1,5 +1,6 @@ using System.Collections; using System.Collections.Generic; +using Player; using UnityEngine; namespace Colliders @@ -11,10 +12,10 @@ public class DestroyObjectCollider : MonoBehaviour public void OnCollisionEnter(Collision collision) { - if (collision.gameObject.CompareTag("NetworkCamera") && !collision.gameObject.CompareTag("Terrain") && gameObject.name != "Terrain") + if (collision.gameObject.CompareTag(GameConstants.NetworkCamera) && !collision.gameObject.CompareTag(GameConstants.Terrain) && gameObject.name != GameConstants.Terrain) { - objectsToDestroy.ForEach(Destroy); objectsToSetActive.ForEach(o => o.SetActive(true)); + objectsToDestroy.ForEach(Destroy); } } } diff --git a/Assets/Scripts/Network/ConnectScreenController.cs b/Assets/Scripts/Network/ConnectScreenController.cs index 9287f29d746ee83b6cf00a2ebecf5589a13d0271..9a8ba9336257b5e079576904fd6a078cba3e1708 100644 --- a/Assets/Scripts/Network/ConnectScreenController.cs +++ b/Assets/Scripts/Network/ConnectScreenController.cs @@ -1,4 +1,5 @@ -using Mirror.Discovery; +using System.Collections; +using Mirror.Discovery; using Network; using TMPro; using UnityEngine; @@ -17,6 +18,9 @@ public class ConnectScreenController : MonoBehaviour [SerializeField] private NetworkDiscovery myNetworkDiscovery; [SerializeField] private MyNetworkManager networkManager; [SerializeField] private GameObject hintBar; + + private Button _connectButtonComponent; + private ServerResponse _serverResponse; @@ -25,18 +29,17 @@ void Awake() myNetworkDiscovery.OnServerFound.AddListener(DisplayDiscoveredServers); networkManager.OnClientConnectAction += IndicateConnectedStatus; networkManager.OnMobileClientDisconnectAction += OnDisconnect; + + _connectButtonComponent = connectButton.GetComponent<Button>(); } + private void DisplayDiscoveredServers(ServerResponse serverResponse) { - Debug.Log("connectable device found"); _serverResponse = serverResponse; deviceName.text = serverResponse.EndPoint.Address.ToString(); - deviceName.gameObject.SetActive(true); - deviceNotFound.SetActive(false); - availabilityStatus.SetSelected(true); - hintBar.SetActive(false); - ActivateConnectButton(); + + StartCoroutine(UpdateConnectUI(true)); } void Start() @@ -46,17 +49,20 @@ void Start() public void OnDisconnect() { - Debug.Log("ON DISCONNECT CONNECT screen controller"); + UpdateConnectUI(false); + connectedText.SetActive(false); connectButton.SetActive(true); - connectButton.GetComponent<Button>().interactable = false; - availabilityStatus.SetSelected(false); - deviceName.gameObject.SetActive(false); - deviceNotFound.SetActive(true); - hintBar.SetActive(true); + myNetworkDiscovery.StartDiscovery(); } - + + /** + * called on press Join button + * - sets the Join button to disabled + * - tries to connect to the found server + * - handles disconnection if the connection could not be established + */ private void Connect() { connectButton.GetComponent<Button>().interactable = false; @@ -73,17 +79,35 @@ private void Connect() } } + private void IndicateConnectedStatus() { connectedText.SetActive(true); connectButton.SetActive(false); } - private void ActivateConnectButton() + private void ActivateConnectButton(bool activate) + { + if (activate) + { + _connectButtonComponent.onClick.AddListener(Connect); + } + else + { + _connectButtonComponent.onClick.RemoveAllListeners(); + } + _connectButtonComponent.interactable = activate; + } + + private IEnumerator UpdateConnectUI(bool serverAvailable) { - var button = connectButton.GetComponent<Button>(); - button.onClick.AddListener(Connect); - button.interactable = true; + availabilityStatus.SetSelected(serverAvailable); + deviceName.gameObject.SetActive(serverAvailable); + deviceNotFound.SetActive(!serverAvailable); + hintBar.SetActive(!serverAvailable); + + yield return new WaitForSecondsRealtime(1); + ActivateConnectButton(serverAvailable); } } } diff --git a/Assets/Scripts/Network/MyNetworkManager.cs b/Assets/Scripts/Network/MyNetworkManager.cs index c07214c08aeb21309aede4346c14528051e49256..1fd8717cd8793ef2ac5a7d98d26bd08de981cd97 100644 --- a/Assets/Scripts/Network/MyNetworkManager.cs +++ b/Assets/Scripts/Network/MyNetworkManager.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using Mirror; +using Player; using UnityEngine; namespace Network @@ -16,12 +17,16 @@ public class MyNetworkManager : NetworkManager public event Action OnMobileClientDisconnectAction; + /** + * callback called automatically after server added player + * 1. instantiates player object + * 2. instantiate object carrying player and cameras + * 3. invokes established connection events + */ public override void OnServerAddPlayer(NetworkConnection conn) { InstantiatePlayer(conn); - - Debug.Log($"server added player. there are {numPlayers} connected."); - + if (numPlayers <= 1) { InstantiateCamera(); @@ -30,12 +35,15 @@ public override void OnServerAddPlayer(NetworkConnection conn) { OnMobileClientConnectAction?.Invoke(); } - - Debug.Log("conn.netid" + conn.identity.netId); - + OnServerAddPlayerAction?.Invoke(); } + /** + * instantiates player with given NetworkConnection + * adds player to Players list + * calls UpdateSceneConnected on the instantiated player to update UI + */ private void InstantiatePlayer(NetworkConnection conn) { GameObject player = Instantiate(playerPrefab); @@ -44,20 +52,19 @@ private void InstantiatePlayer(NetworkConnection conn) NetworkServer.AddPlayerForConnection(conn, player); DontDestroyOnLoad(player); Players.Add(player); - Debug.Log("added a player, players length " + Players.Count); networkPlayer.UpdateSceneConnected(); } + /** + * instantiate gameObject carrying all cameras + */ private void InstantiateCamera() { - Debug.Log("adding a camera"); - - PlayerCamera = Instantiate(spawnPrefabs.Find(prefab => prefab.name == "NetworkPlayerAttachCamera")); + PlayerCamera = Instantiate(spawnPrefabs.Find(prefab => prefab.name == GameConstants.NetworkPlayerAttachCamera)); NetworkServer.Spawn(PlayerCamera); - // for VR it is OVRCameraRig, for mobile it is Camera - var mainCamera = GameObject.FindWithTag("MainCamera"); + var mainCamera = GameObject.FindWithTag(GameConstants.MainCamera); mainCamera.transform.parent = PlayerCamera.transform; DontDestroyOnLoad(PlayerCamera); @@ -65,10 +72,8 @@ private void InstantiateCamera() public override void OnServerDisconnect(NetworkConnection conn) { - //TODO base.OnServerDisconnect(conn); - Debug.Log(numPlayers); if (numPlayers >= 1) { OnMobileClientDisconnectAction?.Invoke(); @@ -83,8 +88,6 @@ public override void OnServerDisconnect(NetworkConnection conn) public override void OnClientDisconnect(NetworkConnection conn) { OnClientDisconnectAction?.Invoke(); - - Debug.Log("client disconnected"); base.OnClientDisconnect(conn); } diff --git a/Assets/Scripts/Network/NetworkPlayer.cs b/Assets/Scripts/Network/NetworkPlayer.cs index 8cf8bc026789bbe980223c1441fdfbc7659328f0..762ae876091c40065aec4b52f389b42c8d95f5c5 100644 --- a/Assets/Scripts/Network/NetworkPlayer.cs +++ b/Assets/Scripts/Network/NetworkPlayer.cs @@ -10,7 +10,7 @@ namespace Network { public class NetworkPlayer : NetworkBehaviour { - [SyncVar(hook = "SetMobile")] public bool mobile = false; + [SyncVar] public bool mobile = false; [SyncVar(hook = "ChangeScene")] public string chosenWorld; @@ -33,7 +33,7 @@ public class NetworkPlayer : NetworkBehaviour private BaseUIController _uiController; - private GameController _gameController; + private VRController _vrController; private BaseController _controller; private SceneLoader _sceneLoader; private NetworkPlayer[] _networkPlayers; @@ -45,7 +45,7 @@ private void Awake() { _controller = FindObjectOfType<BaseController>(); _sceneLoader = FindObjectOfType<SceneLoader>(); - _gameController = FindObjectOfType<GameController>(); + _vrController = FindObjectOfType<VRController>(); _uiController = FindObjectOfType<BaseUIController>(); _networkPlayers = FindObjectsOfType<NetworkPlayer>(); } @@ -80,15 +80,23 @@ public void UpdateSceneConnected() { _controller.AssignPlayers(); - if (SceneManager.GetActiveScene().name == "AppOffline" && isLocalPlayer) + if (SceneManager.GetActiveScene().name == GameConstants.AppOffline && isLocalPlayer) { CmdSetMobile(true); - ((MobileController) _controller).AssignPlayer(this); // mozna presunout do onstrtlocalplayer + ((MobileController) _controller).AssignPlayer(this); } } /** * CALLBACKS + * + * methods below all called whenever a specific SyncVar is changed + */ + + /** + * triggers loading a scene (additively) + * if VR: loads the the chosen scene + * if mobile: loads a mobile version of the chosen scene */ public void ChangeScene(string oldScene, string newScene) { @@ -100,31 +108,29 @@ public void ChangeScene(string oldScene, string newScene) goToLobby = false; DontDestroyOnLoad(this); string sceneToLoad = newScene; - Debug.Log("Change sceen in network player, mobile: " + mobile); if (isLocalPlayer) { - if ((mobile || SceneManager.GetActiveScene().name == "AppOffline")) + if (mobile || SceneManager.GetActiveScene().name == GameConstants.AppOffline) { sceneToLoad = sceneToLoad + "Mobile"; - // sceneToLoad = "EmptySceneMobile"; - } _sceneLoader.LoadScene(sceneToLoad, true); } } - private void SetMobile(bool oldValue, bool mobile) - { - Debug.Log("mobile noe: " + mobile); - } - + /** + * if goToLobby true: set SyncVars to default values and synchronise them across players + * call appropriate methods at mobile and VR players' controllers + */ public void GoToLobby(bool oldValue, bool exit) { if (exit) { playerMoving = false; chosenWorld = String.Empty; + triggerTimeSync = false; + timePlaying = 0f; if (_networkPlayers.Length < 2) { @@ -139,15 +145,19 @@ public void GoToLobby(bool oldValue, bool exit) networkPlayer.CmdTriggerTimeSync(false); } - if (mobile && isLocalPlayer) - { - _controller.OnGoToLobby(); - } - else if (!mobile && isLocalPlayer) + if (isLocalPlayer) { - Debug.Log("network player go to lobby"); - _gameController = FindObjectOfType<GameController>(); - _gameController.GoToLobby(); + if (!mobile) + { + if (!_vrController) + { + AssignGameController(); + } + + _vrController.GoToLobby(); + _controller.OnGoToLobby(); + } + _controller.OnGoToLobby(); } } @@ -155,81 +165,74 @@ public void GoToLobby(bool oldValue, bool exit) public void SetPlayerMoving(bool oldValue, bool moving) { - Debug.Log("set player moving in Network pLayer, moving: " + moving); - if (!mobile && isLocalPlayer && !goToLobby) { - AssignGameController(); //TODO nejak jinak mozna smazat + if (!_vrController) + { + AssignGameController(); + } if (moving) { - Debug.Log(_gameController); - - _gameController.StartMovement(); + _vrController.StartMovement(); } else { - _gameController.PauseMovement(); + _vrController.PauseMovement(); } } } public void SetSpeed(int oldValue, int movingSpeed) { - if (isLocalPlayer) + if (isLocalPlayer && !mobile) { - if (!mobile) + if (!_vrController) { - _gameController.SetMovementSpeed(movingSpeed); + AssignGameController(); } + _vrController.SetMovementSpeed(movingSpeed); } } public void SkipCalibration(bool oldValue, bool skip) { - Debug.Log("set player skip calibration CALLBACK in Network pLayer, skip: " + skip); if (!mobile) { _controller.SkipCalibration(); - // ((VRLobbyController) _controller).GetCartCreator().SkipCalibration(); } } - //called automatically, after calibrationComplete changes private void SetCalibrationComplete(bool oldValue, bool complete) { - Debug.Log("Set calibration complete callback nETWORK PLAYER"); - OnCalibrationComplete?.Invoke(); //ma si to prevzit mobile controller (MobileController) + OnCalibrationComplete?.Invoke(); } + /** + * syncs the time spent in an ongoing VR experience in case the mobile player joins during an ongoing VR experience + */ private void SetTimePlaying(float oldValue, float playTime) { - Debug.Log("set time playing in network player"); - - if (mobile && isLocalPlayer) + Debug.Log(SceneManager.GetSceneAt(0).name); + if (SceneManager.GetSceneAt(0).name.Equals(GameConstants.AppOffline)) { - Debug.Log("((UIControllerMobile) _uiController).UpdateTimer(playerMoving, playTime);" + playerMoving); ((UIControllerMobile) _uiController).UpdateTimer(playerMoving, playTime); } } + /** + * trigger synchronisation of the time spent in an ongoing VR experience + */ private void TriggerTimeSync(bool oldValue, bool timeSyncTrigger) { if (timeSyncTrigger && !mobile && isLocalPlayer) { - Debug.Log("VR local player cmd time sync"); - - if (!_gameController) + if (!_vrController) { AssignGameController(); } - if (!_gameController) - { - return; - } - - var currentTimePlaying = _gameController.GetTimePlaying(); + var currentTimePlaying = _vrController.GetTimePlaying(); if (_networkPlayers.Length < 2) { @@ -238,47 +241,48 @@ private void TriggerTimeSync(bool oldValue, bool timeSyncTrigger) foreach (var networkPlayer in _networkPlayers) { - networkPlayer.CmdSyncTimePlaying(currentTimePlaying); + RpcSetTimePlaying(currentTimePlaying); + networkPlayer.timePlaying = currentTimePlaying; + networkPlayer.triggerTimeSync = false; } } } + /** + * invokes event when world is loaded at the VR client + */ private void OnWorldLoaded(bool oldValue, bool loaded) { - if (loaded) + if (loaded && !mobile) { - Debug.Log("WORLD LOADED"); - if (!mobile) - { - Debug.Log("On world loaded VR playrt invoking onsceneloaded"); - OnSceneLoadedAction?.Invoke(); - } + OnSceneLoadedAction?.Invoke(); } } /** * COMMANDS + * + * methods below change the values of SyncVars + * - called from clients but executed on the server + * - requiresAuthority set to false to be able to sync SyncVars across all players */ - - //mozna ze to coje ted v networkManager se da dat i sem jako serverova strana - [Command(requiresAuthority = false)] //require authority + [Command(requiresAuthority = false)] public void CmdHandleSelectedWorld(string sceneName) { - Debug.Log(chosenWorld); - if (String.IsNullOrEmpty(chosenWorld)) { chosenWorld = sceneName; //changing syncvar as cmd results in server synchronising all clients } } - //volano Controllerem - [Command(requiresAuthority = false)] //require authority + [Command(requiresAuthority = false)] public void CmdSetPlayerMoving(bool moving) { - Debug.Log("cmd set player moving"); - playerMoving = moving; + if (!goToLobby) + { + playerMoving = moving; + } } [Command(requiresAuthority = false)] @@ -287,7 +291,7 @@ public void CmdSkipCalibration(bool skip) skipCalibration = true; } - [Command(requiresAuthority = false)] //require authority + [Command(requiresAuthority = false)] public void CmdGoToLobby() { goToLobby = true; @@ -315,18 +319,13 @@ public void CmdSetSpeed(int movingSpeed) [Command(requiresAuthority = false)] public void CmdSyncTimePlaying(float timePlayingValue) { - Debug.Log("CmdSyncTimePlaying " + timePlayingValue); timePlaying = timePlayingValue; } [Command(requiresAuthority = false)] public void CmdTriggerTimeSync(bool trigger) { - Debug.Log("CmdTriggerTimeSync " + trigger); - if (trigger) - { - triggerTimeSync = true; - } + triggerTimeSync = trigger; } [Command] @@ -335,19 +334,16 @@ public void CmdSetWorldLoaded(bool loaded) worldLoaded = loaded; } - public GameController GetGameController() + [TargetRpc] + public void RpcSetTimePlaying(float time) { - if (_gameController == null) - { - AssignGameController(); - } - - return _gameController; + timePlaying = time; } + private void AssignGameController() { - _gameController = FindObjectOfType<GameController>(); + _vrController = FindObjectOfType<VRController>(); } private void AssignNetworkPlayers() diff --git a/Assets/Scripts/Network/PlayerCamera.cs b/Assets/Scripts/Network/PlayerCamera.cs index d0b2f0b9ade5b1ddb8a115f8fe2babeebd904320..3e294494148998f7d469e2cdf329fb53333642f9 100644 --- a/Assets/Scripts/Network/PlayerCamera.cs +++ b/Assets/Scripts/Network/PlayerCamera.cs @@ -1,44 +1,38 @@ using Mirror; using Player; -using Scenes; using UnityEngine; using UnityEngine.SceneManagement; namespace Network { + /** + * handles syncing of VR player's viewpoint with render-texture cameras + * 1. synchronises the OVRCameraRig position with cameras positions + * 2. synchronises the CenterEyeAnchor rotation with rtCamera and rtCameraWides rotations + */ public class PlayerCamera : NetworkBehaviour { - [SerializeField] private SceneController sceneController; [SerializeField] private GameObject rtCamera; [SerializeField] private GameObject rtWideCamera; [SerializeField] private GameObject rtWideTopCamera; [SerializeField] private GameObject rtTopCamera; - // [SerializeField] private GameObject playerGazeDummy; private bool _vrInstance; - private GameObject _cameraRig; private GameObject _centerEyeAnchor; - private Vector3 _position; // position of player gaze - - private OVRManager _ovrManager; - private GameController _gameController; + private VRController _vrController; private void Awake() { - _vrInstance = SceneManager.GetActiveScene().name == "VROffline"; + _vrInstance = SceneManager.GetActiveScene().name == GameConstants.VROffline; if (_vrInstance) { SceneManager.sceneLoaded += AssignChild; SceneManager.sceneLoaded += UpdateCameraRig; - _cameraRig = GameObject.FindWithTag("MainCamera"); - _ovrManager = _cameraRig.GetComponent<OVRManager>(); - _ovrManager = _cameraRig.GetComponent<OVRManager>(); - - _centerEyeAnchor = GameObject.FindWithTag("CenterEyeAnchor"); + _centerEyeAnchor = GameObject.FindWithTag(GameConstants.CenterEyeAnchor); } } @@ -51,10 +45,7 @@ void Update() } } - - /** - * Update networked RTCamera transforms - */ + private void SyncUserPositionAndRotation() { var playerViewportPosition = _centerEyeAnchor.transform.position; @@ -76,15 +67,13 @@ private void UpdateCameraRig(Scene arg0, LoadSceneMode loadSceneMode) { if (_vrInstance) { - _cameraRig = GameObject.FindWithTag("MainCamera"); - _ovrManager = _cameraRig.GetComponent<OVRManager>(); + _cameraRig = GameObject.FindWithTag(GameConstants.MainCamera); } } private void AssignChild(Scene arg0, LoadSceneMode loadSceneMode) { - _cameraRig = GameObject.FindWithTag("MainCamera"); - Debug.Log("assigning child MAIN CAMERA "); + _cameraRig = GameObject.FindWithTag(GameConstants.MainCamera); _cameraRig.transform.parent = this.transform; } } diff --git a/Assets/Scripts/Player/BaseController.cs b/Assets/Scripts/Player/BaseController.cs index 302fb847630d0b4e0537284a78ea435f27d5d052..02d543bddbee49cdd4992b857a53acec2bc64141 100644 --- a/Assets/Scripts/Player/BaseController.cs +++ b/Assets/Scripts/Player/BaseController.cs @@ -1,8 +1,6 @@ -using System.Collections.Generic; -using System.Linq; + using UnityEngine; using NetworkPlayer = Network.NetworkPlayer; -using Mirror; using Mirror.Discovery; using Network; using Scenes; @@ -37,18 +35,17 @@ public virtual void OnDisconnect() uiController.DisplayError(); } - public virtual void AssignPlayers() + /** + * assigns LocalNetworkPlayer and RemoteNetworkPlayer variables from all player objects in the scene + */ + public void AssignPlayers() { - Debug.Log("assign players in BASE Controller called"); - NetworkPlayers = GameObject.FindObjectsOfType<NetworkPlayer>(); + NetworkPlayers = FindObjectsOfType<NetworkPlayer>(); foreach (var networkPlayer in NetworkPlayers) { if (networkPlayer.isLocalPlayer) { - Debug.Log("found network player LOCAL"); - LocalNetworkPlayer = networkPlayer; - LocalNetworkPlayer.OnCalibrationComplete += OnCalibrationComplete; } else { @@ -57,15 +54,14 @@ public virtual void AssignPlayers() } } - public virtual void OnCalibrationComplete() - { - } + protected virtual void OnCalibrationComplete() { } - public virtual void SkipCalibration() - { - } + public virtual void SkipCalibration() { } - public virtual void SetCalibrationComplete() + /** + * synchronises calibration complete syncVar with all NetworkPlayers in the scene + */ + protected virtual void SetCalibrationComplete() { if (NetworkPlayers.Length < 2) { @@ -74,32 +70,33 @@ public virtual void SetCalibrationComplete() foreach (var networkPlayer in NetworkPlayers) { - Debug.Log("setting cmdsetcalibrationcomplete"); networkPlayer.CmdSetCalibrationComplete(true); } } + /** + * handles selecting a scene (if no world scene is loaded/loading) + * and triggers network synchronisation with Command CmdHandleSelectedWorld on all NetworkPlayers in the scene + */ public virtual void OnSceneSelected(string sceneName) { - Debug.Log("OnSceneSelected ......."); if (SceneManager.sceneCount > 1) { - Debug.Log("sceneCount > 1"); + Debug.Log("scene count > 1"); return; } foreach (var networkPlayer in NetworkPlayers) { - Debug.Log("setting cmd hanlde selected world called"); - // Debug.Log(sceneName); networkPlayer.CmdHandleSelectedWorld(sceneName); - }//message about scene loading to other players + } } - public virtual void OnGoToLobby() - { - } + public virtual void OnGoToLobby() { } + /** + * synchronises triggerGoToLobby syncVar with all NetworkPlayers in the scene + */ public virtual void TriggerGoToLobby() { foreach (var networkPlayer in NetworkPlayers) @@ -108,11 +105,11 @@ public virtual void TriggerGoToLobby() } } - public virtual void OnSceneLoaded() - { - - } + protected virtual void OnSceneLoaded() { } + /** + * handles selected language with given index of the language + */ public void OnLanguageSelected(int index) { LocalizationSettings.SelectedLocale = LocalizationSettings.AvailableLocales.Locales[index]; diff --git a/Assets/Scripts/Player/GameConstants.cs b/Assets/Scripts/Player/GameConstants.cs index 6d2e9e9e8a87b8e3ff00e9bf6dcf7b2c413802d6..0f8711aff98e07bf03c379c81b10666e8e223bd6 100644 --- a/Assets/Scripts/Player/GameConstants.cs +++ b/Assets/Scripts/Player/GameConstants.cs @@ -8,5 +8,8 @@ public class GameConstants public const string AppOffline = "AppOffline"; public const string VROffline = "VROffline"; public const string Cart = "Cart"; + public const string CenterEyeAnchor = "CenterEyeAnchor"; + public const string NetworkPlayerAttachCamera = "NetworkPlayerAttachCamera"; + public const string Terrain = "Terrain"; } } diff --git a/Assets/Scripts/Player/MobileController.cs b/Assets/Scripts/Player/MobileController.cs index f47d12fa4adbe8dff757d57f488f5edb5e567034..b5deb77d9b2cca1071fd68aebcd3e8c6cde920a1 100644 --- a/Assets/Scripts/Player/MobileController.cs +++ b/Assets/Scripts/Player/MobileController.cs @@ -2,7 +2,6 @@ using Scenes; using UI; using UnityEngine; -using UnityEngine.SceneManagement; using NetworkPlayer = Network.NetworkPlayer; using PlayMode = UI.PlayMode; @@ -30,37 +29,29 @@ public void Awake() AssignPlayers(); } - public override void OnSceneLoaded() + /** + * mobile client should wait for the moment a world is loaded in the VR application + * - called on mobile application scene load finish + * - if VR app has scene already loaded, mobile proceeds to display relevant UI + * - if not, an event is subscribed + */ + protected override void OnSceneLoaded() { base.OnSceneLoaded(); - Debug.Log("ON SCENE LOADED"); - - // var scene = SceneManager.GetSceneByName(LocalNetworkPlayer.chosenWorld + "Mobile"); - // var scene = SceneManager.GetSceneByName("EWinterMobile"); - // SceneManager.SetActiveScene(scene); - - // GameObject.FindObjectOfType<Canvas>().gameObject.SetActive(false); if (RemoteNetworkPlayer.worldLoaded) { - Debug.Log("RemoteNetworkPlayer.worldLoaded"); - - uiControllerMobile.EnablePanelExclusive("WatchScreenPortrait"); - uiControllerMobile.EnableTrue("VideoControls"); + uiControllerMobile.EnablePanelExclusive(UIConstants.WatchScreenPortrait); + uiControllerMobile.EnableTrue(UIConstants.VideoControls); uiControllerMobile.OnSceneLoaded(); _playing = RemoteNetworkPlayer.playerMoving; - // if (NetworkPlayers.Length < 2) - // { - // AssignPlayers(); - // } - foreach (var networkPlayer in NetworkPlayers) { networkPlayer.CmdTriggerTimeSync(true); } - + LocalNetworkPlayer.CmdSetPlayerMoving(_playing); uiControllerMobile.SetPlayButtonSelected(_playing); EnableCamera(PlayMode.PlayerCamera, true); @@ -78,14 +69,13 @@ public override void OnDisconnect() uiControllerMobile.EnablePanelExclusive(UIConstants.ConnectScreen); connectController.OnDisconnect(); sceneLoader.UnloadScene(); - - Debug.Log("MobileController.OnDisconnect"); } + /** + * handles pressing the Play button + */ public void OnPlayPressed() { - Debug.Log("playing " + LocalNetworkPlayer.playerMoving); - _playing = !LocalNetworkPlayer.playerMoving; if (NetworkPlayers.Length < 2) @@ -100,76 +90,64 @@ public void OnPlayPressed() uiControllerMobile.OnPlayPressed(_playing); } - - // public void EndDrive() - // { - // Debug.Log("Mobile Controller end drive"); - // LocalNetworkPlayer.CmdSetPlayerMoving(false); - // - // } - public override void SkipCalibration() { - // if (NetworkPlayers.Length < 2) - // { - // AssignPlayers(); - // } - foreach (var networkPlayer in NetworkPlayers) { networkPlayer.CmdSkipCalibration(true); } } + /** + * called when mobile app connects the VR app + * handles the situations, when: + * - VR application is in calibration process + * - VR application is in scene selection process + * - VR application has scene selected + */ public void AssignPlayer(NetworkPlayer networkPlayer) { LocalNetworkPlayer = networkPlayer; _vrPlayer = networkPlayer; - foreach (var player in FindObjectsOfType<NetworkPlayer>().Where(p => !p.isLocalPlayer)) + foreach (var player in FindObjectsOfType<NetworkPlayer>().Where(p => !p.isLocalPlayer && !p.mobile)) { _vrPlayer = player; } - if (_vrPlayer.calibrationComplete) - { - LocalNetworkPlayer.CmdSetCalibrationComplete(true); - } - + Debug.Log("_vrPlayer.mobile " + _vrPlayer.mobile); + // if (_vrPlayer.calibrationComplete) + // { + // LocalNetworkPlayer.CmdSetCalibrationComplete(true); + // } if (_vrPlayer.playerMoving) { LocalNetworkPlayer.CmdSetPlayerMoving(true); } - Debug.Log("ASSIGN PLAYER " + networkPlayer); - - if (_vrPlayer.calibrationComplete) //calibration complete in VR + if (!string.IsNullOrEmpty(_vrPlayer.chosenWorld)) //scene selected in VR { - Debug.Log("calibration complete"); + DisplaySceneSelected(_vrPlayer.chosenWorld); + } + else if (_vrPlayer.calibrationComplete) //calibration complete in VR + { + LocalNetworkPlayer.CmdSetCalibrationComplete(true); OnCalibrationComplete(); } else //calibration in process { - Debug.Log("calibration in processs......."); - uiControllerMobile.EnableTrue("Calibration"); // display "Calibration in process message" + uiControllerMobile.EnableTrue(UIConstants.Calibration); // display "Calibration in process message" LocalNetworkPlayer.OnCalibrationComplete += OnCalibrationComplete; //observe calibration complete process } - if (!string.IsNullOrEmpty(_vrPlayer.chosenWorld)) //scene selected in VR - { - Debug.Log("chosen world " + _vrPlayer.chosenWorld); - DisplaySceneSelected(_vrPlayer.chosenWorld); - } - AssignCameras(); } - public override void OnCalibrationComplete() + protected override void OnCalibrationComplete() { base.OnCalibrationComplete(); - Debug.Log("HIDE CALIBRATION MOBILE CONTROLLER"); if (!string.IsNullOrEmpty(_vrPlayer.chosenWorld)) { DisplaySceneSelected(_vrPlayer.chosenWorld); @@ -191,7 +169,6 @@ public override void OnGoToLobby() private void DisplaySceneSelected(string sceneName) { - Debug.Log("display scene selected"); uiController.EnableFalse(UIConstants.SceneSelection); uiController.EnableTrue(UIConstants.SceneJoin); } @@ -203,10 +180,6 @@ public void OnLoadedSceneJoin() public void SetSpeed(float value) { - Debug.Log("setting speed to " + value); - - // AssignPlayers(); - foreach (var networkPlayer in NetworkPlayers) { networkPlayer.CmdSetSpeed((int) value); diff --git a/Assets/Scripts/Player/PlayerMovement.cs b/Assets/Scripts/Player/PlayerMovement.cs index 4dd06ff74553c4a3789ac1e9913ec37cb9e2c023..7ff4ffcc363e96813eb9c5dcf9dae188fd1f4c09 100644 --- a/Assets/Scripts/Player/PlayerMovement.cs +++ b/Assets/Scripts/Player/PlayerMovement.cs @@ -1,8 +1,5 @@ -using System.Collections.Generic; -using PathCreation; +using PathCreation; using UnityEngine; -using UnityEngine.SceneManagement; -using UnityEngine.Serialization; namespace Player { @@ -16,7 +13,7 @@ public class PlayerMovement : MonoBehaviour private Animator _animator; private PathCreator _pathCreator; - private GameController _controller; + private VRController _controller; private float _distance; private bool _shiftCamera = false; private float _time; @@ -33,7 +30,7 @@ void Awake() void Start() { - _controller = FindObjectOfType<GameController>(); + _controller = FindObjectOfType<VRController>(); _pathCreator = GameObject.FindWithTag("PathCreator").GetComponent<PathCreator>(); var startingPos = _pathCreator.path.GetPoint(0) + offset; @@ -64,14 +61,12 @@ void Update() if (_distance >= _pathCreator.path.length) { - Debug.Log("calling controller.End"); _controller.End(); } } public void SetPathCreator(PathCreator pathCreator) { - Debug.Log("setting path creators"); _pathCreator = pathCreator; } diff --git a/Assets/Scripts/Player/GameController.cs b/Assets/Scripts/Player/VRController.cs similarity index 87% rename from Assets/Scripts/Player/GameController.cs rename to Assets/Scripts/Player/VRController.cs index b664bea178ef3c01a4b5844ef9c6d7fb8ba33ccf..8d0e100ddf8aa0b4f8d16195ad5c0d93521ea062 100644 --- a/Assets/Scripts/Player/GameController.cs +++ b/Assets/Scripts/Player/VRController.cs @@ -9,7 +9,10 @@ namespace Player { - public class GameController : MonoBehaviour + /** + * Controller managing events in VR travelling experience + */ + public class VRController : MonoBehaviour { public List<GameObject> player = new List<GameObject>(); private SceneController _sceneController; @@ -37,8 +40,8 @@ private void Awake() _currentScene = SceneManager.GetActiveScene().name; _customSpeed = _networkPlayer.speed; - _cart = GameObject.FindWithTag("Cart"); - _player = GameObject.FindWithTag("NetworkCamera"); + _cart = GameObject.FindWithTag(GameConstants.Cart); + _player = GameObject.FindWithTag(GameConstants.NetworkCamera); _sceneController = GameObject.FindObjectOfType<SceneController>(); _sceneLoader = GameObject.FindObjectOfType<SceneLoader>(); _pathCreator = FindObjectOfType<PathCreator>(); @@ -75,8 +78,6 @@ public IEnumerator Start() public void StartMovement() { - Debug.Log("game controller starting movement"); - foreach (var script in _playerMovementScripts) { Enable(script); @@ -112,9 +113,7 @@ public void End() { StopCart(); } - - Debug.Log("calling CmdGoToLobby"); - + var networkPlayers = FindObjectsOfType<NetworkPlayer>(); foreach (var networkPlayer in networkPlayers) { @@ -148,19 +147,23 @@ private void StopCart() public void GoToLobby() { - Debug.Log("game controller go to lobby"); StartCoroutine(GoToLobbyCoroutine()); } + /** + * coroutine of VR player returning to lobby + * 1. Waits for defined waiting time + * 2. Sets Lobby as active scene + * 3. Moves player at accurate position in Lobby + * 4. calls async scene unloading + */ private IEnumerator GoToLobbyCoroutine() { yield return new WaitForSecondsRealtime(GameConstants.ReturnToLobbyWaitingTime); - SceneManager.SetActiveScene(SceneManager.GetSceneByName("VROffline")); + SceneManager.SetActiveScene(SceneManager.GetSceneByName(GameConstants.VROffline)); _sceneController.MovePlayersAtStartingPositionLobby(); - - Debug.Log("Unloading scene"); _sceneLoader.UnloadScene(); } @@ -168,7 +171,7 @@ private IEnumerator GoToLobbyCoroutine() public void SetMovementSpeed(int speed) { - if (_playerMovementScripts.Length > 0) + if (_playerMovementScripts.Length > 0) //TODO { foreach (var playerMovement in _playerMovementScripts) { @@ -178,11 +181,13 @@ public void SetMovementSpeed(int speed) } else { - Debug.Log("custom speed set"); _customSpeed = speed; } } + /** + * return time (float) spent in an ongoing VR experience + */ public float GetTimePlaying() { if (_playerMovementScripts.Length > 0) @@ -192,10 +197,9 @@ public float GetTimePlaying() return 0f; } - + private void TriggerPlayerMoving() { - Debug.Log("trigger player move"); _networkPlayer.CmdSetPlayerMoving(true); } } diff --git a/Assets/Scripts/Player/GameController.cs.meta b/Assets/Scripts/Player/VRController.cs.meta similarity index 100% rename from Assets/Scripts/Player/GameController.cs.meta rename to Assets/Scripts/Player/VRController.cs.meta diff --git a/Assets/Scripts/Player/VRLobbyController.cs b/Assets/Scripts/Player/VRLobbyController.cs index 02e61916dc432179c356b02308ee2ccc45413708..9ec9a230da7eb717062c16ee78272aea8aa46b07 100644 --- a/Assets/Scripts/Player/VRLobbyController.cs +++ b/Assets/Scripts/Player/VRLobbyController.cs @@ -1,18 +1,12 @@ using System.Collections; using Cart; using Mirror; +using UI; using UnityEngine; using UnityEngine.SceneManagement; namespace Player { - public enum World - { - MainScene, - WinterScene, - RuralScene - } - public class VRLobbyController : BaseController { [SerializeField] private CartCreator cartCreator; @@ -36,26 +30,6 @@ private IEnumerator Start() networkDiscovery.AdvertiseServer(); } - //debug only - private void Update() - { - if (_debug) - { - if (Input.GetKey(KeyCode.R)) - { - OnSceneSelected(World.RuralScene.ToString()); - } - if (Input.GetKey(KeyCode.W)) - { - OnSceneSelected(World.WinterScene.ToString()); - } - if (Input.GetKey(KeyCode.M)) - { - OnSceneSelected(World.MainScene.ToString()); - } - } - } - private void OnClientConnected() { uiController.Activate("AvailabilityIndicatorVR"); @@ -77,17 +51,10 @@ private void OnClientMobileDisconnected() uiController.Deactivate("AvailabilityIndicatorMobile"); } - public override void SetCalibrationComplete() - { - base.SetCalibrationComplete(); - Debug.Log("SET calibration complete network vRLOBBY CONTROLLER"); - } - - public override void OnCalibrationComplete() + protected override void OnCalibrationComplete() { base.OnCalibrationComplete(); - uiController.EnablePanelExclusive("SceneSelection"); - Debug.Log("ON calibration complete network vRLOBBY CONTROLLER"); + uiController.EnablePanelExclusive(UIConstants.SceneSelection); } public override void SkipCalibration() @@ -96,27 +63,18 @@ public override void SkipCalibration() cartCreator.SkipCalibration(); } - public override void OnSceneLoaded() + protected override void OnSceneLoaded() { uiController.gameObject.SetActive(false); - Debug.Log("LocalNetworkPlayer.chosenWorld " + LocalNetworkPlayer.chosenWorld); var scene = SceneManager.GetSceneByName(LocalNetworkPlayer.chosenWorld); SceneManager.SetActiveScene(scene); } public override void OnGoToLobby() { - Debug.Log("on go to lobbyyyyyyyy"); uiController.gameObject.SetActive(true); LocalNetworkPlayer.CmdSetWorldLoaded(false); } - - public CartCreator GetCartCreator() - { - return cartCreator; - } - - } } \ No newline at end of file diff --git a/Assets/Scripts/Scenes/SceneController.cs b/Assets/Scripts/Scenes/SceneController.cs index b11f8934787e91675c5b0046ba54d7ecb0c0bdbd..0b07834c675dabef386708a6af2377f1caf6da0c 100644 --- a/Assets/Scripts/Scenes/SceneController.cs +++ b/Assets/Scripts/Scenes/SceneController.cs @@ -29,10 +29,6 @@ void Start() { if (!player.mobile) { - Debug.Log("On scene loaded VR"); - - Debug.Log(player); - player.CmdSetWorldLoaded(true); } } @@ -40,8 +36,6 @@ void Start() public void MovePlayersAtStartingPosition() { - Debug.Log("MOVE player at starting position"); - DontDestroyOnLoad(_player); _player.transform.position = startingPoint.position; _player.transform.rotation = startingPoint.rotation; @@ -50,15 +44,12 @@ public void MovePlayersAtStartingPosition() { _mainCamera.transform.parent = _player.transform; _mainCamera.transform.position = _player.transform.position; - // _mainCamera.transform.localPosition = new Vector3(0, 1.5f, -0.273f); _mainCamera.transform.localPosition = new Vector3(0, 1.5f, 0); } } public void MovePlayersAtStartingPositionLobby() { - Debug.Log("move player to lobby"); - if (!_player) { _player = GameObject.FindWithTag(GameConstants.NetworkCamera); diff --git a/Assets/Scripts/Scenes/SceneLoader.cs b/Assets/Scripts/Scenes/SceneLoader.cs index 0015b1b7694846fb022a5bd0ea82e5f1e13afad6..3d64817cec2ed69089daefb106bf67abd2f40d59 100644 --- a/Assets/Scripts/Scenes/SceneLoader.cs +++ b/Assets/Scripts/Scenes/SceneLoader.cs @@ -1,5 +1,6 @@ using System; using System.Collections; +using Player; using UI; using UnityEngine; using UnityEngine.SceneManagement; @@ -20,23 +21,16 @@ public class SceneLoader : MonoBehaviour void Start() { - _camera = GameObject.FindWithTag("MainCamera"); + _camera = GameObject.FindWithTag(GameConstants.MainCamera); } public void LoadScene(string scene, bool additiveSceneMode) { - // _currentSceneName = scene; _currentSceneName = SceneManager.GetActiveScene().name; _loadedSceneName = scene; - Debug.Log("_currentSceneName" + _currentSceneName); - Debug.Log("scene loader.LoadScene"); + loaderUI.DisplayLoader(true); - loaderUI.DisplayLoader(true); //potreba? - - var mobile = _currentSceneName == "AppOffline"; - - // SceneManager.LoadScene(scene, LoadSceneMode.Additive); _sceneLoadingOperation = SceneManager.LoadSceneAsync(scene, LoadSceneMode.Additive); DetachCameraFromNetworkPlayer(); @@ -46,7 +40,7 @@ public void LoadScene(string scene, bool additiveSceneMode) private void DetachCameraFromNetworkPlayer() { - //detach camera from networkCamera + //detach camera from NetworkCamera if (_camera) { _camera.transform.parent = null; @@ -54,7 +48,6 @@ private void DetachCameraFromNetworkPlayer() // move camera out of DontDestroyOnLoad SceneManager.MoveGameObjectToScene(_camera, SceneManager.GetActiveScene()); - // DontDestroyOnLoad(_camera); } private IEnumerator LoadSceneAsync() @@ -76,7 +69,6 @@ private IEnumerator LoadSceneAsync() SceneManager.SetActiveScene(SceneManager.GetSceneByName(_loadedSceneName)); _currentSceneName = _loadedSceneName; - yield return new WaitForSecondsRealtime(1); SceneLoadingEnd?.Invoke(); loaderUI.DisplayLoader(false); @@ -92,7 +84,6 @@ private IEnumerator LoadSceneAsync() public void UnloadScene() { - // SceneManager.UnloadScene(_currentSceneName); SceneManager.UnloadSceneAsync(_currentSceneName); } } diff --git a/Assets/Scripts/UI/BaseUIController.cs b/Assets/Scripts/UI/BaseUIController.cs index 20c108443f66d7ed7a2422c045f64233f3187562..a8bf0adeb8bcf492c62762d12903b0cd54e86b59 100644 --- a/Assets/Scripts/UI/BaseUIController.cs +++ b/Assets/Scripts/UI/BaseUIController.cs @@ -17,13 +17,9 @@ public class BaseUIController : MonoBehaviour [SerializeField] private TMP_Dropdown languagesDropdown; [SerializeField] protected List<GameObject> panels; - - [FormerlySerializedAs("activables")] [SerializeField] - protected List<Selectable> activableSprites; - - [FormerlySerializedAs("enalables")] [SerializeField] - protected List<GameObject> enalableObjects; - + [SerializeField] protected List<Selectable> activableSprites; + [SerializeField] protected List<GameObject> enalableObjects; + [SerializeField] protected MyNetworkManager networkManager; [SerializeField] protected BaseController controller; @@ -83,7 +79,6 @@ public void Deactivate(string activableName) ActivateSprite(activableName, false); } - //todo mozna presunout do Controller public void OnQuit() { Application.Quit(); diff --git a/Assets/Scripts/UI/DisplayStrategy.cs b/Assets/Scripts/UI/DisplayStrategy.cs index 450be7e42c73fa9f9dc49c2ea1ffd37ccb46beee..042358c636ca450a589110f1a02e9b1a7bd6c5b4 100644 --- a/Assets/Scripts/UI/DisplayStrategy.cs +++ b/Assets/Scripts/UI/DisplayStrategy.cs @@ -1,5 +1,8 @@ namespace UI { + /** + * Base class for implementing view strategies / behaviour observing views displayed in the control application + */ public abstract class DisplayStrategy { protected readonly UIControllerMobile UIController; diff --git a/Assets/Scripts/UI/LoaderUI.cs b/Assets/Scripts/UI/LoaderUI.cs index 21e3b2f68097befe165f4e55ce5d09794729731a..a2459d8e6f46c91ce8ef14bfbeb3ed7e80ae843e 100644 --- a/Assets/Scripts/UI/LoaderUI.cs +++ b/Assets/Scripts/UI/LoaderUI.cs @@ -4,6 +4,9 @@ namespace UI { + /** + * Manages displaying of Loader UI element + */ public class LoaderUI : MonoBehaviour { [SerializeField] private GameObject loader; diff --git a/Assets/Scripts/UI/RayTransformSetter.cs b/Assets/Scripts/UI/RayTransformSetter.cs index 9269cbe2c6fbce32813942298973a00e89c5bac6..ab9a55c2c8b401fcdefc3180cd249a8090868f5a 100644 --- a/Assets/Scripts/UI/RayTransformSetter.cs +++ b/Assets/Scripts/UI/RayTransformSetter.cs @@ -1,28 +1,30 @@ -using System; -using System.Collections; -using System.Collections.Generic; -using UnityEngine; +using UnityEngine; using UnityEngine.EventSystems; -public class RayTransformSetter : MonoBehaviour +namespace UI { - [SerializeField] private OVRHand hand; - [SerializeField] private GameObject handAnchor; - [SerializeField] private OVRInputModule ovrInputModule; - - private void Start() + /** + * sets ray transform origin to accurate position within virtual hands + */ + public class RayTransformSetter : MonoBehaviour { - SetRayTransform(); - } + [SerializeField] private OVRHand hand; + [SerializeField] private OVRInputModule ovrInputModule; + + private void Start() + { + SetRayTransform(); + } - void Update() - { - SetRayTransform(); - } + void Update() + { + SetRayTransform(); + } - void SetRayTransform() - { - Transform t = hand.PointerPose; - ovrInputModule.rayTransform = t; + void SetRayTransform() + { + Transform t = hand.PointerPose; + ovrInputModule.rayTransform = t; + } } } diff --git a/Assets/Scripts/UI/Selectable.cs b/Assets/Scripts/UI/Selectable.cs index 3b5595871398b688a2fb0a8c535f182a0ce9f9fe..b33866403f8c1d81495822394e16d41afc2a7714 100644 --- a/Assets/Scripts/UI/Selectable.cs +++ b/Assets/Scripts/UI/Selectable.cs @@ -5,6 +5,9 @@ namespace UI { + /** + * Changes (toggles) sprite of a UI element + */ public class Selectable : MonoBehaviour { [SerializeField] private string spriteName; diff --git a/Assets/Scripts/UI/UIConstants.cs b/Assets/Scripts/UI/UIConstants.cs index 1fa5e4a1dca17e0ca00f5a15b85d34f004ea116a..06d20f5385b2409b3ca557aee33f9b2c15d3059d 100644 --- a/Assets/Scripts/UI/UIConstants.cs +++ b/Assets/Scripts/UI/UIConstants.cs @@ -1,3 +1,5 @@ +using UnityEngine; + namespace UI { public class UIConstants @@ -11,18 +13,12 @@ public class UIConstants public const string MultiviewButton = "MultiviewButton"; public const string TopCameraRT = "TopCameraRT"; public const string PlayerCameraRT = "PlayerCameraRT"; - public const string MaximizeButton = "MaximizeButton"; - public const string PlayButton = "PlayButton"; - public const string ControlsPortrait = "ControlsPortrait"; - public const string ControlsLandscape = "ControlsLandscape"; public const string VideoControls = "VideoControls"; public const string SceneSelection = "SceneSelection"; public const string Calibration = "Calibration"; public const string ErrorPanel = "ErrorPanel"; public const string ErrorBackdrop = "ErrorBackdrop"; - public const string MorePanel = "MorePanel"; public const string BackButton = "BackButton"; - public const string SettingsScreen = "SettingsScreen"; public const string SceneJoin = "SceneJoin"; public const string PlayerCameraRTLandscape = "PlayerCameraRTLandscape"; public const string TopCameraRTLandscape = "TopCameraRTLandscape"; @@ -37,5 +33,7 @@ public class UIConstants public const string Step3 = "Step3"; public const string DoneButton = "DoneButton"; + public static Vector3 ControlsLocalScalePortrait = new Vector3(1.034554f, 0.1034285f, 1.034554f); + public static Vector3 ControlsLocalScaleLandscape = new Vector3(1.559694f, 0.1559289f, 1.559694f); } } \ No newline at end of file diff --git a/Assets/Scripts/UI/UIControllerMobile.cs b/Assets/Scripts/UI/UIControllerMobile.cs index 9538da46ee629bd3b312811c4c4acbe66e6b71ea..7baa3add7c5e6bb8ff58cf122cff01c5cbad49f6 100644 --- a/Assets/Scripts/UI/UIControllerMobile.cs +++ b/Assets/Scripts/UI/UIControllerMobile.cs @@ -3,6 +3,7 @@ using Player; using TMPro; using UnityEngine; +using UnityEngine.Serialization; using UnityEngine.UI; using Utils; @@ -22,19 +23,14 @@ public class UIControllerMobile : BaseUIController [SerializeField] private bool controlsVisible; [SerializeField] private PlayMode currentPlayMode; - [Header("Mobile UI Elements")] [SerializeField] - private List<GameObject> cameraViews; - + [Header("Mobile UI Elements")] + [SerializeField] private List<GameObject> cameraViews; [SerializeField] private GameObject controls; [SerializeField] private GameObject controlButtons; - [SerializeField] private GameObject topBar; [SerializeField] private Timer timer; [SerializeField] private ProgressBar progressBar; [SerializeField] private Button[] sceneButtons; - - [Header("Special Elements")] [SerializeField] - private Selectable playButton; - + [SerializeField] private Selectable playButton; [SerializeField] private Selectable maximizeButton; [SerializeField] private MobileController mobileController; [SerializeField] private Slider speedSlider; @@ -61,7 +57,6 @@ public void EnableCameraView(string cameraViewName) public void OnChangeScreenOrientation() { - Debug.Log("ONchange Screen orientation"); Screen.orientation = portraitOriented ? ScreenOrientation.LandscapeLeft : ScreenOrientation.Portrait; portraitOriented = !portraitOriented; maximizeButton.SetSelected(!portraitOriented); @@ -71,13 +66,8 @@ public void OnChangeScreenOrientation() } timer.gameObject.SetActive(portraitOriented); - // progressBar.gameObject.SetActive(portraitOriented); - // topBar.SetActive(portraitOriented); - controlButtons.transform.localScale = portraitOriented - ? new Vector3(1.034554f, 0.1034285f, 1.034554f) - : new Vector3(1.559694f, 0.1559289f, 1.559694f); - // timer.transform.localScale = portraitOriented ? new Vector3(1.034554f, 1.034554f, 1.034554f) : new Vector3(1.559694f, 1.605603f, 1.559694f); + controlButtons.transform.localScale = portraitOriented ? UIConstants.ControlsLocalScalePortrait : UIConstants.ControlsLocalScaleLandscape; } public void ToggleControlsVisible() @@ -86,18 +76,8 @@ public void ToggleControlsVisible() controls.SetActive(controlsVisible); } - private IEnumerator HideControls() - { - while (controlsVisible) - { - yield return new WaitForSecondsRealtime(5); - controls.SetActive(false); - } - } - public void OnPlayPressed(bool playing) { - Debug.Log("ON PLAY PRESSED MOBLE CONTROLEL playing " + playing); playButton.SetSelected(playing); timer.SetTimerPlaying(playing); progressBar.SetProgressBarPlaying(playing); @@ -107,7 +87,6 @@ public void OnPlayPressed(bool playing) public void OnSceneChosen(string chosenScene) { mobileController.OnSceneSelected(chosenScene); - // endButton.interactable = true; } public void OnSceneLoaded() @@ -135,6 +114,7 @@ public void RemovePanelFromStack() public void SetPlayButtonSelected(bool playing) //TODO { + // playButton.SetSelected(playing); var playButtonImage = playButton.gameObject.GetComponent<Image>(); if (playing) { @@ -164,17 +144,16 @@ public void OnSpeedSliderUpdate() public void OnGoToLobby() { - Debug.Log("on go to lobby"); - StartCoroutine(ActivateButtons(sceneButtons, 0, false)); StartCoroutine(ActivateButtons(sceneButtons, GameConstants.ReturnToLobbyWaitingTime, true)); + EnablePanelExclusive(UIConstants.ConnectScreen); EnableCameraView(UIConstants.PlayerCameraRT); EnableTrue(UIConstants.SceneSelection); EnableFalse(UIConstants.VideoControls); EnableFalse(UIConstants.SceneJoin); + timer.ResetTimer(); - currentPlayMode = PlayMode.None; portraitOriented = false; OnChangeScreenOrientation(); diff --git a/Assets/Scripts/UI/UIControllerVRLobby.cs b/Assets/Scripts/UI/UIControllerVRLobby.cs deleted file mode 100644 index abf4bbc6459eae1fbbc16274c76867e3922079de..0000000000000000000000000000000000000000 --- a/Assets/Scripts/UI/UIControllerVRLobby.cs +++ /dev/null @@ -1,11 +0,0 @@ -using System; -using Network; -using UnityEngine; - -namespace UI -{ - public class UIControllerVRLobby : BaseUIController - { - - } -} \ No newline at end of file diff --git a/Assets/Scripts/UI/UIControllerVRLobby.cs.meta b/Assets/Scripts/UI/UIControllerVRLobby.cs.meta deleted file mode 100644 index e1cf749b4a081c11592717ff0a39ba3088fbb22c..0000000000000000000000000000000000000000 --- a/Assets/Scripts/UI/UIControllerVRLobby.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: aba8b896291343cfb0643fae01e3a47c -timeCreated: 1615830533 \ No newline at end of file diff --git a/Assets/Scripts/UI/VRLobbyUIController.cs b/Assets/Scripts/UI/VRLobbyUIController.cs new file mode 100644 index 0000000000000000000000000000000000000000..6cdd21a72b130f93d4d071aced6d36152bab76c2 --- /dev/null +++ b/Assets/Scripts/UI/VRLobbyUIController.cs @@ -0,0 +1,6 @@ +namespace UI +{ + public class VRLobbyUIController : BaseUIController + { + } +} diff --git a/Assets/Scripts/UI/VRLobbyUIController.cs.meta b/Assets/Scripts/UI/VRLobbyUIController.cs.meta new file mode 100644 index 0000000000000000000000000000000000000000..048e9ea4f282db55e814ca252f876b9af05a60c7 --- /dev/null +++ b/Assets/Scripts/UI/VRLobbyUIController.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 0ce78015d12524e788af9cec17a7fb48 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Utils/Fader.cs b/Assets/Scripts/Utils/Fader.cs index bf8dedb4be8662e848e687c99833ad85579be0e4..0a6988cfd8a0b23dc6fb407494a0f1032ddf858f 100644 --- a/Assets/Scripts/Utils/Fader.cs +++ b/Assets/Scripts/Utils/Fader.cs @@ -13,11 +13,6 @@ public class Fader : MonoBehaviour private Renderer _fadeRenderer; private float _alpha = 0f; - private void Awake() - { - - } - public IEnumerator FadeCoroutine(bool fadeIn) { if (!fadeIn) @@ -52,7 +47,6 @@ public IEnumerator FadeCoroutine(bool fadeIn) } canvas.SetActive(false); - } public void FadeOut() diff --git a/Assets/Scripts/Utils/FogController.cs b/Assets/Scripts/Utils/FogController.cs index 25640181a1f51732d70822352b31cd44a505d342..ffe00b5e676d1ad927a764b624211c25ad47a143 100644 --- a/Assets/Scripts/Utils/FogController.cs +++ b/Assets/Scripts/Utils/FogController.cs @@ -1,8 +1,7 @@ -using System; -using System.Collections; +using System.Collections; using UnityEngine; -namespace Other +namespace Utils { public class FogController : MonoBehaviour { diff --git a/ProjectSettings/DynamicsManager.asset b/ProjectSettings/DynamicsManager.asset index 272afe45003add64a6441f31680502963e255038..18865becb0d4d9e11900bb39f6958f5e402032b6 100644 --- a/ProjectSettings/DynamicsManager.asset +++ b/ProjectSettings/DynamicsManager.asset @@ -17,7 +17,7 @@ PhysicsManager: m_ClothInterCollisionDistance: 0.1 m_ClothInterCollisionStiffness: 0.2 m_ContactsGeneration: 1 - m_LayerCollisionMatrix: f9ffffffcaffffffccffffffffffffffd9ffffffe9fffffffffffffffffffffffffeffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff + m_LayerCollisionMatrix: f9ffffffcaffffffccffffffffffffffd9ffffffe9ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff m_AutoSimulation: 1 m_AutoSyncTransforms: 0 m_ReuseCollisionCallbacks: 1