using UnityEngine; using UnityEngine.AddressableAssets; using UnityEngine.ResourceManagement.AsyncOperations; public class ConstructMicrowave : MonoBehaviour { static GameObject FACE; public static void AddMicrowave(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]); string PLR = C[23]; int LR = 1; if (PLR == "L") LR = -1; string col = "666666_Semi" ;//C[54]; string colU = C[55]; float co = 0; if (_G.OBJs[nO][1].Substring(0, 4) == "MICC") co = 0.5f; GameObject BODY = CreateMcx("BODY", w, h - co, d - 1f, 0, co / 2, 0.5f, 0, 0, 0, col); GameObject DOOR = CreateMcx("DOOR", w, h - co, 0.75f, 0, co / 2, -d / 2 + 0.5f, 0, 0, 0, col); FACE = GameObject.CreatePrimitive(PrimitiveType.Quad); //GameObject UNDER; FACE.transform.position = new Vector3(0, co / 2, -d / 2 - 0.1f); FACE.transform.localRotation = Quaternion.Euler(0, 0, 0); FACE.name = "FACE"; FACE.GetComponent().material = Instantiate(_G.ELEG);//BM.QUADDOOR; //FACE.gameObject.GetComponent().material.mainTexture = Resources.Load("TEXTURES/MICROWAVE/" + _G.OBJs[nO][1]) as Texture2D; Addressables.LoadAssetAsync(_G.OBJs[nO][1]).Completed += face_Completed; FACE.transform.parent = FACE.transform; FACE.transform.localScale = new Vector3(w * LR, h - co, 1); FACE.tag = "unhit"; //create BASE GameObject BASE = GameObject.CreatePrimitive(PrimitiveType.Cube);//new GameObject(); BASE.transform.localScale = new Vector3(w + 0.5f, h + 0.5f, d + 0.5f); BASE.name = _G.OBJs[nO][0]; BASE.transform.parent = GameObject.Find("SCENE").transform; Destroy(GameObject.Find("New Game Object")); //RigidBody BASE.AddComponent(); BASE.GetComponent().useGravity = false; BASE.GetComponent().isKinematic = true; BASE.GetComponent().detectCollisions = true; BASE.GetComponent().isTrigger = true; BODY.transform.parent = BASE.transform; DOOR.transform.parent = BASE.transform; FACE.transform.parent = BASE.transform; if (_G.OBJs[nO][1].Substring(0, 4) == "MICC") { GameObject UNDER = CreateMcx("S1", w - 1, 1, d - 1, 0, -h / 2 + 0.5f, 0.5f, 0, 0, 0, colU); UNDER.transform.parent = BASE.transform; } Mesure.Addpoints("MICR",BASE); //ANCHORE POINT CREATE.Point(BASE, "P1", -w / 2, h / 2, d / 2); CREATE.Point(BASE, "P2", w / 2, h / 2, d / 2); CREATE.Point(BASE, "P3", w / 2, h / 2, -d / 2); CREATE.Point(BASE, "P4", -w / 2, h / 2, -d / 2); //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; } public static GameObject CreateMcx(string Name, float sx, float sy, float sz, float px, float py, float pz, float rx, float ry, float rz, string col) { 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 = Resources.Load("MATERIALS/ST") as Material; // obj.GetComponent().material.color = DOIT.CSc(col, 255); //if(Name=="UNDER") obj.GetComponent().material.color = DOIT.CSc(_G.SC[5], 255); obj.GetComponent().material.mainTextureScale = new Vector2(sx / 12f, sy / 12f); obj.name = Name; obj.tag = "unhit"; return obj; } private static void face_Completed(AsyncOperationHandle handle) { if (handle.Status == AsyncOperationStatus.Succeeded) { Texture2D result = handle.Result; FACE.gameObject.GetComponent().material.mainTexture = result; } } }