Hi Joel,
Thank you for your response. I apologize for insisting, but we're in a rush and could really use some help to get this working. Despite our best efforts, we're struggling to properly use ES3. I believe our issue is that we're still going through the cache, which is getting overloaded because we already have the raw image stored in the file.
Here are our main questions:
How can we save data using WebGL without going through the cache (saving directly on server)?
If we must use the cache, what is the difference between "Cache" and "ES3.StoreCachedFile()"? Based on your last message, it seems we should be using "Cache", is that correct?
When we try to use compressed saving (ES3.Save("myTransform", this.transform, settings);), we can no longer open the saved file using the same load method that works fine in the editor with the uncompressed format.
Error in <3/Scripts/Readers/ES3JSONReader.cs> at line 39:
FormatException: Cannot load from file because the data is not JSON or is encrypted. If the save data is encrypted, please ensure that encryption is enabled when loading and that the same password is used.
In the settings, is there something else we need to configure? So far, we are only using:
ES3.SaveRaw(ByteResult, settings); and settings = new ES3Settings(ES3.Location.Cache);
We truly appreciate your help. We'll submit the form you sent as soon as possible, but in the meantime, if you could help us untangle this, it would be a lifesaver.
Thanks again!
here the SaveManager
Code: Select all
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class SaveManager : MonoBehaviour
{
string filename = "filename123456789";
private ES3Settings settings;
// Start is called before the first frame update
void Awake()
{
settings = new ES3Settings(ES3.Location.Cache);
}
public void SaveBoutonClicked(bool showLoadingPopup = true)
{
StartCoroutine(SaveProcess(showLoadingPopup));
}
public IEnumerator SaveProcess(bool showLoadingPopup)
{
// Save all your data
yield return StartCoroutine(SaveScriptMain());
yield return StartCoroutine(SavePlan());
// Upload the saved file to the cloud.
CloudManager cloudMng = ScriptManager.GetScript_CloudManager();
cloudMng.path = filename;
//Debug.Log("cloudMng.path : " + cloudMng.path);
yield return StartCoroutine(cloudMng.UploadFile());
if (loadingPopup != null)
loadingPopup.GetComponent<Popup>()?.Close();
yield return new WaitForEndOfFrame();
}
public IEnumerator SaveScriptMain()
{
Script_Main script = ScriptManager.GetScript_Main();
if (script == null)
yield return null;
// Save various settings using ES3.
SaveES3(Main_MeasureUnit, script.MeasureUnit); //That's an Enum
SaveES3(Main_StarwallRestriction, script.StarwallRestriction); //That's an Enum
SaveES3(Main_GammeIndex, script.GammeIndex); //That's an Int
SaveES3(Main_Snap, script.snapWall); //That's an Bool
SaveES3(Main_SnapRange, script.rangeSpehereCast); //That's an float
SaveES3(Main_WallMat, script.MaterialDefault); //That's an Enum
SaveES3(Main_PartMat, script.PartitionsMaterials); //That's an Enum
SaveES3(Main_PartDiv, script.PartitionsDivision); //That's an Enum
SaveES3(Main_PartModel, script.PartitionsModel); //That's an Enum
yield return null;
}
public struct SavePlans
{
public string PlanName;
public string LevelName;
public byte[] TextureBytesArray;
public float TextureWidth;
public float TextureHeight;
public bool IsVisible;
public Vector3 Position;
public Vector3 Scale;
}
public class PlanData : MonoBehaviour
{
public string PlanName;
public GameObject Level;
public Texture2D Texture;
public float TextureWidth;
public float TextureHeight;
public byte[] TextureBytesArray;
public bool IsVisible;
public Vector3 Position;
public Vector3 Scale;
}
public IEnumerator SavePlan()
{
#region Get Scripts
ImportPlan impPlan = ScriptManager.GetScript_ImportPlan();
if (impPlan == null)
yield return null;
#endregion
List<string> levelsWithPlan = new List<string>();
foreach (GameObject plan in impPlan.DictioLevelsWithPlan.Values)
{
PlanData planData = plan.GetComponent<PlanData>();
SavePlans savePlan = new SavePlans();
savePlan.PlanName = plan.name;
savePlan.LevelName = planData.Level.name;
savePlan.TextureWidth = planData.TextureWidth;
savePlan.TextureHeight = planData.TextureHeight;
savePlan.IsVisible = planData.IsVisible;
savePlan.Position = planData.Position;
savePlan.Scale = planData.Scale;
Texture2D tempTexture = new Texture2D((int)planData.TextureWidth, (int)planData.TextureHeight);
tempTexture.LoadImage(planData.TextureBytesArray);
byte[] jpgData = tempTexture.EncodeToJPG(75); // JPEG (Lossy, quality 75%)
savePlan.TextureBytesArray = jpgData; //This is the Code that Crash, we can have multiple Texture2D
levelsWithPlan.Add(planData.Level.name);
SaveES3("PlanData_" + savePlan.LevelName, savePlan);
if (levelsWithPlan.Count > 0)
SaveES3("ArrayLevelsWithPlan", levelsWithPlan.ToArray());
}
yield return new WaitForEndOfFrame();
}
private void SaveES3(string key, object value)
{
ES3.Save(key, value, filename, settings);
}
}
CloudManager
Code: Select all
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Ricimi;
namespace Planer
{
public class CloudManager : MonoBehaviour
{
[Space(10)]
[Header("Host")]
public string url;
public string apiKey;
[Space(10)]
[Header("User")]
public string userFTP;//MERCI DE NE PAS TOUCHER
public string passwordFTP;//MERCI DE NE PAS TOUCHER
//public string user;
//public string password;
[Space(10)]
[Header("FilePath")]
public string path;
public byte[] byteResult;
[Space(10)]
[Header("Test")]
public bool testCondition;
public bool conditionMet;
[SerializeField] [Range(0f, 1f)] private float progress;
// Start is called before the first frame update
void Start()
{
testCondition = false;
conditionMet = false;
}
// Update is called once per frame
void Update()
{
if (testCondition)
{
conditionMet = ES3.FileExists(path);
if (conditionMet)
testCondition = false;
}
}
public IEnumerator SaveFile()
{
// Create a new ES3Cloud object with the URL to our ES3.php file.
var cloud = new ES3Cloud(url, apiKey);
// Synchronise a local file with the cloud for a particular user.
yield return StartCoroutine(cloud.Sync(path, userFTP, passwordFTP));
if (cloud.isError)
Debug.LogError(cloud.error);
}
public IEnumerator LoadFile(Popup script)
{
// Create a new ES3Cloud object with the URL to our ES3.php file.
/*var cloud = new ES3Cloud(url, apiKey);
//cloud.downloadProgress;
yield return StartCoroutine(cloud.DownloadFile(path, userFTP, passwordFTP));
if (cloud.isError)
Debug.LogError(cloud.error);
testCondition = true;
yield return new WaitUntil(() => conditionMet);*/
SaveManager saveMng = ScriptManager.GetScript_SaveManager();
saveMng.LoadBoutonClicked(path, byteResult);
//Between this two Method i want to do a loading ...
script.Close();
yield return new WaitForEndOfFrame();
}
public IEnumerator LoadFileGamme(Popup script, string filename)
{
// Create a new ES3Cloud object with the URL to our ES3.php file.
var cloud = new ES3Cloud(url, apiKey);
//cloud.downloadProgress;
yield return StartCoroutine(cloud.DownloadFile(path, userFTP, passwordFTP));
if (!cloud.isError)
{
testCondition = true;
yield return new WaitUntil(() => conditionMet);
SaveManager saveMng = ScriptManager.GetScript_SaveManager();
saveMng.LoadGammeBoutonClicked(filename);
//Between this two Method i want to do a loading ...
script.Close();
}
else
Debug.LogError(cloud.error);
}
public IEnumerator UploadFile(Popup script = null)
{
if (!ES3.FileExists(path))
yield break;
var cloud = new ES3Cloud(url, apiKey);
//Uploading...
// Upload the default file to the server.
yield return StartCoroutine(cloud.UploadFile(path, userFTP, passwordFTP));
// Now check that no errors occurred.
if (cloud.isError)
Debug.LogError(cloud.error);
if (script != null)
script.Close();
}
private IEnumerator CheckExistsOnCloud()
{
// Create a new ES3Cloud object with the URL to our ES3Cloud.php file.
var cloud = new ES3Cloud(url, apiKey);
/* Download the filenames of a particular user which begin with 'myFolder/' and output them to console. */
yield return StartCoroutine(cloud.SearchFilenames(path, userFTP, passwordFTP));
if (cloud.isError)
Debug.LogError(cloud.error);
foreach (var filename in cloud.filenames)
Debug.Log(filename);
// Download the filenames of all global files on the server which begin with 'myFolder/' and output them to console.
yield return StartCoroutine(cloud.DownloadFilenames(userFTP, passwordFTP));
if (cloud.isError)
Debug.LogError(cloud.error);
foreach (var filename in cloud.filenames)
Debug.Log(filename);
}
}
}