1234567891011121314151617181920212223242526272829303132333435363738 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- /// <summary>
- /// 一个WebRequest发送系统的基类
- /// </summary>
- public abstract class WebRequestServerBase : SystemBase {
- List<WebRequestBase> webRequestList = new List<WebRequestBase>();
- protected void AddWebRequest(WebRequestBase webRequest) {
- webRequestList.Add(webRequest);
- CheckQueue();
- }
- void CheckQueue() {
- if (webRequestList.Count == 0) {
- return;
- }
- StartCoroutine(SendRequest());
- }
- IEnumerator SendRequest() {
- ///加yield return null目的是将Web请求延迟到下一帧开始,避免web回复委托还没添加,web已经回复,导致错过信息
- yield return null;
- WebRequestBase webRequest = webRequestList[0];
- webRequestList.RemoveAt(0);
- yield return StartCoroutine(webRequest.SendRequest());
- CheckQueue();
- }
- public override void SystemStop() {
- base.SystemStop();
- StopAllCoroutines();
- webRequestList.Clear();
- }
- }
|