using System.Collections; using System.Collections.Generic; using UnityEngine; using TMPro; using UnityEngine.UI; using UnityEngine.UI.Extensions; public class Positioning : MonoBehaviour { public static int WallsNumber; public static Sprite _selectedWindows; public static bool CheckRightValue; public static bool CheckLeftValue; public static string ObjectName; public static void Start(){ AddWallsCollider("POSITIONING"); GameObject listObject=Get.o1("OBSTACLELIST"); foreach(Transform O in listObject.transform){ print("O.name========================================"+O.name); Get.o2(O.name,"Circle").transform.GetComponent().color= Color.red; } } public void OK() { ADDOBJECT.newObstacle(); Get.o2("Canvas", "PanelPosition").SetActive(false); } public static void AddWallsCollider(string pnl){ DOIT.DELETEAllChild("Canvas/"+pnl+"/Plan"); //Vector2[] wallPoints = Get.o3("Canvas", pnl, "Plan").GetComponent().Points; // _G.wW = new float[_G.WallPoints2D.Count]; // for(int i=0; i<_G.WallPoints2D.Count; i++) // { // int next=i+1; // if(next==_G.WallPoints2D.Count)next=0; // _G.wW[i]=Vector2.Distance(_G.WallPoints2D[i],_G.WallPoints2D[next]); // } int count = _G.WallPoints2D.Count; float wallThickness = 10f; RectTransform parentPlan = (RectTransform)Get.o2("Canvas/"+pnl,"Plan").transform; for (int i = 0; i < count; i++) { Vector2 A = _G.WallPoints2D[i]; Vector2 B = _G.WallPoints2D[(i + 1) % count]; Vector2 dir = (B - A); float length = dir.magnitude; if (length <= 0.001f) continue; Vector2 center = (A + B) * 0.5f; float angleDeg = Mathf.Atan2(dir.y, dir.x) * Mathf.Rad2Deg; // Create UI wall GameObject wall = new GameObject($"w{i + 1}", typeof(RectTransform), typeof(Image)); wall.transform.SetParent(parentPlan, false); RectTransform rt = wall.GetComponent(); rt.localScale = Vector3.one; rt.anchoredPosition = center; rt.sizeDelta = new Vector2(length, wallThickness); rt.localRotation = Quaternion.Euler(0f, 0f, angleDeg); Image img = wall.GetComponent(); img.color = Color.black; // Trigger 2D (pour UI Canvas) var col = wall.AddComponent(); col.isTrigger = true; col.size = new Vector2(length, wallThickness); var rb = wall.AddComponent(); rb.bodyType = RigidbodyType2D.Kinematic; rb.simulated = true; } //for (int i = 0; i < _G.WallPoints2D.Count; i++) { //create a 2D collider Image GameObject Wall = new("w"+(i+1).ToString()); // Wall.AddComponent(); // //size Wall.transform.GetComponent().sizeDelta=new Vector2(_G.wW[i]*1,10); // Wall.transform.GetComponent().color=Color.black; // Wall.transform.SetParent(Get.o3("Canvas", pnl,"Plan").transform); // Wall.transform.SetLocalPositionAndRotation(new Vector3(_G.wCP[i].x*1,_G.wCP[i].y*2,0), Quaternion.Euler(0, 0 ,-_G.wa[i])); // Wall.transform.localScale = new Vector3(1,1,1); // Wall.AddComponent(); // Wall.GetComponent().isTrigger= true; // Wall.GetComponent().size=new Vector3(_G.wW[i]*1,10,50); // Wall.AddComponent(); // Wall.GetComponent().useGravity=false; } } }