public static void ShowToast(string message, ToastDuration duration = ToastDuration.Short) { CheckInstance(); ToastsQueue.Enqueue(ToastStructure.CreateToast(message, duration)); if (toastCoroutine == null) { toastCoroutine = Instance.StartCoroutine(ShowToastsQueueCoroutine()); } }
private static void ShowToast(ToastStructure toast) { // Instance.Log("ShowToast", "Showing " + toast.message + " for a " + toast.duration + " time."); UnityActivity?.Call("runOnUiThread", new AndroidJavaRunnable(() => { ToastObject.Call("setText", toast.message); ToastObject.Call("setDuration", (int)toast.duration); ToastObject.Call("show"); })); }
private static IEnumerator ShowToastsQueueCoroutine() { while (ToastsQueue.Count > 0) { ToastStructure toast = ToastsQueue.Dequeue(); ShowToast(toast); yield return(new WaitForSeconds(toast.DurationInSeconds())); } AndroidManager.toastCoroutine = null; }
/// <summary>Shows a toast according to the given toast structure.</summary> private static void ShowToast(ToastStructure toast) { // Instance.Log("ShowToast", "Queue Remains: " + ToastsQueue.Count + "\nShowing: " + toast); CurrentActivity?.Call("runOnUiThread", new AndroidJavaRunnable(() => { ToastObject.Call("setText", toast.message); ToastObject.Call("setDuration", (int)toast.duration); ToastObject.Call("show"); })); // Instance.Log("ShowToast", "Toasted: " + toast); }
private static IEnumerator ShowToastsQueueCoroutine() { while (ToastsQueue.Count > 0) { ToastStructure toast = ToastsQueue.Dequeue(); try { ShowToast(toast); } catch (Exception exception) { Instance.Error("ShowToastsQueueCoroutine", "Failed to send " + toast + "\n" + exception); } yield return(new WaitForSeconds(toast.DurationInSeconds() + 0.5f)); } toastCoroutine = null; }