using System.Collections.Generic; using MS_Outline; using Unity.VisualScripting; using UnityEngine; using UnityEngine.AddressableAssets; using UnityEngine.InputSystem.LowLevel; using UnityEngine.ResourceManagement.AsyncOperations; public class ConstructLamp : MonoBehaviour { // L'instanciation est ASYNCHRONE : plusieurs lampes peuvent être en cours de chargement en même // temps (AI : lampe évier puis spots de plafond ; chargement d'un design : toutes les lampes d'un // coup). L'index, le modèle chargé et le drapeau FromAI sont donc capturés PAR APPEL — avec des // statiques partagées, la dernière demande écrasait les précédentes et toutes les lampes // atterrissaient à la position de la dernière. public static void AddLamp(int NO) { _G.Load = false; //GameObject.Find("HIDER").transform.Find("LoadingCircle").gameObject.SetActive(true); int nO = NO; bool fromAI = _G.SC != null && _G.SC[100] == "FromAI"; Addressables.InstantiateAsync(_G.OBJs[nO][1]).Completed += handle => { if (handle.Status != AsyncOperationStatus.Succeeded) { Debug.LogError("[ConstructLamp] Chargement de " + _G.OBJs[nO][1] + " échoué."); _G.Load = true; return; } AddLampPaint(nO, handle.Result, fromAI); GameObject.Find("HIDER").transform.Find("LoadingCircle").gameObject.SetActive(false); _G.Load = true; }; } static void AddLampPaint(int nO, GameObject Lamp, bool fromAI) { 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]); print("C[60]======"+C[60]); // if(fromAI) { // C[60]="333333_glossy_none"; // C[61]="333333_glossy_none"; // } 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; child.AddComponent(); child.GetComponent().GlowIntensity=12; child.tag = "Glow"; } if(child.name.IndexOf("Glass")!=-1){ child.GetComponent().sharedMaterial=_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; } if(child.name.IndexOf("Candle")!=-1){ child.GetComponent().material=Mat1; child.GetComponent().shadowCastingMode = 0; } } } Mesure.Addpoints("LAMP",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; // Pas d'ombres sur les suspensions : chaque spot qui projette occupe une case de // l'atlas d'ombres des lumieres additionnelles (2048 dans Ultra_PipelineAsset). Des // deux suspensions, URP divisait la resolution par 4 pour les faire tenir et le // prevenait par un avertissement a chaque frame. Ces lampes sont des lumieres // d'ambiance : l'ombrage de la piece vient du soleil et du plafonnier. lightGameObject.GetComponent().shadows = LightShadows.None; 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; } }