ES2Web
Constructors
public ES2Web(string url, ES2Settings settings=null)
Parameters
[table th=”0″]url,”The URL pointing to our ES2.php file.”
settings,”Optional. A user-created ES2Settings object containing options not specified in path.”[/table]
Properties
[table th=”0″ ]bool,isDone,”Whether our ES2Web object has finished performing it’s operation.”
bool,isError,”Whether our ES2Web object returned an error.”
string,error,”The error message of the error which occurred, if any.”
string,errorCode,”The error code for the error which occurred, if any. For example: 04″
HashType,hashType,”What type of hashing to use for the password. Accepted values are:~~ES2Web.HashType.MD5 (Default)~~ES2Web.HashType.None“[/table]
Methods
Upload/Download Methods
[table th=”0″]ES2Web.Upload,”Initiates an upload.”ES2Web.UploadRaw,”Initiates a raw upload.”
ES2Web.UploadFile,”Uploads a local file to the server.”
ES2Web.UploadImage,”Uploads an image (Texture2D) to the server as a PNG.”
ES2Web.Download,”Initiates a download.”
ES2Web.DownloadFilenames,”Initiates a download of filenames.”[/table]
Load Methods
[table th=”0″]ES2Web.Load,”Loads data from the downloaded data.”ES2Web.LoadArray,”Loads an array from the downloaded data.”
ES2Web.Load2DArray,”Loads a 2D array from the downloaded data.”
ES2Web.Load3DArray,”Loads a 3D array from the downloaded data.”
ES2Web.LoadList,”Loads a List from the downloaded data.”
ES2Web.LoadDictionary,”Loads a Dictionary from the downloaded data.”
ES2Web.LoadHashSet,”Loads a HashSet from the downloaded data.”
ES2Web.LoadQueue,”Loads a Queue from the downloaded data.”
ES2Web.LoadStack,”Loads a Stack from the downloaded data.”
ES2Web.LoadRaw,”Loads the raw bytes from the downloaded data.”[/table]
Other Methods
[table th=”0″]ES2Web.SaveToFile,”Saves the downloaded data to a local file.”ES2Web.AppendToFile,”Appends the downloaded data to a local file.”
ES2Web.Delete,”Deletes the specified data from the database.”
ES2Web.GetFilenames,”Gets all stored filenames on the server.”[/table]
Error Codes
These are the error codes which can be encountered using ES2Web. You can check for errors using the isError, errorCode and error variables of ES2Web.
[table th=”0″]00[attr style=”width:50px”],”Unity has reported an upload error. This might be because URL does not exist, or server is down. See message for details.”01,”Could not connect to database. Database or login details are incorrect.”
02,”Username and password specified in Unity does not match that specified in ES2.php file.”
03,”No data was received at ES2.php.”
04,”ES2 MySQL table could not be found on database.”
05,”The data you are trying to load does not exist.”[/table]
Description
The ES2Web object is used to upload and download data from a MySQL database, using the ES2.php and ES2.sql files supplied with Easy Save.
Note: See Saving And Loading From Web for details on how to install ES2.php and ES2.sql.
Note: Requires knowledge of Coroutines to use.
C#
A coroutine to Upload a Mesh to the server with a given tag
public IEnumerator UploadMesh(Mesh mesh, string tag) { string myURL = "https://www.server.com/ES2.php?webfilename=myFile.txt"; ES2Web web = new ES2Web(myURL + "&tag=" + tag); // Start uploading our data and wait for it to finish. yield return StartCoroutine(web.Upload(mesh)); if(web.isError) { // Enter your own code to handle errors here. // For a list of error codes, see www.moodkie.com/easysave/ES2Web.ErrorCodes.php Debug.LogError(web.errorCode + ":" + web.error); } }
A coroutine which Downloads all data stored in myFile.txt on the server
public IEnumerator DownloadEntireFile() { // As we don't specify a tag, it will download everything // within the file 'myFile.txt'. string myURL = "https://www.server.com/ES2.php?webfilename=myFile.txt"; ES2Web web = new ES2Web(myURL); // Start downloading our data and wait for it to finish. yield return StartCoroutine(web.Download()); if(web.isError) { // Enter your own code to handle errors here. // For a list of error codes, see www.moodkie.com/easysave/ES2Web.ErrorCodes.php Debug.LogError(web.errorCode + ":" + web.error); } // Now save our data to file so we can use ES2.Load to load it. web.SaveToFile("myFile.txt"); }
Deletes data from the server with the given tag
public IEnumerator DeleteTag(string tag) { string myURL = "https://www.server.com/ES2.php?webfilename=myFile.txt"; ES2Web web = new ES2Web(myURL + "&tag=" + tag); // Send request to delete our data and wait for it to finish. yield return StartCoroutine(web.Delete()); if(web.isError) { // Enter your own code to handle errors here. // For a list of error codes, see www.moodkie.com/easysave/ES2Web.ErrorCodes.php Debug.LogError(web.errorCode + ":" + web.error); } }
JS
A coroutine to Upload a Mesh to the server with a given tag
function UploadMesh(mesh : Mesh, tag : String) { var myURL = "https://www.server.com/ES2.php?webfilename=myFile.txt"; var web = new ES2Web(myURL + "&tag=" + tag); // Start uploading our data and wait for it to finish. yield StartCoroutine(web.Upload(mesh)); if(web.isError) { // Enter your own code to handle errors here. // For a list of error codes, see docs.moodkie.com/easy-save-2/api/es2web/ Debug.LogError(web.errorCode + ":" + web.error); } }
A coroutine which Downloads all data stored in myFile.txt on the server
function DownloadEntireFile() { // As we don't specify a tag, it will download everything // within the file 'myFile.txt'. var myURL = "https://www.server.com/ES2.php?webfilename=myFile.txt"; var web = new ES2Web(myURL); // Start downloading our data and wait for it to finish. yield StartCoroutine(web.Download()); if(web.isError) { // Enter your own code to handle errors here. // For a list of error codes, see docs.moodkie.com/easy-save-2/api/es2web/ Debug.LogError(web.errorCode + ":" + web.error); } // Now save our data to file so we can use ES2.Load to load it. web.SaveToFile("myFile.txt"); }
Deletes data from the server with the given tag
function DeleteTag(tag : String) { var myURL = "https://www.server.com/ES2.php?webfilename=myFile.txt"; var web = new ES2Web(myURL + "&tag=" + tag); // Send request to delete our data and wait for it to finish. yield StartCoroutine(web.Delete()); if(web.isError) { // Enter your own code to handle errors here. // For a list of error codes, see docs.moodkie.com/easy-save-2/api/es2web/ Debug.LogError(web.errorCode + ":" + web.error); } }