示例#1
0
        IEnumerator CoroutineWithInternalErrorHandling()
        {
            startMessage = "STARTED";
            yield return(new WaitForSecondsRealtime(1));

            //we can yield it with catch or wait on it and check errors
            //we will use an empty catch to completely swallow the error
            yield return(new CFunc(ThrowExceptionCoroutine()).Catch(e => { }));

            endMessage = "FINISHED";

            yield return(new WaitForSecondsRealtime(1));

            //Here we will use our own wait and check the error manually. then we don't need a catch block.
            //The reason it does not buble the error is because we don't yield the ICFunc
            startMessage = "STARTED ANOTHER";

            ICFunc coroFunc2 = CoroutineUtility.Start(ThrowExceptionCoroutine());

            while (!coroFunc2.IsDone)
            {
                yield return(null);
            }
            if (coroFunc2.Error != null)
            {
                Debug.Log("We should have already seen an error log, but here is another..");
            }

            endMessage = "FINISHED ANOTHER";
        }
 void Start()
 {
     for (int i = 0; i < 10; i++)
     {
         CoroutineUtility.Start(ParentCoroutine("id=" + i));
     }
 }
示例#3
0
        public void Send <T>(IUploadWebRequest <T> request, Action <T> onResult = null) where T : WebResult, new()
        {
            var unityWebRequest = CreateUnityWebRequest(request);

            CoroutineUtility.Start(SendRequest(unityWebRequest, () =>
            {
                var result = new T();
                result.SetUnityWebRequest(unityWebRequest);
                onResult?.Invoke(result);
            }));
        }
示例#4
0
        static void SendRequest(UnityWebRequest request, Action <UnityWebRequest> callback)
        {
            if (s_Cache.ContainsKey(request.url))
            {
                callback.Invoke(s_Cache[request.url]);
                return;
            }

            CoroutineUtility.Start(SendRequestCoroutine(request, (result) =>
            {
                s_Cache.Add(result.url, result);
                callback.Invoke(result);
            }));
        }
        void DrawMenu()
        {
            Rect r = new Rect(10, 10, 200, 100);

            using (new GUILayout.AreaScope(r)) {
                GUI.enabled = !IsCoroutineRunning;
                if (GUILayout.Button("Start Using Example Singleton"))
                {
                    _coroutine = ExampleSingleton.Inst.Start(ShowHelloWorldCoroutine());
                }
                if (GUILayout.Button("Start Using Utility Singleton"))
                {
                    _coroutine = CoroutineUtility.Start(ShowHelloWorldCoroutine());
                }
                if (GUILayout.Button("Start Using Private Runner"))
                {
                    _coroutineRunner.Start(ShowHelloWorldCoroutine());
                }
                GUI.enabled = true;
            }
        }