diff --git a/T3-Unity/Assets/Scenes/Map_Tests1.unity b/T3-Unity/Assets/Scenes/Map_Tests1.unity index 1f799e3c43c19a1d04b464e4b41491be29fd0a5a..873906332b9a5165399680698bda1ad3b6fa8f63 100644 --- a/T3-Unity/Assets/Scenes/Map_Tests1.unity +++ b/T3-Unity/Assets/Scenes/Map_Tests1.unity @@ -38,7 +38,7 @@ RenderSettings: m_ReflectionIntensity: 1 m_CustomReflection: {fileID: 0} m_Sun: {fileID: 170076734} - m_IndirectSpecularColor: {r: 0.44657898, g: 0.4964133, b: 0.5748178, a: 1} + m_IndirectSpecularColor: {r: 0.44657874, g: 0.49641258, b: 0.5748172, a: 1} m_UseRadianceAmbientProbe: 0 --- !u!157 &3 LightmapSettings: @@ -538,7 +538,6 @@ MonoBehaviour: nbJoueur: 15 parent: {fileID: 313702767} copy: {fileID: 114736490466060796, guid: 4256cfb91b73ae34aab9be42e6a067de, type: 3} - _listRunners: [] moyenneMotivation: 0 --- !u!4 &313702767 Transform: @@ -2005,7 +2004,7 @@ MonoBehaviour: m_Calls: - m_Target: {fileID: 964767769} m_MethodName: changeFame - m_Mode: 5 + m_Mode: 1 m_Arguments: m_ObjectArgument: {fileID: 0} m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine diff --git a/T3-Unity/Assets/Scripts/IA/Runners.cs b/T3-Unity/Assets/Scripts/IA/Runners.cs index 85001736eb22e1136d4218848fd010dca5850ac3..91e316fd999fdcae9623b95a5dbcdc479ceded5a 100644 --- a/T3-Unity/Assets/Scripts/IA/Runners.cs +++ b/T3-Unity/Assets/Scripts/IA/Runners.cs @@ -2,45 +2,43 @@ namespace Scripts.IA { using UnityEngine; using Scripts.Waypoints; - using Mapbox.Utils; using Mapbox.Unity.Map; //! @authors Wakestufou - //! @brief "Insérer description rapide" - //! @details "Insérer description détaillée" + //! @brief Script pour un coureur + //! @details Le coureur suit un chemain constitué de waypoints avec une vitesse et une motivation public class Runners : MonoBehaviour { // Champs publiques - public float speed = 10f; //<! "Insérer description de la variable" - public float motivation; //<! "Insérer description de la variable" + public float speed = 10f; //<! Vitesse du joueur + public float motivation; //<! Motivation du joueur // Champs privés - private Vector3 target; //<! "Insérer description de la variable" - private int waypointIndex = 0; //<! "Insérer description de la variable" - private AbstractMap _map; //<! "Insérer description de la variable" + private Vector3 _target; //<! Le prochain waypoints à atteindre pour le coureur + private int _waypointIndex = 0; //<! Numéro du waypoints + private AbstractMap _map; //<! Map Google Street View. //! @brief Se lance au lancement du script. - //! @details "Insérer description détaillée" + //! @details Definie la vitesse @a speed void Start() { motivation = 50f; _map = GameObject.Find("Map").GetComponent<AbstractMap>(); - Debug.Log("JE SUIS CREE !"); - target = _map.GeoToWorldPosition(WaypointsFactory.getInstance().getWp()[0]); + _target = _map.GeoToWorldPosition(WaypointsFactory.getInstance().getWp()[0]); float vitesse = (float.Parse(RunnersFactory.getInstance().getRandom().Next(75, 125).ToString()) / 100f) * 10f; speed = vitesse; } //! @brief Se répète toutes les 14ms (temps par défaut dans Unity). - //! @details "Insérer description détaillée" + //! @details Effectue le déplacement du coureur en changant @a _target et changant la motivation @a motivation private void Update() { - Vector3 dir = target - transform.position; + Vector3 dir = _target - transform.position; transform.Translate(dir.normalized * speed * Time.deltaTime, Space.World); - if (Vector3.Distance(transform.position, target) <= 0.3f) //Marge d'erreur + if (Vector3.Distance(transform.position, _target) <= 0.3f) //Marge d'erreur { GetNextWaypoint(); } @@ -61,19 +59,19 @@ namespace Scripts.IA if (motivation <= 0) Destroy(gameObject); } - //! @brief "Insérer description rapide" - //! @details "Insérer description détaillée" + //! @brief Prochain Waypoints + //! @details Definie @a _target et incrémente @a _waypointIndex private void GetNextWaypoint() { - Debug.Log(target.ToString()); - if (waypointIndex >= WaypointsFactory.getInstance().getWp().Count - 1) + Debug.Log(_target.ToString()); + if (_waypointIndex >= WaypointsFactory.getInstance().getWp().Count - 1) { Destroy(gameObject); return; } - waypointIndex++; - target = _map.GeoToWorldPosition(WaypointsFactory.getInstance().getWp()[waypointIndex]); + _waypointIndex++; + _target = _map.GeoToWorldPosition(WaypointsFactory.getInstance().getWp()[_waypointIndex]); } } } diff --git a/T3-Unity/Assets/Scripts/IA/RunnersFactory.cs b/T3-Unity/Assets/Scripts/IA/RunnersFactory.cs index 476395e8ab3941682909db47049fbe2db3b3ba28..393bb27b479066b904cdf52d8aaaa098e96adb06 100644 --- a/T3-Unity/Assets/Scripts/IA/RunnersFactory.cs +++ b/T3-Unity/Assets/Scripts/IA/RunnersFactory.cs @@ -6,29 +6,30 @@ namespace Scripts.IA using System.Collections.Generic; //! @authors Wakestufou - //! @brief "Insérer description rapide" - //! @details "Insérer description détaillée" + //! @brief Gère les coureurs + //! @details Cette classe permet de créer le nombre de coureur et d'avoir la moyenne de leurs motivations public class RunnersFactory : MonoBehaviour { // Champs publiques - public int nbJoueur; //<! "Insérer description de la variable" - public Transform parent; //<! "Insérer description de la variable" - public Runners copy; //<! "Insérer description de la variable" - public List<GameObject> _listRunners; //<! "Insérer description de la variable" - public float moyenneMotivation = 0; //<! "Insérer description de la variable" + public int nbJoueur; //<! Nombre de coureur à créer + public Transform parent; //<! Objet qui va contenir les coureurs + public Runners copy; //<! Prefabs Runners + public float moyenneMotivation = 0; //<! Moyenne de la motivation de tous les coureurs - private System.Random rdn; //<! "Insérer description de la variable" - private static RunnersFactory instance; //<! "Insérer description de la variable" - private AbstractMap _map; //<! "Insérer description de la variable" + // Champs privés + private System.Random _rdn; //<! Variable qui sert à créer de l'aléatoire + private static RunnersFactory _instance; //<! Instance de RunnersFactory + private AbstractMap _map; //<! Map Google Street View. + private List<GameObject> _listRunners; //<! Liste des coureurs existant //! @brief Se lance au lancement du script. - //! @details "Insérer description détaillée" + //! @details Création des coureurs void Start() { _listRunners = new List<GameObject>(); _map = GameObject.Find("Map").GetComponent<AbstractMap>(); - instance = this; - rdn = new System.Random(); + _instance = this; + _rdn = new System.Random(); nbJoueur = 5 + Ui.fame * 2; @@ -43,7 +44,7 @@ namespace Scripts.IA } //! @brief Se répète toutes les 14ms (temps par défaut dans Unity). - //! @details "Insérer description détaillée" + //! @details Met à jour la moyenne de motivation @a moyenneMotivation private void Update() { _listRunners.Clear(); @@ -74,18 +75,18 @@ namespace Scripts.IA } } - //! @brief "Insérer description rapide" - //! @details "Insérer description détaillée" + //! @brief Retourne @a _rdn + //! @details Retourne @a _rdn public System.Random getRandom() { - return rdn; + return _rdn; } - //! @brief "Insérer description rapide" - //! @details "Insérer description détaillée" + //! @brief Retourne @a _instance + //! @details Retourne l'instance de la classe public static RunnersFactory getInstance() { - return instance; + return _instance; } } diff --git a/T3-Unity/Assets/Scripts/Routes/RouteTracer.cs b/T3-Unity/Assets/Scripts/Routes/RouteTracer.cs index 4328eac134cef3df6749512fee081e2c2a6aa983..aba4b66ca5bfe5a3c570525d1d8bddf7434fe7ef 100644 --- a/T3-Unity/Assets/Scripts/Routes/RouteTracer.cs +++ b/T3-Unity/Assets/Scripts/Routes/RouteTracer.cs @@ -61,9 +61,6 @@ GameObject.Find("Sportifs").GetComponent<RunnersFactory>().enabled = true; - - - } //! @param start Position du @b GameObject de départ. diff --git a/T3-Unity/Assets/Scripts/Waypoints/SpawnOnMap.cs b/T3-Unity/Assets/Scripts/Waypoints/SpawnOnMap.cs index 5f00eec92faef0760083c11bbaf8b4d2fb87bb52..7e8090cd24232d543c05e4290275343ab76c38bd 100644 --- a/T3-Unity/Assets/Scripts/Waypoints/SpawnOnMap.cs +++ b/T3-Unity/Assets/Scripts/Waypoints/SpawnOnMap.cs @@ -3,83 +3,74 @@ using UnityEngine; using Mapbox.Utils; using Mapbox.Unity.Map; - using Mapbox.Unity.MeshGeneration.Factories; using Mapbox.Unity.Utilities; using System.Collections.Generic; using Scripts.Routes; - using Scripts.Map; + //! @authors MapBox + //! Wakestufou + //! @brief Fait apparaître des waypoints sur la Map. + //! @details Cette classe s'occupe de transformer une liste de coordonnées GPS en waypoints liés à la map. + //! De cette maniètre la caméra peut bouger, les waypoints resterons à leur position de base. + //! du placement des waypoints et tu tracé de la route. public class SpawnOnMap : MonoBehaviour - { - [SerializeField] - AbstractMap _map; + { + // Champs publiques + public List<GameObject> spawnedObjects; //!< Liste des waypoints placés. + public Transform parent; //!< Parent de la liste des waypoints placés. - [SerializeField] - [Geocode] - Vector2d[] _locations; - - [SerializeField] - float _spawnScale = 1f; - - [SerializeField] - float _spawnScaleStartEnd = 6f; - - [SerializeField] - GameObject _markerPrefab; - - [SerializeField] - GameObject _prefabDebut; - - [SerializeField] - GameObject _prefabFin; - - public List<GameObject> _spawnedObjects; - - public Transform parent; - private float _zoom; - private static SpawnOnMap instance; + // Champs privés + private float _zoom; //!< Valeur du zoom de la caméra sur la map. + private static SpawnOnMap _instance; //!< Instance actuelle. + [SerializeField] AbstractMap _map; //!< Map Google Street View. + [SerializeField] [Geocode] Vector2d[] _locations; //!< Liste des positions GPS des waypoints à placer. + [SerializeField] float _spawnScale = 1f; //!< Taille d'un waypoint de base. + [SerializeField] float _spawnScaleStartEnd = 6f; //!< Taille des waypoints de départ et d'arrivée. + [SerializeField] GameObject _markerPrefab; //!< Préfabriqué d'un waypoint de base. + [SerializeField] GameObject _startPrefab; //!< Préfabriqué du waypoint de départ. + [SerializeField] GameObject _endPrefab; //!< Préfabriqué du waypoint d'arrivée. + //! @brief Se lance au lancement du script. + //! @details Crée les waypoints sur la map à partir des coordonnées GPS. void Start() { - instance = this; + _instance = this; List<Vector2d> Waypoints = new List<Vector2d>(WaypointsFactory.getInstance().getWp()); _locations = new Vector2d[Waypoints.Count]; - _spawnedObjects = new List<GameObject>(); + spawnedObjects = new List<GameObject>(); for (int i = 0; i < _locations.Length; i++) { _locations[i] = Waypoints[i]; - var instances = Instantiate(_markerPrefab, parent); ; + var _instances = Instantiate(_markerPrefab, parent); ; if (i == 0) { - instances = Instantiate(_prefabDebut, parent); - instances.transform.localScale = new Vector3(_spawnScaleStartEnd, _spawnScaleStartEnd, _spawnScaleStartEnd); + _instances = Instantiate(_startPrefab, parent); + _instances.transform.localScale = new Vector3(_spawnScaleStartEnd, _spawnScaleStartEnd, _spawnScaleStartEnd); } else if (i == _locations.Length - 1) { - instances = Instantiate(_prefabFin, parent); - instances.transform.localScale = new Vector3(_spawnScaleStartEnd, _spawnScaleStartEnd, _spawnScaleStartEnd); + _instances = Instantiate(_endPrefab, parent); + _instances.transform.localScale = new Vector3(_spawnScaleStartEnd, _spawnScaleStartEnd, _spawnScaleStartEnd); } else { - instances.transform.localScale = new Vector3(_spawnScale, _spawnScale, _spawnScale); + _instances.transform.localScale = new Vector3(_spawnScale, _spawnScale, _spawnScale); } - - instances.transform.localPosition = _map.GeoToWorldPosition(_locations[i], true); - _spawnedObjects.Add(instances); + + _instances.transform.localPosition = _map.GeoToWorldPosition(_locations[i], true); + spawnedObjects.Add(_instances); } - //GameObject.Find("Map").GetComponent<QuadTreeCameraMovement>().enabled = true; - //_cam = GameObject.Find("GameManager").GetComponent<QuadTreeCameraMovement>(); - //_cam.enabled = true; - //_cam.minZoom = 0; _zoom = _map.Zoom; } + //! @brief Se répète toutes les 14ms (temps par défaut dans Unity). + //! @details Met à jour les waypoints de la map afin qu'ils gardent leur place réelle et non leur position Unity. private void Update() { - int count = _spawnedObjects.Count; + int count = spawnedObjects.Count; for (int i = 0; i < count; i++) { - var spawnedObject = _spawnedObjects[i]; + var spawnedObject = spawnedObjects[i]; var location = _locations[i]; spawnedObject.transform.localPosition = _map.GeoToWorldPosition(location, true); spawnedObject.transform.localScale = new Vector3(_spawnScale, _spawnScale, _spawnScale); @@ -88,12 +79,11 @@ if (VerifVisible()) { GameObject.Find("GameManager").GetComponent<RouteTracer>().enabled = true; - //this.enabled = false; - } else if (_zoom <= 2) + } + else if (_zoom <= 2) { GameObject.Find("GameManager").GetComponent<RouteTracer>().enabled = true; - //this.enabled = false; - } + } else { _zoom -= 0.25f; @@ -101,24 +91,32 @@ } } + //! @brief Test la visibilité des waypoints. + //! @details Si un waypoints n'est dans le champs de vision de la caméra. + //! @return @e bool Si un waypoint n'est pas visible renvoie @b false, sinon renvoie @b true private bool VerifVisible() { bool verif = true; - for (int i = 0; i<_spawnedObjects.Count; i++) + for (int i = 0; i < spawnedObjects.Count; i++) { - if (!_spawnedObjects[i].GetComponent<Renderer>().isVisible) verif = false; + if (!spawnedObjects[i].GetComponent<Renderer>().isVisible) verif = false; } return verif; } + //! @brief Récupère les objets crées. + //! @return @e List<GameObject> Liste des waypoints qui ont été placés. public List<GameObject> getSpawnedObject() { - return _spawnedObjects; + return spawnedObjects; } + //! @brief Récupère l'instance de Waypoints.SpawnOnMap + //! @details Récupère l'instance du script actuel afin de respecter un patterne @b singleton. + //! @return @e SpawnOnMap Instance actuelle. public static SpawnOnMap getInstance() { - return instance; + return _instance; } } } \ No newline at end of file diff --git a/T3-Unity/Assets/Scripts/Waypoints/WaypointsFactory.cs b/T3-Unity/Assets/Scripts/Waypoints/WaypointsFactory.cs index f9d68c0f2f10752e2f13fa765998832db3e1c147..c66769746bbee22b5b2092a84cba11de0ec5871f 100644 --- a/T3-Unity/Assets/Scripts/Waypoints/WaypointsFactory.cs +++ b/T3-Unity/Assets/Scripts/Waypoints/WaypointsFactory.cs @@ -11,24 +11,30 @@ using Mapbox.Unity.Map; using Mapbox.Unity.Utilities; + + //! @authors Wakestufou + //! @brief Gère les Waypoints + //! @details Cette classe permet de créer les waypoints pour créer la course public class WaypointsFactory : MonoBehaviour { - public static List<Vector2d> points; - private string coordonnee1; - private string coordonnee2; - public Transform _prefab; - public Transform _prefabs_parent; - private AbstractMap abstractmap; - Directions _directions; - private GameObject map; - private static WaypointsFactory instance; - - Vector2d[] _coordinates; - - DirectionResource _directionResource; - private DirectionsResponse DirectionResourceResultat; - private bool test = true; - + // Champs publiques + public static List<Vector2d> points; //<! Coordonnées des waypoints + private string coordonnee1; //<! Coordonnées du point de départ + private string coordonnee2; //<! Coordonnées du point de fin + public Transform _prefabs_parent; //<! Objet qui va contenir les waypoints + + // Champs privés + Directions _directions; //<! Contient les informations gps de la course + private GameObject map; //<! Map + private static WaypointsFactory instance; //<! Instance de @b Waypoints.WaypointsFactory + Vector2d[] _coordinates; //<! Va contenir @a coordonnee1 et @a coordonnee2 + DirectionResource _directionResource; //<! Contient les informations sous forme de json deserialize + private DirectionsResponse _DirectionResourceResultat; //<! Contient les informations de @a _directionRessource + private bool test = true; //<! Test si la création des waypoints est finie + private AbstractMap abstractmap; //<! Map Google Street View. + + //! @brief Se lance au lancement du script. + //! @details Initialise les variables void Start() { instance = this; @@ -41,26 +47,35 @@ _coordinates = new Vector2d[2]; - // Can we make routing profiles an enum? _directionResource = new DirectionResource(_coordinates, RoutingProfile.Driving); _directionResource.Steps = true; } + //! @brief Retourne l'instance + //! @details return @a instance public static WaypointsFactory getInstance() { return instance; } + //! @brief Retourne si les waypoints ont fini d'être crée + //! @details Retourne si les waypoints ont fini d'être crée public bool getTest() { return test; } + + //! @brief Retourne les coordonnées des waypoints + //! @details Retourne la liste des coordonnées des waypoints public List<Vector2d> getWp() { return points; } + + //! @brief Créer la route + //! @details Créer la route avec le point de départ et de fin void Route() { _coordinates[0] = Conversions.StringToLatLon(coordonnee1); @@ -69,13 +84,18 @@ _directions.Query(_directionResource, HandleDirectionsResponse); } + + //! @brief Enregistre les informations + //! @details Enregistre les informations en format json deserialize void HandleDirectionsResponse(DirectionsResponse res) { - DirectionResourceResultat = res; - //var data = JsonConvert.SerializeObject(res, Formatting.Indented, JsonConverters.Converters); + _DirectionResourceResultat = res; test = false; } + + //! @brief Lance la création de route + //! @details Lance la création de route public void click(string coord1, string coord2) { coordonnee1 = coord1; @@ -86,6 +106,8 @@ } + //! @brief Lance la création de route + //! @details Lance la création de route IEnumerator createRoad() { if (coordonnee1 == "" || coordonnee2 == "") @@ -98,7 +120,7 @@ yield return new WaitUntil(() => test == false); PlacementWaypoint(abstractmap.WorldToGeoPosition(GameObject.FindGameObjectWithTag("start_wp").transform.position)); - foreach (var val in DirectionResourceResultat.Routes[0].Legs[0].Steps) + foreach (var val in _DirectionResourceResultat.Routes[0].Legs[0].Steps) { foreach (var inter in val.Intersections) { @@ -115,6 +137,9 @@ } } + + //! @brief Enregistre un waypoints + //! @details Enregistre les coordonnées d'un waypoints void PlacementWaypoint(Vector2d coordonnesPoints) { points.Add(coordonnesPoints);