using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.ResourceManagement.AsyncOperations; using UnityEngine.AddressableAssets; public class ConstructMirror : MonoBehaviour { static GameObject S; static int nO; public static void AddMirror(int NO) { //print("CONTRUCT MIRRORS__________________________________________________________" + nO); nO = NO; string[] C = _G.OBJs[nO]; C[1] =C[1] .Replace("MIRD","MIRR"); if (C[1] == "MIRR105") { LoadObject3D("MIRD105"); } else { float w = DOIT.ConvertStringToNumber(C[6]); float h = DOIT.ConvertStringToNumber(C[7]); float d = DOIT.ConvertStringToNumber(C[8]); float e = DOIT.ConvertStringToNumber(C[11]); 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 c = C[61]; //create BASE GameObject BASE = GameObject.CreatePrimitive(PrimitiveType.Cube);//new GameObject(); BASE.transform.localScale = new Vector3(w + 0.5f, h + 0.5f, d + 2f); BASE.name = _G.OBJs[nO][0]; BASE.transform.SetParent(GameObject.Find("SCENE").transform); GameObject Mirror = new("Mirror"); //print("C[1]=="+C[1]); Material MatA=UIT_MATERIAL.GetMaterial(C[60]); //Model DECO if (C[1] == "MIRR101") { GameObject M = GameObject.CreatePrimitive(PrimitiveType.Cube); M.transform.localScale = new Vector3(w, h, d); M.name = "T1"; M.transform.SetParent(Mirror.transform); M.transform.localRotation = Quaternion.Euler(0, 180, 0); M.GetComponent().material = _G.MIRROR; } if (C[1] == "MIRR102") { GameObject M = GameObject.CreatePrimitive(PrimitiveType.Cylinder); M.transform.localScale = new Vector3(w, d, h); M.name = "T1"; M.transform.SetParent(Mirror.transform); M.transform.localRotation = Quaternion.Euler(90, 0, 0); M.GetComponent().material = _G.MIRROR; } if (C[1] == "MIRR103") { GameObject M = GameObject.CreatePrimitive(PrimitiveType.Cube); M.transform.localScale = new Vector3(w - e * 2, h - e * 2, d); M.name = "MF"; M.transform.SetParent(Mirror.transform); M.transform.localRotation = Quaternion.Euler(0, 180, 0); M.GetComponent().material = _G.MIRROR; GameObject MB = GameObject.CreatePrimitive(PrimitiveType.Cube); MB.transform.localScale = new Vector3(w, h, d / 2); MB.name = "MB"; MB.transform.SetParent(Mirror.transform); MB.transform.localRotation = Quaternion.Euler(0, 180, 0); MB.GetComponent().material = MatA;//new Material(Shader.Find("Universal Render Pipeline/Lit")); //MB.GetComponent().material.color = DOIT.CSc(C[61], 100); } if (C[1] == "MIRR104") { GameObject M = GameObject.CreatePrimitive(PrimitiveType.Cylinder); M.transform.localScale = new Vector3(w - e * 2, d, h - e * 2); M.name = "MF"; M.transform.SetParent(Mirror.transform); M.transform.localRotation = Quaternion.Euler(90, 0, 0); M.GetComponent().material = _G.MIRROR; M.GetComponent().probeAnchor = GameObject.Find("Reflection Probe").transform; GameObject MB = GameObject.CreatePrimitive(PrimitiveType.Cylinder); MB.transform.localScale = new Vector3(w, d / 2, h); MB.name = "MB"; MB.transform.SetParent(Mirror.transform); MB.transform.localRotation = Quaternion.Euler(90, 0, 0); MB.GetComponent().material = MatA;// new Material(Shader.Find("Universal Render Pipeline/Lit")); MB.GetComponent().probeAnchor = GameObject.Find("Reflection Probe").transform; //MB.GetComponent().material.color = DOIT.CSc(C[61], 100); } //RigidBody BASE.AddComponent(); BASE.GetComponent().useGravity = false; BASE.GetComponent().isKinematic = true; BASE.GetComponent().detectCollisions = true; BASE.GetComponent().isTrigger = true; Mirror.transform.SetParent(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; } } public static void LoadObject3D(string Objectname) { print("----NEW MIRRIR-----"); _G.Load = false; GameObject.Find("HIDER").transform.Find("LoadingCircle").gameObject.SetActive(true); //nO=NO; Addressables.InstantiateAsync(Objectname).Completed += face_Completed; } public static void AddMirrorPaint() { 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]); Material MatA=UIT_MATERIAL.GetMaterial(C[60]); //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")); //Model //GameObject S = Instantiate(Resources.Load("OBJECTS/MIRROR/" + C[1], typeof(GameObject))) as GameObject; S.transform.localRotation = Quaternion.Euler(0, 0, 0); float sw = DOIT.ConvertStringToNumber(_OL.GetValue(C[1],"w")); float sh = DOIT.ConvertStringToNumber(_OL.GetValue(C[1],"h")); float sd = DOIT.ConvertStringToNumber(_OL.GetValue(C[1],"d")); S.transform.localScale = new Vector3(w / sw, h / sh, d / sd); S.name = "S1"; S.transform.parent = BASE.transform; GameObject c1 = BASE.transform.Find("S1").transform.Find("C1").gameObject; GameObject c2 = BASE.transform.Find("S1").transform.Find("C2").gameObject; for (int i = 0; i < c1.transform.childCount; i++) { c1.transform.GetChild(i).GetComponent().material= _G.MIRROR; c1.transform.GetChild(i).GetComponent().probeAnchor = GameObject.Find("Reflection Stainless").transform; } for (int i = 0; i < c2.transform.childCount; i++) { c2.transform.GetChild(i).GetComponent().material = MatA; //c3.transform.GetChild(i).GetComponent().probeAnchor = GameObject.Find("Reflection Stainless").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; } private static void face_Completed(AsyncOperationHandle handle) { if (handle.Status == AsyncOperationStatus.Succeeded) { S = handle.Result; AddMirrorPaint(); GameObject.Find("HIDER").transform.Find("LoadingCircle").gameObject.SetActive(false); _G.Load = true; } } }