46 lines
1.4 KiB
C#
46 lines
1.4 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
namespace MMO
|
|
{
|
|
public class MMOAPIRequestManager : MMOSingleton<MMOAPIRequestManager>
|
|
{
|
|
private List<MMOAPIRequestUnit> mRequestList = new List<MMOAPIRequestUnit>();
|
|
private Dictionary<Type, object> mRespondDataDic = new Dictionary<Type, object>();
|
|
|
|
public T GetData<T>() where T : MMORespondBase
|
|
{
|
|
Type tTypeKey = typeof(T);
|
|
if (mRespondDataDic.ContainsKey(tTypeKey))
|
|
{
|
|
return mRespondDataDic[tTypeKey] as T;
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
public void SetData<T>(T pData) where T : MMORespondBase
|
|
{
|
|
mRespondDataDic[typeof(T)] = pData;
|
|
}
|
|
|
|
public void SendRequest<T, U>(T pRequestData, Action<U> pRespondCallback = null, Action<int> pErrorCallback = null) where T : MMORequestBase
|
|
{
|
|
MMOAPIRequestUnit tUnit = gameObject.AddComponent<MMOAPIRequestUnit>();
|
|
mRequestList.Add(tUnit);
|
|
tUnit.DelOver = OnRequestOver;
|
|
tUnit.SendRequest(pRequestData, pRespondCallback, pErrorCallback);
|
|
}
|
|
|
|
private void OnRequestOver(MMOAPIRequestUnit pUnit)
|
|
{
|
|
if (mRequestList.Contains(pUnit))
|
|
{
|
|
mRequestList.Remove(pUnit);
|
|
Destroy(pUnit);
|
|
}
|
|
}
|
|
}
|
|
} |