Beispiel #1
0
        private static string ExecuteGameObjectsEmulation(string nameOrPath, string parent, string root, string upath, Func <List <GameObject>, string> onComplete)
        {
            var autoEvent = new AutoResetEvent(false);

            var response = "";

            MainThreadHelper.QueueOnMainThread(() => {
                try
                {
                    List <GameObject> listOfGOs;
                    if (!string.IsNullOrEmpty(upath))
                    {
                        listOfGOs = FindGameObjectHelper.FindGameObjectsByUPath(upath);
                    }
                    else
                    {
                        listOfGOs = FindGameObjectHelper.GetGameObjects(nameOrPath, root, parent);
                    }

                    response = onComplete(listOfGOs);
                } 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);
        }
Beispiel #2
0
        public static string ExecuteGameObjectsEmulation(string upath, Func <List <GameObject>, string> onComplete)
        {
            var autoEvent = new AutoResetEvent(false);

            var response = ErrorMessages.MainThreadIsUnavailable; // If response was not changed then MainThreadHelper is not initialized.

            MainThreadQueue.QueueOnMainThread(() =>
            {
                try
                {
                    var listOfGOs = FindGameObjectHelper.FindGameObjectsByUPath(upath);

                    response = onComplete(listOfGOs);
                }
                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);
        }
Beispiel #3
0
        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);
        }
Beispiel #4
0
        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);
        }