116 lines
4.1 KiB
C#
116 lines
4.1 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using asap.core;
|
|
using cfg;
|
|
using game;
|
|
using GameCore;
|
|
using UnityEngine;
|
|
|
|
namespace OrderManager
|
|
{
|
|
public static class OrderManager
|
|
{
|
|
private static List<IOrderSuccess> _orderSuccesses;
|
|
private static List<IOrderReplenishment> _orderReplenishments;
|
|
public static List<IOrderSuccess> GetOrderSuccesses()
|
|
{
|
|
return _orderSuccesses;
|
|
}
|
|
public static List<IOrderReplenishment> GetOrderReplenishments()
|
|
{
|
|
return _orderReplenishments;
|
|
}
|
|
public static void Init(Type type)
|
|
{
|
|
InitOrderSuccess(type);
|
|
InitReplenishment(type);
|
|
}
|
|
|
|
public static void RegisterReplenishment(IOrderReplenishment replenishment)
|
|
{
|
|
_orderReplenishments ??= new List<IOrderReplenishment>();
|
|
if (!_orderReplenishments.Contains(replenishment))
|
|
_orderReplenishments.Add(replenishment);
|
|
}
|
|
|
|
public static void UnregisterReplenishment(IOrderReplenishment replenishment)
|
|
{
|
|
_orderReplenishments?.Remove(replenishment);
|
|
}
|
|
|
|
public static void RegisterOrderSuccess(IOrderSuccess success)
|
|
{
|
|
_orderSuccesses ??= new List<IOrderSuccess>();
|
|
if (!_orderSuccesses.Contains(success))
|
|
_orderSuccesses.Add(success);
|
|
}
|
|
|
|
public static void UnregisterOrderSuccess(IOrderSuccess success)
|
|
{
|
|
_orderSuccesses?.Remove(success);
|
|
}
|
|
|
|
private static void InitOrderSuccess(Type type)
|
|
{
|
|
_orderSuccesses ??=new List<IOrderSuccess>();
|
|
try
|
|
{
|
|
var res = typeof(IOrderSuccess).IsAssignableFrom(type) && type.IsClass && !type.IsAbstract;
|
|
if (!res) return;
|
|
var @interface = (IOrderSuccess)GContext.container.Resolve((type, string.Empty));
|
|
if (@interface == null)
|
|
{
|
|
Debug.LogWarning($"interface is null type: {type.Name}");
|
|
return;
|
|
}
|
|
if(!_orderSuccesses.Contains(@interface))
|
|
_orderSuccesses.Add(@interface);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
Debug.LogError($"[OrderReplenishmentManager] Error processing type {type.Name}: {e.Message}");
|
|
}
|
|
}
|
|
private static void InitReplenishment(Type type)
|
|
{
|
|
_orderReplenishments ??=new List<IOrderReplenishment>();
|
|
try
|
|
{
|
|
var res = typeof(IOrderReplenishment).IsAssignableFrom(type) && type.IsClass && !type.IsAbstract;
|
|
if (!res) return;
|
|
var @interface = (IOrderReplenishment)GContext.container.Resolve((type, string.Empty));
|
|
if (@interface == null)
|
|
{
|
|
#if UNITY_EDITOR
|
|
|
|
Debug.LogWarning($"interface is null type: {type.Name}");
|
|
#endif
|
|
return;
|
|
}
|
|
if(!_orderReplenishments.Contains(@interface))
|
|
_orderReplenishments.Add(@interface);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
Debug.LogError($"[OrderReplenishmentManager] Error processing type {type.Name}: {e.Message}");
|
|
}
|
|
}
|
|
|
|
public static void OnReplenish(ShopBuyTypeData buyType, IAPItemList iAPItemList, List<ItemData> itemDataGift, RewardType rewardShowType, bool voucher = false)
|
|
{
|
|
foreach (var replenishment in _orderReplenishments)
|
|
{
|
|
replenishment.OnReplenish(buyType,iAPItemList, itemDataGift, rewardShowType, voucher);
|
|
}
|
|
}
|
|
|
|
public static void OnOrderSuccess(ShopBuyTypeData buyType, IAPItemList iAPItemList, List<ItemData> itemDataGift,
|
|
RewardType rewardShowType, bool voucher = false)
|
|
{
|
|
foreach (var orderSuccess in _orderSuccesses)
|
|
{
|
|
orderSuccess.OnOrderSuccess(buyType, iAPItemList, itemDataGift, rewardShowType, voucher);
|
|
}
|
|
}
|
|
}
|
|
} |