using UnityEngine.UI; using UnityEngine; using UnityEngine.EventSystems; using System.Collections; using System.Net; using System.Net.Sockets; using UnityEngine.Networking; using System.Text; using System.Globalization; using TMPro; using System.Collections.Generic; using System; using System.Threading; public class MenuScript : MonoBehaviour { public delegate void MobileDetected(bool isMobile); public MobileDetected _OnMobileDetected; AutoRotate _autoRotate; [HideInInspector] public GameObject Pnl_plan2d; [HideInInspector] public GameObject Pnl_start; [HideInInspector] public GameObject Pnl_scene; [HideInInspector] public GameObject MainPnl; [SerializeField, HideInInspector] GameObject _touchInputPanel; [SerializeField] Paths _path = Paths.Ukitchenit; [SerializeField] GameObject _mobileWarningPanel; public static float timeKeyHold = 0; public static float timePassed = 0; public GameObject SUN; //[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)] // -------------------- NEW: debounce refresh (remplace Update timer) -------------------- private bool _refreshPending = false; private const float REFRESH_DELAY = 0.05f; private void Awake() { // CultureInfo.DefaultThreadCurrentCulture = CultureInfo.InvariantCulture; // CultureInfo.DefaultThreadCurrentUICulture = CultureInfo.InvariantCulture; // System.Threading.Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture; //Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture; //Thread.CurrentThread.CurrentUICulture = CultureInfo.InvariantCulture; CultureInfo invariant = CultureInfo.InvariantCulture; Thread.CurrentThread.CurrentCulture = invariant; Thread.CurrentThread.CurrentUICulture = invariant; //Debug.Log("[CultureFix] Culture forcée en InvariantCulture"); SetVersionNumberFromProjectSettings(); _autoRotate = Camera.main.GetComponent(); SetFrameRate(); _touchInputPanel.SetActive(false); // Application.logMessageReceived += (condition, stackTrace, type) => { // if (type == LogType.Exception) // Debug.LogError($"EXCEPTION: {condition}\n{stackTrace}"); // }; } // -------------------- NEW: subscribe global event + refresh on enable -------------------- void OnEnable() { UIEvents.RefreshRequested += RefreshUI_Deferred; // Optionnel debug UIEvents.RefreshRequestedBy += OnRefreshReason; // Quand l'objet devient actif => refresh UIEvents.RequestRefresh("MenuScript OnEnable"); } void OnDisable() { UIEvents.RefreshRequested -= RefreshUI_Deferred; UIEvents.RefreshRequestedBy -= OnRefreshReason; // sécurité: annuler invoke si désactivé CancelInvoke(nameof(DoRefresh)); _refreshPending = false; } void OnRefreshReason(string reason) { // Tu peux commenter si trop de logs //Debug.Log("[UI Refresh] " + reason); } public void Start() { #if UNITY_WEBGL // On teste l'URL SANS la valeur fournie par l'utilisateur (courriel de ?mt_ / ?ai_ / _savefromai) : // "hb3d63@gmail.com" contient "3d" et declenchait la redirection, ce qui empechait // l'ouverture automatique du fichier sur https://ukitchenit.com/free/?mt_... string urlToCheck = UrlWithoutUserValues(Application.absoluteURL); if (urlToCheck.IndexOf("free") != -1 && urlToCheck.IndexOf("3d") != -1 || urlToCheck.IndexOf("Free") != -1 && urlToCheck.IndexOf("sd") != -1) { Link.OpenWindow("free", "https://ukitchenit.com/free/"); return; } #endif Application.targetFrameRate = -1; SceneModeManager.Instance.SetSceneModeVisibility(); ReadURL.Path(); CheckForPath(); WaitCircle.Setting(true, TRANS.This("M_Download")); if (Camera.main != null) Camera.main.targetTexture = null; _G.PATH = _G.PATH.ToLower(); Load_G(); _G.OBJs[299] = new string[100]; _G.OBJs[299][0] = "null"; _G.OBJs[299][1] = "null"; DOIT.CloseALLPNL(); Pnl_start.SetActive(true); Pnl_scene.SetActive(false); // Le worker de rendu n'existe que sur la version Windows : masquer le bouton ailleurs (WebGL). GameObject btnRenderServer = Get.o2("HIDER", "BtnRenderServer"); if (btnRenderServer != null) { bool isWindows = Application.platform == RuntimePlatform.WindowsPlayer || Application.platform == RuntimePlatform.WindowsEditor; btnRenderServer.SetActive(isWindows); } UIEvents.RequestRefresh("Start init"); for (int i = 1; i < 25; i++) { _G.WallsMaterial[i - 1] = _G.GYPSE; _G.WallsTexture[i - 1] = "GypseHorizontal"; } _G.ceilm = _G.GYPSECEIL; _G.ceilt = "GypseHorizontal"; SceneModeManager.Instance.SetSceneMode(SceneModes.Start); UIT_LoadLibrary.Load(); Get.o2("HIDER", "Login").SetActive(false); Get.o2("Canvas", "PATH").GetComponent().text = _G.PATH; DASH.HDset(false); Get.o2("Canvas/Panel_main", "TEMPLATE").SetActive(_G.PATH == "laminam"); //Get.o2("Canvas", "PATH").GetComponent().text = Application.absoluteURL; if (Application.absoluteURL.Contains("?mt_")) { Get.o2("Canvas", "PATH").GetComponent().text = Application.absoluteURL; Load_WEB.OpenFileMT(Application.absoluteURL); } if (Application.absoluteURL.Contains("?ai_")) { Get.o2("Canvas", "PATH").GetComponent().text = Application.absoluteURL; _G.FlieCategory="ai"; Load_WEB.OpenFileAI(Application.absoluteURL); } // Lien email du design AI : ...3d?{PATH}?{email}_savefromai -> ouvre le fichier automatiquement. // ("_savefromai" sans '?' devant : le nom de fichier précède le suffixe dans l'URL.) if (Application.absoluteURL.Contains("_savefromai")) { Get.o2("Canvas", "PATH").GetComponent().text = Application.absoluteURL; Load_WEB.OpenFileSaveFromAI(Application.absoluteURL); } Set.GlobalColorAndTranslate(); //Get.o1("Global Volume").SetActive(false);// StartCoroutine(InitHDToLow()); } // Retire de l'URL la valeur fournie par l'utilisateur (le courriel qui suit ?mt_, ?ai_ // ou qui precede _savefromai) avant tout test de mots-cles sur l'URL. private static string UrlWithoutUserValues(string url) { if (string.IsNullOrEmpty(url)) return ""; int cut = url.IndexOf("?mt_"); if (cut == -1) cut = url.IndexOf("?ai_"); if (cut == -1 && url.Contains("_savefromai")) cut = url.LastIndexOf('?'); return cut == -1 ? url : url.Substring(0, cut); } private IEnumerator InitHDToLow() { yield return new WaitForEndOfFrame(); _G.HD = false; // ensure correct initial state for HD button toggle } private void SetVersionNumberFromProjectSettings() { _G.VER = Application.version; } private static void SetFrameRate() { #if !UNITY_EDITOR && UNITY_WEBGL Debug.Log("This is a WebGL build"); _G.IsEditor = false; Application.targetFrameRate = -1; Get.o2("Canvas/Language", "Adminbtn").SetActive(false); #endif #if UNITY_EDITOR //Debug.Log("This is the Unity Editor build"); _G.IsEditor = true; QualitySettings.vSyncCount = 0; //Application.targetFrameRate = -1; Application.targetFrameRate = 60; QualitySettings.vSyncCount = 0; Get.o2("Canvas/Language", "Adminbtn").SetActive(true); #endif #if UNITY_STANDALONE _G.IsEditor = false; Debug.Log("This is a standalone build"); QualitySettings.vSyncCount = 0; Application.targetFrameRate = -1; #endif #if UNITY_ANDROID _G.IsEditor = false; Debug.Log("This is an Android build"); Application.targetFrameRate = -1; #endif #if UNITY_IOS _G.IsEditor = false; Debug.Log("This is an iOS build"); Application.targetFrameRate = -1; #endif } void CheckForPath() { if (!string.IsNullOrEmpty(_G.PATH)) return; Paths path = _path; if (!_G._Paths.ContainsKey(path)) { Debug.Log("No path defined in _G for " + path.ToString()); return; } _G.PATH = _G._Paths[path]; } void Update() { // if (Camera.main?.targetTexture != null) // Debug.LogWarning($"⚠️ Camera.main.targetTexture != null : {Camera.main.targetTexture.name}"); bool isMouseInsideScreenBoundaries = MouseCheck.InOut(); if (isMouseInsideScreenBoundaries == false && !SceneModeManager.CompareSceneMode(SceneModes.MouseOut)) { SceneModeManager.Instance.OnMouseOut(); } if (isMouseInsideScreenBoundaries && !SceneModeManager.CompareSceneMode(SceneModes.MouseOut)) { bool isPanal = Get.o2("Canvas", "Panel_SCENE").activeInHierarchy; if (!EventSystem.current.IsPointerOverGameObject() && !SceneModeManager.CompareSceneMode(SceneModes.Plan2D) && isPanal) { HitObject.CheckHIT(); } GameObject newEmptyGameObject = GameObject.Find("New Game Object"); if (newEmptyGameObject) {Destroy(newEmptyGameObject);} if (!SceneModeManager.CompareSceneMode(SceneModes.Plan2D) && !SceneModeManager.CompareSceneMode(SceneModes.ShowTips) && !SceneModeManager.CompareSceneMode(SceneModes.CounterView) && !SceneModeManager.CompareSceneMode(SceneModes.ZoomTouch) && !SceneModeManager.CompareSceneMode(SceneModes.Ai)) { GameObject[] MENU = GameObject.FindGameObjectsWithTag("Menu"); GameObject[] PNL = GameObject.FindGameObjectsWithTag("pnl"); if (MENU.Length != 0 || PNL.Length != 0 || _G.NAVIGATE == false) { if (!_G.LockInState) { if (SceneModeManager.CompareSceneMode(SceneModes.Navigate) || _G.NAVIGATE == false) { if (!SceneModeManager.CompareSceneMode(SceneModes.Paint) && !SceneModeManager.CompareSceneMode(SceneModes.Measure) && !SceneModeManager.CompareSceneMode(SceneModes.Align) && !SceneModeManager.CompareSceneMode(SceneModes.Plan2D) && !SceneModeManager.CompareSceneMode(SceneModes.GroupMove) && !SceneModeManager.CompareSceneMode(SceneModes.Move) && !SceneModeManager.CompareSceneMode(SceneModes.Hit) && !SceneModeManager.CompareSceneMode(SceneModes.Duplicate) && !SceneModeManager.CompareSceneMode(SceneModes.ReadyMove)) { SceneModeManager.Instance.SetSceneMode(SceneModes.Panel); } } } } else { SceneModeManager.Instance.SetSceneMode(SceneModes.Navigate); } } } HandleKeyboardInput(); for (int i = 0; i < _G.HIDELIST.Count; i++) { GameObject go = GameObject.Find(_G.HIDELIST[i]); if (go != null) go.SetActive(false); } _G.NAVIGATE = true; if (!SceneModeManager.CompareSceneMode(SceneModes.CounterView) && !SceneModeManager.CompareSceneMode(SceneModes.Plan2D) && !SceneModeManager.CompareSceneMode(SceneModes.Calcule)) { if (_G.HD == true) { SUN.SetActive(SelectLight.OpenOnScene()); } } if (isMouseInsideScreenBoundaries && SceneModeManager.CompareSceneMode(SceneModes.MouseOut)) { SceneModeManager.Instance.OnMouseIn(); } if(SceneModeManager.Selected!=null){ if(timeKeyHold==0 || timeKeyHold>30){ GameObject sel = SceneModeManager.Selected; int nO = Get.GetObjectIndex(SceneModeManager.SelectedName); if(!Input.GetKey(KeyCode.LeftShift) && !Input.GetKey(KeyCode.RightShift) ) { Vector3 SelPosition=sel.transform.position; float CamY=Camera.main.transform.eulerAngles.y; //print("CamY===="+CamY); float X = 0; float Z = 0; float Y = 0; if(_G.OBJs[nO][22]=="floor"){ if(CamY>315 || CamY<45){ if (Input.GetKey(KeyCode.DownArrow))Z-=1; else if (Input.GetKey(KeyCode.LeftArrow))X-=1; else if (Input.GetKey(KeyCode.RightArrow))X+=1; else if (Input.GetKey(KeyCode.UpArrow))Z+=1;; } if(CamY<=315 && CamY>=225){ if (Input.GetKey(KeyCode.DownArrow))X+=1; else if (Input.GetKey(KeyCode.LeftArrow))Z-=1; else if (Input.GetKey(KeyCode.RightArrow))Z+=1; else if (Input.GetKey(KeyCode.UpArrow))X-=1; } if(CamY<225 && CamY>135){ if (Input.GetKey(KeyCode.DownArrow))Z+=1; else if (Input.GetKey(KeyCode.LeftArrow))X+=1; else if (Input.GetKey(KeyCode.RightArrow))X-=1; else if (Input.GetKey(KeyCode.UpArrow))Z-=1; } if(CamY<=135 && CamY>=45){ if (Input.GetKey(KeyCode.DownArrow))X-=1; else if (Input.GetKey(KeyCode.LeftArrow))Z+=1; else if (Input.GetKey(KeyCode.RightArrow))Z-=1; else if (Input.GetKey(KeyCode.UpArrow))X+=1; } sel.transform.position=new(SelPosition.x+X,SelPosition.y+Y,SelPosition.z+Z); } if(_G.OBJs[nO][22]!="floor"){ if (Input.GetKey(KeyCode.LeftArrow)) {sel.transform.position-=sel.transform.right;} if (Input.GetKey(KeyCode.RightArrow)){sel.transform.position+=sel.transform.right;} if (Input.GetKey(KeyCode.DownArrow)){sel.transform.position-=sel.transform.forward;} if (Input.GetKey(KeyCode.UpArrow)) {sel.transform.position+=sel.transform.forward;} } //SceneModeManager.Selected.transform.GetComponent().HandelObjectArrowMove(StartPoint,sel.transform.position,attachedTo.transform); } if(Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift) ) { if(Input.GetKey(KeyCode.DownArrow)){sel.transform.position-=sel.transform.up;} if (Input.GetKey(KeyCode.UpArrow)) {sel.transform.position+=sel.transform.up;} } } } if (Input.GetKey(KeyCode.DownArrow) || Input.GetKey(KeyCode.LeftArrow) || Input.GetKey(KeyCode.RightArrow) || Input.GetKey(KeyCode.UpArrow)){ if(SceneModeManager.Selected!=null){ timeKeyHold+=1; //TopControl.showMesure(); GameObject sel = SceneModeManager.Selected; Vector3 StartPoint=sel.transform.position; int nO = Get.GetObjectIndex(SceneModeManager.SelectedName); sel.transform.GetComponent().HandelObjectArrowMove(StartPoint,sel.transform.position,_G.OBJs[nO][22]); } } } // -------------------- MouseDown => déclenche event global -------------------- void OnMouseDown() { UIEvents.RequestRefresh("OnMouseDown"); } // -------------------- PUBLIC: tu peux appeler ça depuis Button OnClick -------------------- public void RequestRefreshFromUI() { UIEvents.RequestRefresh("UI Button"); } // -------------------- NEW: debounce refresh 0.05s -------------------- public void RefreshUI_Deferred() { if (_refreshPending) return; _refreshPending = true; Invoke(nameof(DoRefresh), REFRESH_DELAY); } void DoRefresh() { _refreshPending = false; Set.GlobalColorAndTranslate(); } // -------------------- Ton refresh original -------------------- // public static void RefreshUI() // { // TRANS.go(); // BTN_Hide.ShowBTNS(); // COLORSET.On(); // ColorSet.Do(); // } //--------------------------------------Setting------------------------------------------------------------------ private void HandleKeyboardInput() { //Return key //if (Input.GetKeyDown(KeyCode.Return)) { if (Get.Active("MESURE")) { MesureChange.Changevalue(); } } if (Input.GetMouseButtonUp(0)){ if (_G.HD == true)ReflectionProbesUpdater.Instance.UpdateProbes(); if(SceneModeManager.CompareSceneMode(SceneModes.MoveHandle) && SceneModeManager.Selected.CompareTag("cabwall")) { //_MOL.SetMolding(); } } if (Input.GetMouseButtonDown(0)) { _OnMobileDetected?.Invoke(false); if(SceneModeManager.CompareSceneMode(SceneModes.Navigate)){Get.o2("HIDER","RightClickMenu").SetActive(false);} } if (Input.touchCount > 0) { //_OnMobileDetected?.Invoke(true); } if (Input.GetKeyDown(KeyCode.Return)) { if (Get.Active("KEYBOARDNUMBER")) { Get.o2("KEYBOARDNUMBER", "btnOK").GetComponent