Exemplo n.º 1
0
        void onInvoke(int id)
        {
            // Check the state of the request running with this id.
            var wrappedRequest = runningRequests.FirstOrDefault(x => x.ID == id);

            if (wrappedRequest != null && wrappedRequest.Request.isDone)
            {
                if (wrappedRequest.Request.isNetworkError ||   !string.IsNullOrEmpty(wrappedRequest.Request.error))
                {
                    // Invoke Failed event in case of any error with the request.
                    if (Failed != null)
                    {
                        Failed(wrappedRequest, wrappedRequest.Request.error);
                    }
                }
                else
                {
                    // Invoke Completed event once the request is done.
                    if (Completed != null)
                    {
                        Completed(wrappedRequest);
                    }
                }

                // Stop the TaskInvoker task once the request is done.
                TaskInvoker.StopTask(id);
                runningRequests.Remove(wrappedRequest);
            }
        }
Exemplo n.º 2
0
        // Sends a WebRequest given as a parameter and checks its status every millisecondsPerUpdate
        public UnityWebRequestAsyncOperation Send(UnityWebRequest request, int millisecondsPerUpdate)
        {
            // Start a TaskInvoker task and send the UnityWebRequest.
            int taskID = TaskInvoker.StartTask(millisecondsPerUpdate, onInvoke, onExpire);

            runningRequests.Add(new WrappedRequest(request, taskID));
            return(request.SendWebRequest());
        }
Exemplo n.º 3
0
 void OnApplicationPause(bool paused)
 {
     // Start the counter on pause
     if (paused)
     {
         // Start a task that invokes once every second (1000 milliseconds)
         currentTaskID = TaskInvoker.StartTask(1000, onInvoke, onExpire);
     }
     else if (currentTaskID != -1)
     {
         // Stop the running task when entering foreground
         TaskInvoker.StopTask(currentTaskID);
     }
 }