Exemple #1
0
        /// <summary>
        /// Verifies the state of the currently monitored ongoing request. Displays progress bar for the request if
        /// it is still going on. If the response is available, the scheduled post-completion action will be invoked on
        /// the www instance of the ongoing request, the request will stop being monitored and resources used by this
        /// request will be disposed.
        /// </summary>
        public static void Update()
        {
            if (_ongoingRequest == null)
            {
                return;
            }

            if (_ongoingRequest.RequestWww.isDone)
            {
                EditorUtility.ClearProgressBar();
                var onGoingRequest = _ongoingRequest;
                // Set the static field _requestInProgress to null before invoking the  post-completion action
                // because the action could be executing an action that will read or overwrite the static field.
                _ongoingRequest = null;
                onGoingRequest.OnResponseAvailableAction(onGoingRequest.RequestWww);
                onGoingRequest.Dispose();
            }
            else
            {
                if (EditorUtility.DisplayCancelableProgressBar(_ongoingRequest.ProgressBarTitleText,
                                                               string.Format("Progress: {0}%", Math.Floor(_ongoingRequest.RequestWww.uploadProgress * 100)),
                                                               _ongoingRequest.RequestWww.uploadProgress))
                {
                    EditorUtility.ClearProgressBar();
                    _ongoingRequest.Dispose();
                    _ongoingRequest = null;
                }
            }
        }
Exemple #2
0
        /// <summary>
        /// Monitor an HTTP request being made. Assumes one request will be made at a time, therefore will throw
        /// an exception if a previous request is still being monitored.
        /// </summary>
        /// <param name="www">A www instance holding a request that was made</param>
        /// <param name="progressBarTitleText">A descriptive text to display as the title of the progress bar.</param>
        /// <param name="onResponseAvailableAction">An action to be invoked on www once the response to the request
        /// is available.</param>
        public static void TrackProgress(WWW www, string progressBarTitleText, Action <WWW> onResponseAvailableAction)
        {
            if (_ongoingRequest != null)
            {
                throw new Exception("Cannot start another request while the previous one is not complete.");
            }

            _ongoingRequest = new OngoingRequest(www, progressBarTitleText, onResponseAvailableAction);
        }