using System; using System.Collections.Generic; using UnityEngine; public class AiGet : MonoBehaviour { public static float Gap(string ObjectName) { float Gap = 0; int ADN = Get.GetObjectIndex(ObjectName); string Category = _G.OBJs[ADN][2]; switch (Category) { case "Patio": Gap = 2; break; case "Door": Gap = 2; break; case "Opening": Gap = 2; break; case "Window": Gap = 3; break; case "Appliance": Gap = 1; break; } if (ObjectName.Contains("frid")) {Gap = _AI.FridgeGab;} //print("ObjectName===" + ObjectName + " Gap" + Gap); return Gap; } public static Vector3 WallStartPoint(string Wallstring) { Wallstring = Wallstring.Replace("m", "w"); int IndexWall = int.Parse(Wallstring[1..]) - 1; return _G.ExteriorWallPoints[IndexWall][0]; } public static Vector3 WallEndPoint(string Wallstring) { Wallstring = Wallstring.Replace("m", "w"); int IndexWall = int.Parse(Wallstring[1..]) - 1; return _G.ExteriorWallPoints[IndexWall][1]; } public static float ObjectAngle(GameObject Obstacle) { int ADN = Get.GetObjectIndex(Obstacle.name); return DOIT.ConvertStringToNumber(DOIT.CSs(_G.OBJs[ADN][19])); } public static float ObjectWide(GameObject Obstacle) { int ADN = Get.GetObjectIndex(Obstacle.name); return DOIT.ConvertStringToNumber(DOIT.CSs(_G.OBJs[ADN][6])); } public static float ObjectHeight(GameObject Object) { int ADN = Get.GetObjectIndex(Object.name); return DOIT.ConvertStringToNumber(DOIT.CSs(_G.OBJs[ADN][7])); } public static float ObjectDepth(GameObject Object) { int ADN = Get.GetObjectIndex(Object.name); return DOIT.ConvertStringToNumber(DOIT.CSs(_G.OBJs[ADN][8])); } public static Vector3 ObstacleStartPoint(GameObject Obstacle) { return Obstacle.transform.Find("PBLB").position; } public static Vector3 ObstacleEndPoint(GameObject Obstacle) { return Obstacle.transform.Find("PBRB").position; } public static float AngleBetweenWallAndPrevious(string Wall, string Previous) { Vector3 Previous_start = WallStartPoint(Previous); Vector3 Previous_End = WallEndPoint(Previous); Vector3 Wall_End = WallEndPoint(Wall); return AngleOnXZ(Previous_start, Previous_End, Wall_End); } public static float AngleBetweenWallAndNext(string Wall, string Next) { Vector3 Wall_start = WallStartPoint(Wall); Vector3 Wall_End = WallEndPoint(Wall); Vector3 Next_End = WallEndPoint(Next); return AngleOnXZ(Wall_start, Wall_End, Next_End); } public static float AngleOnXZ(Vector3 A, Vector3 B, Vector3 C) { Vector2 dir1 = new Vector2(A.x - B.x, A.z - B.z).normalized; Vector2 dir2 = new Vector2(C.x - B.x, C.z - B.z).normalized; float angle = Vector2.SignedAngle(dir1, dir2); // can be negative return angle; // in degrees } public static float WallSpaceDeltaOnWallFrom(string Wallstring, List WallObstacles, string From) { // List WallObstacles = AllObjectsOnWall(Wallstring, "All", "All", _AI.FloorLine + _AI.CabinetHeight, _AI.FloorLine, From); Wallstring = Wallstring.Replace("m", "w"); int WallDeltaQty = WallObstacles.Count + 1; Vector3 StartPoint = WallStartPoint(Wallstring); Vector3 EndPoint = WallEndPoint(Wallstring); print("WallDeltaQty====="+WallDeltaQty); string side = "PBLB"; if (From == "From End") { side = "PBRB"; (StartPoint, EndPoint) = (EndPoint, StartPoint); } if (WallDeltaQty == 1) { print("StartPoint======" + StartPoint + " EndPoint=====" + EndPoint); return Vector3.Distance(StartPoint, EndPoint); } if (WallDeltaQty > 1) { EndPoint = WallObstacles[0].transform.Find(side).transform.position; return Vector3.Distance(StartPoint, EndPoint); } return 0; } public static Vector3 DirectionbyWall(string WallNumber) { return Get.o2("ROOM", WallNumber.Replace("m", "w")).transform.right.normalized; } public static Vector3 FowardbyObject(GameObject Target) { return Target.transform.forward.normalized; } public static Vector3 FowardbyWall(string Wallnumber) { Wallnumber = Wallnumber.Replace("m", "w"); return -Get.o2("ROOM", Wallnumber).transform.forward.normalized; } // public static Vector3 StartPointMiniousPrevious(string WallNumber) // { // Vector3 StartPoint = AiGet.WallStartPoint(WallNumber); // //GameObject OnPreviuos = CheckPreviousWall(string WallNumber, float Upline, float downline); // //AI.SetDeltaPoint(WallNumber, StartPoint, Vector3 EndPoint, true, Vector3 Direction, string Category); // } public static List AllObjectsOnWall(string Wallnunber, string Category, string Model, float UpLine, float downLine) { //Wallstring, "All", "All", _AI.CeilingLine, _AI.FloorLine + 64); List Obsatcles = new(); Wallnunber = Wallnunber.Replace("m", "w"); bool isUnderline = false;//36 int IndexWall = int.Parse(Wallnunber[1..]) - 1; Vector3 StartPoint = _G.ExteriorWallPoints[IndexWall][0]; //print("UpLine=====" + UpLine + " downLine=====" + downLine); List Modellist = new(); if (Model == "CornerBASE") { Model = "B2"; Modellist = new() { "B1","B2", "B3", "B4", "B5", "B9", "B10","T1" }; } if (Model == "CornerWall") { Model = "W2"; Modellist = new() { "W1","W2", "W3", "W4", "W5", "W9", "W10" ,"T1" }; } for (int i = 0; i < _G.OBJnum; i++) { if (DOIT.exist(i) && _G.OBJs[i][22] == Wallnunber) { if (_G.OBJs[i][2] == Category || Category == "All") { GameObject Target = Get.o2("SCENE", _G.OBJs[i][0]); float LineBASE = Target.transform.Find("PBLB").transform.position.y; float LineTop = Target.transform.Find("PBLU").transform.position.y; if (LineBASE <= UpLine && LineBASE >= downLine || LineTop <= UpLine && LineTop >= downLine) { isUnderline = true; } if (_G.OBJs[i][4] == Model || Model == "All" || Modellist.Contains(_G.OBJs[i][4])) { if (isUnderline) { Obsatcles.Add(Get.o2("SCENE", _G.OBJs[i][0])); print("Obstacle name===" + _G.OBJs[i][0] + " unique name====" + _G.OBJs[i][1]); isUnderline = false; } } } } } Obsatcles.Sort((obj1, obj2) => { float sqrDist1 = (obj1.transform.position - StartPoint).sqrMagnitude; float sqrDist2 = (obj2.transform.position - StartPoint).sqrMagnitude; return sqrDist1.CompareTo(sqrDist2); }); //if (Sorting == "From End"){Obsatcles.Reverse();} return Obsatcles; } public static GameObject SinkOnWall(List WallSelected) { for (int i = 0; i < _G.OBJnum; i++) { if (DOIT.exist(i) && _G.OBJs[i][1] == _AI.BASESINK && WallSelected.Contains( _G.OBJs[i][22].Replace("w","m") )) { return Get.o2("SCENE", _G.OBJs[i][0]); } } return null; } public static GameObject NextWall(GameObject Wall) { int IntNextWall = int.Parse(Wall.name[1..]) + 1; if (IntNextWall > _G.NWExterior) { IntNextWall = 1; } string NextWallName = "w" + IntNextWall.ToString(); return Get.o2("ROOM", NextWallName); } public static GameObject PreviousWall(GameObject Wall) { int IntPreviousWall = int.Parse(Wall.name[1..]) - 1; if (IntPreviousWall == 0) { IntPreviousWall = _G.NWExterior; } string PreviousWallName = "w" + IntPreviousWall.ToString(); return Get.o2("ROOM", PreviousWallName); } public static string PreviousWallName(string Wallstring) { GameObject Wall = Get.o2("ROOM", Wallstring.Replace("m", "w")); return PreviousWall(Wall).name; } public static string NextWallName(string Wallstring) { GameObject Wall = Get.o2("ROOM", Wallstring.Replace("m", "w")); return NextWall(Wall).name; } public static GameObject CheckPreviousWall(string WallNumber, float Upline, float downline) { //print("Pass SetDeltaPoint and CheckPreviousWal for wall " + WallNumber); int IndexWall = int.Parse(WallNumber[1..]); int IndexWallprevious = IndexWall - 1; if (IndexWallprevious == 0) { IndexWallprevious = _G.NWExterior; } string WallPrevious = "w" + IndexWallprevious.ToString(); //Vector3 StartPoint = _G.ExteriorWallPoints[IndexWall][0]; Vector3 EndPoint = _G.ExteriorWallPoints[IndexWall - 1][0]; for (int i = 0; i < _G.OBJnum; i++) { if (!DOIT.exist(i)) continue; if (_G.OBJs[i][22] == WallPrevious) { GameObject Target = Get.o2("SCENE", _G.OBJs[i][0]); Vector3 ObjPositionUnder = Target.transform.Find("PBRB").transform.position; float Distance = Vector3.Distance(PointAlign(ObjPositionUnder, -_G.HEIGHT * 0.5f), PointAlign(EndPoint, -_G.HEIGHT * 0.5f)); //print("PreviousObject=====" + _G.OBJs[i][0] + " Distance===" + Distance); if (Distance <= 38 && ObjPositionUnder.y <= Upline && ObjPositionUnder.y >= downline) { return Target; } } } return null; } public static GameObject CheckNextWall(string WallNumber, float Upline, float downline) { int IndexWall = int.Parse(WallNumber[1..]); int IndexWallnext = IndexWall + 1; if (IndexWallnext > _G.NWExterior) { IndexWallnext = 1; } string WallNext = "w" + IndexWallnext.ToString(); Vector3 StartPoint = _G.ExteriorWallPoints[IndexWall - 1][1]; for (int i = 0; i < _G.OBJnum; i++) { if (!DOIT.exist(i)) continue; if (_G.OBJs[i][22] == WallNext) { GameObject Target = Get.o2("SCENE", _G.OBJs[i][0]); Vector3 ObjPositionUnder = Target.transform.Find("PBLB").transform.position; float Distance = Vector3.Distance(PointAlign(ObjPositionUnder, _AI.FloorLine), PointAlign(StartPoint, _AI.FloorLine)); if (Distance <= 24 && ObjPositionUnder.y <= Upline && ObjPositionUnder.y >= downline) { //print("Target.name=========" + Target.name); return Target; } } } return null; } public static Vector3 PointAlign(Vector3 Point, float Hight) { Vector3 NewPoint = new(Point.x, Hight, Point.z); return NewPoint; } public static float GetSpaceSide(string[] ADN, string sens) { SceneModeManager.Instance.SetSceneMode(SceneModes.Calcule); CameraAround.Show(); GameObject Cabinet = Get.o2("SCENE", ADN[0]); Vector3 origin = Cabinet.transform.position; Vector3 Direction = -Cabinet.transform.right; Vector3 DirectionOrigin = -Cabinet.transform.right; if (sens == "Right") {Direction = Cabinet.transform.right; } float Delta = ObjectWide(Cabinet)* 0.5f; float DeltaDepth = 0; if (!new List { "B1", "W1", "T1", "panel", "frid" }.Contains(ADN[4]))//Windows ,Hood, stove { DirectionOrigin = -Cabinet.transform.forward; DeltaDepth = ObjectDepth(Cabinet) * 0.5f; } if (ADN[4]=="frid") { print("ADN[4]====" + ADN[4]); DirectionOrigin = Cabinet.transform.forward; DeltaDepth = ObjectDepth(Cabinet)* 0.5f+1; } origin += (Delta - 1) * Direction+DeltaDepth*DirectionOrigin; print("origin====" + origin); CameraAround.Show(); if (Physics.Raycast(origin, Direction, out RaycastHit hit, 36)) { string HiteName = hit.transform.gameObject.name; print("HiteName from "+ADN[0]+" ====" + HiteName); if (hit.distance <= 6) { if (HiteName.Contains("cabi")) { return hit.distance - 0.75f; } if (HiteName.Contains("m") && HiteName.Length < 4) { return hit.distance - 0.75f; } if (HiteName.Contains("stov")) { return hit.distance - 1.75f; } if (HiteName.Contains("hood")) { return 1000; } if (HiteName.Contains("open")) { return 1000; } if (HiteName.Contains("pati")) { return 1000; } } if (hit.distance > 6) { if (HiteName.Contains("pati")) { return hit.distance - 2f; } if (HiteName.Contains("open")) { return hit.distance - 2f; } if (HiteName.Contains("door")) { return hit.distance - 2f; } if (HiteName.Contains("wind")) { return hit.distance - 2f; } } //return hit.distance - 0.75f; //return 0; } return 1000; } }