Ejemplo n.º 1
0
        // Use this for initialization
        void Start()
        {
            Task.Run(() =>
            {
                return(Task.FromException(new System.Exception()));
            }).Unwrap().AsForeground().ContinueWith(t =>
            {
                if (t.IsFaulted)
                {
                    return(UnityTask.FromException(t.Exception));
                }
                else
                {
                    return(UnityTask.FromResult(0));
                }
            }).Unwrap().AsBackground().ContinueWith(t =>
            {
                if (t.IsFaulted)
                {
                    Debug.Log(t.Exception);
                }
            });
            //UnityTask.Run(FirstTask).ContinueWith(t =>
            //{
            //    UnityTask.Run(ThirdSecondTask);
            //    return SecondTask();
            //}).ContinueWith(t =>
            //{
            //    Debug.Log("complete");
            //});

            //Task.Run(() =>
            //{
            //    Thread.Sleep(5000);
            //});
            //Task.Run<int>(() =>
            //{
            //    for (int i = 0; i < 10; i++)
            //    {
            //        Debug.Log(i);
            //    }
            //    return 100;
            //}).ContinueWith(t =>
            //{
            //    Task.Run(() =>
            //    {
            //        for (int i = 0; i < 50; i++)
            //        {
            //            Debug.Log(i);
            //        }
            //    });
            //}).ContinueWith(t =>
            //{
            //    Debug.Log("complete");
            //});
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 登录
        /// </summary>
        /// <param name="userName">用户名</param>
        /// <param name="password">密码</param>
        /// <returns></returns>
        private Task Login(string userName, string password)
        {
            if (string.IsNullOrEmpty(userName) || string.IsNullOrEmpty(password))
            {
                _loginErrorText.text = "账号或密码不能为空";
                return(Task.FromResult(0));
            }

            //存在该用户,进行登录
            return(AVUser.LogInAsync(_accountInput.text, _passwordInput.text).ContinueToForeground(p =>
            {
                if (p.IsFaulted)
                {
                    //TODO
                    return UnityTask.FromException(p.Exception);
                }

                PlayerPrefs.SetString(_theLastLoginUser, _accountInput.text);
                PlayerPrefs.SetInt(_isRememberPassword, _rememberPasswordToggle.isOn ? 1 : 0);
                Debug.Log("登录成功!");
                return UnityTask.FromResult(0);
            }).AsBackground());
        }