using System.Collections.Generic; using UnityEngine; using System.Linq; using System.Collections; using TMPro; using UnityEngine.UI; public class HOLE : MonoBehaviour { static public HOLE Instance { get; private set; } [Header("Reposition limits from wall")] [SerializeField] float _maxPositionDistance = 100.0f; [SerializeField] float _maxSideDistance = 50.0f; [SerializeField] float _maxForwardDegree = 30.0f; static public float MaxPositionDistanceFromWall => Instance._maxPositionDistance; static public float MaxSideDistanceFromWall => Instance._maxSideDistance; static public float MaxForwardDegreeFromWall => Instance._maxForwardDegree; static int IndeXExteriorPoint; private void Awake() { Instance = this; } public static void RefreshAllWalls() { print("SceneModeManager.Selected.name===1=" + SceneModeManager.SelectedName); if (SceneModeManager.SelectedName != "") { print("SceneModeManager.Selected.name===2=" + SceneModeManager.SelectedName); int ADN = Get.GetObjectIndex(SceneModeManager.SelectedName); string Attacheto = _G.OBJs[ADN][22]; StaticCoroutine.Start(wall(Attacheto)); } else { StaticCoroutine.Start(RefreshAllWallsCoroutine()); } } private static IEnumerator RefreshAllWallsCoroutine() { WaitCircle.Setting(true, TRANS.This("M_Triangulation")); yield return null; for (int i = 1; i < _G.NW + 1; i++) { string wallName = "w" + i.ToString(); GameObject wallObj = GameObject.Find(wallName); List OpenList = GetAllOpenInWall(i.ToString()); if (wallObj != null && !_G.WALLS_HIDDEN_LIST.Contains(i.ToString()) && OpenList.Count > 0) { //WaitCircle.Setting(true, TRANS.This("M_Triangulation")); //yield return null; yield return wall(wallName); } } // ✅ Cacher le cercle après la fin de toutes les coroutines WaitCircle.Setting(false, ""); if (_G.WMK[0] != "ND") { ConstructMolding.AddMolding("B"); } } public static IEnumerator wall(string nW) { WaitCircle.Setting(true, TRANS.This("M_Triangulation")); yield return null; if (_G.ExteriorWalllist.Contains(nW)) { //print("From--wall =====1====" + nW); if (nW[..1] == "w") { //print("From--wall =====2====" + nW); IndeXExteriorPoint = int.Parse(nW[1..]) - 1; Transform wall = SceneModeManager.GetObjectInRoom(nW); List OpenList = GetAllOpenInWall(nW[1..]); List[] OpenPoints = new List[OpenList.Count]; for (int i = 0; i < OpenList.Count; i++) { OpenPoints[i] = GetOpenPoints(OpenList[i]); } //print("From--wall =====3====" + OpenPoints[0]); //print("------Create Hole-----" + " time===" + Time.time); yield return TimerForCutting(wall.gameObject, _G.ExteriorWallPoints[IndeXExteriorPoint], OpenPoints); } yield return null; } WaitCircle.Setting(false, ""); } public static void DeleteFromWall(string nW) { //print("Fromm who----DeleteFromwall"); if (!_G.WALLS_HIDDEN_LIST.Contains(nW) && _G.ExteriorWalllist.Contains(nW) ) { if (nW[..1] == "w") { IndeXExteriorPoint=int.Parse(nW[1..])-1; Transform wall = SceneModeManager.GetObjectInRoom(nW); List OpenList = GetAllOpenInWall(nW); List[] OpenPoints= new List[OpenList.Count]; for(int i=0; i OuterPolygon, List[] Holes) { //GameObject.Find("HIDER").transform.Find("LoadingCircle").gameObject.SetActive(true); //yield return new WaitForSeconds(1); CutHolesinMesh.RedoMesh(Wall, OuterPolygon, Holes); yield return new WaitForEndOfFrame(); } public static bool CheckifAllPointsIsInWall(GameObject Open,string nW){ List OpenPoints = GetOpenPoints(Open); int IndexOfWll=int.Parse(nW[1..])-1; Vector2 CenterWallPoint=GetCenterPointXZ(_G.ExteriorWallPoints[IndexOfWll]); float WallWide=GetMaxXZDistance(_G.ExteriorWallPoints[IndexOfWll]); Vector2 OpenCenter=GetCenterPointXZ(OpenPoints); float OpenWide=GetMaxXZDistance(OpenPoints); float CenterDelta=Vector2.Distance(CenterWallPoint,OpenCenter); if(CenterDelta+OpenWide*0.5f>WallWide*0.5f-1){print("Is wall ====false");return false;} //print("Is wall ====true"); return true; } public static Vector2 GetCenterPointXZ(List points) { if (points == null || points.Count == 0) return Vector2.zero; Vector2 sum = Vector2.zero; foreach (var point in points) { sum += new Vector2(point.x, point.z); } return sum / points.Count; } public static float GetMaxXZDistance(List points) { if (points == null || points.Count < 2) return 0f; float maxDistance = 0f; for (int i = 0; i < points.Count; i++) { for (int j = i + 1; j < points.Count; j++) { Vector2 a = new Vector2(points[i].x, points[i].z); Vector2 b = new Vector2(points[j].x, points[j].z); float distance = Vector2.Distance(a, b); if (distance > maxDistance) maxDistance = distance; } } return maxDistance; } static public bool IsHoleObject(string objectName) { string objectType = objectName[..4]; return objectType switch { "open" or "door" or "pati" or "wind" => true, _ => false, }; } ///---------------GET----------------------------------- static List GetAllOpenInWall(string nW){ List list = new (); for (int i = 0; i < _G.OBJnum; i++) { //&& !_G.WALLS_HIDDEN_LIST.Contains(_G.OBJs[i][22][1..]) if (DOIT.exist(i) ) { if (_G.OBJs[i][22] [1..]== nW) { //print("i from hole==="+i); if (IsHoleObject(_G.OBJs[i][0]) && !_G.HIDELIST.Contains(_G.OBJs[i][0])) { GameObject Open = Get.o2("SCENE", _G.OBJs[i][0]); bool isInsideBond = CheckifAllPointsIsInWall(Open, _G.OBJs[i][22]); //print("isInsideBon====" + isInsideBond); if (isInsideBond) { list.Add(Get.o2("SCENE", _G.OBJs[i][0])); } } } } } return list; } static List GetOpenPoints(GameObject Open){ List List= new() { Open.transform.Find("P1").transform.position, Open.transform.Find("P2").transform.position, Open.transform.Find("P3").transform.position, }; for(int i=4; i<24; i++){ if(Open.transform.Find("P"+i.ToString())){List.Add(Open.transform.Find("P"+i.ToString()).transform.position);} } return List; } }