void Start() { infos = object_linked.GetComponent <ObjectsInformations>(); title_field = GameObject.Find("text_title").GetComponent <Text>(); description_field = GameObject.Find("text_description").GetComponent <Text>(); }
void Start() { readObjects = GameObject.Find("CSV_objets_lecture").GetComponent <ReadObjects>(); allObjects = readObjects.allObjects; for (var i = 0; i < allObjects.Count; i++) { float yPos = i * 35; pos = new Vector3(0, -yPos); GameObject bouton = Instantiate(bouton_liste); bouton.name = "bouton_" + allObjects[i].name; bouton.transform.SetParent(ObjectParent.transform); bouton.GetComponent <RectTransform>().anchoredPosition = pos; Text bouton_texte = bouton.GetComponentInChildren <Text>(); ObjectsInformations infos = allObjects[i].GetComponent <ObjectsInformations>(); bouton.GetComponent <bouton_hierarchyList>().object_linked = allObjects[i]; bouton_texte.text = infos.title; if (i % 2 == 0) { bouton.GetComponent <Image>().color = col; } Canvas.ForceUpdateCanvases(); } }
public void Onclick() { if (object_linked != null) { infos = object_linked.GetComponent <ObjectsInformations> (); title_field.text = infos.title; description_field.text = infos.description; GameObject[] zones = GameObject.FindGameObjectsWithTag("Zone"); foreach (GameObject go in zones) { go.transform.localScale = Vector3.zero; } if (infos.geometry_mock_up != null && infos.geometry_mock_up != "") { GameObject obj_zone = GameObject.Find(object_linked.name + "_zone"); obj_zone.transform.localScale = Vector3.one; } //Mise à jour des informations du bandeau details details = GameObject.Find("texte_version"); details.GetComponent <Text>().text = infos.version; details = GameObject.Find("texte_id"); details.GetComponent <Text>().text = infos.id; details = GameObject.Find("texte_statut"); details.GetComponent <Text>().text = infos.status; } }
public void DisplayList() //Cette fonction crée une liste de boutons et l'affiche dans la section dédiée du panneau latéral droit. Elle permet également l'affichage des labels des objets sélectionnés. { for (var i = 0; i < SelectedObj.Count; i++) { //Création des boutons de la liste d'objects sélectionnés float yPos = i * 25; Vector3 pos = new Vector3(1, -yPos); GameObject bouton = Instantiate(bouton_liste); bouton.name = "bouton_" + SelectedObj[i].name; bouton.transform.SetParent(ObjectParent.transform); bouton.GetComponent <RectTransform>().anchoredPosition = pos; bouton.GetComponent <RectTransform>().sizeDelta = new Vector2(370, 25); Text bouton_texte = bouton.GetComponentInChildren <Text>(); ObjectsInformations infos = SelectedObj[i].GetComponent <ObjectsInformations>(); bouton.GetComponent <bouton_hierarchyList>().object_linked = SelectedObj[i]; bouton_texte.text = infos.title; if (i % 2 == 0) { bouton.GetComponent <Image> ().color = new Vector4(1, 1, 1, 1); } //Si nécessaire, on agrandit le menu des objets sélectionnés if (i > 10) { Vector2 dec = new Vector2(0, 25); Cont_rect.sizeDelta += dec; Doc_rect.sizeDelta += dec; } //On force la mise à jour des canevas Canvas.ForceUpdateCanvases(); //On place les boutons créés dans une liste SelectedButton.Add(bouton); //Affichage des labels des objets sélectionnés label_script = infos.label.GetComponent <Label_UI> (); label_script.label_pointe_RT.localScale = Vector3.one; label_script.isVisible = true; } }
public void ClearLabels() //Cette fonction permet d'effacer les labels sur la maquette et de vider la liste des objets sélectionnés. { foreach (GameObject go in SelectedObj) { //On efface les labels de tous les objets sélectionnés sauf si l'un d'entre eux est l'objet actif if (go != GameObject.Find("Active_object").GetComponent <Active_object> ().active) { infos = go.GetComponent <ObjectsInformations> (); label_script = infos.label.GetComponent <Label_UI> (); label_script.label_pointe_RT.localScale = Vector3.zero; label_script.isVisible = false; } } SelectedObj.Clear(); //On vide la liste des objets sélectionnés }
public void OnClick() { if (title_field.text != "") { foreach (GameObject go in allObjects) { ObjectsInformations infos = go.GetComponent <ObjectsInformations>(); if (infos.title == title_field.text) { activeObject = go; label_script = infos.label.GetComponent <Label_UI>(); label_script.label_pointe_RT.localScale = Vector3.one; label_script.isVisible = true; break; } } } mainCam_goTo.GoTo(activeObject.transform); }
//Active le label de l'objet, et affiche les infos dans le panneau latéral //À noter : lorsque l'on veut faire apparaître un label, on fait passer sa "localSize" de 0 à 1 public void DisplayLabel() { infos = gameObject.GetComponent <ObjectsInformations> (); title_field = GameObject.Find("text_title").GetComponent <Text> (); description_field = GameObject.Find("text_description").GetComponent <Text> (); label_script = infos.label.GetComponent <Label_UI> (); title_field.text = infos.title; description_field.text = infos.description; visible = GameObject.Find("Button_afficherZones").GetComponent <ShowZones> ().visible; if (!visible) { GameObject[] zones = GameObject.FindGameObjectsWithTag("Zone"); foreach (GameObject go in zones) { go.transform.localScale = Vector3.zero; } if (infos.geometry_mock_up != "") { GameObject obj_zone = GameObject.Find(gameObject.name + "_zone"); obj_zone.transform.localScale = Vector3.one; } } label_script.label_pointe_RT.localScale = Vector3.one; label_script.isVisible = true; //On met à jour les informations du bandeau details details = GameObject.Find("texte_version"); details.GetComponent <Text> ().text = infos.version; details = GameObject.Find("texte_id"); details.GetComponent <Text> ().text = infos.id; details = GameObject.Find("texte_statut"); details.GetComponent <Text> ().text = infos.status; }
void Start() { readObjects = GameObject.Find("CSV_objets_lecture").GetComponent <ReadObjects>(); allObjects = readObjects.allObjects; for (var i = 0; i < allObjects.Count; i++) { GameObject obj = allObjects[i]; ObjectsInformations infos = obj.GetComponent <ObjectsInformations>(); GameObject obj_label = Instantiate(label_prefab); obj_label.name = "label_" + obj.name; obj_label.tag = "Label"; obj_label.transform.SetParent(gameObject.transform); obj_label.transform.position = obj.transform.position; obj_label.GetComponentInChildren <Text>().text = infos.title; obj_label.GetComponentInChildren <CameraFacingBillboard>().m_Camera = GameObject.Find("Main Camera").GetComponent <Camera>(); infos.label = obj_label; } }
// Update is called once per frame void Update() { //Si on a un objet actif on va modifier le panneau détail if (GameObject.Find("text_title").GetComponent <Text> ().text != "Titre") { Vector2 dec = new Vector2(0, 22); //Vecteur utile pour le redimensionnement du panneau détail //On récupère l'objet actif et ses objets en relations actif = GameObject.Find("Active_object").GetComponent <Active_object> ().active; relations = actif.GetComponent <ObjectsInformations> ().objets_en_relation; //Si on change d'objet actif... if (previous != actif) { //On revient à la définition initiale du panneau détails Pan_details_rect.sizeDelta = size_init; Pan_details_rect.anchoredPosition = pos_init; //On détruit les boutons relations existants foreach (GameObject go in RelatList) { Destroy(go); } //S'il existe des éléments en relation... if (relations.Count > 0) { //On retire le texte sous la section "Objets en relations" GameObject.Find("texte_relations").GetComponent <Text> ().text = ""; //Création des boutons pour chaque objet en relation for (var i = 0; i < relations.Count; i++) { //Permet de positionner le bouton float yPos = i * 24; Vector3 pos = new Vector3(-16, -yPos); //On instantie un prefab de bouton et on paramètre toutes ses caractéristiques GameObject bouton = Instantiate(bouton_liste); bouton.name = "bouton_relation_" + relations [i].GetComponent <ObjectsInformations> ().id; //nom bouton.transform.SetParent(ObjectParent.transform); //objet parent sur le canevas bouton.GetComponent <RectTransform> ().anchoredPosition = pos; //position bouton.GetComponent <RectTransform> ().localScale = new Vector3(1, 1, 1); //échelle bouton.GetComponent <RectTransform> ().sizeDelta = new Vector2(504, 24); //taille bouton.GetComponent <Image> ().color = new Vector4(1, 1, 1, 1); //couleur du fond (blanc) bouton.GetComponent <bouton_hierarchyList> ().object_linked = relations [i]; //élément pointé par le bouton //Texte affiché sur le bouton Text bouton_texte = bouton.GetComponentInChildren <Text> (); ObjectsInformations infos = relations [i].GetComponent <ObjectsInformations> (); bouton_texte.text = infos.title; // On change la couleur des boutons impairs if (i % 2 == 1) { bouton.GetComponent <Image> ().color = new Vector4(0.8f, 0.8f, 0.8f, 1); } //Agrandissement du panneau détail pour insérer les boutons (seulement s'il y a plus de 1 bouton) if (i != 0) { Pan_details_rect.sizeDelta += dec; Pan_details_rect.anchoredPosition -= dec; } //On ajoute le boutons à la liste RelatListe RelatList.Add(bouton); //On force la mise à jour du canevas Canvas.ForceUpdateCanvases(); } } //Si on a pas d'objets en relation avec l'objet actif, on modifie le texte de la section en conséquence else { GameObject.Find("texte_relations").GetComponent <Text> ().text = "Pas d'éléments en relation"; } } previous = actif; } }
///////////Valider la recherche/////////// public void ValideResearch() { print("validé"); ObjectsInformations objectSearched_infos = null; ObjetOnClick objetSearched_onClick = null; List <List <GameObject> > objets_relations_all = new List <List <GameObject> >(); researchIsActive = false; print("objet de la recherche : '" + research_name + "'"); foreach (GameObject go in objets_all) { ///Trouver l'objet par correspondance de titre.../// ObjectsInformations infos = go.GetComponent <ObjectsInformations>(); if (infos.title == research_name) { objectSearched = go; objectSearched_infos = objectSearched.GetComponent <ObjectsInformations>(); objetSearched_onClick = objectSearched.GetComponent <ObjetOnClick>(); } } ///Si l'objet n'a pas de relations, afficher direct les infos/// if (objectSearched_infos.objets_en_relation.Count == 0 || profondeur_de_relations == 0) { objetSearched_onClick.DisplayLabel(); SetupCamera(objectSearched); } ///S'il en a, établir une liste de liste de tout les objets en relation/// if (objectSearched_infos.objets_en_relation.Count != 0 && profondeur_de_relations != 0) { ///La liste 0 est uniquement constituée de l'objet recherché/// objets_relations_all.Add(new List <GameObject>()); objets_relations_all[0].Add(objectSearched); for (var i = 1; i < profondeur_de_relations; i++) { objets_relations_all.Add(new List <GameObject>()); for (var j = 0; j < objets_relations_all[i - 1].Count; j++) { ObjectsInformations infos = objets_relations_all[i - 1][j].GetComponent <ObjectsInformations>(); if (infos.objets_en_relation != null) { for (var k = 0; k < infos.objets_en_relation.Count; k++) { objets_relations_all[i].Add(infos.objets_en_relation[k]); } } } } ///Afficher enfin toute les informations/// int compteTotal = 0; float r = 255f; for (var i = 0; i < objets_relations_all.Count; i++) { r -= 255 / profondeur_de_relations; for (var j = 0; j < objets_relations_all[i].Count; j++) { ///Affichage des titres/// objets_relations_all[i][j].GetComponent <ObjetOnClick>().DisplayLabel(); ///Incrémentation de la couleur/// Renderer rend = objets_relations_all[i][j].GetComponent <Renderer>(); rend.material.color = new Color(r / 255, 0, 0, 1); compteTotal++; } } print("Au total : " + compteTotal); ///L'affichage des lignes de relation se fait dans une loop à part/// float lineWidht = 0.8f; Color lineColor = new Color(); float rCol = 1; for (var i = 0; i < objets_relations_all.Count - 1; i++) { lineWidht -= (lineWidht / objets_relations_all.Count); rCol -= 0.16f; lineColor.a = rCol; lineColor.r = rCol; lineColor.g = 0; lineColor.b = 0; ///Deux distributions pour deux caméras/// for (var j = 0; j < objets_relations_all[i].Count; j++) { ObjectsInformations infos = objets_relations_all[i][j].GetComponent <ObjectsInformations>(); if (infos.objets_en_relation != null) { for (var k = 0; k < infos.objets_en_relation.Count; k++) { GameObject lineObject = Instantiate(lineRenderer); lineObject.transform.SetParent(GameObject.Find("Relations").transform); lineObject.layer = 12; WorldSpaceLines lineInit = lineObject.GetComponent <WorldSpaceLines>(); lineInit.camDisplay = Cam.mainCam; lineInit.startObject = objets_relations_all[i][j]; lineInit.endObject = infos.objets_en_relation[k]; } } } } SetupCamera(objectSearched); objectSearched.transform.position += new Vector3(0, 20, 0); } }
public void setActive() //Enregistre les caractéristiques de l'objet actif et les modifie pour le mettre en valeur //On récupère l'objet actif à partir de son nom { active = GameObject.Find(nom); //On stocke son matériau d'origine puis on lui donne un matériau de mise en valeur cur_mat = active.GetComponent <MeshRenderer> ().material; active.GetComponent <MeshRenderer> ().material = act_mat; //On récupère les informations attachées à l'objet actif infos = active.GetComponent <ObjectsInformations> (); //Si l'objet actif possède une zone associée... if (infos.geometry_mock_up != "") { obj_zone_act = GameObject.Find(active.name + "_zone"); //On récupère l'objet zone // Si la zone est actuellement mise en valeur, son matériau d'origine est stockée dans l'attribut start_mat de "ZoneOnClick". if (obj_zone_act.GetComponent <ZoneOnClick> ().highlighted) { cur_zone_mat = obj_zone_act.GetComponent <ZoneOnClick> ().start_mat; } // Sinon, on récupère tout simplement le matériau sur l'objet zone. else { cur_zone_mat = obj_zone_act.GetComponent <MeshRenderer> ().material; } // Gestion de la zone associée à l'objet actif highlight_Zone(); } //Si on a un objet précédent, on va lui redonner ses caractéristiques d'origine et effacer son label if (begin) { //On redonne à l'objet précédent son matériau d'origine previous.GetComponent <MeshRenderer> ().material = pre_mat; //On récupère les informations attachées à l'objet précédent infos = previous.GetComponent <ObjectsInformations> (); //On efface le label de l'objet précédent sauf s'il appartient à la liste d'objets sélectionnés SelectedObj = GameObject.Find("Documents").GetComponent <ObjectSelection> ().SelectedObj; if (!SelectedObj.Contains(previous)) { label_script = infos.label.GetComponent <Label_UI> (); label_script.label_pointe_RT.localScale = Vector3.zero; label_script.isVisible = false; } //Si l'objet précédent possède une zone associée, on redonne à cette zone son matériau d'origine if (infos.geometry_mock_up != "") { obj_zone_pre.GetComponent <MeshRenderer> ().material = pre_zone_mat; // On modifie son matériau } } //On passe les paramètres de l'objet actif dans l'objet précédent previous = active; obj_zone_pre = obj_zone_act; pre_mat = cur_mat; pre_zone_mat = cur_zone_mat; //On enregistre le fait qu'on a un objet précédent begin = true; }
private void PlacerLesObjets() { ///////////Placer les objets...//////////// ///...spatialisés.../// for (var i = 0; i < spatializedObjects.Count; i++) { GameObject obj = spatializedObjects[i]; ObjectsInformations infos = obj.GetComponent <ObjectsInformations>(); obj.GetComponent <Renderer>().material = spatialized_mat; pos = infos.GPS_converted * coordonates_Multiplicater - new Vector3(offsetX, -8.70f, offsetZ); /////On vérifie qu'aucun objet n'est présent à la position ciblée Collider[] hitColliders = Physics.OverlapSphere(pos, 0.51f); if (hitColliders.Length > 0) { // print(obj.name + " : " + hitColliders.Length); pos += new Vector3(0, 1.3f * hitColliders.Length, 0); obj.transform.position = pos; } else if (hitColliders.Length == 0) { obj.transform.position = pos; } ///////On ajuste la hauteur par rapport au maillage de la maquette //float high = 10; //RaycastHit hit; //if (Physics.Raycast(obj.transform.position, -obj.transform.up, out hit, 500.0f)) //{ // print(hit.transform.name); // high = hit.point.y + 1; // print(obj.transform.position); // obj.transform.position = new Vector3(obj.transform.position.x, high, obj.transform.position.z); //} } ///...et non spatializés/// for (var i = 0; i < noSpatializedObjects.Count; i++) { GameObject obj = noSpatializedObjects[i]; ObjectsInformations infos = obj.GetComponent <ObjectsInformations>(); Vector3 sumPosition = new Vector3(0, 0, 0); Vector3 averagePosition; obj.GetComponent <Renderer>().material = noSpatialized_mat; if (infos.objets_en_relation.Count > 1) { for (var j = 0; j < infos.objets_en_relation.Count; j++) { sumPosition += infos.objets_en_relation[j].transform.position; } averagePosition = sumPosition / infos.objets_en_relation.Count; obj.transform.position = new Vector3(averagePosition.x, 25, averagePosition.y); } else { obj.transform.position = new Vector3(0, 0, 0); } } /////////On crée des objets enfants, pour accueillir les mesh de zone for (var i = 0; i < allObjects.Count; i++) { GameObject obj = allObjects[i]; ObjectsInformations infos = obj.GetComponent <ObjectsInformations>(); if (infos.geometry_mock_up != "") { GameObject emptyChild = Instantiate(emptyObject) as GameObject; emptyChild.name = obj.name + "_zone"; emptyChild.transform.SetParent(GameObject.Find("Zones").transform); emptyChild.layer = 13; emptyChild.tag = "Zone"; emptyChild.transform.localScale = Vector3.zero; } } ZoneList = true; }
void Awake() { ///////////Créer les objets et assigner les informations//////////// var hostName = "http://localhost"; var port = ":3000"; #region getting objects try { var uriObjects = hostName + port + "/Objects"; var objects = GetObjectList <ObjectDB>(uriObjects); foreach (var myObj in objects) { GameObject obj; obj = Instantiate(prefab, pos, prefab.transform.rotation) as GameObject; obj.name = "object" + myObj.Id as string; obj.transform.SetParent(GameObject.Find("Objects").transform); obj.GetComponent <ObjectsInformations>().id = myObj.Id.ToString(); obj.GetComponent <ObjectsInformations>().title = myObj.Title; obj.GetComponent <ObjectsInformations>().description = myObj.Abstract; obj.GetComponent <ObjectsInformations>().version = myObj.VersionNb.ToString(); obj.GetComponent <ObjectsInformations>().status = myObj.Status; obj.GetComponent <ObjectsInformations>().geometry_mock_up = myObj.Geometry; allObjects.Add(obj); } } catch (Exception e) { throw e; } #endregion #region getting Relations try { var uriRelations = hostName + port + "/Relations"; var relations = GetObjectList <Relation>(uriRelations); foreach (var relation in relations) { GameObject obj = GameObject.Find("object" + relation.A as string); GameObject objRelated = GameObject.Find("object" + relation.B as string); ObjectsInformations comp = obj.GetComponent <ObjectsInformations>(); comp.objets_en_relation.Add(objRelated); } } catch (Exception e) { throw e; } #endregion #region getting spatial data try { var uriSpatiale = hostName + port + "/Spatial"; var spatials = GetObjectList <Spatial>(uriSpatiale); foreach (var spatial in spatials) { GameObject obj = GameObject.Find("object" + spatial.Id); ObjectsInformations comp = obj.GetComponent <ObjectsInformations>(); if (spatial.Longitude.HasValue && spatial.Latitude.HasValue) { comp.isSpatialized = true; comp.GPS_longitude = spatial.Longitude.Value; comp.GPS_lattitude = spatial.Latitude.Value; comp.GPS_converted = GPSEncoder.GPSToUCS(new Vector2(spatial.Latitude.Value, spatial.Longitude.Value)); spatializedObjects.Add(obj); } else { comp.isSpatialized = false; noSpatializedObjects.Add(obj); } } } catch (Exception e) { throw e; } #region group /*try * { * foreach (var spatial_i in spatials) * { * GameObject obj_i = GameObject.Find("object" + spatial_i.Id); * ObjectsInformations comp_i = obj_i.GetComponent<ObjectsInformations>(); * * foreach (var spatial_j in spatials) * { * GameObject obj_j = GameObject.Find("object" + spatial_j.Id); * * if (spatial_i.Id != spatial_j.Id && * comp_i.GPS_lattitude > 0 && * spatial_i.Latitude == spatial_j.Latitude && * spatial_i.Longitude == spatial_j.Longitude) * { * sharedCoordinates.Add(new List<GameObject>() { obj_i, obj_j }); * } * } * } * * Debug.Log(sharedCoordinates.Count); * } * catch (Exception e) * { * * throw e; * }*/ #endregion #endregion }
IEnumerator Wait() { yield return(new WaitForSeconds(2f)); allObjects = GameObject.FindGameObjectsWithTag("Objet"); foreach (GameObject obj in allObjects) { ObjectsInformations infos = obj.GetComponent <ObjectsInformations>(); if (infos.geometry_mock_up != "") { GameObject obj_zone = GameObject.Find(obj.name + "_zone"); // Use the triangulator to get indices for creating triangles Triangulator tr = new Triangulator(infos.orthophoto_coo); int[] indices = tr.Triangulate(); // Create the Vector3 vertices Vector3[] vertices = new Vector3[infos.orthophoto_coo.Length]; for (int i = 0; i < vertices.Length; i++) { vertices[i] = new Vector3(infos.orthophoto_coo[i].x, 0, infos.orthophoto_coo[i].y); } // Create the mesh Mesh msh = new Mesh(); msh.vertices = vertices; msh.triangles = indices; msh.RecalculateNormals(); msh.RecalculateBounds(); // Set up game object with mesh; obj_zone.AddComponent(typeof(MeshRenderer)); MeshFilter filter = obj_zone.AddComponent(typeof(MeshFilter)) as MeshFilter; filter.mesh = msh; // Set up the material obj_zone.GetComponent <Renderer>().material = mat[Random.Range(0, mat.Length)]; obj_zone.AddComponent <DrawZoneLines>(); obj_zone.AddComponent <ZoneOnClick> (); obj_zone.AddComponent <MeshCollider> (); ///////Génération des lignes //for (var j = 0; j < infos.orthophoto_coo.Length - 1; j++) //{ // GameObject lineObject = Instantiate(emptyObject) as GameObject; // lineObject.layer = 13; // lineObject.name = obj_zone.name + "_lineRenderer" + j.ToString(); // lineObject.transform.SetParent(obj_zone.transform); // LineRenderer lineRend = lineObject.GetComponent<LineRenderer>(); //} } } TransformData td = GameObject.Find("Zones_transform").transform.Clone(); parent.position = td.position; parent.localPosition = td.localPosition; parent.localRotation = td.localRotation; parent.localScale = td.localScale; //parent.transform.localScale *= 0.144f; //float smooth = 100f; //parent.transform.position += new Vector3(172.9f, 5.5f, 165.8f); //Vector3 targetAngles = parent.transform.eulerAngles + 180f * Vector3.right; // what the new angles should be //parent.transform.eulerAngles = Vector3.Lerp(parent.transform.eulerAngles, targetAngles, smooth * Time.deltaTime); }