using System.Reflection.Emit; using System.Runtime.InteropServices.WindowsRuntime; using UnityEngine; using UnityEngine.AddressableAssets; using UnityEngine.ResourceManagement.AsyncOperations; public class ConstructVase : MonoBehaviour { static GameObject S; static int nO; static GameObject BASE; static Material MatA; static Material MatB; static float w,h,d,px,py,pz,rx,ry,rz,sw,sh,sd,w2,h2,d2,BASE_W,BASE_H,BASE_D; static string Model_Vase; static string Model_Plant; public static void AddVase(int NO) { _G.Load = false; nO = NO; BASE = GameObject.CreatePrimitive(PrimitiveType.Cube);//new GameObject(); string[] C = _G.OBJs[nO]; print("_G.Load=nO=="+nO); print("Vase c1==="+C[1]);//Vase c1===KUI-W1236-11GL if(C[1].IndexOf("VASE")!=-1){ Model_Vase=C[1].Split("?")[0]; Model_Plant=C[1].Split("?")[1]; w = DOIT.ConvertStringToNumber(C[6]); h = DOIT.ConvertStringToNumber(C[7]); d = DOIT.ConvertStringToNumber(C[8]); w2 = DOIT.ConvertStringToNumber(C[36]); h2 = DOIT.ConvertStringToNumber(C[37]); d2= DOIT.ConvertStringToNumber(C[38]); px = DOIT.ConvertStringToNumber(C[15]); py = DOIT.ConvertStringToNumber(C[16]); pz = DOIT.ConvertStringToNumber(C[17]); rx = DOIT.ConvertStringToNumber(C[18]); ry = DOIT.ConvertStringToNumber(C[19]); rz = DOIT.ConvertStringToNumber(C[20]); sw = DOIT.ConvertStringToNumber(_OL.GetValue(Model_Vase,"w")); sh = DOIT.ConvertStringToNumber(_OL.GetValue(Model_Vase,"h")); sd = DOIT.ConvertStringToNumber(_OL.GetValue(Model_Vase,"d")); BASE_W=Mathf.Max(w,w2); BASE_H=h+h2; BASE_D=Mathf.Max(d,d2); BASE.name = C[0]; BASE.transform.localScale = new Vector3(BASE_W + 0.5f, BASE_H + 0.5f, BASE_D + 0.5f); print("C[60]===="+C[60]); MatA=UIT_MATERIAL.GetMaterial(C[60]); //MatA.SetFloat("_cull",2); //int m_CullId = Shader.PropertyToID("_Cull"); MatA.SetFloat("_Cull",0); // int m_CullId = Shader.PropertyToID("_Cull"); // MatA.SetInteger(m_CullId , 2); //MatA.EnableKeyword("_CULLINGMODE_Off"); //MatB=UIT_MATERIAL.GetMaterial(C[61]); Addressables.InstantiateAsync(Model_Vase).Completed += Vase_Completed; } } public static void AddVasePaint() { S.transform.localPosition= new(0,-BASE_H*0.5f+h*0.5f ,0); S.transform.localScale = new Vector3(w / sw, h / sh, d / sd); S.name = "S1_"+Model_Vase; S.transform.SetParent(BASE.transform); S.GetComponent().material=MatA; S.GetComponent().probeAnchor = GameObject.Find("Reflection Probe").transform; } private static void Vase_Completed(AsyncOperationHandle handle) { if (handle.Status == AsyncOperationStatus.Succeeded) { S = handle.Result; AddVasePaint(); //print("Model_Plant===="+Model_Plant); if(Model_Plant!="FLOW100"){ //Addressables.InstantiateAsync(Model_Plant).Completed += Plant_Completed_Flower; AddFlower(); } else{ SetinScene(); } } } private static void AddFlower(){ //print("Model_Plant===="+Model_Plant); GameObject Flower=Instantiate(Resources.Load("OBJECTS/FLOW/"+Model_Plant)); Flower.name="Flower101"; sw = DOIT.ConvertStringToNumber(_OL.GetValue(Model_Plant,"w")); sh = DOIT.ConvertStringToNumber(_OL.GetValue(Model_Plant,"h")); sd = DOIT.ConvertStringToNumber(_OL.GetValue(Model_Plant,"d")); Flower.transform.localScale = new Vector3(w2 / sw, h2 / sh, d2 / sd); //float scale = (w+d)/24; Flower.transform.position=new(0,BASE_H*0.5f-h2*0.5f ,0); //Flower.transform.localScale=new(1, 1,1); Flower.transform.SetParent(BASE.transform); SetinScene(); } private static void Plant_Completed_Flower(AsyncOperationHandle handle) { if (handle.Status == AsyncOperationStatus.Succeeded) { float plantsw = DOIT.ConvertStringToNumber(_OL.GetValue(Model_Plant,"w")); float plantsh = DOIT.ConvertStringToNumber(_OL.GetValue(Model_Plant,"h")); float plantsd = DOIT.ConvertStringToNumber(_OL.GetValue(Model_Plant,"d")); GameObject Flower=handle.Result; //Material[] materials = new Material[2]; //Flower.GetComponent().material=MatA; //Flower.transform.localScale = new Vector3(w / plantsw, h / plantsh , d / plantsd ); Flower.transform.localScale = new Vector3(2, 2, 2); Flower.transform.position=new(0, h*0.5f,0); Flower.transform.SetParent(BASE.transform); SetinScene(); } } public static void SetinScene(){ 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.transform.parent = GameObject.Find("SCENE").transform; Mesure.Addpoints("BASE",BASE); _G.Load = true; } }