using UnityEngine; using System.Linq; using TMPro; using System.Collections.Generic; public class Recover : MonoBehaviour { static string ColorID; public static void AddtoCabinetFromEditPNL(string GlobalNumberSelectedColor,string SideON) { bool isOnCover =true; //print("GlobalNumberSelectedColor==="+GlobalNumberSelectedColor); if (GlobalNumberSelectedColor=="NONE")isOnCover =false; ColorID=UIT.Global(Header.Ext,int.Parse(GlobalNumberSelectedColor[1..])).Split("?")[0]; string Coverfit=Get.o2("Panel_SCENE/PNL/EDITCABpnl/EDITOR/DropdownList","DropSelection1").GetComponent().options[0].text; if(Coverfit!="No Match"){ SetParameters(Coverfit,SideON,isOnCover ); AddToCabinet(); } else{ _M.PH(30,0,"ffffff",1,1); } } public static void AddCoverFromRightClick(string SideON,bool isOnCover){ ColorID=GetColorID(); if(SideON!="NONE"){ //print("ColorID====="+ColorID); string Coverfit=GetCoverfit(SideON); if(Coverfit!="No Match"){ SetParameters(Coverfit,SideON,isOnCover ); AddToCabinet(); } else{ _M.PH(30,0,"ffffff",1,1); } } else { string[] ADN = GetADN(); ADN[81]="0_0_0_0_0_0_0"; SetCounterProjection("LEFT","0"); SetCounterProjection("RIGHT","0"); AddToCabinet(); } } public static void SetParameters(string Coverfit,string SideON,bool isOnCover ){ string CoverID=GetCoverIDFromUniqueName(Coverfit); //print("CoverID======"+CoverID); string Thickness=UIT.Value(Library.Panel,CoverID,Header.Thick); if(Thickness.Split("_").Length==3)Thickness=Thickness.Split("_")[1]; int IndexRecover=GetIndexOfRecover(); if(SideON=="LEFT"){IndexRecover=0;} string PanelCode=CoverID+"?"+ColorID+"?"+Thickness; if(isOnCover){ SetNewValueOnCoverRecipe(IndexRecover, PanelCode); SetCounterProjection(SideON,"1"); } else { PanelCode="0"; SetNewValueOnCoverRecipe(0, PanelCode); SetNewValueOnCoverRecipe(IndexRecover, PanelCode); SetCounterProjection("NONE","0"); } } public static void AddRecoverOnCab(GameObject Base,string[] C,float leftbox,float backbox,float rightbox) { string[] Recipe=C[81].Split("_"); print("AddRecoverOnCab==="+C[81]);//AddRecoverOnCab===0_0_P_01?14?0_0_0_0_0 for(int i=0; i<7; i++) { if(Recipe[i]!="0") { ConstructPanel(Base,C,i,Recipe[i],leftbox,backbox,rightbox); } } } public static void AddRecoverOnCornerCab(GameObject Base,string[] C,float leftbox,float backbox,float rightbox) { string[] Recipe=C[81].Split("_"); //print("AddRecoverOnCab==="+C[81]); for(int i=0; i<7; i++) { if(Recipe[i]!="0") { ConstructPanel(Base,C,i,Recipe[i],leftbox,backbox,rightbox); } } } public static void ConstructPanel(GameObject BASE, string[] ADN, int Side, string PanelColor, float leftbox, float backbox, float rightbox) { print("PanelColor====" + PanelColor);//0_0_2?1?0_0_0_0_0 string PanelID = PanelColor.Split('?')[0]; ColorID = PanelColor.Split('?')[1]; float w = DOIT.ConvertStringToNumber(UIT.Value(Library.Panel, PanelID, Header.Wide)); float h = DOIT.ConvertStringToNumber(UIT.Value(Library.Panel, PanelID, Header.Height)); float d = DOIT.ConvertStringToNumber(UIT.Value(Library.Panel, PanelID, Header.Thick)); if (_P.ListSwitch["ALLOW_RECOVER_RESIZE"]) { w = DOIT.ConvertStringToNumber(ADN[8]); h = DOIT.ConvertStringToNumber(ADN[7]) - DOIT.ConvertStringToNumber(ADN[10]); if (_P.ListSwitch["RECOVER_UP_TO_FLOOR"]) { h = DOIT.ConvertStringToNumber(ADN[7]); if (ADN[4] == "T1" && h < 72) h += 36; } } if (new List { "B2", "B4", "B9", "W2", "W4", "W9", "B3", "B4", "B10", "W3", "W5", "W10" }.Contains(ADN[4])) { if (Side == 0) { w = DOIT.ConvertStringToNumber(ADN[28]); } if (Side == 3) { w = DOIT.ConvertStringToNumber(ADN[29]); } } Material Mat = UIT_MATERIAL.GetMaterial(ColorID); float ct = DOIT.ConvertStringToNumber(UIT.Value(Library.Panel, PanelID, Header.Cthick)); float eh = DOIT.ConvertStringToNumber(UIT.Value(Library.Panel, PanelID, Header.E_H)); float ev = DOIT.ConvertStringToNumber(UIT.Value(Library.Panel, PanelID, Header.E_V)); float sw = DOIT.ConvertStringToNumber(UIT.Value(Library.Panel, PanelID, Header.Slat)); string Model = UIT.Value(Library.Panel, PanelID, Header.Model); switch (Model) { case "P_01": PanelShow.Model_P_01(w, h, d, Mat); break; case "P_02": PanelShow.Model_P_02(w, h, d, Mat); break; case "P_03": PanelShow.Model_P_03(w, h, d, ct, eh, ev, Mat); break; case "P_04": PanelShow.Model_P_04(w, h, d, ct, eh, ev, Mat); break; case "P_05": PanelShow.Model_P_05(w, h, d, ct, eh, ev, Mat); break; case "P_06": PanelShow.Model_P_06(w, h, d, ct, eh, ev, Mat); break; case "P_07": PanelShow.Model_P_07(w, h, d, sw, Mat); break; case "P_08": PanelShow.Model_P_08(w, h, d, sw, Mat); break; case "P_09": PanelShow.Model_P_09(w, h, d, ct, sw, eh, ev, Mat); break; case "P_10": PanelShow.Model_P_10(w, h, d, ct, sw, eh, ev, Mat); break; case "P_11": PanelShow.Model_P_11(w, h, d, ct, sw, eh, ev, Mat); break; case "P_12": PanelShow.Model_P_12(w, h, d, ct, sw, eh, ev, Mat); break; case "P_13": PanelShow.Model_P_13(w, h, d, ct, eh, ev, Mat); break; case "P_14": PanelShow.Model_P_14(w, h, d, ct, eh, ev, Mat); break; case "P_15": PanelShow.Model_P_15(w, h, d, ct, eh, ev, Mat); break; case "P_16": PanelShow.Model_P_16(w, h, d, ct, eh, ev, Mat); break; } GameObject Panel = Get.o1("3D Object Show").transform.GetChild(0).gameObject; Panel.name = "RECOVER PANEL" + Model; Panel.transform.position = new(0, 0, 0); Panel.layer = 0; foreach (Transform go in Panel.transform) { go.gameObject.layer = 0; } string[] C42 = ADN[42].Split('_'); float Counterheight = DOIT.ConvertStringToNumber(C42[0]); float PositioY = DOIT.ConvertStringToNumber(ADN[7]) * 0.5f - Counterheight * 0.5f - h * 0.5f; float sideleft = DOIT.ConvertStringToNumber(ADN[28]); float sideRight = DOIT.ConvertStringToNumber(ADN[29]); if (new List { "B1", "W1", "T1" }.Contains(ADN[4])) { if (Side == 0) { Panel.transform.eulerAngles = new(0, 90, 0); Panel.transform.position = new(leftbox - d * 0.5f, PositioY, 0); } if (Side == 1) { Panel.transform.eulerAngles = new(0, 180, 0); Panel.transform.position = new(backbox - d * 0.5f, PositioY, 0); } if (Side == 2) { Panel.transform.eulerAngles = new(0, -90, 0); Panel.transform.position = new(rightbox + d * 0.5f, PositioY, 0); } } if (new List { "B2", "B4", "B9", "W2", "W4", "W9" }.Contains(ADN[4])) { if (Side == 0) { Panel.transform.eulerAngles = new(0, 0, 0); Panel.transform.position = new(leftbox + sideleft * 0.5f, PositioY, -backbox); } if (Side == 3) { Panel.transform.eulerAngles = new(0, -90, 0); Panel.transform.position = new(rightbox + d * 0.5f, PositioY, backbox - sideRight * 0.5f); } } if (new List { "B3", "B5", "B10", "W3", "W5", "W10" }.Contains(ADN[4])) { if (Side == 0) { Panel.transform.eulerAngles = new(0, -90, 0); Panel.transform.position = new(leftbox, PositioY, backbox - sideleft * 0.5f); } if (Side == 3) { Panel.transform.eulerAngles = new(0, 0, 0); Panel.transform.position = new(rightbox - sideRight * 0.5f, PositioY, -backbox); } } Panel.transform.SetParent(BASE.transform); //Panel.GetComponent().probeAnchor = GameObject.Find("Reflection Probe").transform; } public static void AddToCabinet(){ //print("------------------Add to cabinet-------------"); //print("------------------Add to cabinet--_G.OBJs[_G.nO][81]======"+_G.OBJs[_G.nO][81]); 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(); float Wide=DOIT.ConvertStringToNumber(wide); float WideOnNow; if (SideON=="LEFT"){ WideOnNow = DOIT.ConvertStringToNumber(CTpr[1]); if(CTpr[1]=="0" || Wide < WideOnNow) CTpr[1]=wide; } if (SideON=="RIGHT"){ WideOnNow = DOIT.ConvertStringToNumber(CTpr[index]); 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{"B1","W1","T1"}.Contains(ADN[4])){ Wide= DOIT.ConvertStringToNumber(ADN[6]); Height= DOIT.ConvertStringToNumber(ADN[7]); Depth= DOIT.ConvertStringToNumber(ADN[8]); } if(new List{"B2","B3","B4","B5","B9","B10","W2","W3","W4","W5","W9","W10"}.Contains(ADN[4])){ Wide= DOIT.ConvertStringToNumber(ADN[28]); Height= DOIT.ConvertStringToNumber(ADN[7]); Depth= DOIT.ConvertStringToNumber(ADN[29]); } return new(Wide,Height,Depth); } public static string GetCoverfit(string SideON) { string[] ADN = GetADN(); //print("ColorID======="+ColorID); float HeightToVerify=GetCabinetSize().y-1; float WideToVerify=0; if(new List{"B1","W1","T1"}.Contains(ADN[4])){ WideToVerify=GetCabinetSize().z; } else if(new List{"B2","B3","B4","B5","B9","B10","W2","W3","W4","W5","W9","W10"}.Contains(ADN[4])){ if(SideON=="LEFT")WideToVerify=GetCabinetSize().x; if(SideON=="RIGHT")WideToVerify=GetCabinetSize().z; } int IndHeight=UIT.Ind(Library.Panel,Header.Height); int IndWide=UIT.Ind(Library.Panel,Header.Wide); int IndUniqueName=UIT.Ind(Library.Panel,Header.Unique_Name); int IndModel=UIT.Ind(Library.Panel,Header.Model); float HeightCSV; float WideCSV; //int PanelID; int IndColorID=UIT.Ind(Library.Panel,Header.ColorID); string CoverFit="No Match"; string SmallestCoverFit="No Match"; float Offset=6; float SmallessOffset=100; foreach(string line in _G.UIT_LibraryPanels) { string[] L=line.Split(','); if (!string.IsNullOrEmpty(L[0]) && Set.Chars(L[0]) != "ID" && L[IndModel][..2] == "P_")//L[0]======ID { string Wide = L[IndWide]; if (Wide.Contains("_")) Wide = Wide.Split("_")[2]; WideCSV = DOIT.ConvertStringToNumber(Set.Chars(Wide)); string Height = L[IndHeight]; if (Height.Contains("_")) Height = Height.Split("_")[2]; HeightCSV = DOIT.ConvertStringToNumber(Set.Chars(Height)); print(WideCSV + " vs " + WideToVerify + " " + HeightCSV + " vs " + HeightToVerify + " Color===" + ColorID + " vs " + L[IndColorID]); //1 vs 23.625 72 vs 34.5 Color===1 vs All if (L[IndColorID] == "All") { L[IndColorID] = ColorID; } bool isColorOnList = L[IndColorID].Split("_").Contains(ColorID); string Substitute = UIT.Value(Library.CabTexture, ColorID, Header.Substitute); if (!isColorOnList && Substitute != "0" && Substitute != ColorID) { ColorID = Substitute; isColorOnList = true; } float HeightOffset = HeightCSV - HeightToVerify; float WideOffset = WideCSV - WideToVerify; if (HeightOffset < 2 && WideOffset < 2 && isColorOnList && HeightOffset > 0 && WideOffset > 0) { float NewOffset = HeightOffset + WideOffset; print("Model===="+L[IndUniqueName]+" Offset==="+NewOffset+" WideCSV===="+WideCSV+" WideToVerify===="+WideToVerify); if (NewOffset <= Offset) { CoverFit = L[IndUniqueName]; Offset = NewOffset; } } print("HeightOffset====" + HeightOffset + " WideOffset====" + WideOffset); if (HeightOffset >= 0 && WideOffset >= 0 && isColorOnList && _P.ListSwitch["ALLOW_RECOVER_RESIZE"]) { float SmallestNewOffset = HeightOffset + WideOffset; //print("Model===="+L[IndUniqueName]+" Offset==="+NewOffset); if (SmallestNewOffset <= SmallessOffset) { SmallestCoverFit = L[IndUniqueName]; SmallessOffset = SmallestNewOffset; } } } } if(_P.ListSwitch["ALLOW_RECOVER_RESIZE"]){ return SmallestCoverFit; } return CoverFit; } public static string GetColorID(){ int ObjectNumber=Get.GetObjectIndex(SceneModeManager.SelectedName); return _G.OBJs[ObjectNumber][61].Split("?")[1]; } public static string GetCoverIDFromUniqueName(string UniqueName){ string ID =""; int indexOfUnique_Name=UIT.Ind(Library.Panel,Header.Unique_Name); foreach(string sel in _G.UIT_LibraryPanels){ string ID_Panel=sel.Split(',')[0]; if(ID_Panel.IndexOf("ID")==-1 && !string.IsNullOrEmpty(ID_Panel)){ string Unique_Name=sel.Split(',')[indexOfUnique_Name]; if(Unique_Name==UniqueName){ ID=ID_Panel;} } } return ID; } public static int GetIndexOfRecover(){ string[] ADN=GetADN(); switch (ADN[4]){ case "B1":case "W1":case "T1":return 2; case "B9":case "W9":case "B10":case "W10":case "B2":case "B3":case "W2":case "W3":return 3; case "B6":case "W26":case "B7":case "W27":case "B11":case "B12":return 4; default: break; } return 0; } }