using System.Collections.Generic; using UnityEngine; using UnityEngine.AddressableAssets; using UnityEngine.ResourceManagement.AsyncOperations; public class ConstructWD : MonoBehaviour { static GameObject FACE; static GameObject FACETOP; static GameObject FACEHEAD; public static void AddWD(int nO) { print("Construct WWWWWEDDDD"); 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]); float hh = DOIT.ConvertStringToNumber(_OL.GetValue(C[1],"hh")); float hf = 1; string code=C[27]+"_Glossy"; Material mat = UIT_MATERIAL.GetMaterial(code); Material matW = Instantiate(_G.ELEG); //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.SetParent(GameObject.Find("SCENE").transform); GameObject BODY; GameObject HEAD; GameObject TOPBODY; float h,w,hp; string Ns = C[1].Substring(4, 3); FACE = GameObject.CreatePrimitive(PrimitiveType.Quad); SetMat("FACE", FACE, matW, "WADA" + Ns); if (new List {"101","102","110","111","119","120"}.Contains(C[1][4..])) { w = W; h = H - hh - hf - 1.5f; hp = hf / 2 - hh / 2 - 0.75f; BODY = CreateMcx("BODY", w, h, D, 0, hp, 0, 0, 0, 0); SetMat("BODY", BODY, mat, ""); BODY.transform.SetParent(BASE.transform); FACE.transform.localScale = new Vector3(w, h, 1); FACE.transform.position = new Vector3(0, hp, -D / 2 - 0.1f); FACE.transform.SetParent(BASE.transform); hp = H / 2 - hh - 0.75f; TOPBODY = CreateMcx("TOPBODY", w, 1, D, 0, H / 2 - hh - 0.75f, 0, 0, 0, 0); SetMat("TOPBODY", TOPBODY, mat, ""); TOPBODY.transform.SetParent(BASE.transform); FACETOP = GameObject.CreatePrimitive(PrimitiveType.Quad); SetMat("FACETOP", FACETOP, matW, "WADB" + Ns); FACETOP.transform.position = new Vector3(0, hp + 0.6f, 0); FACETOP.transform.localScale = new Vector3(w, D, 1); FACETOP.transform.localRotation = Quaternion.Euler(90, 0, 0); FACETOP.transform.SetParent(BASE.transform); hp = H / 2 - hh / 2; HEAD = CreateMcx("HEAD", w, hh, 2, 0, hp, D / 2 - 1f, 0, 0, 0); SetMat("HEAD", HEAD, mat, ""); HEAD.transform.SetParent(BASE.transform); FACEHEAD = GameObject.CreatePrimitive(PrimitiveType.Quad); SetMat("FACEHEAD", FACEHEAD, matW, "WADC" + Ns); FACEHEAD.transform.position = new Vector3(0, hp, D / 2 - 2.1f); FACEHEAD.transform.localScale = new Vector3(w, hh, 1); FACEHEAD.transform.SetParent(BASE.transform); } if (new List { "103","104","105","106","107","108","109", "112","113","114","115","116","117","118", "121","122","123","124","125","126","127"}.Contains(C[1][4..])) { w = W; h = H - hf; hp = hf / 2; BODY = CreateMcx("BODY", w, h, D, 0, hp, 0, 0, 0, 0); SetMat("BODY", BODY, mat, ""); BODY.transform.SetParent(BASE.transform); FACE.transform.localScale = new Vector3(w, h, 1); FACE.transform.position = new Vector3(0, hp, -D / 2 - 0.1f); FACE.transform.SetParent(BASE.transform); } //LEG AddLeg("L1", BASE, -W / 2 + 1, -H / 2 + 0.5f, -D / 2 + 2); AddLeg("L2", BASE, -W / 2 + 1, -H / 2 + 0.5f, D / 2 - 2); AddLeg("L3", BASE, W / 2 - 1, -H / 2 + 0.5f, D / 2 - 2); AddLeg("L4", BASE, W / 2 - 1, -H / 2 + 0.5f, -D / 2 + 2); //SPLASH DOBS.SplashC(BASE, C[55], W, H, D, C[54]); //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); Mesure.Addpoints("BASE",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 = _G.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) { 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 = _G.MATGREY;//Resources.Load("MATERIALS/ST") as Material; //obj.GetComponent().material.color = Color.grey; //obj.GetComponent().material.mainTextureScale = new Vector2(sx / 12f, sy / 12f); //obj.GetComponent().probeAnchor = GameObject.Find("Reflection Stainless").transform; 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); } public static void AddLeg(string name, GameObject B, float xp, float hp, float zp) { GameObject L1 = GameObject.CreatePrimitive(PrimitiveType.Cube);//new GameObject(); L1.name = name; L1.transform.localScale = new Vector3(1, 1, 1); L1.transform.position = new Vector3(xp, hp, zp); L1.gameObject.GetComponent().material = UIT_MATERIAL.GetMaterial("444444_Matt"); L1.transform.SetParent(B.transform); } public static void SetMat(string Name, GameObject O, Material mat, string path) { O.name = Name; O.GetComponent().material = mat; O.GetComponent().probeAnchor = GameObject.Find("Reflection Probe").transform; O.GetComponent().reflectionProbeUsage = UnityEngine.Rendering.ReflectionProbeUsage.Simple; if (path.IndexOf("WADA") != -1) { Addressables.LoadAssetAsync(path).Completed += faceA_Completed; } if (path.IndexOf("WADB") != -1) { Addressables.LoadAssetAsync(path).Completed += faceB_Completed; } if (path.IndexOf("WADC") != -1) { Addressables.LoadAssetAsync(path).Completed += faceC_Completed; } O.tag = "unhit"; } private static void faceA_Completed(AsyncOperationHandle handleA) { if (handleA.Status == AsyncOperationStatus.Succeeded) { Texture2D result = handleA.Result; FACE.gameObject.GetComponent().material.mainTexture = result; } } private static void faceB_Completed(AsyncOperationHandle handleB) { if (handleB.Status == AsyncOperationStatus.Succeeded) { Texture2D result = handleB.Result; FACETOP.gameObject.GetComponent().material.mainTexture = result; } } private static void faceC_Completed(AsyncOperationHandle handleC) { if (handleC.Status == AsyncOperationStatus.Succeeded) { Texture2D result = handleC.Result; FACEHEAD.gameObject.GetComponent().material.mainTexture = result; } } }