using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using UnityEngine.UI.Extensions; using Shapes2D; using TMPro; using System.Linq; public class SetPlan : MonoBehaviour { static private SetPlan _instance; [SerializeField] private Transform _roomContainer; [SerializeField] private Transform _sceneContainer; private List _pointPositions = new(); private List _wallIndexPairs = new(); private const float _presetRoomSize = 192.0f; private const float _presetRoomHeight = 96.0f; private Vector3 _roomPosition; private float _roomHeight = _presetRoomHeight; private void Awake() { if (_instance != null && _instance != this) { Destroy(gameObject); return; } else { _instance = this; } } public static void newRooms(){ _G.WIDE = 192; _G.DEPTH = 168; _G.HEIGHT = 96; DOIT.DELETEAllChild("Plan"); _G.ROOMCLOSE=true; Rooms(); } // public void RESETDRAWROOM(){ // DRAWROOM(); // } // public static void DRAWROOM(){ // _G.Down = false; // _G.Open = true; // _G.WIDE = 192; // _G.DEPTH = 168; // _G.HEIGHT = 96; // _G.closingWall=1; // Get.o2("Canvas","DRAWPlan").SetActive(true); // DOIT.DELETEAllChild("Plan"); // //Get.o2("Canvas","Panel_ShowPlan").SetActive(false); // _G.NW=1; // GameObject PNL=Get.o3("Canvas",_G.PNL,"Plan"); // UILineRenderer pr=PNL.transform.GetComponent(); // var pointlist = new List(); // pr.Points = pointlist.ToArray(); // DOIT.DELETEAllChild("Plan"); // _G.wP=new Vector2[24]; // Get.o3("DRAWPlan","StartHere","T_Start").GetComponent().text=TRANS.This("T_StartHere"); // Measure.okShow("DRAWPlan", "FINISH", false); // } public static void Rooms(){ DOIT.DELETEAllChild("Plan"); print("_G.ROOM =============================== "+_G.ROOM ); Addpoints(); AddFloor(); //RoomSize(); // for(int i=1; i<_G.NW; i++){ // _G.wD[i-1]=DRAW.sense(_G.wP[i-1],_G.wP[i]); // } // _G.wD[_G.NW-1]=DRAW.sense(_G.wP[_G.NW-1],_G.wP[1-1]); // addpoints(_G.NW); // // //addFloor(_G.NW); // if (_G.ROOM == "R1") { // _G.wP[1-1]=new Vector2(-_G.WIDE/2,_G.DEPTH/2); // _G.wP[2-1]=new Vector2(_G.WIDE/2,_G.DEPTH/2); // _G.wP[3-1]=new Vector2(_G.WIDE/2,-_G.DEPTH/2); // _G.wP[4-1]=new Vector2(-_G.WIDE/2,-_G.DEPTH/2); // addpoints(4); // if(_G.PNL=="SETDIM")addMesures(4); // addFloor(4); // } // if (_G.ROOM == "R2") { // _G.wP[1-1]=new Vector2(-_G.WIDE/2,_G.DEPTH/2); // _G.wP[2-1]=new Vector2(-_G.WIDE/2 + _G.wW[1-1],_G.DEPTH/2); // _G.wP[3-1]=new Vector2(_G.WIDE/2,-_G.DEPTH/2+_G.wW[3-1]); // _G.wP[4-1]=new Vector2(_G.WIDE/2,-_G.DEPTH/2); // _G.wP[5-1]=new Vector2(-_G.WIDE/2,-_G.DEPTH/2); // addpoints(5); // if(_G.PNL=="SETDIM")addMesures(5); // addFloor(5); // } // if (_G.ROOM == "R3"){ // _G.wP[1-1]=new Vector2(-_G.WIDE/2+_G.wW[5-1]*0.707f,_G.DEPTH/2); // _G.wP[2-1]=new Vector2(_G.WIDE/2,_G.DEPTH/2); // _G.wP[3-1]=new Vector2(_G.WIDE/2,-_G.DEPTH/2); // _G.wP[4-1]=new Vector2(-_G.WIDE/2,-_G.DEPTH/2); // _G.wP[5-1]=new Vector2(-_G.WIDE/2,-_G.DEPTH/2+_G.wW[4-1]); // addpoints(5); // if(_G.PNL=="SETDIM")addMesures(5); // addFloor(5); // } // if (_G.ROOM == "R4"){ // _G.wP[1-1]=new Vector2(-_G.WIDE/2,_G.DEPTH/2); // _G.wP[2-1]=new Vector2(-_G.WIDE/2+_G.wW[1-1],_G.DEPTH/2); // _G.wP[3-1]=new Vector2(-_G.WIDE/2+_G.wW[1-1],_G.DEPTH/2-+_G.wW[2-1]); // _G.wP[4-1]=new Vector2(_G.WIDE/2,-_G.DEPTH/2+_G.wW[4-1]); // _G.wP[5-1]=new Vector2(_G.WIDE/2,-_G.DEPTH/2); // _G.wP[6-1]=new Vector2(-_G.WIDE/2,-_G.DEPTH/2); // addpoints(6); // if(_G.PNL=="SETDIM")addMesures(6); // addFloor(6); // } // if (_G.ROOM == "R5"){ // _G.wP[1-1]=new Vector2(_G.WIDE/2-_G.wW[1-1] ,_G.DEPTH/2); // _G.wP[2-1]=new Vector2(_G.WIDE/2,_G.DEPTH/2); // _G.wP[3-1]=new Vector2(_G.WIDE/2,-_G.DEPTH/2); // _G.wP[4-1]=new Vector2(-_G.WIDE/2,-_G.DEPTH/2); // _G.wP[5-1]=new Vector2(-_G.WIDE/2,_G.DEPTH/2-_G.wW[6-1] ); // _G.wP[6-1]=new Vector2(-_G.WIDE/2+_G.wW[5-1] ,_G.DEPTH/2-_G.wW[6-1] ); // addpoints(6); // if(_G.PNL=="SETDIM")addMesures(6); // addFloor(6); // } // if (_G.ROOM == "R6"){ // _G.wP[1-1]=new Vector2(-_G.WIDE/2,-_G.DEPTH/2+_G.wW[8-1]); // _G.wP[2-1]=new Vector2(-_G.WIDE/2+_G.wW[1-1],-_G.DEPTH/2+_G.wW[8-1]); // _G.wP[3-1]=new Vector2(-_G.WIDE/2+_G.wW[1-1],-_G.DEPTH/2+_G.wW[8-1]-_G.wW[2-1]); // _G.wP[4-1]=new Vector2(_G.WIDE/2-_G.wW[5-1],-_G.DEPTH/2+_G.wW[6-1]-_G.wW[4-1]); // _G.wP[5-1]=new Vector2(_G.WIDE/2-_G.wW[5-1],-_G.DEPTH/2+_G.wW[6-1]); // _G.wP[6-1]=new Vector2(_G.WIDE/2,-_G.DEPTH/2+_G.wW[6-1]); // _G.wP[7-1]=new Vector2(_G.WIDE/2,-_G.DEPTH/2); // _G.wP[8-1]=new Vector2(-_G.WIDE/2,-_G.DEPTH/2); // addpoints(8); // if(_G.PNL=="SETDIM")addMesures(8); // addFloor(8); // } // if (_G.ROOM == "R7"){ // _G.wW[1-1]= _G.WIDE; // _G.wW[2-1] = _G.DEPTH; // _G.wW[4-1] = _G.DEPTH; // _G.wP[1-1]=new Vector2(-_G.WIDE/2,_G.DEPTH/2); // _G.wP[2-1]=new Vector2(_G.WIDE/2,_G.DEPTH/2); // _G.wP[3-1]=new Vector2(_G.WIDE/2,-_G.DEPTH/2); // _G.wP[4-1]=new Vector2(-_G.WIDE/2,-_G.DEPTH/2); // _G.wa[1-1] = getA( (_G.wP[2-1]-_G.wP[1-1]).normalized ); // _G.wa[2-1] = getA( (_G.wP[3-1]-_G.wP[2-1]).normalized ); // _G.wa[4-1] = getA( (_G.wP[1-1]-_G.wP[4-1]).normalized ); // GameObject p=Get.o2("Panel_ShowPlan","Plan"); // p.SetActive(true); // UILineRenderer pr=p.transform.GetComponent(); // var pointlist = new List(); // pointlist.Add(_G.wP[4-1]*2); // pointlist.Add(_G.wP[1-1]*2); // pointlist.Add(_G.wP[2-1]*2); // pointlist.Add(_G.wP[3-1]*2); // pr.Points = pointlist.ToArray(); // setM("M101",_G.wP[1-1]*2,_G.wP[2-1]*2); // setM("M102",_G.wP[2-1]*2,_G.wP[3-1]*2); // setM("M104",_G.wP[4-1]*2,_G.wP[1-1]*2); // Create3D.setMesureNew(_G.wW[1-1], "m101"); // Create3D.setMesureNew(_G.wW[2-1], "m102"); // Create3D.setMesureNew(_G.wW[4-1], "m104"); // //wCP // _G.wCP[1-1]=(_G.wP[1-1] + _G.wP[2-1])/2; // _G.wCP[2-1]=(_G.wP[2-1] + _G.wP[3-1])/2; // _G.wCP[4-1]=(_G.wP[4-1] + _G.wP[1-1])/2; // } // if (_G.ROOM == "R8"){ // _G.wW[1-1]= _G.WIDE; // _G.wW[4-1] = _G.DEPTH; // _G.wP[1-1]=new Vector2(-_G.WIDE/2,_G.DEPTH/2); // _G.wP[2-1]=new Vector2(_G.WIDE/2,_G.DEPTH/2); // _G.wP[3-1]=new Vector2(_G.WIDE/2,-_G.DEPTH/2); // _G.wP[4-1]=new Vector2(-_G.WIDE/2,-_G.DEPTH/2); // _G.wa[1-1] = getA( (_G.wP[2-1]-_G.wP[1-1]).normalized ); // _G.wa[4-1] = getA( (_G.wP[1-1]-_G.wP[4-1]).normalized ); // GameObject p=Get.o2("Panel_ShowPlan","Plan"); // p.SetActive(true); // UILineRenderer pr=p.transform.GetComponent(); // var pointlist = new List(); // pointlist.Add(_G.wP[4-1]*2); // pointlist.Add(_G.wP[1-1]*2); // pointlist.Add(_G.wP[2-1]*2); // pr.Points = pointlist.ToArray(); // setM("M101",_G.wP[1-1]*2,_G.wP[2-1]*2); // setM("M104",_G.wP[4-1]*2,_G.wP[1-1]*2); // Create3D.setMesureNew(_G.wW[1-1], "m101"); // Create3D.setMesureNew(_G.wW[4-1], "m104"); // //wCP // _G.wCP[1-1]=(_G.wP[1-1] + _G.wP[2-1])/2; // _G.wCP[4-1]=(_G.wP[4-1] + _G.wP[1-1])/2; // } // if (_G.ROOM == "R9") { // _G.wP[1-1] = new Vector2(-_G.WIDE/2, -_G.DEPTH/2 + _G.wW[8-1]); // _G.wP[2-1] = new Vector2(-_G.WIDE/2+_G.wW[1-1], -_G.DEPTH/2 + _G.wW[8-1]); // _G.wP[3-1] = new Vector2(-_G.WIDE/2+_G.wW[1-1]+_G.wW[2-1]*0.707f, _G.DEPTH/2); // _G.wP[4-1] = new Vector2(_G.WIDE/2-_G.wW[5-1]-_G.wW[4-1]*0.707f, _G.DEPTH/2); // _G.wP[5-1] = new Vector2(_G.WIDE/2-_G.wW[5-1], _G.DEPTH/2-_G.wW[4-1]*0.707f); // _G.wP[6-1] = new Vector2(_G.WIDE/2, _G.DEPTH/2-_G.wW[4-1]*0.707f); // _G.wP[7-1] = new Vector2(_G.WIDE/2, -_G.DEPTH/2); // _G.wP[8-1] = new Vector2(-_G.WIDE/2, -_G.DEPTH/2); // addpoints(8); // if(_G.PNL=="SETDIM")addMesures(8); // addFloor(8); // } // if (_G.ROOM == "R10"){ // _G.wP[1-1]=new Vector2(-_G.WIDE/2,-_G.DEPTH/2+_G.wW[8-1]); // _G.wP[2-1]=new Vector2(-_G.WIDE/2+_G.wW[1-1],-_G.DEPTH/2+_G.wW[8-1]); // _G.wP[3-1]=new Vector2(-_G.WIDE/2+_G.wW[1-1],_G.DEPTH/2); // _G.wP[4-1]=new Vector2(_G.WIDE/2-_G.wW[5-1],_G.DEPTH/2); // _G.wP[5-1]=new Vector2(_G.WIDE/2-_G.wW[5-1],-_G.DEPTH/2+_G.wW[6-1]); // _G.wP[6-1]=new Vector2(_G.WIDE/2,-_G.DEPTH/2+_G.wW[6-1]); // _G.wP[7-1]=new Vector2(_G.WIDE/2,-_G.DEPTH/2); // _G.wP[8-1]=new Vector2(-_G.WIDE/2,-_G.DEPTH/2); // addpoints(8); // if(_G.PNL=="SETDIM")addMesures(8); // addFloor(8); // } // if(_G.ROOM != "R7" && _G.ROOM != "R8" && _G.ROOM != "R8"){ // for(int i=1; i<_G.NW; i++){_G.wD[i-1]=DRAW.sense(_G.wP[i-1],_G.wP[i]);} // _G.wD[_G.NW-1]=DRAW.sense(_G.wP[_G.NW-1],_G.wP[1-1]); // RoomSize(); // } // if(_G.ROOM == "RDRAW"){ // for(int i=1; i<_G.NW; i++){_G.wD[i-1]=DRAW.sense(_G.wP[i-1],_G.wP[i]);} // _G.wD[_G.NW-1]=DRAW.sense(_G.wP[_G.NW-1],_G.wP[1-1]); // addpoints(_G.NW); // RoomSize(); // addFloor(_G.NW); // } // _G.NW = 0; // _G.NWExterior = 0; // _G.NWInterior = 0; //CreateRoom2D(); if(_G.PNL=="WALLCAB")AddWallNum(); } static public void SetRoomHeight(float value) { _instance._roomHeight = value; _G.HEIGHT = value; } public static void Addpoints(){ //Add Plan true GameObject plan=Get.o3("Canvas",_G.PNL,"Plan"); plan.SetActive(true); //Set linerender UILineRenderer pr=plan.transform.GetComponent(); pr.Points=new Vector2[_G.WallPoints2D.Count+1]; _G.WallPoints2D.Clear(); foreach(Vector3 V3 in _G.WallPoints) { Vector2 point= new(V3.x,V3.y); _G.WallPoints2D.Add(new(V3.x,V3.y)); print("V2===="+point); } _G.WallPoints2D.Add(_G.WallPoints2D[0]); pr.Points=_G.WallPoints2D.ToArray(); ///_G.NW=Q; // var pointlist = new List(); // int i=1; // pr.Points = pointlist.ToArray(); // for(i=1; i(); var pointlist = new List(); for(i=1; i<_G.NW+1; i++){ pointlist.Add(_G.wP[i-1]); } pointlist.Add(_G.wP[1-1]); pr.Points = pointlist.ToArray(); for(i=1; i<_G.NW; i++) { setM("M10"+i.ToString(),_G.wP[i-1],_G.wP[i]); _G.wCP[i-1]=(_G.wP[i-1] + _G.wP[i])/2; _G.wW[i-1] = Vector2.Distance(_G.wP[i-1],_G.wP[i])/2; } //setM("M10"+_G.NW.ToString(),_G.wP[_G.NW-1],_G.wP[1-1]*1); _G.wW[_G.NW-1] = Vector2.Distance(_G.wP[_G.NW-1],_G.wP[1-1])/2; _G.wCP[_G.NW-1]=(_G.wP[_G.NW-1]+_G.wP[1-1])/2; for(i=1; i<_G.NW+1; i++){ Create3D.setMesureNew(Mathf.Abs(_G.wW[i-1]), "m"+(100+i).ToString()); } RoomSize(); } public static void RedrawRoom78(string Ms,float Value){ print("Ms===="+Ms); if(Ms=="m101")_G.WIDE=Value; if(Ms=="m104")_G.DEPTH=Value; if(Ms=="m102")_G.DEPTH=Value; Rooms(); } public static void setM(string M,Vector2 p1,Vector2 p2){ GameObject Mesure=(GameObject)Instantiate(Get.o2("HIDER","Mesure")); Mesure.name=M; Mesure.SetActive(true); Mesure.transform.Find("m").name=M.Replace("M","m"); Mesure.transform.SetParent(Get.o2(_G.PNL,"Plan").transform,false); Mesure.transform.localPosition=(p1+p2)/2; int i= int.Parse(M.Substring(1, M.Length-1)); Mesure.transform.Find("no").gameObject.GetComponent().text=(i-100).ToString(); } public static void addMesures(int Q){ for(int i=1; i().color=col; Get.o1(no+"Rond").GetComponent().color=col; Get.o1(no+"no").GetComponent().color=col; Get.o1(no).GetComponent().blocksRaycasts=false; } public static void AddWallNum() { int count = _G.WallPoints2D.Count; if (count < 2) return; if (count > 2 && _G.WallPoints2D[count - 1] == _G.WallPoints2D[0]) count -= 1; for (int i = 0; i < count; i++) { Vector2 A = _G.WallPoints2D[i]; Vector2 B = _G.WallPoints2D[(i + 1) % count]; Vector2 center = (A + B) * 0.5f; Get.o2("HIDER", "BTNwn").SetActive(true); GameObject WN = Instantiate(Get.o2("HIDER", "BTNwn")); WN.transform.Find("NW").GetComponent().text = (i + 1).ToString(); WN.name = "w" + (i + 1).ToString(); WN.transform.SetParent(Get.o2("WALLCAB", "Plan").transform, false); // UI: utilise localPosition si ton parent est en coords locales UI, // sinon remplace par anchoredPosition (recommandé) //WN.transform.localPosition = new Vector3(center.x * 2f, center.y * 2f, 0f); WN.GetComponent().anchoredPosition = center * 1f; Get.o2("HIDER", "BTNwn").SetActive(false); } _G.NW = count; } public static float getA(Vector2 d){ float A=0; d.x= Mathf.Round(d.x * 10f) / 10f; d.y= Mathf.Round(d.y * 10f) / 10f; if(d.x==1 && d.y==0.0f)A=0; if(d.x==0.7f && d.y==-0.7f)A=45; if(d.x==0.0f && d.y==-1.0f)A=90; if(d.x==-1.0f && d.y==0.0f)A=180; if(d.x==0.0f && d.y==1.0f)A=270; if(d.x==0.7f && d.y==0.7f)A=315; return A; } public static void RoomSize() { // _G.NW-=1; for(int i=1; i<_G.NW+1; i++){ _G.wW[i-1] = Vector2.Distance(_G.wP[i-1],_G.wP[i]); //print("_G.wW[i-1]==="+_G.wW[i-1]); } _G.wW[_G.NW-1] = Vector2.Distance(_G.wP[_G.NW-1],_G.wP[1-1]); float Xmax=0; float Xmin=0; float Ymax=0; float Ymin=0; for(int i=1; i<_G.NW+1; i++){ if(_G.wP[i-1].xXmax)Xmax=_G.wP[i-1].x; if(_G.wP[i-1].yYmax)Ymax=_G.wP[i-1].y; } for(int i=1; i<_G.NW; i++){ _G.wD[i-1]=DRAW.sense(_G.wP[i-1],_G.wP[i]); } _G.wD[_G.NW-1]=DRAW.sense(_G.wP[_G.NW-1],_G.wP[1-1]); for(int i=1; i<_G.NW+1; i++){ _G.wCP[i-1]=(_G.wP[i-1] + _G.wP[i])/2; } _G.wCP[_G.NW-1]=(_G.wP[_G.NW-1] + _G.wP[1-1])/2; _G.WIDE=Xmax-Xmin; _G.DEPTH=Ymax-Ymin; //_G.NW+=1; } public static void AddFloor() { //print("Add floor"); //scale room float scR=800/_G.WIDE/3;//2.5 if(_G.DEPTH*scR>1200)scR=1200/_G.DEPTH/3;//1.5 Get.o2(_G.PNL,"Plan").transform.localScale=new Vector3(scR,scR,1); // GameObject plan=Get.o2(_G.PNL,"Shapes2D Panel"); // Shapes2D.Shape shape = plan.GetComponent(); // Vector2[] verts = new Vector2[nW]; // float sX=192/scR;//scR; // float sY=250/scR;//scR; // verts[0] = new Vector2(_G.wP[0].x/sX, _G.wP[0].y/sY); // verts[1] = new Vector2(_G.wP[1].x/sX, _G.wP[1].y/sY); // verts[2] = new Vector2(_G.wP[2].x/sX, _G.wP[2].y/sY); // //verts[3] = new Vector2(_G.wP[3].x/sX, _G.wP[3].y/sY); // for(int i=3; ii)verts[i] = new Vector2(_G.wP[i].x/sX, _G.wP[i].y/sY); // } // shape.ComputeAndApply(); // shape.settings.polyVertices = verts; } }