/// <summary>
        /// Saves the authentication token channels permissions in the ORTC server.
        /// </summary>
        public UnityTask <bool> PostAuthentication()
        {
            #region Sanity Checks

            if (String.IsNullOrEmpty(Url))
            {
                return(UnityTask.FailedTask <bool>(new OrtcException(OrtcExceptionReason.InvalidArguments, "URL is null or empty.")));
            }
            if (String.IsNullOrEmpty(ApplicationKey))
            {
                return(UnityTask.FailedTask <bool>(new OrtcException(OrtcExceptionReason.InvalidArguments, "Application Key is null or empty.")));
            }
            if (String.IsNullOrEmpty(AuthenticationToken))
            {
                return(UnityTask.FailedTask <bool>(new OrtcException(OrtcExceptionReason.InvalidArguments, "Authentication Token is null or empty.")));
            }
            if (String.IsNullOrEmpty(PrivateKey))
            {
                return(UnityTask.FailedTask <bool>(new OrtcException(OrtcExceptionReason.InvalidArguments, "Private Key is null or empty.")));
            }
            if (Permissions != null && Permissions.Count == 0)
            {
                return(UnityTask.FailedTask <bool>(new OrtcException(OrtcExceptionReason.InvalidArguments, "No permissions set.")));
            }

            #endregion

            return(UnityTask.RunCoroutine <bool>(PostAuthenticationAsync));
        }
        /// <summary>
        /// Sends a message to a channel.
        /// </summary>
        public UnityTask <bool> SendMessage()
        {
            if (String.IsNullOrEmpty(Url))
            {
                UnityTask.FailedTask <bool>(new OrtcException(OrtcExceptionReason.InvalidArguments, "Server URL can not be null or empty."));
            }

            return(UnityTask.RunCoroutine <bool>(SendMessageAsync));
        }
示例#3
0
        /// <summary>
        /// Retrieves an Ortc Server url from the Ortc Balancer
        /// </summary>
        /// <returns></returns>
        public UnityTask <string> GetServerUrl()
        {
            if (!String.IsNullOrEmpty(Url) && IsCluster)
            {
                return(UnityTask.RunCoroutine <string>(GetServerFromBalancerAsync));
            }

            return(UnityTask.SuccessTask(Url));
        }
        void BackgroundToRotine()
        {
            UnityTask.Run(() =>
            {
                Debug.Log("Thread A Running");

                var task = UnityTask.RunCoroutine(RoutineFunction());

                while (task.IsRunning)
                {
                    Debug.Log(".");
                    UnityTask.Delay(500);
                }

                Debug.Log("Thread A Done");
            });
        }
 /// <summary>
 /// Disables presence for the specified channel.
 /// </summary>
 public UnityTask <string> DisablePresence()
 {
     return(UnityTask.RunCoroutine <string>(DiablePresenceAsync));
 }
 /// <summary>
 /// Gets the subscriptions in the specified channel and if active the first 100 unique metadata.
 /// </summary>
 public UnityTask <Presence> GetPresence()
 {
     return(UnityTask.RunCoroutine <Presence>(GetPresenceAsync));
 }
示例#7
0
 /// <summary>
 /// Retrieves an Ortc Server url from the Ortc Balancer
 /// </summary>
 /// <remarks></remarks>
 public UnityTask <string> GetServerFromBalancer()
 {
     return(UnityTask.RunCoroutine <string>(GetServerFromBalancerAsync));
 }
 /// <summary>
 /// Does the get cluster server logic.
 /// </summary>
 /// <returns></returns>
 public UnityTask <string> GetClusterServerWithRetry()
 {
     return(UnityTask.RunCoroutine <string>(GetClusterServerWithRetryAsync));
 }
 void CoroutineUnityTaskState()
 {
     UnityTask.RunCoroutine <string>(CoroutineUnityTaskStateAsync).ContinueWith(o => Debug.Log(o.Result));
 }
示例#10
0
        public IEnumerator Start()
        {
            Output.text = string.Empty;
            Counter     = 0;
            Application.logMessageReceived += Application_logMessageReceived;
            yield return(1);


            UnityTask.Run(() =>
            {
                Counter++;
                Debug.Log("1 Run");
            });
            yield return(new WaitForSeconds(1));

            Assert(() => Counter == 1, 1);

            UnityTask.Run(Test2, "2 Run With Param");
            yield return(new WaitForSeconds(1));

            Assert(() => Counter == 2, 2);

            UnityTask.RunCoroutine(Test3);
            yield return(new WaitForSeconds(1));

            Assert(() => Counter == 3, 3);

            var t4 = UnityTask.RunCoroutine(Test4()).ContinueWith(t =>
            {
                Counter++;
                Debug.Log("5 Coroutine with Continue");
            });

            yield return(StartCoroutine(t4.WaitRoutine()));

            Assert(() => Counter == 5, 5);
            yield return(new WaitForSeconds(1));

            var t5 = UnityTask.RunCoroutine(Test5).ContinueWith(t =>
            {
                Counter++;
                Debug.Log("5 Continued");
            });

            yield return(StartCoroutine(t5.WaitRoutine()));

            Assert(() => Counter == 7, 7);
            yield return(new WaitForSeconds(1));

            var t6 = UnityTask.Run(() => { return("6 Run with Result And Continue"); }).ContinueWith(t => { Counter++; Debug.Log(t.Result); });

            yield return(StartCoroutine(t6.WaitRoutine()));

            Assert(() => Counter == 8, 8);
            yield return(new WaitForSeconds(1));

            var t7 = UnityTask.Run <string, string>(Test7, "7 Run with Param and Result And Continue").ContinueWith(t => { Counter++; Debug.Log(t.Result); });

            yield return(StartCoroutine(t7.WaitRoutine()));

            yield return(new WaitForSeconds(1));

            Assert(() => Counter == 10, 10);

            var t1 = UnityTask.RunCoroutine <string>(Test8);

            yield return(StartCoroutine(t1.WaitRoutine()));

            Debug.Log(t1.Result);
            Assert(() => Counter == 11, 11);
            yield return(new WaitForSeconds(1));

            var t2 = UnityTask.RunCoroutine <string>(Test9).ContinueWith(t => { Counter++; Debug.Log(t.Result); });

            yield return(StartCoroutine(t2.WaitRoutine()));

            Assert(() => Counter == 13, 13);


            var t12 = UnityTask.Run(() => { return("1"); }).ConvertTo <int>(task =>
            {
                Debug.Log("10 ConvertTo Extension");
                Counter++;
                return(int.Parse(task.Result));
            });

            Assert(() => t12.Result == 1, 14);
            Assert(() => Counter == 14, 14);

            Debug.Log("Success");
        }
示例#11
0
 void Routine()
 {
     UnityTask.RunCoroutine(RoutineFunction());
 }
示例#12
0
        public IEnumerator Start()
        {
            log = string.Empty;
            Debug.Log("Test Starting");
            Counter = 0;
            yield return(new WaitForSeconds(2));

            // Action
            Debug.Log("Action...");
            var mtask = UnityTask.Run(() => { Counter++; });

            yield return(mtask);

            Assert(() => Counter == 1, "Action");
            yield return(new WaitForSeconds(2));

            // Action with
            Debug.Log("Action w/ Continue...");
            yield return(new WaitForSeconds(1));

            yield return(UnityTask.Run(() =>
            {
                Counter++;
            }).ContinueWith(task =>
            {
                Counter++;
            }));

            Assert(() => Counter == 3, "Action w/ Continue");

            // Coroutine
            Debug.Log("Continue...");
            yield return(new WaitForSeconds(1));

            yield return(UnityTask.RunCoroutine(DemoCoroutine));

            Assert(() => Counter == 4, "Coroutine");

            // Coroutine with Continue
            Debug.Log("Coroutine w/ Continue...");
            yield return(new WaitForSeconds(1));

            yield return(UnityTask.RunCoroutine(DemoCoroutine).ContinueWith(task => { Counter++; }));

            Assert(() => Counter == 6, "Coroutine w/ Continue");

            // Coroutine with result
            Debug.Log("Coroutine w/ result...");
            yield return(new WaitForSeconds(1));

            var ctask = UnityTask.RunCoroutine <string>(DemoCoroutineWithResult);

            yield return(ctask);

            Assert(() => Counter == 7, "Coroutine w/ result (A)");
            Assert(() => ctask.Result == "Hello", "Coroutine w/ result (B)");


            // Coroutine with result and Continue
            Debug.Log("CoroutineCoroutine w/ result and continue...");
            yield return(new WaitForSeconds(1));

            var ctask2 = UnityTask.RunCoroutine <string>(DemoCoroutineWithResult).ContinueWith(t =>
            {
                Assert(() => t.Result == "Hello", "Coroutine w/ result and continue (A)");
                t.Result = "Goodbye";
                Counter++;
            });

            yield return(ctask2);

            Assert(() => Counter == 9, "Coroutine w/ result and continue (B)");
            Assert(() => ctask2.Result == "Goodbye", "Coroutine w/ result and continue (C)");


            // Function
            Debug.Log("Function...");
            yield return(new WaitForSeconds(1));

            var ftask = UnityTask.Run(() =>
            {
                Counter++;
                return("Hello");
            });

            yield return(ftask);

            Assert(() => Counter == 10, "Function");
            Assert(() => ftask.Result == "Hello", "Function");

            //Exception
            Debug.Log("Exception...");
            yield return(new WaitForSeconds(1));

            var etask = UnityTask.Run(() => { Counter++; throw new Exception("Hello"); });

            yield return(etask);

            Assert(() => Counter == 11, "Exception");
            Assert(() => etask.IsFaulted && etask.Exception.Message == "Hello", "Exception");

            //Main Thread
            log = string.Empty;
            Debug.Log("Basic Tests Passed");
            Debug.Log("Threading Tests...");
            Debug.Log("Background....");
            yield return(new WaitForSeconds(1));

            yield return(UnityTask.Run(() =>
            {
                UnityTask.Delay(50);
                Debug.Log("Sleeping...");
                UnityTask.Delay(2000);
                Debug.Log("Slept");
            }));

            yield return(1);

            Debug.Log("BackgroundToMain");
            yield return(new WaitForSeconds(1));

            yield return(UnityTask.Run(() =>
            {
                UnityTask.Delay(100);

                var task = UnityTask.RunOnMain(() =>
                {
                    Debug.Log("Hello From Main");
                });

                while (task.IsRunning)
                {
                    log += ".";
                    UnityTask.Delay(100);
                }
            }));

            yield return(1);

            Debug.Log("BackgroundToRotine");
            yield return(new WaitForSeconds(1));

            yield return(UnityTask.Run(() =>
            {
                var task = UnityTask.RunCoroutine(LongCoroutine());

                while (task.IsRunning)
                {
                    log += ".";
                    UnityTask.Delay(500);
                }
            }));

            yield return(1);

            Debug.Log("BackgroundToBackground");
            yield return(new WaitForSeconds(1));

            yield return(UnityTask.Run(() =>
            {
                Debug.Log("1 Sleeping...");

                UnityTask.Run(() =>
                {
                    Debug.Log("2 Sleeping...");
                    UnityTask.Delay(2000);
                    Debug.Log("2 Slept");
                });
                UnityTask.Delay(2000);
                Debug.Log("1 Slept");
            }));

            yield return(1);

            Debug.Log("Success All");
        }