IsMainThread() публичный статический Метод

Checks if the thread is a game/main/unity thread
public static IsMainThread ( ) : bool
Результат bool
        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);
        }
Пример #2
0
        private static XDocument LoadConfigFromResource()
        {
            XDocument xDoc      = null;
            TextAsset awsConfig = null;
            Action    action    = delegate
            {
                awsConfig = (Resources.Load("awsconfig") as TextAsset);
                if (awsConfig != null && awsConfig.get_bytes().Count() > 0)
                {
                    using (Stream stream = new MemoryStream(awsConfig.get_bytes()))
                    {
                        using (StreamReader textReader = new StreamReader(stream))
                        {
                            xDoc = XDocument.Load(textReader);
                        }
                    }
                }
            };

            if (UnityInitializer.IsMainThread())
            {
                action();
            }
            else
            {
                ManualResetEvent e = new ManualResetEvent(initialState: false);
                UnityRequestQueue.Instance.ExecuteOnMainThread(delegate
                {
                    action();
                    e.Set();
                });
                e.WaitOne();
            }
            return(xDoc);
        }
Пример #3
0
        static void LoadEndpointDefinitionsFromEmbeddedResource()
        {
            Action action = () =>
            {
                TextAsset awsEndpoints = Resources.Load(REGIONS_FILE) as TextAsset;
                using (Stream stream = new MemoryStream(awsEndpoints.bytes))
                {
                    using (StreamReader reader = new StreamReader(stream))
                    {
                        ReadEndpointFile(stream);
                    }
                }

                awsEndpoints = Resources.Load(REGIONS_CUSTOMIZATIONS_FILE) as TextAsset;
                using (Stream stream = new MemoryStream(awsEndpoints.bytes))
                {
                    using (StreamReader reader = new StreamReader(stream))
                    {
                        ReadEndpointFile(stream);
                    }
                }
            };

            if (UnityInitializer.IsMainThread())
            {
                action();
            }
            else
            {
                ManualResetEvent e = new ManualResetEvent(false);
                UnityRequestQueue.Instance.ExecuteOnMainThread(() =>
                {
                    action();
                    e.Set();
                });
                e.WaitOne();
            }
        }