using UnityEngine; public class ConstructPatio : MonoBehaviour { //static GameObject mt; //static GameObject mr; //static GameObject ml; //static GameObject mb; static GameObject mtc; static GameObject mrc; static GameObject mlc; static Color colf; static Color colm; static string molding; static string colfs; static string colms; static string colfsOver; static string colmsOver; //static float os = 1f; static int ADN; public static void AddPatio(int nO) { ADN=nO; string Name = _G.OBJs[nO][0]; float w = DOIT.ConvertStringToNumber(_G.OBJs[nO][6]); float h = DOIT.ConvertStringToNumber(_G.OBJs[nO][7]); float d = DOIT.ConvertStringToNumber(_G.OBJs[nO][8]); float px = DOIT.ConvertStringToNumber(_G.OBJs[nO][15]); float py = DOIT.ConvertStringToNumber(_G.OBJs[nO][16]); float pz = DOIT.ConvertStringToNumber(_G.OBJs[nO][17]); float rx = DOIT.ConvertStringToNumber(_G.OBJs[nO][18]); float ry = DOIT.ConvertStringToNumber(_G.OBJs[nO][19]); float rz = DOIT.ConvertStringToNumber(_G.OBJs[nO][20]); string model = _G.OBJs[nO][1]; if(string.IsNullOrEmpty(_G.OBJs[nO][5])){_G.OBJs[nO][5]="mx";} molding = _G.OBJs[nO][5]; float ed = DOIT.ConvertStringToNumber(_G.OBJs[nO][23]); colfs = _G.OBJs[nO][62];//Color frame string colfsOver = colfs; if (colfs == "wood1") colfsOver = "EAEAEA"; if (colfs == "wood2") colfsOver = "CBADAD"; colf = DOIT.CSc(colfsOver, 1); //color colms = _G.OBJs[nO][63];//Color frame string colmsOver = colms; if (colms == "wood1") colmsOver = "EAEAEA"; if (colms == "wood2") colmsOver = "CBADAD"; colm = DOIT.CSc(colmsOver, 1); //color float fti = 0.75f;//frame thickness float mw = 0.5f;//Meno wide float gw = w - ed * 2 - fti * 2;//glass wide float gh = h - ed - ed * 2;//glass height float pc1 = -w / 4 + fti;//Center door 1 float pc2 = w / 4 - fti;//Center door 2 //create Patio GameObject BASE = GameObject.CreatePrimitive(PrimitiveType.Cube); BASE.transform.localScale = new(w + 0.5f, h + 0.5f, d + 0.5f); BASE.name = Name; // 2D Plan Top View CREATE.Point(BASE, "PBLU", -w * 0.5f, h * 0.5f, 0f);//P1 CREATE.Point(BASE, "PBRU", w * 0.5f, h * 0.5f, 0f);//P2 CREATE.Point(BASE, "PFLU", -w * 0.5f, h * 0.5f, 0f);//P3 CREATE.Point(BASE, "PFRU", w * 0.5f, h * 0.5f, 0f);//P4 CREATE.Point(BASE, "PBLB", -w * 0.5f, -h * 0.5f, 0f);//P1 CREATE.Point(BASE, "PBRB", w * 0.5f, -h * 0.5f, 0f);//P2 CREATE.Point(BASE, "PFLB", -w * 0.5f, -h * 0.5f, 0f);//P3 CREATE.Point(BASE, "PFRB", w * 0.5f, -h * 0.5f, 0f);//P4 CREATE.Point(BASE, "PFLBB", -w * 0.5f, -h * 0.5f, d);// Back point CREATE.Point(BASE, "PFLUB", -w * 0.5f, h * 0.5f, d);// Back point CREATE.Point(BASE, "PFRUB", w * 0.5f, h * 0.5f, d);// Back point CREATE.Point(BASE, "PFRBB", w * 0.5f, -h * 0.5f, d);// Back point CREATE.Point(BASE, "P1", w * 0.5f, -h * 0.5f+0.1f, 0f);//P4 CREATE.Point(BASE, "P2", -w * 0.5f, -h * 0.5f+0.1f, 0f);//P3 CREATE.Point(BASE, "P3", -w * 0.5f, h * 0.5f, 0f);//P3 CREATE.Point(BASE, "P4", w * 0.5f, h * 0.5f, 0f);//P4 //Create Frame GameObject FRAME = new ("frame"); FRAME.transform.parent = BASE.transform; //Create Moding GameObject MOLDING = new ("Molding"); MOLDING.transform.parent = BASE.transform; float FramePos = d * 0.5f; float InnerPos = d - 1f; //create frame CreateMcx(FRAME, "ft", w, fti, d, 0, h / 2 - fti / 2, FramePos); CreateMcx(FRAME, "fr", fti, h - fti * 2, d, w / 2 - fti / 2, 0, FramePos); CreateMcx(FRAME, "fl", fti, h - fti * 2, d, -w / 2 + fti / 2, 0, FramePos); CreateMcx(FRAME, "fb", w, fti * 2, d, 0, -h / 2 + fti, FramePos); //create inner if (model == "PATI101" || model == "PATI102" || model == "PATI103") { pc1 = 0; CreateMcx(FRAME, "et", gw, ed, 2.0f, 0, h / 2 - fti - ed / 2, InnerPos); CreateMcx(FRAME, "er", ed, h - fti - fti * 2, 2.0f, w / 2 - fti - ed / 2, fti / 2, InnerPos); CreateMcx(FRAME, "el", ed, h - fti - fti * 2, 2.0f, -w / 2 + fti + ed / 2, fti / 2, InnerPos); CreateMcx(FRAME, "eb", gw, ed * 2, 2.0f, 0, -h / 2 + fti + ed / 2, InnerPos); AddGlass(BASE,new Vector3(gw,gh,0.25f),new Vector3(0,0,InnerPos)); } if (model == "PATI104" || model == "PATI105" || model == "PATI106") { gw = w / 2 - ed * 2 - 0.75f; CreateMcx(FRAME, "et", w / 2 - fti - ed * 2, ed, 2.0f, -w / 4 + 0.75f / 2, h / 2 - fti - ed / 2, InnerPos+1); CreateMcx(FRAME, "er", ed, h - fti - fti * 2, 2.0f, -ed / 2, fti / 2, InnerPos+1); CreateMcx(FRAME, "el", ed, h - fti - fti * 2, 2.0f, -w / 2 + fti + ed / 2, fti / 2, InnerPos+1); CreateMcx(FRAME, "eb", w / 2 - fti - ed * 2, ed * 2, 2.0f, -w / 4 + fti / 2, -h / 2 + fti + ed / 2, InnerPos+1); AddGlass(BASE,new Vector3(gw,gh,0.25f),new Vector3( -w / 4 + 0.75f / 2,0,InnerPos+1)); CreateMcx(FRAME, "et2", w / 2 - fti - ed * 2, ed, 2.0f, w / 4 - fti / 2, h / 2 - fti - ed / 2, InnerPos-1); CreateMcx(FRAME, "er2", ed, h - fti - fti * 2, 2.0f, w / 2 - fti - ed / 2, fti / 2, InnerPos-1); CreateMcx(FRAME, "el2", ed, h - fti - fti * 2, 2.0f, ed / 2, fti / 2, InnerPos-1); CreateMcx(FRAME, "eb2", w / 2 - fti - ed * 2, ed * 2, 2.0f, w / 4 - fti / 2, -h / 2 + fti + ed / 2, InnerPos-1); AddGlass(BASE,new Vector3(gw,gh,0.25f),new Vector3( w / 4 - fti / 2,0,InnerPos-1)); } //create molding float MoldingPos = -0.5f; float CoverPos = -1.1f; if (molding != "mx") { float mow = 3; float l = w - fti * 2 + mow * 2; CreateMcx(MOLDING, "mt", l, mow, 1.0f, 0, h / 2 + mow / 2 - fti, MoldingPos); CreateMcx(MOLDING, "mr", mow, h - fti, 1.0f, w / 2 + mow / 2 - fti, -fti / 2, MoldingPos); CreateMcx(MOLDING, "ml", mow, h - fti, 1.0f, -w / 2 - mow / 2 + fti, -fti / 2, MoldingPos); l = w - fti * 2 + mow * 2; mtc = CreateMcxCover("ct", -l / 2, mow / 2, l / 2, mow / 2, l / 2 - mow, -mow / 2, -l / 2 + mow, -mow / 2); mtc.transform.position = new Vector3(0, h / 2 - fti + mow / 2, CoverPos); mtc.transform.SetParent(MOLDING.transform); l = h - fti + mow; mrc = CreateMcxCover("cr", -l / 2, mow / 2, l / 2, mow / 2, l / 2, -mow / 2, -l / 2 + mow, -mow / 2); mrc.transform.position = new Vector3(w / 2 - fti + mow / 2, -fti / 2 + mow / 2, CoverPos); mrc.transform.localRotation = Quaternion.Euler(0, 0, -90); mrc.transform.SetParent(MOLDING.transform); mlc = CreateMcxCover("cl", -l / 2, mow / 2, l / 2, mow / 2, l / 2 - mow, -mow / 2, -l / 2, -mow / 2); mlc.transform.position = new Vector3(-w / 2 + fti - mow / 2, -fti / 2 + mow / 2, CoverPos); mlc.transform.localRotation = Quaternion.Euler(0, 0, 90); mlc.transform.SetParent(MOLDING.transform); } //create Background if(!_G.PHOTO){ GameObject bg = GameObject.CreatePrimitive(PrimitiveType.Quad); bg.name = "background"; bg.transform.localScale = new(w + 6, h + 6, 0.25f ); bg.transform.position = new(0, 0, InnerPos+3); bg.GetComponent().material = _G.BGPATIO; bg.GetComponent().probeAnchor = GameObject.Find("Reflection Probe ext").transform; bg.GetComponent().shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off; bg.transform.parent = BASE.transform; //bg.layer=21; } //create meno float MenoPos = d - 1; if (model == "PATI102") { CreateMcx(FRAME, "me1", gw, mw, mw, 0, (gh / 10) * 1, MenoPos); CreateMcx(FRAME, "me2", gw, mw, mw, 0, (gh / 10) * 3, MenoPos); CreateMcx(FRAME, "me3", gw, mw, mw, 0, -(gh / 10) * 1, MenoPos); CreateMcx(FRAME, "me4", gw, mw, mw, 0, -(gh / 10) * 3, MenoPos); } if (model == "PATI103") { CreateMcx(FRAME, "me1", gw, mw, mw, 0, (gh / 10) * 1, MenoPos); CreateMcx(FRAME, "me2", gw, mw, mw, 0, (gh / 10) * 3, MenoPos); CreateMcx(FRAME, "me3", gw, mw, mw, 0, -(gh / 10) * 1, MenoPos); CreateMcx(FRAME, "me4", gw, mw, mw, 0, -(gh / 10) * 3, MenoPos); CreateMcx(FRAME, "me5", 1, gh, 1.0f, 0, 0 + ed / 4, MenoPos); } if (model == "PATI105") { CreateMcx(FRAME, "me1", gw, mw, mw, pc1, (gh / 10) * 1, MenoPos+1); CreateMcx(FRAME, "me2", gw, mw, mw, pc1, (gh / 10) * 3, MenoPos+1); CreateMcx(FRAME, "me3", gw, mw, mw, pc1, -(gh / 10) * 1, MenoPos+1); CreateMcx(FRAME, "me4", gw, mw, mw, pc1, -(gh / 10) * 3, MenoPos+1); CreateMcx(FRAME, "me5", gw, mw, mw, pc2, (gh / 10) * 1, MenoPos - 1); CreateMcx(FRAME, "me6", gw, mw, mw, pc2, (gh / 10) * 3, MenoPos - 1); CreateMcx(FRAME, "me7", gw, mw, mw, pc2, -(gh / 10) * 1, MenoPos - 1); CreateMcx(FRAME, "me8", gw, mw, mw, pc2, -(gh / 10) * 3, MenoPos - 1); } if (model == "PATI106") { CreateMcx(FRAME, "me1", gw, mw, mw, pc1, (gh / 10) * 1, MenoPos+1); CreateMcx(FRAME, "me2", gw, mw, mw, pc1, (gh / 10) * 3, MenoPos+1); CreateMcx(FRAME, "me3", gw, mw, mw, pc1, -(gh / 10) * 1, MenoPos+1); CreateMcx(FRAME, "me4", gw, mw, mw, pc1, -(gh / 10) * 3, MenoPos+1); CreateMcx(FRAME, "me5", 1, gh, mw, pc1, 0 + ed / 4, MenoPos+1); CreateMcx(FRAME, "me6", gw, mw, mw, pc2, (gh / 10) * 1, MenoPos - 1); CreateMcx(FRAME, "me7", gw, mw, mw, pc2, (gh / 10) * 3, MenoPos - 1); CreateMcx(FRAME, "me8", gw, mw, mw, pc2, -(gh / 10) * 1, MenoPos - 1); CreateMcx(FRAME, "me9", gw, mw, mw, pc2, -(gh / 10) * 3, MenoPos - 1); CreateMcx(FRAME, "me10", 1, gh, mw, pc2, 0 + ed / 4, MenoPos - 1); } Mesure.Addpoints("WALL",BASE); //RigidBody BASE.AddComponent(); BASE.GetComponent().useGravity = false; BASE.GetComponent().isKinematic = true; BASE.GetComponent().detectCollisions = true; BASE.GetComponent().isTrigger = true; //Stet in scene BASE.transform.position = new Vector3(px, py, pz); BASE.transform.localRotation = Quaternion.Euler(rx, ry, rz); BASE.AddComponent(typeof(MoveObject)); BASE.GetComponent().material = Resources.Load("MATERIALS/INVISIBLE") as Material; //BM.INV; BASE.transform.SetParent(SceneModeManager.Scene); for (int i = 0; i < FRAME.transform.childCount; i++) { FRAME.transform.GetChild(i).tag = "doorframe"; } //for (int i = 0; i < MOLDING.transform.childCount; i++) { MOLDING.transform.GetChild(i).tag = "molding"; } } static void CreateMcx(GameObject O, string n, float sx, float sy, float sz, float px, float py, float pz) { GameObject obj = GameObject.CreatePrimitive(PrimitiveType.Cube); obj.GetComponent().enabled = false; obj.transform.localScale = new(sx, sy, sz); obj.transform.position = new(px, py, pz ); //Color Frame string colorFrame=_G.OBJs[ADN][62]; if(colorFrame.Split('_').Length==1){colorFrame+="_Semi";} Material Mat=Instantiate(UIT_MATERIAL.GetMaterial(colorFrame)); obj.GetComponent().material = Mat;//new Material(Shader.Find("Diffuse")); //Mat.SetFloat("_Smoothness",0.2f); // Mat.SetFloat("_Metallic",0.2f); //obj.GetComponent().material.color = colf; Mat.SetColor("_c1",colf); //obj.GetComponent().material.renderQueue = 1; if (colfs.Substring(0, 4) == "wood") { obj.GetComponent().material.SetTexture("_TExture",Resources.Load("Molding/m101w") as Texture2D);} if (colfs == "wood2") { obj.GetComponent().material.color = colm; } if (n == "mt" || n == "mb" || n == "mr" || n == "ml") { obj.GetComponent().material.SetColor("_c1",colm); } obj.name = n; obj.transform.SetParent(O.transform); obj.GetComponent().enabled = false; if (O.name == "Molding") obj.tag = "framemolding"; else obj.tag = "frame"; } public static GameObject CreateMcxCover(string n, float P1x, float P1y, float P2x, float P2y, float P3x, float P3y, float P4x, float P4y) { GameObject obj = new (n); obj.AddComponent(typeof(MeshFilter)); obj.AddComponent(typeof(MeshRenderer)); obj.GetComponent().mesh = CreateMesh(P1x, P1y, P2x, P2y, P3x, P3y, P4x, P4y); obj.transform.position = new(0, 0, -5.1f); //Color Cover string colorFrame=_G.OBJs[ADN][63];//G.OBJs[ADN][62]===#DEC497_Glossy_none if(colorFrame.Split('_').Length==1){colorFrame+="_Semi";} Material Mat=Instantiate(UIT_MATERIAL.GetMaterial(colorFrame)); obj.GetComponent().material = Mat;//new Material(Shader.Find("Diffuse")); obj.name = n; obj.GetComponent().material.mainTexture = Resources.Load("Molding/" + molding) as Texture2D; if (colfs.Substring(0, 4) == "wood") { obj.GetComponent().material.SetTexture("_Texture", Resources.Load("Molding/" + molding + "w") as Texture2D); obj.GetComponent().material.SetColor("_c1",colf); } // obj.tag = "framemolding"; //print("------------------------CreateMcx-------------------------------cover------End======="+obj.name); return obj; } public static Mesh CreateMesh(float P1x, float P1y, float P2x, float P2y, float P3x, float P3y, float P4x, float P4y) { Mesh m = new() { name = "ScriptedMesh", vertices = new Vector3[] { new(P1x, P1y, 0.01f), new(P2x, P2y, 0.01f), new(P3x, P3y, 0.01f), new(P4x, P4y, 0.01f) }, uv = new Vector2[] { new (0, 1), new (1, 1), new(1, 0), new (0, 0) }, triangles = new int[] { 0, 1, 2, 0, 2, 3 } }; m.RecalculateNormals(); return m; } public static void AddGlass(GameObject BASE,Vector3 Size,Vector3 Position){ //Glass GameObject Glass = GameObject.CreatePrimitive(PrimitiveType.Quad); Glass.name = "glass"; Glass.transform.localScale = Size; Glass.transform.position = Position; Glass.GetComponent().material = _G.GLASS; Glass.GetComponent().shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off; Glass.transform.parent = BASE.transform; Glass.GetComponent().probeAnchor = GameObject.Find("Reflection Probe").transform; } }