public Task <T> Execute()
        {
            var task = new TaskCompletionSource <UnityWebRequest>();

            return(MainThreadTask.Run(async() =>
            {
                Debug.Log($"Creating Web Request: {method} {endpoint}");
                var unityWebRequest = new UnityWebRequest(endpoint, method);
                unityWebRequest.SetRequestHeader("Accept", "application/json");
                if (needsAuth)
                {
                    var token = await authorizationProvider();
                    if (string.IsNullOrEmpty(token))
                    {
                        throw new RegenAuthenticationException("token was not retrieved for endpoint " + endpoint);
                    }

                    unityWebRequest.SetRequestHeader("Authorization", $"Bearer {token}");
                }

                if (body != null)
                {
                    unityWebRequest.SetRequestHeader("Content-Type", "application/json; charset=utf-8");
                    unityWebRequest.uploadHandler = new UploadHandlerRaw(Encoding.UTF8.GetBytes(body));
                }

                unityWebRequest.downloadHandler = new DownloadHandlerBuffer();
                Debug.Log($"Sending Web Request: {method} {endpoint}");
                Debug.Log("Authorization: " + unityWebRequest.GetRequestHeader("Authorization"));
                var request = unityWebRequest.SendWebRequest();
                request.completed += operation =>
                {
                    var r = request.webRequest;
                    Debug.Log($"Web Request Complete: {method} {endpoint} {r.responseCode} {r.downloadHandler.text}");
                    if (r.isNetworkError)
                    {
                        task.SetException(new HttpRequestException("Encountered Network Error" + r.error));
                    }
                    else if (r.isHttpError)
                    {
                        task.SetException(new HttpResponseException("Encountered Http Error", r));
                    }
                    else
                    {
                        task.SetResult(r);
                    }
                };
                await task.Task;
                var map = mapping(task.Task.Result);
                Debug.Log($"Mapping Result: {map}");
                return map;
            }));
        }
            private String Run(Domain domain, IEnumerable <String> args)
            {
                var first  = args.FirstOrDefault();
                var subcmd = first != null ? this[first] : null;

                if (first != null && subcmd != null)
                {
                    return(subcmd.Run(domain, args.Skip(1)));
                }

                if (_delegate != null && (_attribute.Domain & domain) == domain)
                {
                    try
                    {
                        try
                        {
                            return(_delegate(new ConCommandArgs(domain, _prefix, args.ToArray())).ToString());
                        }
                        catch (Exception e)
                        {
                            if (!e.Message.Contains("can only be called from the main thread."))
                            {
                                throw e;
                            }

                            if (_sMainThread == null)
                            {
                                throw new Exception("Command must be performed on the main thread, "
                                                    + "but ConCommand.PerformMainThreadTasks() has not been called.");
                            }

                            var task = new MainThreadTask(() => Run(domain, args));
                            _sMainThreadTasks.Enqueue(task);

                            return(task.AwaitResult <String>(MainThreadTaskTimeout));
                        }
                    }
                    catch (Exception e)
                    {
                        UnityEngine.Debug.LogError(e);
                        throw new ConCommandException(domain, _prefix.Concat(args), e);
                    }
                }

                var options = _subCommands.Keys.Where(x => _subCommands[x].ContainsCallable(domain));

                throw first == null
                    ? new ConCommandNotFoundException(domain, _prefix, options, args)
                    : new ConCommandNotFoundException(domain, _prefix, first, options, args);
            }
    public void LogInWithFB()
    {
        Action <string> success = token =>
        {
            ReGenClient.Instance.Authentication.SignInUserWithFacebook(token).Success(user =>
            {
                NotificationManager.Instance.SetLoadingPanel(false);
                SwitchToMainMenu("Login Successful");
            }).Failure(error =>
            {
                NotificationManager.Instance.SetLoadingPanel(false);
                OnAccountActionAttempt?.Invoke(error.Message);
            });
        };

        FacebookManager.Instance.Login(success, error =>
        {
            MainThreadTask.Run(async() =>
            {
                NotificationManager.Instance.SetLoadingPanel(false);
                OnAccountActionAttempt?.Invoke(error);
            });
        });
    }
Exemple #4
0
 void Awake()
 {
     instance = this;
     DontDestroyOnLoad(gameObject);
 }