using UnityEngine.UI; using UnityEngine; using System.Text; using System.Collections; public class Autosaving : MonoBehaviour { private static bool _savingInProgress; public static void StartAuto(float seconds = 600f) { Debug.Log("--- autosaving just start ---"); _G.SavingTimer = Mathf.Max(1f, seconds); _G.saving = true; } public static void StopAuto() { Debug.Log("--- autosaving just stop ---"); _G.saving = false; } void Update() { if (!_G.saving) return; // unscaledDeltaTime pour que l’autosave fonctionne même si Time.timeScale change _G.SavingTimer -= Time.unscaledDeltaTime; if (_G.SavingTimer > 0f) return; // pas encore l’heure if (_savingInProgress) return; // déjà en train de sauvegarder StartCoroutine(DoAutosave()); _G.SavingTimer = 600.0f; // relance le compte à rebours } IEnumerator DoAutosave() { _savingInProgress = true; try { byte[] bytes = SaveXML.BuildXmlBytes(); string xmls = Encoding.UTF8.GetString(bytes); // si SendTextToFileBK retourne une IEnumerator/Coroutine yield return StartCoroutine(Save_WEB.SendTextToFileBK(xmls)); } finally { _savingInProgress = false; } } private void PromptUserToSave() { //STRAT if (_G.saving) { if (Get.o2("Panel_SCENE", "DASH")) { Get.o2("HIDER", "MESSAGESAVING").SetActive(true); } //print("-----Message You have to save Show-----"); } //LOCAL if (_G.savingLocal) { Get.o2("PNL", "SAVEpnl").SetActive(true); //print("-----Message SAVEpnl Show-----"); } //WEB if (_G.savingWeb) { Get.o2("PNL", "SAVEWEBpnl").SetActive(true); //emailcheck.CheckEmail(Get.o3("PNL", "SAVEWEBpnl", "InputField")); //print("----Message SAVEWEBpnl Show-----"); } //print("-------tame to save---------"); _G.SavingTimer = 900.0f; } // public void stop_auto() // { // if (this.GetComponent().isOn == true) { _G.saving = false; } // else { _G.saving = true; } // } public void SavingLocal() { if (Get.o1("AutoSaving").GetComponent().isOn == true) _G.savingLocal = true; } public void SavingWeb() { if (Get.o1("AutoSaving").GetComponent().isOn == true) _G.savingWeb = true; } public void stopLocalsaving() { if (this.GetComponent().isOn == true) { _G.savingLocal = true; } else { _G.savingLocal = false; } } public void stopWebsaving() { if (this.GetComponent().isOn == true) { _G.savingWeb = true; } else { _G.savingWeb = false; } } public void ON() { Get.o1("AutoSaving").GetComponent().isOn = true; if (Get.o1("AutoSaving").transform.parent.name == "SAVEpnl") SavingLocal(); if (Get.o1("AutoSaving").transform.parent.name == "SAVEWEBpnl") SavingWeb(); } }//end