Good day,
For my generic dialog (yes/no, input check, loading progress) I’m looking for a dynamic way of creating a loading action (UI is covered and working).
But I’m stuck with the loading part. I wrote an coroutine to check if the timeout/requirements have been met, and if so run the action (endaction/timeoutaction).
This way, I can use the dialog for multiple calls. But it seems a coroutine wont accept a ref parameter, so it more or less ‘restricts’ me to use a local/class variable which i want to keep dynamic.
I have wrote a function:
public class ModalHandler : MonoBehaviour {
private bool boolToCheck;
public void ModalLoad(ref bool valueToCheck, string loadingText, UnityAction startAction, UnityAction endAction, UnityAction timeOutAction, float timeOut){
this.boolToCheck = valueToCheck;
StartCoroutine (checkLoading(startAction, endAction, timeOutAction, timeOut));
Debug.Log ("Code goes on!");
}
IEnumerator checkLoading(UnityAction startAction, UnityAction endAction, UnityAction timeOutAction, float timeOut){
// call the start action
startAction.Invoke();
// check if we run into the timeout
float timer = 0f;
while (timer <= timeOut) {
if (boolToCheck) { // the check variable has been set to true!
// the condion has been met run the action and close this window
endAction.Invoke ();
ClosePanel ();
yield break;
}
timer += 1f;
yield return new WaitForSeconds (1);
}
// the timeout has been reached
timeOutAction.Invoke ();
ClosePanel ();
yield break;
}
So when i call the ModalLoad. I want to be able to supply a ref bool, instead of a fixed value. So i can use it with any boolean in my game. But when i copy the ref input to a local bool it loses its reference. And i cannot pass the reference into the coroutine, because thats not allowed.
Any light/help on this matter would be much welcome!