private static string ExecuteGameObjectEmulation(string rootName, string nameOrPath, string parent, string upath, Func <GameObject, string> onComplete, string notFoundMsg = null) { // event used to wait the answer from the main thread. AutoResetEvent autoEvent = new AutoResetEvent(false); string response = ""; MainThreadHelper.QueueOnMainThread(() => { try { GameObject go; if (!string.IsNullOrEmpty(upath)) { go = FindGameObjectHelper.FindGameObjectByUPath(upath); } else { go = FindGameObjectHelper.FindGameObject(rootName, nameOrPath, parent); } if (go != null) { response = onComplete(go); } else { if (notFoundMsg != null) { response = notFoundMsg; } else { response = "not found (" + (parent != null ? parent + "/" : "") + nameOrPath + ")"; } } } catch (Exception e) { Log(e); response = e.Message; } finally { // set the event to "unlock" the thread autoEvent.Set(); } }); // wait for the end of the 'action' executed in the main thread autoEvent.WaitOne(); return(response); }
public static string ExecuteGameObjectEmulation(string upath, Func <GameObject, string> onComplete) { // event used to wait the answer from the main thread. AutoResetEvent autoEvent = new AutoResetEvent(false); var response = ErrorMessages.MainThreadIsUnavailable; // If response was not changed then MainThreadHelper is not initialized. MainThreadQueue.QueueOnMainThread(() => { try { var gameObject = FindGameObjectHelper.FindGameObjectByUPath(upath); if (gameObject != null) { response = onComplete(gameObject); } else { response = ErrorMessages.GameObjectWasNotFound; } } catch (Exception e) { Utils.Logger.Log(e); response = Error + e.ToString(); } finally { // set the event to "unlock" the thread autoEvent.Set(); } }); // wait for the end of the 'action' executed in the main thread or 5 seconds timeout autoEvent.WaitOne(5000); return(response); }