using UnityEngine; using System; using UnityEngine.AddressableAssets; using UnityEngine.ResourceManagement.AsyncOperations; using System.Collections.Generic; public class ConstructDoor : MonoBehaviour { //static string Url; //static string Url2; static Color cold; static Color colm; //static GameObject mt; //static GameObject mr; //static GameObject ml; static GameObject mtc; static GameObject mrc; static GameObject mlc; //static Boolean LOAD; static float os = 0f; static GameObject doorModel; static GameObject glass; public static void AddDoor(int nO) { string[] C = _G.OBJs[nO]; string Name = _G.OBJs[nO][0]; _G.OBJs[nO][1]=DoorCodeConvert(_G.OBJs[nO][1]); float w = DOIT.ConvertStringToNumber(C[6]); float h = DOIT.ConvertStringToNumber(C[7]); float d = 6;//Get.ThicknessWall(C[22]); 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]); cold = DOIT.CSc(C[62], 255); colm = DOIT.CSc(C[63], 255); //color float mw = 3f; //create door GameObject BASE = GameObject.CreatePrimitive(PrimitiveType.Cube); BASE.transform.localScale = new Vector3(w + 0.5f, h + 0.5f, 1 + 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, 0f);//P4 CREATE.Point(BASE, "P2", w * 0.5f, -h * 0.5f + 0.1f, 0f);//P4 CREATE.Point(BASE, "P3", -w * 0.5f, -h * 0.5f + 0.1f, 0f);//P3 CREATE.Point(BASE, "P4", -w * 0.5f, h * 0.5f, 0f);//P3 //Create Frame GameObject FRAME = new(); FRAME.name = "frame"; FRAME.transform.parent = BASE.transform; //Create Moding GameObject MOLDING = new() { name = "Molding" }; MOLDING.transform.parent = BASE.transform; float FramePos = d * 0.5f; float InnerPos = d - 1f; //create frame CreateMcx(FRAME, "ft", w, 1.0f, 6.0f, 0, h / 2 - 0.5f, FramePos, C[1]); CreateMcx(FRAME, "fr", 1.0f, h - 1, 6.0f, w / 2 - 0.5f, -0.5f, FramePos, C[1]); CreateMcx(FRAME, "fl", 1.0f, h - 1, 6.0f, -w / 2 + 0.5f, -0.5f, FramePos, C[1]); CreateMcx(FRAME, "fl", w, 0.1f, 6.0f, 0, -h / 2 + 0.05f, FramePos, C[1]); //create frame inner CreateMcx(FRAME, "it", w - 2, 1f, 1.0f, 0, h / 2 - 1.25f, InnerPos, C[1]); CreateMcx(FRAME, "ir", 1f, h - 1.5f, 1.0f, w / 2 - 1.25f, -0.75f, InnerPos, C[1]); CreateMcx(FRAME, "il", 1f, h - 1.5f, 1.0f, -w / 2 + 1.25f, -0.75f, InnerPos, C[1]); //create molding float MoldingPos = -0.5f; float CoverPos = -1.1f; if (string.IsNullOrEmpty(C[61])) { C[61] = "mx"; } if (C[61] != "mx")//if molding { CreateMcx(MOLDING, "mt", w + 2 * mw - 2, mw, 1.0f, 0, h / 2 + mw / 2 - 1, MoldingPos, C[1]); CreateMcx(MOLDING, "mr", mw, h, 1.0f, w / 2 + mw / 2 - 1, 0, MoldingPos, C[1]); CreateMcx(MOLDING, "ml", mw, h, 1.0f, -w / 2 - mw / 2 + 1, 0, MoldingPos, C[1]); float l = w - 2 + mw * 2; mtc = CreateMcxCover("ct", -l / 2, mw / 2, l / 2, mw / 2, l / 2 - mw, -mw / 2, -l / 2 + mw, -mw / 2, C[1]); mtc.transform.position = new Vector3(0, h / 2 - 1 + mw / 2, CoverPos); mtc.transform.SetParent(MOLDING.transform); l = h - 1 + mw; mrc = CreateMcxCover("cr", -l / 2, mw / 2, l / 2, mw / 2, l / 2, -mw / 2, -l / 2 + mw, -mw / 2, C[1]); mrc.transform.position = new Vector3(w / 2 - 1 + mw / 2, -0.5f + mw / 2, CoverPos); mrc.transform.localRotation = Quaternion.Euler(0, 0, -90); mrc.transform.SetParent(MOLDING.transform); mlc = CreateMcxCover("cl", -l / 2, mw / 2, l / 2, mw / 2, l / 2 - mw, -mw / 2, -l / 2, -mw / 2, C[1]); mlc.transform.position = new Vector3(-w / 2 + 1 - mw / 2, -0.5f + mw / 2, CoverPos); mlc.transform.localRotation = Quaternion.Euler(0, 0, 90); mlc.transform.SetParent(MOLDING.transform); } //create doormodel Material Mat = Instantiate(UIT_MATERIAL.GetMaterial("ffffff_Matt")); doorModel = GameObject.CreatePrimitive(PrimitiveType.Cube); doorModel.transform.localScale = new Vector3(w - 2, h - 1f, -1.5f); doorModel.transform.position = new Vector3(0, -0.5f, d * 0.5f); doorModel.GetComponent().material = Mat;//Instantiate(Get.ColorGlobal("ffffff_Matt")); Addressables.LoadAssetAsync(C[1]).Completed += Face_Completed; Mat.mainTextureScale = new Vector2(-1, 1); Mat.SetColor("_c1", cold); doorModel.GetComponent().enabled = false; doorModel.transform.parent = FRAME.transform; doorModel.name = "dr"; doorModel.tag = "door"; //Material Mat.SetFloat("_Smoothness", 0.2f); Mat.SetFloat("_Metallic", 0.2f); Mat.SetColor("_c1", cold); Mat.SetColor("_c2", DOIT.CSc("#878787", 255));//FFEDC6 if (C[1].IndexOf("W") != -1) Mat.SetColor("_c1", DOIT.CSc("#FFEDC6", 255)); doorModel.GetComponent().probeAnchor = GameObject.Find("Reflection Probe").transform; //Create Glass if (new List(){ "DOOS115","DOOS116","DOOS117","DOOS118", "DOOD115", "DOOD116","DOOD117","DOOD118", "DOWS112","DOWS116","DOWS117","DOWS118", "DOWD112","DOWD116","DOWD117", "DOWD118"}.Contains(_G.SC[0])) { Material GlassMat = Instantiate(_G.TRANS); glass = GameObject.CreatePrimitive(PrimitiveType.Cube); glass.transform.localScale = new Vector3(w - 2, h - 1f, -1.8f); glass.transform.position = new Vector3(0, -0.5f, 0.75f); string nd = C[1] + "G"; glass.GetComponent().material = GlassMat; Addressables.LoadAssetAsync(nd).Completed += Glass_Completed; // GlassMat.SetFloat("_Mode", 3); // GlassMat.mainTextureScale = new Vector2(-1, 1); // GlassMat.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.SrcAlpha); // GlassMat.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha); // GlassMat.SetInt("_ZWrite", 0); // GlassMat.DisableKeyword("_ALPHATEST_ON"); // GlassMat.EnableKeyword("_ALPHABLEND_ON"); // GlassMat.DisableKeyword("_ALPHAPREMULTIPLY_ON"); GlassMat.renderQueue = 3000; glass.name = "glass"; glass.GetComponent().enabled = false; glass.transform.parent = BASE.transform; } //Create knob GameObject knob = AddDoorknob.knob(); if (C[23] == "R") knob.transform.position = new Vector3(w / 2 - 4, -h / 2 + 34, -2.25f); if (C[23] == "L") knob.transform.position = new Vector3(-w / 2 + 4, -h / 2 + 34, -2.25f); knob.transform.parent = BASE.transform; if (C[1][..4] == "DOOD" || C[1].Substring(0, 4) == "DOWD") { knob.transform.position = new Vector3(-3, -h / 2 + 40, -2.25f); GameObject knob2 = AddDoorknob.knob(); knob2.transform.position = new Vector3(3, -h / 2 + 40, -2.25f); knob2.transform.parent = BASE.transform; } //RigidBody BASE.AddComponent(); BASE.GetComponent().useGravity = false; BASE.GetComponent().isKinematic = true; BASE.GetComponent().detectCollisions = true; BASE.GetComponent().isTrigger = true; Mesure.Addpoints("WALL", BASE); //Set 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 = _G.INV;//Resources.Load("MATERIALS/INVISIBLE") as Material; //BM.INV; BASE.GetComponent().shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off; for (int i = 0; i < FRAME.transform.childCount; i++) { FRAME.transform.GetChild(i).tag = "doorframe"; } BASE.transform.SetParent(SceneModeManager.Scene); // 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, string C1) { 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 + os); obj.GetComponent().material = Instantiate(UIT_MATERIAL.GetMaterial("ffffff_Matt"));//new Material(Shader.Find("Standard")); //Instantiate(Get.ColorGlobal("ffffff_Matt"));//Resources.Load("MATERIALS/ST") as Material; obj.GetComponent().material.SetColor("_c1", colm); obj.GetComponent().material.SetColor("_c2", DOIT.CSc("959595",255)); if (C1.Substring(2, 1) == "W") obj.GetComponent().material.mainTexture = Resources.Load("Molding/m101w") as Texture2D; if (n == "mt" || n == "mr" || n == "ml") { obj.GetComponent().material.color = colm; } obj.name = n; obj.transform.SetParent(O.transform); 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, string C1) { GameObject obj = new("TopCover"); obj.AddComponent(typeof(MeshFilter)); obj.AddComponent(typeof(MeshRenderer)); obj.GetComponent().mesh = CreateMesh(P1x, P1y, P2x, P2y, P3x, P3y, P4x, P4y); obj.transform.position = new Vector3(0, 0, -5.1f); obj.name = n; obj.GetComponent().material = Instantiate(UIT_MATERIAL.GetMaterial("ffffff_Matt"));//new Material(Shader.Find("Standard")); //Instantiate(Get.ColorGlobal("ffffff_Matt"));//new Material(Shader.Find("Standard")); //obj.GetComponent().material.color = colm; obj.GetComponent().material.SetColor("_c1", colm); string m_w = ""; if (C1.Substring(2, 1) == "W") m_w = "w"; obj.GetComponent().material.mainTexture = Resources.Load("Molding/" + C1 + m_w) as Texture2D; obj.tag = "framemolding"; 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(); m.name = "ScriptedMesh"; m.vertices = new Vector3[] { new(P1x, P1y, 0.01f), new(P2x, P2y, 0.01f), new(P3x, P3y, 0.01f), new(P4x, P4y, 0.01f) }; m.uv = new Vector2[] { new (0, 1), new (1, 1), new (1, 0), new (0, 0) }; m.triangles = new int[] { 0, 1, 2, 0, 2, 3 }; m.RecalculateNormals(); return m; } private static void Face_Completed(AsyncOperationHandle handle) { if (handle.Status == AsyncOperationStatus.Succeeded) { Texture2D result = handle.Result; doorModel.GetComponent().material.SetTexture("_Texture", result); } } private static void Glass_Completed(AsyncOperationHandle handle) { if (handle.Status == AsyncOperationStatus.Succeeded) { Texture2D result = handle.Result; glass.GetComponent().material.SetTexture("_BaseMap", result); } } public static string DoorCodeConvert(string Code) { if(Code.Contains("DOOR")){ int DoorNumber = int.Parse(Code[4..]); if (DoorNumber <= 118) {return "DOOS" + DoorNumber.ToString();} else if (DoorNumber <= 136) {return "DOOD" + (DoorNumber - 18).ToString();} else if (DoorNumber <= 154){return "DOWS" + (DoorNumber - 36).ToString();} else if (DoorNumber > 154){return "DOWD" + (DoorNumber - 54).ToString();} } return Code; } }