using System.Linq; using UnityEngine; using TMPro; using System.Collections.Generic; public class Filler : MonoBehaviour { public static void AddtoCabinet(string UniqueName, string GlobalNumberSelectedColor, string SideON, bool isGhost, string ColorID) { if (isGhost) { _G.OBJs[_G.nO][49] = "GHOST"; } else { _G.OBJs[_G.nO][49] = "COLLISION"; } //string[] ADN = GetADN(); string FillerID = GetFillerIDFromUniqueName(UniqueName); bool isOnFiller = true; if (GlobalNumberSelectedColor == "NONE") { isOnFiller = false; SideON = "NONE"; } string wide = GetFillerWide(FillerID); GameObject InputField = Get.o2("EDITCABpnl/EDITOR", "InputField"); if (InputField.activeInHierarchy) { //print("----FILLER----==="+InputField.GetComponent().text); wide = InputField.GetComponent().text; } SetCounterProjection(SideON, wide); SetFillerOn(SideON, isOnFiller, FillerID, ColorID, wide);//string SideON,bool isON,string FillerID,string ColorID,string wide AddToCabinet(); } public static void AddFillerFromRightClick(string SideON, bool isOnFiller) { string Fillerfit = GetFillerfit(); print("Fillerfit==="+Fillerfit); if (Fillerfit != "No Match") { string ColorID = GetColorID(); string FillerID = GetFillerIDFromUniqueName(Fillerfit); string wide = GetFillerWide(FillerID);//FA_1 SetFillerOn(SideON, isOnFiller, FillerID, ColorID, wide); SetCounterProjection(SideON, wide); AddToCabinet(); } else { _M.PH(30, 0, "ffffff", 1, 1); } } public static void AddFillerFromAI(GameObject Cabinet, string SideON, bool isOnFiller) { //_G.nO = Get.GetObjectIndex(Cabinet.name); //SceneModeManager.Selected = Get.o1(Cabinet.name).transform; SceneModeManager.SelectedName = Cabinet.name; string Fillerfit = GetFillerfit(); //print("Fillerfit==="+Fillerfit); if (Fillerfit != "No Match") { string ColorID = GetColorID(); string FillerID = GetFillerIDFromUniqueName(Fillerfit); string wide = GetFillerWide(FillerID);//FA_1 SetFillerOn(SideON, isOnFiller, FillerID, ColorID, wide); SetCounterProjection(SideON, wide); DOIT.REDOCAB(_G.nO); //DOIT.CloseALLPNL(); if (_G.OBJs[_G.nO][4].IndexOf("W") != -1) _MOL.SetMolding(); else PRICE.Calprice(); } else { _M.PH(30, 0, "ffffff", 1, 1); } } public static void AddToCabinet() { DOIT.REDOCAB(_G.nO); DOIT.CloseALLPNL(); if (_G.OBJs[_G.nO][4].IndexOf("W") != -1) _MOL.SetMolding(); else PRICE.Calprice(); } ///---------------------------SETTING----------------------------------- public static void SetCounterProjection(string SideON, string wide) { string[] ADN = GetADN(); string[] CTpr = ADN[42].Split("_"[0]); int index = GetCounterIndex(); //print("wide==================================="+wide); //print("index===="+index); float Wide = DOIT.ConvertStringToNumber(wide); float WideOnNow; float MaxWide = 2.5f; if (SideON == "LEFT") { WideOnNow = DOIT.ConvertStringToNumber(CTpr[1]); if (WideOnNow <= MaxWide) { WideOnNow = MaxWide; } if (CTpr[1] == "0" || Wide <= WideOnNow) CTpr[1] = wide; } if (SideON == "RIGHT") { WideOnNow = DOIT.ConvertStringToNumber(CTpr[index]); if (WideOnNow <= MaxWide) { WideOnNow = MaxWide; } if (CTpr[index] == "0" || Wide <= WideOnNow) CTpr[index] = wide; } if (SideON == "NONE") { CTpr[1] = "0"; CTpr[index] = "0"; } ADN[42] = ""; for (int i = 0; i < CTpr.Length; i++) { ADN[42] += CTpr[i]; if (i < CTpr.Length - 1) ADN[42] += "_"; } } public static void SetFillerOn(string SideON, bool isOnFiller, string FillerID, string ColorID, string wide) { string[] ADN = GetADN(); string Sens = "90"; int IndexSide = 50; int IndexWide = 37; if (SideON == "RIGHT") { IndexSide = 51; IndexWide = 38; } ADN[IndexSide] = FillerID + "?" + ColorID + "?" + Sens + '?' + wide; ADN[IndexWide] = wide; if (!isOnFiller) { ADN[50] = "NONE"; ADN[37] = "0"; ADN[51] = "NONE"; ADN[38] = "0"; } //print("ADN[IndexSide]===="+ADN[IndexSide]); } ///---------------------------GET--------------------------------------- public static string GetFillerIDFromUniqueName(string UniqueName) { string ID = ""; foreach (string sel in _G.UIT_LibraryMoldings) { string[] Line = sel.Split(','); int IndCaegory = UIT.Ind(Library.Molding, Header.Category); if (Line[0].IndexOf("ID") == -1 && !string.IsNullOrEmpty(Line[0]) && Line[IndCaegory] == "Filler") { string Unique_Name = UIT.Value(Library.Molding, Line[0], Header.Unique_Name); if (Unique_Name == UniqueName) { ID = Line[0]; } } } return ID; } public static Vector3 GetCabinetSize() { string[] ADN = GetADN(); float Wide = DOIT.ConvertStringToNumber(ADN[6]); float Height = DOIT.ConvertStringToNumber(ADN[7]); float Depth = DOIT.ConvertStringToNumber(ADN[8]); return new(Wide, Height, Depth); } public static string[] GetADN() { _G.nO = Get.GetObjectIndex(SceneModeManager.SelectedName); return _G.OBJs[_G.nO]; } public static string GetFillerWide(string FillerID) { //print("FillerID==="+FillerID); string[] FillerWide = UIT.Value(Library.Molding, FillerID, Header.Wide).Split("_"); if (FillerWide.Length > 1) { return FillerWide[1]; } return FillerWide[0]; } public static int GetCounterIndex() { string[] ADN = GetADN(); switch (ADN[4]) { case "B1": case "W1": case "T1": return 3; case "B9": case "W9": case "B10": case "W10": case "B2": case "B3": case "W2": case "W3": return 4; case "B6": case "W26": case "B7": case "W27": case "B11": case "B12": return 5; default: break; } return 1; } public static string GetFillerfit() { //int ObjectNumber=Get.GetObjectIndex(SceneModeManager.SelectedName); //string UniqueName=_G.OBJs[ObjectNumber][1]; //INDEX int IndHeight = UIT.Ind(Library.Molding, Header.Height); int IndCaegory = UIT.Ind(Library.Molding, Header.Category); int IndUnique_Name = UIT.Ind(Library.Molding, Header.Unique_Name); int IndColorID = UIT.Ind(Library.Molding, Header.Color_ID); //From Cabinet float HeihgtToVerify = GetCabinetSize().y; float HeightCSV; string ColorID = GetColorID(); List HeightInList = new(); foreach (string line in _G.UIT_LibraryMoldings) { string[] L = line.Split(','); if (!string.IsNullOrEmpty(L[0]) && line != _G.UIT_LibraryMoldings[0] && L[IndCaegory] == "Filler")//L[0]======ID { //print("L[IndCaegory]====1="+L[IndCaegory]); HeightCSV = DOIT.ConvertStringToNumber(Set.Chars(L[IndHeight])); if (!HeightInList.Contains(HeightCSV)) { print("HeightInList.Add======" + HeightCSV); HeightInList.Add(HeightCSV); } } } if (_P.ListSwitch["FILLER_BY_ITEMS"]) { //float lowest = 120; foreach (string line in _G.UIT_LibraryMoldings) { string[] L = line.Split(','); if (!string.IsNullOrEmpty(L[0]) && line != _G.UIT_LibraryMoldings[0] && L[IndCaegory] == "Filler")//L[0]======ID { HeightCSV = DOIT.ConvertStringToNumber(Set.Chars(L[IndHeight])); if (!HeightInList.Contains(HeihgtToVerify)) { foreach (float Hight in HeightInList) { if (Hight >= HeihgtToVerify ) { HeihgtToVerify = Hight; } } } //Colors string[] ColorIDlist = L[IndColorID].Split("_");//2_3_4_5_6_8_9_10_11_7_13 if (ColorIDlist[0] == "All") { ColorIDlist[0] = ColorID; } bool isColorOnList = ColorIDlist.Contains(ColorID); string Substitute = UIT.Value(Library.CabTexture, ColorID, Header.Substitute); if (!isColorOnList && Substitute != "0" && Substitute != ColorID) { ColorID = Substitute; isColorOnList = true; } // print("isColorOnList==================ColorID=="+ColorID); // print("isColorOnList==================L[IndColorID]=="+L[IndColorID]); // print("Condition Vs==================vs=="+HeightCSV+" vs "+HeihgtToVerify); // print("Condition isColorOnList==================vs=="+isColorOnList); // print("Condition L[IndCaegory]==================vs=="+L[IndCaegory]); //Conditions if (Mathf.Abs(HeightCSV - HeihgtToVerify) < 6 && isColorOnList && L[IndCaegory] == "Filler") { return L[IndUnique_Name]; } } } } else { foreach (string line in _G.UIT_LibraryMoldings) { string[] L = line.Split(','); if (!string.IsNullOrEmpty(L[0]) && line != _G.UIT_LibraryMoldings[0]) { string[] ColorIDlist = L[IndColorID].Split("_"); if (ColorIDlist[0] == "All") ColorIDlist[0] = ColorID; if (!string.IsNullOrEmpty(L[0]) && line != _G.UIT_LibraryMoldings[0] && L[IndCaegory] == "Filler" && ColorIDlist.Contains(ColorID))//L[0]======ID { //print("L[IndCaegory]====3="+L[IndCaegory]); return L[IndUnique_Name]; } } } } return "No Match"; } public static string GetColorID() { int ObjectNumber = Get.GetObjectIndex(SceneModeManager.SelectedName); string DoorCode = _G.OBJs[ObjectNumber][61]; if (!new List() { "nodoor", "none" }.Contains(DoorCode)) { print("_G.OBJs[ObjectNumber][61]=====" + _G.OBJs[ObjectNumber][61] + " object name ===" + _G.OBJs[ObjectNumber][0]); return _G.OBJs[ObjectNumber][61].Split("?")[1]; } return _G.OBJs[ObjectNumber][69].Split("?")[0]; } // public static string GetColorID(GameObject Selected){ // int ObjectNumber=Get.GetObjectIndex(Selected.name); // string DoorCode=_G.OBJs[ObjectNumber][61]; // if(!new List(){"nodoor","none"}.Contains(DoorCode) ){ // print("_G.OBJs[ObjectNumber][61]=====" + _G.OBJs[ObjectNumber][61]+" object name ==="+_G.OBJs[ObjectNumber][0]); // return _G.OBJs[ObjectNumber][61].Split("?")[1]; // } // return _G.OBJs[ObjectNumber][69].Split("?")[0]; // } }