using System.Collections; using UnityEngine; using UnityEngine.Networking; using System.Text; using System.Collections.Generic; using System.Globalization; using UnityEngine.UIElements.Experimental; using UnityEngine.UI; using System.Linq; public class UIT_LoadLibrary : MonoBehaviour { private static WaitForSeconds _waitForSeconds1 = new WaitForSeconds(1f); public static void Load() { //BackgroundSave.Instance.ValidateRefId(); //print("-------------------------------------------------------------------------UUIIIT LOOADING"); StaticCoroutine.Start(ImportLibrary()); } public static IEnumerator ImportLibrary() { string basepath = "https://ukitchenit.com/members/"; StringBuilder sb = new(basepath); sb.Append(_G.PATH); sb.Append("/start/"); Loadlogo.FileSelected(sb.ToString() + "logo.png"); LoadBG.FileSelected(sb.ToString() + "background.png"); sb.Clear(); sb.Append(basepath); sb.Append(_G.PATH); sb.Append("/library/"); string libraryPath = sb.ToString(); string PriceListnameCSV = "PRICEList.csv"; // Fichiers OBLIGATOIRES if (_G.PATH == "armoiredepot") StaticCoroutine.Start(LoadURL(libraryPath + "CABTEXTUREListNew.csv", "CabTexture")); else StaticCoroutine.Start(LoadURL(libraryPath + "CABTEXTUREList.csv", "CabTexture")); //StaticCoroutine.Start(LoadURL(libraryPath + "CABTEXTUREList.csv", "CabTexture")); StaticCoroutine.Start(LoadURL(libraryPath + "GLOBALSTARTList.csv", "GlobalStart")); StaticCoroutine.Start(LoadURL(libraryPath + "PREFERENCESList.csv", "Preferences")); StaticCoroutine.Start(LoadURL(libraryPath + "SOFTCOLORList.csv", "SoftColor")); if (_G.PATH == "armoiredepot") StaticCoroutine.Start(LoadURL(libraryPath + "DOORListNew.csv", "Door")); else StaticCoroutine.Start(LoadURL(libraryPath + "DOORList.csv", "Door")); StaticCoroutine.Start(LoadURL(libraryPath + "BOXTEXTUREList.csv", "BoxTexture")); StaticCoroutine.Start(LoadURL(libraryPath + "MOLDINGList.csv", "Molding")); StaticCoroutine.Start(LoadURL(libraryPath + "PANELList.csv", "Panel")); StaticCoroutine.Start(LoadURL(libraryPath + "CABINETList.csv", "Cabinet")); // Fichiers OPTIONNELS StaticCoroutine.Start(LoadURLOptional(libraryPath + PriceListnameCSV, "Price")); StaticCoroutine.Start(LoadURLOptional(libraryPath + "STOREList.csv", "Store")); StaticCoroutine.Start(LoadURLOptional(libraryPath + "LEXIQUEList.csv", "Lexique")); StaticCoroutine.Start(LoadURLOptional(libraryPath + "ITEMSList.csv", "Items")); if (_G.PATH == "laminam") StaticCoroutine.Start(LoadURLOptional(libraryPath + "TOPCOUNTERList.csv", "TopCounter")); // Attendre que tous les fichiers soient chargés yield return new WaitUntil(() => IsReady()); // Exécuter directement les coroutines avec yield return yield return Preferences.Members(); yield return LoadLOGO2L(); // MAINTENANT on peut désactiver le cercle de chargement WaitCircle.Setting(false, "From loading"); } #if UNITY_WEBGL && !UNITY_EDITOR public static IEnumerator LoadURL(string url, string library) { url = url + "?" + Random.value.ToString(); using UnityWebRequest www = UnityWebRequest.Get(url); UnityWebRequest.ClearCookieCache(); yield return www.SendWebRequest(); if (www.result != UnityWebRequest.Result.Success) { Debug.LogError($"Error loading {library}: {www.error}"); } else { if (www.downloadHandler.data == null) yield break; string load = BinaryToText(www.downloadHandler.data); string[] loads = load.Split(new char[] { '\n' }); _G.LibraryLoads = new List(); foreach (string line in loads) {string l = line.Replace("/", "|"); _G.LibraryLoads.Add(l); } SetLibrary(loads, library); } yield return new WaitUntil(() => IsReady()); } public static IEnumerator LoadURLOptional(string url, string library) { url = url + "?" + Random.value.ToString(); using UnityWebRequest www = UnityWebRequest.Get(url); UnityWebRequest.ClearCookieCache(); yield return www.SendWebRequest(); if (www.result == UnityWebRequest.Result.Success && www.downloadHandler.data != null) { // Fichier trouvé, on le charge string load = BinaryToText(www.downloadHandler.data); string[] loads = load.Split(new char[] { '\n' }); _G.LibraryLoads = new List(); foreach (string line in loads) { string l = line.Replace("/", "|"); _G.LibraryLoads.Add(l); } SetLibrary(loads, library); Debug.Log($"✓ Loaded optional file: {library}"); } else { // Fichier non trouvé - c'est OK pour un fichier optionnel Debug.Log($"○ Optional file not found (skipped): {library}"); } } #endif #if UNITY_STANDALONE && !UNITY_EDITOR public static IEnumerator LoadURL(string url, string library) { url = url + "?" + Random.value.ToString(CultureInfo.InvariantCulture); using UnityWebRequest www = UnityWebRequest.Get(url); UnityWebRequest.ClearCookieCache(); yield return www.SendWebRequest(); if (www.result != UnityWebRequest.Result.Success) { Debug.LogError($"Error loading {library}: {www.error}"); } else { if (www.downloadHandler.data == null) yield break; string load = BinaryToText(www.downloadHandler.data); string[] loads = load.Split(new char[] { '\n' }); _G.LibraryLoads = new List(); foreach (string line in loads) { string l = line.Replace("/", "|"); _G.LibraryLoads.Add(l); } SetLibrary(loads, library); } } public static IEnumerator LoadURLOptional(string url, string library) { url = url + "?" + Random.value.ToString(CultureInfo.InvariantCulture); using UnityWebRequest www = UnityWebRequest.Get(url); UnityWebRequest.ClearCookieCache(); yield return www.SendWebRequest(); if (www.result == UnityWebRequest.Result.Success && www.downloadHandler.data != null) { // Fichier trouvé, on le charge string load = BinaryToText(www.downloadHandler.data); string[] loads = load.Split(new char[] { '\n' }); _G.LibraryLoads = new List(); foreach (string line in loads) { string l = line.Replace("/", "|"); _G.LibraryLoads.Add(l); } SetLibrary(loads, library); Debug.Log($"✓ Loaded optional file: {library}"); } else { // Fichier non trouvé - c'est OK pour un fichier optionnel Debug.Log($"○ Optional file not found (skipped): {library}"); } } #endif #if UNITY_EDITOR public static IEnumerator LoadURL(string url, string library) { url = url + "?" + Random.value.ToString(CultureInfo.InvariantCulture); using UnityWebRequest www = UnityWebRequest.Get(url); { UnityWebRequest.ClearCookieCache(); yield return www.SendWebRequest(); if (www.result != UnityWebRequest.Result.Success) { Debug.LogError($"Error loading {library}: {www.error} - URL: {url}"); } else { if (www.downloadHandler.data == null) yield break; string load = BinaryToText(www.downloadHandler.data); string[] loads = load.Split(new char[] { '\n' }); _G.LibraryLoads = new List(); foreach (string line in loads) { string l = line.Replace("/", "|"); if (l != "" && l != " ") _G.LibraryLoads.Add(l); } //if(library=="Panel" && _G.PATH=="free"){UkitchenitDIY();} SetLibrary(loads, library); } } } public static IEnumerator LoadURLOptional(string url, string library) { url = url + "?" + Random.value.ToString(CultureInfo.InvariantCulture); using UnityWebRequest www = UnityWebRequest.Get(url); { UnityWebRequest.ClearCookieCache(); yield return www.SendWebRequest(); if (www.result == UnityWebRequest.Result.Success && www.downloadHandler.data != null) { // Fichier trouvé, on le charge string load = BinaryToText(www.downloadHandler.data); string[] loads = load.Split(new char[] { '\n' }); _G.LibraryLoads = new List(); foreach (string line in loads) { string l = line.Replace("/", "|"); if (l != "" && l != " ") _G.LibraryLoads.Add(l); } SetLibrary(loads, library); Debug.Log($"✓ Loaded optional file: {library}"); } else { // Fichier non trouvé - c'est OK pour un fichier optionnel Debug.Log($"○ Optional file not found (skipped): {library}"); } } } #endif public static string BinaryToText(byte[] data) { return System.Text.Encoding.UTF8.GetString(data); } public static void SetLibrary(string[] loads, string library) { List ListLoad = new(loads); switch (library) { case "CabTexture": _G.UIT_LibraryCabTextures = ListLoad; break;//StaticCoroutine.Start(AddYourLibrary()) case "GlobalStart": _G.UIT_LibraryGlobalStart = ListLoad; break; case "Preferences": AddtoDictionaryPreferences(loads); StaticCoroutine.Start(LanguagePreferenceSetting()); break; case "Cabinet": _G.UIT_LibraryCabinets = ListLoad; break; case "BoxTexture": _G.UIT_LibraryBoxTextures = ListLoad; break; case "Door": _G.UIT_LibraryDoors = ListLoad; break; case "Molding": _G.UIT_LibraryMoldings = ListLoad; break; case "Panel": _G.UIT_LibraryPanels = ListLoad; break; case "Price": _G.UIT_LibraryPrices = ListLoad; break; case "Store": _G.UIT_LibraryStores = ListLoad; StaticCoroutine.Start(StoreSelection()); break; case "Items": _G.UIT_LibraryItems = ListLoad; break; case "TopCounter": _G.UIT_LibraryTopCounters = ListLoad; break; case "Lexique": AddtoDictionaryLexique(loads); break; case "SoftColor": _G.UIT_LibrarySoftColors = new List(loads); StaticCoroutine.Start(ColorSetting()); break; default: break; } } public static void AddtoDictionaryPreferences(string[] loads) { for (int i = 0; i < loads.Length; i++) { if (!string.IsNullOrEmpty(loads[i])) { string Key = loads[i].Split(",")[0].Replace(" ", string.Empty); string Value = loads[i].Split(",")[1].Replace(" ", string.Empty); _P.List.Add(Key, Value); } } _P.Listfloat = new(){ {"GLOBAL_QTY" ,DOIT.ConvertStringToNumber(_P.List["GLOBAL_QTY"]) }, {"KICK_HEIGHT" ,DOIT.ConvertStringToNumber(_P.List["KICK_HEIGHT"]) }, {"KICK_FRONT_RETRACTION" ,DOIT.ConvertStringToNumber(_P.List["KICK_FRONT_RETRACTION"]) }, {"COUNTER_HEIGHT" ,DOIT.ConvertStringToNumber(_P.List["COUNTER_HEIGHT"]) }, {"COUNTER_FRONT_PROJECTION" ,DOIT.ConvertStringToNumber(_P.List["COUNTER_FRONT_PROJECTION"]) }, {"DOOR_GAP" ,DOIT.ConvertStringToNumber(_P.List["DOOR_GAP"]) }, {"BASE_HEIGHT" ,DOIT.ConvertStringToNumber(_P.List["BASE_HEIGHT"]) }, {"WALL_HEIGHT" ,DOIT.ConvertStringToNumber(_P.List["WALL_HEIGHT"]) }, {"TALL_HEIGHT" ,DOIT.ConvertStringToNumber(_P.List["TALL_HEIGHT"]) }, {"BASE_DEPTH" ,DOIT.ConvertStringToNumber(_P.List["BASE_DEPTH"]) }, {"WALL_DEPTH" ,DOIT.ConvertStringToNumber(_P.List["WALL_DEPTH"]) }, {"TALL_DEPTH" ,DOIT.ConvertStringToNumber(_P.List["TALL_DEPTH"]) }, }; List Plist = _P.List.Keys.ToList(); for (int i = 0; i < Plist.Count; i++) { if (_P.List[Plist[i]].IndexOf("y") != -1) { _P.ListSwitch.Add(Plist[i], true); } if (_P.List[Plist[i]].IndexOf("n") != -1) { _P.ListSwitch.Add(Plist[i], false); } } StaticCoroutine.Start(Preferences.Members()); } public static void AddtoDictionaryLexique(string[] loads) { for (int i = 0; i < loads.Length; i++) { if (!string.IsNullOrEmpty(loads[i])) { string Key = loads[i].Split(',')[0]; string Value = loads[i].Split(',')[1]; //print(Key+" value===="+Value); _G.Lexique.Add(Key, Value); } } } public static IEnumerator LanguagePreferenceSetting() { yield return new WaitForSeconds(1f); Set.LanguageSelection(); Set.SetSystemMesurePreference(); } public static IEnumerator AddYourLibrary() { yield return new WaitForSeconds(1f); string[] YL = _G.UIT_YourLibrary.Split('_'); for (int i = 0; i < YL.Length; i++) { if (!string.IsNullOrEmpty(YL[i])) { _G.UIT_LibraryCabTextures.Add(YL[i]); } } Restart.SetGlobal123(); yield return null; } public static IEnumerator ColorSetting() { yield return _waitForSeconds1; Global(); yield return null; } public static void Global() { string[] sC = _G.UIT_LibrarySoftColors[1].Split(','); _G.colorBar = DOIT.CSc(sC[1], byte.Parse(sC[2]));//Bar_Color,Bar_Alpha _G.colorButton = DOIT.CSc(sC[3], byte.Parse(sC[4]));//Button_Color,Button_Alpha _G.colorIcon = DOIT.CSc(sC[5], byte.Parse(sC[6]));//Icon_Color,Icon_Alpha _G.colorText = DOIT.CSc(sC[7], byte.Parse(sC[8]));//Icon_Color,Icon_Alpha _G.colorBG = DOIT.CSc(sC[9], byte.Parse(sC[10]));//Text_Color,Text_Alpha _G.Color1 = sC[3]; _G.Color2 = sC[5]; } public static IEnumerator UkitchenitCabinet() { string path = "LibrairyCSV/UIT_CABINETList"; var load = Resources.Load(path); string[] loads = load.text.Split(new char[] { '\n' }); _G.UKITCHENIT_LibraryCabinets = new List(); foreach (string line in loads) { string l = line.Replace("/", "|"); _G.UKITCHENIT_LibraryCabinets.Add(l); } yield return null; } public static IEnumerator StoreSelection() { string StoreName = _G.UIT_LibraryStores[1].Split(',')[0]; if (!string.IsNullOrEmpty(StoreName)) _G.StoreSelect = StoreName; yield return null; } private static bool IsReady() { if (_G.UIT_LibraryCabTextures == null || _G.UIT_LibraryCabTextures.Count == 0) return false; if (_G.UIT_LibraryCabinets == null || _G.UIT_LibraryCabinets.Count == 0) return false; if (_G.UIT_LibraryDoors == null || _G.UIT_LibraryDoors.Count == 0) return false; if (_G.UIT_LibraryMoldings == null || _G.UIT_LibraryMoldings.Count == 0) return false; if (_G.UIT_LibraryPanels == null || _G.UIT_LibraryPanels.Count == 0) return false; if (_G.UIT_LibrarySoftColors == null || _G.UIT_LibrarySoftColors.Count == 0) return false; // if (_G.UIT_LibraryPreferences == null || _G.UIT_LibraryPreferences.Count == 0) // { // Debug.Log("LibraryPreferences is not ready"); // return false; // } if (_G.UIT_LibraryGlobalStart == null || _G.UIT_LibraryGlobalStart.Count == 0) { Debug.Log("LibraryGlobalStart is not ready"); return false; } // if (_G.UIT_LibraryPrices == null || _G.UIT_LibraryPrices.Count == 0) // { // Debug.Log("_G.UIT_LibraryPrices is not ready"); // return false; // } // if (_G.LibraryCounters == null || _G.LibraryCounters.Count == 0) // { // Debug.Log("LibraryCounters is not ready"); // return false; // } // if (_G.LibraryKnobs == null || _G.LibraryKnobs.Count == 0) // { // Debug.Log("LibraryKnobs is not ready"); // return false; // } return true; } public static IEnumerator LoadLOGO2L() { //WaitCircle.Setting(true, TRANS.This("M_Download")); yield return null; if (Get.PreferenceBool("LOGO2")) { string basepath = "https://ukitchenit.com/members/"; string logoUrl = basepath + "/" + _G.PATH + "/start/logo2.png"; // Vérification avec HEAD request using (UnityWebRequest checkWww = UnityWebRequest.Head(logoUrl)) { yield return checkWww.SendWebRequest(); if (checkWww.result == UnityWebRequest.Result.Success) { // Fichier existe, on le charge Set.alpha(Get.o1("logo2"), true); Loadlogo.FileSelected(logoUrl); } else { // Fichier n'existe pas, on log un warning Debug.Log($"○ Logo2 not found (optional): {logoUrl}"); Set.alpha(Get.o1("logo2"), false); } } } yield return null; //WaitCircle.Setting(false, ""); } }