using UnityEngine; using UnityEngine.AddressableAssets; using UnityEngine.ResourceManagement.AsyncOperations; public class ConstructPlatestove : MonoBehaviour { static GameObject FACETOP; public static void AddStovePlates(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]); int Ni = int.Parse(C[1].Substring(4, 3)); string code="ffffff_Glossy"; if (Ni <= 107) {code="888888_Glossy"; } if (Ni > 108 && Ni <= 114) { code="444444_Glossy";} if (Ni > 114) { code="ffffff_Glossy"; } Material mat = UIT_MATERIAL.GetMaterial(code); GameObject BODY = CreateMCX("BODY", w, h, d, 0, 0, 0, 0, 0, 0, mat); FACETOP = GameObject.CreatePrimitive(PrimitiveType.Quad); FACETOP.transform.position = new Vector3(0, h / 2 + 0.2f, 0); FACETOP.transform.localRotation = Quaternion.Euler(90, 0, 0); FACETOP.name = "FACETOP"; FACETOP.GetComponent().material = Instantiate(_G.ELEG); Addressables.LoadAssetAsync(C[1]).Completed += FaceA_Completed; FACETOP.transform.localScale = new Vector3(w - 2, d - 2, 1); FACETOP.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 = C[0]; BASE.transform.parent = GameObject.Find("SCENE").transform; Destroy(GameObject.Find("New Game Object")); //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); //RigidBody BASE.AddComponent(); BASE.GetComponent().useGravity = false; BASE.GetComponent().isKinematic = true; BASE.GetComponent().detectCollisions = true; BASE.GetComponent().isTrigger = true; BODY.transform.parent = BASE.transform; FACETOP.transform.parent = BASE.transform; //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 = _G.INV;//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, Material M) { 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 = M; obj.name = Name; obj.tag = "unhit"; return obj; } static void FaceA_Completed(AsyncOperationHandle handleA) { if (handleA.Status == AsyncOperationStatus.Succeeded) { Texture2D result = handleA.Result; FACETOP.gameObject.GetComponent().material.mainTexture = result; } } }