using UnityEngine; using UnityEngine.UI.Extensions; using UnityEngine.UI; using System.Collections.Generic; using System.Collections; using System.Globalization; using System; public class PaternDraw : MonoBehaviour { public static void Paterns(GameObject Cab, string[] code25, string[] code26, string name) { DoPaterns(Cab,code25,name,1); if(!string.IsNullOrEmpty(code26[0]))DoPaterns(Cab,code26,name,-1); } public static void DoPaterns(GameObject Cab, string[] code, string name,int sens) { float move = 50; string model; if(UIT.TogOn("FILTERS")=="Ukitchenit"){model=UIT.Value("CabinetUkitchenit",name,"Model");} else {model=UIT.Value("Cabinet",name,"Model");} float w = DOIT.ConvertStringToNumber(code[0]); float h = DOIT.ConvertStringToNumber(code[1]); float scale = 90 / h; if (scale * w > 90) scale = 90 / w; float lt = 2f;//line tickness float Ps = scale; float pyc = 0; int nd = (code.Length - 2) / 4;//number of door float PW = DOIT.ConvertStringToNumber(code[0]) * Ps; float PH = DOIT.ConvertStringToNumber(code[1]) * Ps; float sx = DOIT.ConvertStringToNumber(code[3]) * Ps; float sy = DOIT.ConvertStringToNumber(code[4]) * Ps; float px = 0 - PW*0.5f + sx*0.5f; float py = pyc + PH*0.5f- sy*0.5f; float ofs = 0; if (model == "B2" || model == "W2") { ofs = sx*0.5f*sens; if (code.Length > 8) { ofs = sx*sens; } } if (model == "B3" || model == "W3") { ofs = -sx*0.5f*sens; if (code.Length > 8) { ofs = -sx*sens; } } Vector2 vp;//position patern center Vector2[] v2; for (int i = 0; i < nd ; i++){ int a = 2 + 4 * i; if (i>0 ){ px +=( DOIT.ConvertStringToNumber(code[a-3])*0.5f+DOIT.ConvertStringToNumber(code[a+1])*0.5f )* Ps; if (px >= PW*0.5f ) { px = - PW / 2f + DOIT.ConvertStringToNumber(code[a+1])*0.5f * Ps; py -= (DOIT.ConvertStringToNumber(code[a-2])*0.5f + DOIT.ConvertStringToNumber(code[a+2])*0.5f) * Ps; } sx = DOIT.ConvertStringToNumber(code[a+1]) * Ps; sy = DOIT.ConvertStringToNumber(code[a+2]) * Ps; } vp = new (px + ofs, py); v2 = new Vector2[] { new (-sx*0.5f + move, -sy*0.5f + move), new (-sx*0.5f + move, sy*0.5f + move), new (sx*0.5f + move, sy*0.5f + move), new (sx*0.5f+ move, -sy*0.5f + move) }; if (code[a] == "g") { DrawlineGlass(Cab, sx, sy, px, py, name, move, scale, 1); } if (code[a] == "c") { DrawlineCutout(Cab, sx, sy, px, py, name, move, scale, 1); } if (code[a] == "t") { DrawlineTambour(Cab, sx, sy, px, py, name, move, scale, 1); } if (code[a] == "o") { DrawlineOpen(Cab, sx, sy, px, py, name, move, scale); } if (code[a] == "w") { AddSprite(Cab, code[2], sx, sy, px, py, 0); } if (code[a] == "dd") { DrawlineCenter(Cab, vp, Color.white, v2, lt); if (code[a+3] != "0") { AddKnobs(Cab, sx, sy*0.5f, px + ofs, py+sy*0.25f, code[a+3], 0.75f, 0.75f,code[a]); AddKnobs(Cab, sx, sy*0.5f, px + ofs, py-sy*0.25f, code[a+3], 0.75f, 0.75f,code[a]); } } DrawlineRectangle(Cab, vp, Color.white, v2, lt); if (code[a+3] != "0" &&code[a] != "dd") AddKnobs(Cab, sx, sy, px + ofs, py, code[a+3], 0.75f, 0.75f,code[a]); } } public static void AddKnobs(GameObject O, float w, float h, float x, float y, string p, float SW, float SH,string cat) { Color Col = Color.white; if (O.name == "CASE IMAGE") { Col = Color.grey; } if (O.name == "T1") { } GameObject S = new("knob", typeof(RectTransform)); S.AddComponent(); S.GetComponent().sprite = _G.knoR; S.GetComponent().color = Col; S.transform.localScale = new Vector3(0.05f * SW, 0.05f * SH, 1); float os = 6; if (p == "1") { x += -w*0.5f + os; y += h*0.5f - os; } if (p == "2") { x += -0; y += h*0.5f - os; } if (p == "3") { x += w*0.5f - os; y += h*0.5f - os; } if (p == "4") { x += -w*0.5f + os; y += 0; } if (p == "5") { x += 0; y += 0; } if (p == "6") { x += w*0.5f - os; y += 0; } if (p == "7") { x += -w*0.5f + os; y += -h*0.5f + os; } if (p == "8") { x += 0; y += -h*0.5f + os; } if (p == "9") { x += w*0.5f - os; y += -h*0.5f + os; } S.layer = 5; S.transform.SetParent(O.transform); S.transform.localPosition = new Vector3(x, y, -1); } public static void AddSprite(GameObject O, string pat, float w, float h, float x, float y, float border) { Sprite image = _G.pat1; if (pat == "o") { image = _G.patO; } if (pat == "g") { image = _G.patG; } if (pat == "w") { image = _G.patW; } if (pat == "c") { image = _G.patC; } if (pat == "t") { image = _G.patT; } GameObject S = new("patern"); S.AddComponent(); S.GetComponent().sprite = image; S.GetComponent().color = Color.white; S.GetComponent().rectTransform.sizeDelta = new (w - border, h - border); S.GetComponent().type = Image.Type.Sliced; S.transform.SetParent(O.transform); S.transform.localPosition = new Vector3(x, y, 1); } //HELPERS---------------------------------------------------------------------------------------------------- public static void DrawlineRectangle(GameObject Cab, Vector2 p, Color C, Vector2[] v2, float lt) { GameObject Pat = new("linRectangle"); Pat.AddComponent(); Pat.AddComponent(); var pointlist = new List(); UILineRenderer pr = Pat.transform.GetComponent(); Color Col = Color.white; if (Cab.name == "CASE IMAGE") { Col = Color.grey; } if (Cab.name == "CASE IMAGE PNL") { Col = Color.grey; } pr.color = Col; pr.LineThickness = lt; pointlist.Add(v2[0] + p); pointlist.Add(v2[1] + p); pointlist.Add(v2[2] + p); pointlist.Add(v2[3] + p); pointlist.Add(v2[0] + p); pr.Points = pointlist.ToArray(); Pat.transform.SetParent(Cab.transform); } public static void Drawline(GameObject Cab, Vector2 p, Color C, Vector2[] v2, float lt) { GameObject Pat = new("linRectangle"); Pat.AddComponent(); Pat.AddComponent(); var pointlist = new List(); UILineRenderer pr = Pat.transform.GetComponent(); pr.color = C; pr.LineThickness = lt; pointlist.Add(v2[0] + p); pointlist.Add(v2[1] + p); pr.Points = pointlist.ToArray(); Pat.transform.SetParent(Cab.transform); } public static void DrawlineGlass(GameObject Cab, float sx, float sy, float px, float py, string name, float move, float scale, float lt) { //draw contour float ofs = 0; float bT = 2 * scale; float bR = 2 * scale; float bB = 2 * scale; float bL = 2 * scale; Vector2 vp = new (px + ofs, py); Vector2[] v2 = { new (-sx*0.5f + move + bL, -sy*0.5f + move + bB), new (-sx*0.5f + move + bL, sy*0.5f + move - bT), new (sx*0.5f + move - bR, sy*0.5f + move - bT), new (sx*0.5f + move - bR, -sy*0.5f + move + bT) }; DrawlineRectangle(Cab, vp, Color.white, v2, lt); //draw line 45 float sw = sx - bR - bL; if (sw > sy - bT - bB) sw = sy - bT - bB; Vector2[] v2C = { new (-sw / 4 + move, -sw / 4 + move), new (sw / 4 + move, sw / 4 + move) }; Drawline(Cab, vp, Color.white, v2C, lt); Vector2[] v2T = { new (-sw / 6 + move, -sw / 6 + move + sw / 6), new (sw / 6 + move, sw / 6 + move + sw / 6) }; Drawline(Cab, vp, Color.white, v2T, lt); Vector2[] v2B = { new (-sw / 6 + move, -sw / 6 + move - sw / 6), new (sw / 6 + move, sw / 6 + move - sw / 6) }; Drawline(Cab, vp, Color.white, v2B, lt); } public static void DrawlineCutout(GameObject Cab, float sx, float sy, float px, float py, string name, float move, float scale, float lt) { //draw contour float ofs = 0; float bT = 2 * scale; float bR = 2 * scale; float bB = 2 * scale; float bL = 2 * scale; Vector2 vp = new (px + ofs, py); float hs = sy - bT - bB; float posx1 = -sx*0.5f + bL; float posx2 = sx*0.5f - bR; float posy = -sy*0.5f + bB + hs*0.5f; Vector2[] v2C = { new (move + posx1, move + posy), new (move + posx2, move + posy) }; Drawline(Cab, vp, DOIT.CSc("5E5E5E", 255), v2C, hs); Vector2[] v2 = { new (-sx*0.5f + move + bL, -sy*0.5f + move + bB), new (-sx*0.5f + move + bL, sy*0.5f + move - bT), new (sx*0.5f + move - bR, sy*0.5f + move - bT), new (sx*0.5f + move - bR, -sy*0.5f + move + bT) }; DrawlineRectangle(Cab, vp, Color.white, v2, lt); } public static void DrawlineTambour(GameObject Cab, float sx, float sy, float px, float py, string name, float move, float scale, float lt) { string ReT = UIT.Value(_G.Cab_Labrary_On,_G.SC[0],"Tambour"); if(string.IsNullOrEmpty(ReT)){ReT="1_1_1_1";} if(ReT=="0_0_0_0"){ReT="1_1_1_1";} string[] Re = ReT.Split('_'); float ofs = 0; float bT = DOIT.ConvertStringToNumber(Re[0]) * scale; float bR = DOIT.ConvertStringToNumber(Re[1]) * scale; float bB = DOIT.ConvertStringToNumber(Re[2]) * scale; float bL = DOIT.ConvertStringToNumber(Re[3]) * scale; Vector2 vp = new (px + ofs, py); Vector2[] v2 = { new (-sx/2+move+bL,-sy/2+move+bB), new (-sx/2+move+bL,sy/2+move-bT), new (sx/2+move-bR,sy/2+move-bT), new (sx/2+move-bR,-sy/2+move+bB) }; DrawlineRectangle(Cab, vp, Color.white, v2, lt); float sh = (sy - bT - bB); float qty = sh / scale*0.5f; float sw = sx - bR - bL; float hs = 2 * scale; for (int i = 1; i < qty; i++) { float posy = -sy*0.5f + bB + i * hs; float posx1 = -sx*0.5f + bL; float posx2 = sx*0.5f - bR; Vector2[] v2C = { new (move + posx1, move + posy), new (move + posx2, move + posy) }; Drawline(Cab, vp, Color.white, v2C, lt); } } public static void DrawlineOpen(GameObject Cab, float sx, float sy, float px, float py, string name, float move, float scale) { //draw contour float ofs = 0; float bT = 0.5f * scale; float bR = 0.5f * scale; float bB = 0.5f * scale; float bL = 0.5f * scale; Vector2 vp = new (px + ofs, py); float hs = sy - bT - bB; float posx1 = -sx*0.5f + bL; float posx2 = sx*0.5f - bR; float posy = -sy*0.5f + bB + hs*0.5f; Vector2[] v2C = { new (move + posx1, move + posy), new (move + posx2, move + posy) }; Drawline(Cab, vp, DOIT.CSc("5E5E5E", 255), v2C, hs); } public static void DrawlineCenter(GameObject Cab, Vector2 p, Color C, Vector2[] v2, float lt) { Vector2 left=(v2[0]+v2[1] )*0.5f; Vector2 right=(v2[2]+v2[3] )*0.5f; v2 = new Vector2[] { left,right}; Drawline(Cab, p, C, v2, lt); } }