using System.Collections.Generic; using UnityEditor; using UnityEngine; using UnityEngine.AddressableAssets; using UnityEngine.ResourceManagement.AsyncOperations; public class ConstructLamp : MonoBehaviour { static GameObject Lamp; static int nO; public static void AddLamp(int NO) { _G.Load = false; //GameObject.Find("HIDER").transform.Find("LoadingCircle").gameObject.SetActive(true); nO = NO; Addressables.InstantiateAsync(_G.OBJs[nO][1]).Completed += face_Completed; } public static void AddLampPaint() { 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 Mat1=UIT_MATERIAL.GetMaterial(C[60]); Material Mat2=UIT_MATERIAL.GetMaterial(C[61]); //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 = SceneModeManager.Scene; //Model //GameObject S = Instantiate(Resources.Load("OBJECTS/LAMP/" + C[1], typeof(GameObject))) as GameObject; Lamp.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")); Lamp.transform.localScale = new Vector3(w / sw, h / sh, d / sd); Lamp.name = "S1"; Lamp.transform.parent = BASE.transform; if(C[0].IndexOf("lamp")!=-1) { foreach(Transform child in Lamp.transform) { if(child.name.IndexOf("_C1")!=-1){ child.GetComponent().material=Mat1; child.GetComponent().probeAnchor = GameObject.Find("Reflection Probe").transform; child.GetComponent().shadowCastingMode = 0; } if(child.name.IndexOf("_C2")!=-1){ child.GetComponent().material=Mat2; child.GetComponent().probeAnchor = GameObject.Find("Reflection Probe").transform; child.GetComponent().shadowCastingMode = 0; } if(child.name.IndexOf("Bulp")!=-1 || child.name.IndexOf("bulp" )!=-1 || child.name.IndexOf("bulb" )!=-1 || child.name.IndexOf("Bulb")!=-1 || child.name.IndexOf("Bukp")!=-1){ child.GetComponent().material=_G.GLOW; child.GetComponent().shadowCastingMode = 0; } if(child.name.IndexOf("Glass")!=-1){ child.GetComponent().material=_G.GLASS; child.GetComponent().shadowCastingMode = 0; } // if(child.name=="S1"){ // if(child.Find("Bukp")){ // child.Find("Bukp").gameObject.GetComponent().material=_G.GLOW; // child.GetComponent().shadowCastingMode = 0; // } // } if(child.name.IndexOf("Frame")!=-1){ child.GetComponent().material=Mat1; child.GetComponent().shadowCastingMode = 0; } } } Mesure.Addpoints("BASE",BASE); //ADD SpotLIGHT List LampWithSopt = new() { "101" ,"102","103","105","109","111","114","115","116","119","120","122","123"}; if(LampWithSopt.Contains(C[1][4..])){ //ADD LIGHT GameObject lightGameObject = new("LampSpotLight"){tag = "LampSpotLight"}; lightGameObject.AddComponent(); lightGameObject.transform.localRotation = Quaternion.Euler(90, 0, 0); lightGameObject.transform.position = new Vector3(0, -h / 2 -1, 0); lightGameObject.transform.parent = BASE.transform; lightGameObject.GetComponent().type = LightType.Spot; lightGameObject.GetComponent().intensity =250;//_G.LightSetting["LampSpotIntensity"]; lightGameObject.GetComponent().spotAngle = 120; lightGameObject.GetComponent().range = 120; lightGameObject.GetComponent().renderMode = LightRenderMode.ForcePixel; lightGameObject.GetComponent().shadows = LightShadows.Hard; lightGameObject.GetComponent().enabled = true; lightGameObject.name="LampSpotLight"; } //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; BASE.GetComponent().shadowCastingMode = 0; } private static void face_Completed(AsyncOperationHandle handle) { if (handle.Status == AsyncOperationStatus.Succeeded) { Lamp = handle.Result; AddLampPaint(); GameObject.Find("HIDER").transform.Find("LoadingCircle").gameObject.SetActive(false); _G.Load = true; } } }