public static bool IsMainThread() { if (null == _mainThread) { throw new Exception("Main thread has not been set, is the AWSPrefab on the scene?"); } return Thread.CurrentThread.Equals(_mainThread); }
private static XDocument LoadConfigFromResource() { XDocument xDoc = null; TextAsset awsEndpoints = null; Action action = () => { awsEndpoints = Resources.Load(CONFIG_FILE) as TextAsset; using (Stream stream = new MemoryStream(awsEndpoints.bytes)) { using (StreamReader reader = new StreamReader(stream)) { xDoc = XDocument.Load(reader); } } }; if (UnityInitializer.IsMainThread()) { action(); } else { ManualResetEvent e = new ManualResetEvent(false); UnityRequestQueue.Instance.ExecuteOnMainThread(() => { action(); e.Set(); }); e.WaitOne(); } return(xDoc); }