diff --git a/Assets/GameManager/GameManager.cs b/Assets/GameManager/GameManager.cs index 62850eb..0e82c80 100644 --- a/Assets/GameManager/GameManager.cs +++ b/Assets/GameManager/GameManager.cs @@ -1,10 +1,7 @@ using UnityEngine; using GeoSus.Client; using Subsystems; -using System.Threading; -using System.Threading.Tasks; using System.Collections; -using System.Collections.Generic; using System; using TMPro; /* diff --git a/Assets/GameManager/GameManager_Input.cs b/Assets/GameManager/GameManager_Input.cs index 2c42f6f..af90aa1 100644 --- a/Assets/GameManager/GameManager_Input.cs +++ b/Assets/GameManager/GameManager_Input.cs @@ -1,8 +1,21 @@ using UnityEngine; using GeoSus.Client; using System; +using System.Collections; + namespace Subsystems { + internal class CoroutineHost : MonoBehaviour + { + public CoroutineHost() { } + } + internal enum GPSState + { + Uninitialized, + Initializing, + Running, + Failed + } public static class PositonExtensions { public static Position ToLocal(this Position position, Position center) @@ -37,8 +50,11 @@ namespace Subsystems private Position _lastSentPosition; private GameObject _player; private bool _testMode; + + private GPSState _GPSState = GPSState.Uninitialized; private float _speed = 0.00001f; private Position _mapCenter; + private CoroutineHost _coroutineHost = new CoroutineHost(); public GameManager_Input(GameClient gameClient, GameObject player, bool testMode) { _gameClient = gameClient; @@ -54,7 +70,7 @@ namespace Subsystems if (_testMode) { - if (_currentPosition == null || _currentPosition == new Position(0,0)) + if (_currentPosition == null || _currentPosition == new Position(0, 0)) { //Init blok _currentPosition = _gameClient.CurrentLobbyState.MapData.Center; @@ -66,7 +82,37 @@ namespace Subsystems } else { - //TODO: Real GPS + if (_GPSState == GPSState.Uninitialized) + { + _coroutineHost.StartCoroutine(InitiallizeGPS()); + return; + } + else if (_GPSState == GPSState.Initializing) + { + return; + } + else if (_GPSState == GPSState.Running) + { + try + { + if (_currentPosition != _lastSentPosition) + { + _gameClient.UpdatePosition(_currentPosition); + _lastSentPosition = _currentPosition; + _player.transform.position = _currentPosition.ToLocalVector3(_mapCenter); + _player.transform.rotation = Quaternion.Euler(0, (float)CalculateHeading(_lastSentPosition.ToLocalVector3(_mapCenter), _currentPosition.ToLocalVector3(_mapCenter)), 0); + } + } + catch (Exception ex) + { + Debug.Log(ex); + } + } + else + { + Debug.Log("GPS failed, trying again...");) + _GPSState = GPSState.Uninitialized; + } } } } @@ -150,5 +196,59 @@ namespace Subsystems return heading; } } + IEnumerator InitiallizeGPS() + { + _GPSState = GPSState.Initializing; + if (!Input.location.isEnabledByUser) + { + Debug.LogError("Location not enabled on device or app does not have permission to access location"); + } + // Starts the location service. + + float desiredAccuracyInMeters = 10f; + float updateDistanceInMeters = 10f; + + Input.location.Start(desiredAccuracyInMeters, updateDistanceInMeters); + + // Waits until the location service initializes + int maxWait = 20; + while (Input.location.status == LocationServiceStatus.Initializing && maxWait > 0) + { + yield return new WaitForSeconds(1); + maxWait--; + } + + // If the service didn't initialize in 20 seconds this cancels location service use. + if (maxWait < 1) + { + _GPSState = GPSState.Failed; + Debug.LogError("Timed out"); + yield break; + } + _GPSState = GPSState.Running; + yield return _coroutineHost.StartCoroutine(GPSService()); + } + IEnumerator GPSService() + { + // Check if the user has location service enabled. + + + // If the connection failed this cancels location service use. + if (Input.location.status == LocationServiceStatus.Failed) + { + Debug.LogError("Unable to determine device location"); + yield break; + } + else + { + // If the connection succeeded, this retrieves the device's current location and displays it in the Console window. + _currentPosition = new Position(Input.location.lastData.latitude, Input.location.lastData.longitude); + Debug.Log("Location: " + Input.location.lastData.latitude + " " + Input.location.lastData.longitude + " " + Input.location.lastData.altitude + " " + Input.location.lastData.horizontalAccuracy + " " + Input.location.lastData.timestamp); + yield return new WaitForSeconds(5f); + } + + // Stops the location service if there is no need to query location updates continuously. + yield return _coroutineHost.StartCoroutine(GPSService()); + } } } \ No newline at end of file diff --git a/Assets/GameManager/ITask.cs b/Assets/GameManager/ITask.cs index 11d1362..3c1bfef 100644 --- a/Assets/GameManager/ITask.cs +++ b/Assets/GameManager/ITask.cs @@ -2,10 +2,10 @@ using GeoSus.Client; using System; using UnityEngine; -public enum TaskType +/*public enum TaskType { Task //TODO: Typy úkolù -} +}*/ @@ -14,7 +14,7 @@ public interface ITask public string TaskID { get; } // Unikátní ID úkolu pro server public TaskType TaskType { get; } // Typ úkolu public string TaskName { get; } // Viditelný název úkolu - public (double, double) TaskLocation { get; } // Polohy na mapì + public Position TaskLocation { get; } // Polohy na mapì public bool IsCompleted { get; } // Stav dokonèení úkolu void Initialize(Action onCompleted); // Vytvoøení tasku + naètení postupu @@ -27,7 +27,7 @@ public class Wires : ITask{ public string TaskID { get; set; } // Unikátní ID úkolu pro server public TaskType TaskType { get; set; } // Typ úkolu public string TaskName { get; set; } // Viditelný název úkolu - public (double, double) TaskLocation { get; set; } // Poloha na mapì + public Position TaskLocation { get; set; } // Poloha na mapì public bool IsCompleted { get; private set; } // Stav dokonèení úkolu private Action _onCompleted; diff --git a/Assets/UI Toolkit/UnityThemes/UnityDefaultRuntimeTheme.tss.meta b/Assets/UI Toolkit/UnityThemes/UnityDefaultRuntimeTheme.tss.meta deleted file mode 100644 index 7ee4f0b..0000000 --- a/Assets/UI Toolkit/UnityThemes/UnityDefaultRuntimeTheme.tss.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: d133669256f71014fade8f776dc9e12f -ScriptedImporter: - internalIDToNameTable: [] - externalObjects: {} - serializedVersion: 2 - userData: - assetBundleName: - assetBundleVariant: - script: {fileID: 12388, guid: 0000000000000000e000000000000000, type: 0} - disableValidation: 0 diff --git a/Packages/manifest.json b/Packages/manifest.json index 8e8fd7d..702f6be 100644 --- a/Packages/manifest.json +++ b/Packages/manifest.json @@ -7,7 +7,7 @@ "com.unity.ide.visualstudio": "2.0.25", "com.unity.localization": "1.5.9", "com.unity.multiplayer.center": "1.0.0", - "com.unity.remote-config": "4.2.3", + "com.unity.remote-config": "4.2.5", "com.unity.ugui": "2.0.0", "com.unity.modules.accessibility": "1.0.0", "com.unity.modules.ai": "1.0.0", diff --git a/Packages/packages-lock.json b/Packages/packages-lock.json index e68e1de..3dba7d0 100644 --- a/Packages/packages-lock.json +++ b/Packages/packages-lock.json @@ -226,7 +226,7 @@ "url": "https://packages.unity.com" }, "com.unity.remote-config": { - "version": "4.2.3", + "version": "4.2.5", "depth": 0, "source": "registry", "dependencies": {