private static IEnumerator FetchRoutine(MonoBehaviour origin, FetchIPComplete onComplete) { IPAddress resIP = null; foreach (string provider in PUBLIC_IP_SERVICES) { yield return(WebRequest.Get(origin, provider, (req, res, error, errorMsg) => { res = res.Trim(); if (res != "" && IPAddress.TryParse(res, out IPAddress ip)) { resIP = ip; } })); if (resIP != null) { break; } } onComplete(resIP); }
public static Coroutine Fetch(MonoBehaviour origin, FetchIPComplete onComplete) { return(origin.StartCoroutine(FetchRoutine(origin, onComplete))); }