Added gps and ITask update
This commit is contained in:
@@ -1,10 +1,7 @@
|
|||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using GeoSus.Client;
|
using GeoSus.Client;
|
||||||
using Subsystems;
|
using Subsystems;
|
||||||
using System.Threading;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System;
|
using System;
|
||||||
using TMPro;
|
using TMPro;
|
||||||
/*
|
/*
|
||||||
|
|||||||
@@ -1,8 +1,21 @@
|
|||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using GeoSus.Client;
|
using GeoSus.Client;
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections;
|
||||||
|
|
||||||
namespace Subsystems
|
namespace Subsystems
|
||||||
{
|
{
|
||||||
|
internal class CoroutineHost : MonoBehaviour
|
||||||
|
{
|
||||||
|
public CoroutineHost() { }
|
||||||
|
}
|
||||||
|
internal enum GPSState
|
||||||
|
{
|
||||||
|
Uninitialized,
|
||||||
|
Initializing,
|
||||||
|
Running,
|
||||||
|
Failed
|
||||||
|
}
|
||||||
public static class PositonExtensions
|
public static class PositonExtensions
|
||||||
{
|
{
|
||||||
public static Position ToLocal(this Position position, Position center)
|
public static Position ToLocal(this Position position, Position center)
|
||||||
@@ -37,8 +50,11 @@ namespace Subsystems
|
|||||||
private Position _lastSentPosition;
|
private Position _lastSentPosition;
|
||||||
private GameObject _player;
|
private GameObject _player;
|
||||||
private bool _testMode;
|
private bool _testMode;
|
||||||
|
|
||||||
|
private GPSState _GPSState = GPSState.Uninitialized;
|
||||||
private float _speed = 0.00001f;
|
private float _speed = 0.00001f;
|
||||||
private Position _mapCenter;
|
private Position _mapCenter;
|
||||||
|
private CoroutineHost _coroutineHost = new CoroutineHost();
|
||||||
public GameManager_Input(GameClient gameClient, GameObject player, bool testMode)
|
public GameManager_Input(GameClient gameClient, GameObject player, bool testMode)
|
||||||
{
|
{
|
||||||
_gameClient = gameClient;
|
_gameClient = gameClient;
|
||||||
@@ -66,7 +82,37 @@ namespace Subsystems
|
|||||||
}
|
}
|
||||||
else
|
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;
|
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());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2,10 +2,10 @@ using GeoSus.Client;
|
|||||||
using System;
|
using System;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
public enum TaskType
|
/*public enum TaskType
|
||||||
{
|
{
|
||||||
Task //TODO: Typy úkolù
|
Task //TODO: Typy úkolù
|
||||||
}
|
}*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -14,7 +14,7 @@ public interface ITask
|
|||||||
public string TaskID { get; } // Unikátní ID úkolu pro server
|
public string TaskID { get; } // Unikátní ID úkolu pro server
|
||||||
public TaskType TaskType { get; } // Typ úkolu
|
public TaskType TaskType { get; } // Typ úkolu
|
||||||
public string TaskName { get; } // Viditelný název ú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
|
public bool IsCompleted { get; } // Stav dokonèení úkolu
|
||||||
|
|
||||||
void Initialize(Action<ITask> onCompleted); // Vytvoøení tasku + naètení postupu
|
void Initialize(Action<ITask> 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 string TaskID { get; set; } // Unikátní ID úkolu pro server
|
||||||
public TaskType TaskType { get; set; } // Typ úkolu
|
public TaskType TaskType { get; set; } // Typ úkolu
|
||||||
public string TaskName { get; set; } // Viditelný název ú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
|
public bool IsCompleted { get; private set; } // Stav dokonèení úkolu
|
||||||
private Action<ITask> _onCompleted;
|
private Action<ITask> _onCompleted;
|
||||||
|
|
||||||
|
|||||||
@@ -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
|
|
||||||
@@ -7,7 +7,7 @@
|
|||||||
"com.unity.ide.visualstudio": "2.0.25",
|
"com.unity.ide.visualstudio": "2.0.25",
|
||||||
"com.unity.localization": "1.5.9",
|
"com.unity.localization": "1.5.9",
|
||||||
"com.unity.multiplayer.center": "1.0.0",
|
"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.ugui": "2.0.0",
|
||||||
"com.unity.modules.accessibility": "1.0.0",
|
"com.unity.modules.accessibility": "1.0.0",
|
||||||
"com.unity.modules.ai": "1.0.0",
|
"com.unity.modules.ai": "1.0.0",
|
||||||
|
|||||||
@@ -226,7 +226,7 @@
|
|||||||
"url": "https://packages.unity.com"
|
"url": "https://packages.unity.com"
|
||||||
},
|
},
|
||||||
"com.unity.remote-config": {
|
"com.unity.remote-config": {
|
||||||
"version": "4.2.3",
|
"version": "4.2.5",
|
||||||
"depth": 0,
|
"depth": 0,
|
||||||
"source": "registry",
|
"source": "registry",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
|||||||
Reference in New Issue
Block a user