using System.Collections.Generic; using UnityEngine; using UnityEngine.AddressableAssets; using UnityEngine.ResourceManagement.AsyncOperations; public class ConstructDishwasher : MonoBehaviour { static GameObject FACE; public static void AddDishwasher(int nO) { string[] C = _G.OBJs[nO]; float W = DOIT.ConvertStringToNumber(C[6]); float H = DOIT.ConvertStringToNumber(C[7]); float D = DOIT.ConvertStringToNumber(C[8]); float px = DOIT.ConvertStringToNumber(C[15]); float py = DOIT.ConvertStringToNumber(C[16]); float pz = DOIT.ConvertStringToNumber(C[17]); float rx = DOIT.ConvertStringToNumber(C[18]); float ry = DOIT.ConvertStringToNumber(C[19]); float rz = DOIT.ConvertStringToNumber(C[20]); //print("C[42]=====" + C[42]);//C[42]=====1.25_0_0_0_2.25_0_0 string[] CP = C[42].Split("_"[0]);//Counter projectionP float T = DOIT.ConvertStringToNumber(CP[0]); float pf = DOIT.ConvertStringToNumber(CP[4]);//Over top front float pb = DOIT.ConvertStringToNumber(CP[2]);//Projection back float pl = DOIT.ConvertStringToNumber(CP[1]);//Projection left float pr = DOIT.ConvertStringToNumber(CP[3]);//Projection right float pbr = DOIT.ConvertStringToNumber(CP[6]);//Projection back right float pbl = DOIT.ConvertStringToNumber(CP[5]);//Projection back left //float pfcab= pf-(_G.caBD-D);//Matching Counter depth float leftFall = C[45] == "ON" ? T : 0.0f; float backFall = C[46] == "ON" ? T : 0.0f; float rightFall = C[47] == "ON" ? T : 0.0f; C[11] = T.ToString(); string PLR = C[23]; string colorbody = C[27]; string colorUnder = C[26]; float OS1 = 0; float OS2 = 0; float OS3 = 0; float OS4 = 0; string[] C81 = C[81].Split(','); // if (C[48] == "COLLISION" ) { // OS1 += pl; // OS2 += pb; // OS3 += pr; // OS4 += pf; // } //SETTING COLLISION VOLUME if (C[48] == "COLLISION" && C[49] == "GHOST") { OS1 = pl + leftFall; OS2 = pb + backFall; OS3 = pr + rightFall; OS4 = pf; } if (C[48] == "COLLISION" && C[49] == "COLLISION") { OS1 = pl + leftFall; OS3 = pr + rightFall; OS2 = pb + backFall; OS4 = pf; } // if (C[48] == "GHOST" && C[49] == "COLLISION") { // OS1 = fw50; // OS3 = fw51; // } Material matdoor = Instantiate(_G.ELEG); //Create BASE GameObject BASE = GameObject.CreatePrimitive(PrimitiveType.Cube);//new GameObject(); BASE.transform.localScale = new(W + OS1 + OS3 + 0.5f, H + 0.5f, D + OS2 + OS4 + 0.5f); BASE.name = C[0]; BASE.transform.parent = GameObject.Find("SCENE").transform; Vector3 CenterBox = new(OS1 * 0.5f - OS3 * 0.5f, -T * 0.5f, -OS2 * 0.5f + OS4 * 0.5f); //SPLASH DOBS.SplashC(BASE, C[55], W, H, D, C[54]); //print("pf===="+pf+" D==="+D); float back = D * 0.5f + pb; float backBox = D * 0.5f; float frontBox = D * 0.5f; float front = -D * 0.5f - pf; float right = W * 0.5f + pr; float left = -W * 0.5f - pl; float rightBox = W * 0.5f; float leftBox = -W * 0.5f; float centerBox_X = 0; // if (C[48] == "COLLISION" ) { // back=(D + OS2 + OS4)*0.5f; // backBox=back-pb; // front=-(D + OS2 + OS4)*0.5f; // right=W*0.5f+pr; // left=-W*0.5f-pl; // rightBox=W*0.5f; // leftBox=left+pl; // centerBox_X=left+pl+W*0.5f; // } //COUNTER if (CP[0] != "0") { Vector3 PC2 = new(left, H * 0.5f, back); Vector3 PC3 = new(right, H * 0.5f, back); Vector3 PC4 = new(right, H * 0.5f, front); Vector3 PC1 = new(left, H * 0.5f, front); CreatePoint(BASE, "PC1", PC1.x, PC1.y, PC1.z); CreatePoint(BASE, "PC2", PC2.x, PC2.y, PC2.z); CreatePoint(BASE, "PC3", PC3.x, PC3.y, PC3.z); CreatePoint(BASE, "PC4", PC4.x, PC4.y, PC4.z); CREATE.EmptyPoint(BASE, "PBLU", leftBox, (H * 0.5f) - T, backBox);//P CREATE.EmptyPoint(BASE, "PBRU", rightBox, (H * 0.5f) - T, backBox);//P2 CREATE.EmptyPoint(BASE, "PFLU", leftBox, (H * 0.5f) - T, frontBox);//P3 CREATE.EmptyPoint(BASE, "PFRU", rightBox, (H * 0.5f) - T, frontBox);//P4 CREATE.EmptyPoint(BASE, "PBLB", leftBox, -H * 0.5f, backBox);//P1 CREATE.EmptyPoint(BASE, "PBRB", rightBox, -H * 0.5f, backBox);//P2 CREATE.EmptyPoint(BASE, "PFLB", leftBox, -H * 0.5f, frontBox);//P3 CREATE.EmptyPoint(BASE, "PFRB", rightBox, -H * 0.5f, frontBox);//P4 GameObject COUNTER = CounterMCX.MCX4V("CounterTop", T, PC1, PC2, PC3, PC4, C[41]); COUNTER.name = "CABCOUNTER"; COUNTER.transform.parent = BASE.transform; if (C[45] == "ON") { GameObject SIDEL = CounterMCX.SideL(T, H, PC1, PC2); SIDEL.name = "SIDER"; SIDEL.transform.parent = BASE.transform; } if (C[46] == "ON") { GameObject SIDEB = CounterMCX.SideB(T, H, PC2, PC3); SIDEB.name = "SIDER"; SIDEB.transform.parent = BASE.transform; } if (C[47] == "ON") { GameObject SIDER = CounterMCX.SideR(T, H, PC3, PC4); SIDER.name = "SIDER"; SIDER.transform.parent = BASE.transform; } } GameObject BODY = CreateMcx("BODY", W - 1, H - T - 3, D - 1f, centerBox_X, -T / 2 + 1.5f, backBox - (D - 1) * 0.5f, 0, 0, 0); BODY.GetComponent().material.color = DOIT.CSc(colorbody, 255); GameObject DOOR = CreateMcx("DOOR", W - 1, H - T - 3.5f, 1f, centerBox_X, -T / 2 + 1.25f, backBox - (D - 1) - 0.5f, 0, 0, 0); DOOR.GetComponent().material.color = DOIT.CSc(colorbody, 255); GameObject UNDER = CreateMcx("UNDER", W - 1, 3, D - 2f, centerBox_X, -H / 2 + 1.5f, backBox - (D - 2) * 0.5f, 0, 0, 0); UNDER.GetComponent().material.color = DOIT.CSc(colorUnder, 255); FACE = GameObject.CreatePrimitive(PrimitiveType.Quad); FACE.GetComponent().enabled = false; FACE.transform.position = new Vector3(centerBox_X, -T / 2 + 1.25f, backBox - D - 0.1f); FACE.transform.localRotation = Quaternion.Euler(0, 0, 0); FACE.name = "FACE"; FACE.GetComponent().material = matdoor; Addressables.LoadAssetAsync(C[1]).Completed += face_Completed; //FACE.gameObject.GetComponent().material.mainTexture = Resources.Load("TEXTURES/DISHWASHER/" + C[1]) as Texture2D; FACE.GetComponent().probeAnchor = GameObject.Find("Reflection Probe").transform; FACE.transform.parent = FACE.transform; FACE.transform.localScale = new Vector3(W - 1, H - T - 3.5f, 1); FACE.tag = "unhit"; //SIDE PANEL //DOSIDE.PNL(BASE, nO); //ANCHORE POINT CREATE.Point(BASE, "P1", left, H * 0.5f, back); CREATE.Point(BASE, "P2", right, H * 0.5f, back); CREATE.Point(BASE, "P3", right, H * 0.5f, front); CREATE.Point(BASE, "P4", left, H * 0.5f, front); CREATE.EmptyPoint(BASE, "CenterBox", CenterBox.x, 0, CenterBox.z);//P1 //RigidBody BASE.AddComponent(); BASE.GetComponent().useGravity = false; BASE.GetComponent().isKinematic = true; BASE.GetComponent().detectCollisions = true; BASE.GetComponent().isTrigger = true; BASE.tag = "dishwasher"; Mesure.Addpoints("DISH", BASE); //Colors BODY.GetComponent().material = UIT_MATERIAL.GetMaterial("#999999_Matt"); DOOR.GetComponent().material = UIT_MATERIAL.GetMaterial(C[26] + "_Gloss"); UNDER.GetComponent().material = UIT_MATERIAL.GetMaterial(C[27] + "_Matt"); //COUNTER.transform.parent = BASE.transform; BODY.transform.parent = BASE.transform; DOOR.transform.parent = BASE.transform; UNDER.transform.parent = BASE.transform; FACE.transform.parent = BASE.transform; //Stet in scene Vector3 CabinetPosition = new(px, py, pz); BASE.transform.position = CabinetPosition; BASE.transform.localRotation = Quaternion.Euler(rx, ry, rz); BASE.AddComponent(typeof(MoveObject)); BASE.GetComponent().material = _G.INV; // if (SceneModeManager.Selected != null) // { // if (!string.IsNullOrEmpty(_G.SC[15])) // { // float PosX = float.Parse(_G.SC[15]); _G.SC[15] = ""; // float PosZ = float.Parse(_G.SC[17]); _G.SC[17] = ""; // Vector3 OldCenterBox = new(PosX, py, PosZ); // Vector3 NewCenterPosition = BASE.transform.Find("CenterBox").transform.position; // NewCenterPosition = new(NewCenterPosition.x, py, NewCenterPosition.z); // float distance = Vector3.Distance(OldCenterBox, NewCenterPosition); // var direction = (OldCenterBox - NewCenterPosition).normalized; // CabinetPosition += distance * direction; // BASE.transform.position = CabinetPosition; // DOIT.SaveObjectPositionInData(BASE.transform); // } // } } public static GameObject CreateMcx(string Name, float sx, float sy, float sz, float px, float py, float pz, float rx, float ry, float rz) { GameObject obj = GameObject.CreatePrimitive(PrimitiveType.Cube); obj.GetComponent().enabled = false; obj.transform.localScale = new Vector3(sx, sy, sz); obj.transform.position = new Vector3(px, py, pz); obj.transform.localRotation = Quaternion.Euler(rx, ry, rz); //obj.GetComponent().material = UIT_MATERIAL.GetMaterial("888888_Matt"); obj.name = Name; obj.tag = "unhit"; return obj; } public static void CreatePoint(GameObject Base, string Name, float x, float y, float z) { GameObject point = GameObject.CreatePrimitive(PrimitiveType.Cube); point.GetComponent().enabled = false; point.name = Name; point.transform.position = new Vector3(x, y, z); point.transform.parent = Base.transform; point.transform.localScale = new Vector3(0, 0, 0); } private static void face_Completed(AsyncOperationHandle handle) { if (handle.Status == AsyncOperationStatus.Succeeded) { Texture2D result = handle.Result; FACE.gameObject.GetComponent().material.mainTexture = result; } } }