namespace Scripts { using UnityEngine; using UnityEngine.EventSystems; using Mapbox.Unity.Map; using Scripts.Map; using Scripts.Routes; using Scripts.Waypoints; //! @authors MrWarzo //! Wakestufou //! @brief Met en commun différents scripts afin de controller les Waypoints, les Routes et l'IA. //! @details Cette classe s'occupe de l'affichage des deux premiers HUD ainsi que //! du placement des waypoints et tu tracé de la route. public class GameManager : MonoBehaviour { // Champs publiques public GameObject[] waypoints; //!< Préfabriqués des waypoints START et END => {Waypoint_START, Waypoint_END} public AbstractMap map; //!< Map Google Street View. public Canvas canvasStep1; //!< Première étape de l'HUD, phase de recherche d'un emplacement. public Canvas canvasStep2; //!< Deuxième étape de l'HUD, phase de pose du départ et de l'arrivée. // Champs privés private Plane _yPlane; //!< Plan servant à représenter ce qui est visible par la caméra sur le terrain 3D. [SerializeField] int _indexWaypoint = 0; //!< Index pour choisir le waypoint dans @a waypoints. [SerializeField] bool _locked = false; //!< @b true si la @a map est bloquée, @b false sinon. //! @brief Se lance au lancement du script. //! @details Définie le plan @a _yPlane. void Start() { _yPlane = new Plane(Vector3.up, Vector3.zero); } //! @brief Se répète toutes les 14ms (temps par défaut dans Unity). //! @details Permet deposer les waypoints START et END à partir du clic et de la position de la souris. //! Active le script @b Routes.RouteTracer de manière à tracer les routes entre les deux waypoints. //! La variable @a indexWaypoint sert à récupérer le préfabriquée voulu dans waypoints et pour noter à quel étape de création est le joueur. void Update() { if (Input.GetKeyDown(KeyCode.Mouse0) && _locked && _indexWaypoint < 2) { if (EventSystem.current.IsPointerOverGameObject()) { return; } Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); float enter = 0.0f; if (_yPlane.Raycast(ray, out enter)) { Instantiate(waypoints[_indexWaypoint], ray.GetPoint(enter) + Vector3.up, new Quaternion(0, 0, 0, 0), WaypointsFactory.getInstance()._prefabs_parent); switch (_indexWaypoint) { case 0: canvasStep2.transform.GetChild(0).GetChild(0).gameObject.SetActive(false); canvasStep2.transform.GetChild(0).GetChild(1).gameObject.SetActive(true); break; case 1: canvasStep2.gameObject.SetActive(false); break; } _indexWaypoint++; } } if (Ui.start == true) { if (GameObject.FindGameObjectWithTag("start_wp") != null && GameObject.FindGameObjectWithTag("end_wp") != null) { if (_indexWaypoint == 2) { WaypointsFactory.getInstance().click(map.WorldToGeoPosition(GameObject.FindGameObjectWithTag("start_wp").transform.position).x.ToString().Replace(',', '.') + ',' + map.WorldToGeoPosition(GameObject.FindGameObjectWithTag("start_wp").transform.position).y.ToString().Replace(',', '.'), map.WorldToGeoPosition(GameObject.FindGameObjectWithTag("end_wp").transform.position).x.ToString().Replace(',', '.') + ',' + map.WorldToGeoPosition(GameObject.FindGameObjectWithTag("end_wp").transform.position).y.ToString().Replace(',', '.') ); _indexWaypoint = 4; } } } } //! @brief Bloque la caméra et empêche tout mouvement. //! @details Le composant @b Map.QuadTreeCameraMovement de la map est désactivé. Sans celui-ci, elle ne peut plus se déplacer. //! L'HUD de recherche d'emplacement (@a canvasStep1) se désactive laissant place à l'HUD de placement des waypoint (@a canvasStep2). //! La variable privée @a _locked passe alors à @e true afin de récupérer l'état de la map. public void lockMovement() { map.GetComponent<QuadTreeCameraMovement>().enabled = false; canvasStep1.gameObject.SetActive(false); _locked = true; canvasStep2.GetComponentInChildren<Transform>().gameObject.SetActive(true); } } }