- Home /
Custom AsyncOperation to show LoadingImage for slowish XML conversion & email upload method in Unity?
Hi,
I have a Unity UI tool project that converts user input for stories into XML that can be read as game data (Basically a story content creator) Once the conversion is done - it sends the XML as a string via email.
During the conversion / sending process - there's a little bit of a pause before my "successfully sent!" message pops up and I wanted to add an animated loading image in that time and it got me interested in trying to figure out Coroutines with a seemingly non-persistent function.
My slow function would be "ConvertAndUpload()":
it includes multiple try / catches for error reporting to the user(E.g. If they've filled out information incorrectly or missed out filling certain things, or not followed certain story writing conditions needed for the game) and only calls a "DisplayDoneMessage()" if the conversion has been successful and the email has also been sent successfully. For this reason, I feel like it's not exactly a persistent process as such, because it can be interrupted.
Research:
Using AsyncOperation for our own services | (Was interested in CasualT's implementation , however, felt I needed clarification on how to setup the "slow function" due to my unique code scenario, OR that I should be implementing this differently in a way I wasn't aware of)
My previous use of Coroutines:
Simple with 2D/3D animations, regular version of "WaitForSeconds(n);
Question:
I was wondering if anyone could give me some direction on how I could go about implementing this. An implementation that could handle try/catches occurring within the slow function, while displaying some kind of loading animation until the slow function has been successfully completed in terms of:
Successful conversion
Successful email sent
Answer by neuroKip · Oct 13, 2017 at 11:09 AM
I am not sure if this applies for the OP situation, but hope it at least helps someone in a similar situation.
https://docs.unity3d.com/ScriptReference/CustomYieldInstruction.html