using System;
|
using System.Collections;
|
using System.Collections.Generic;
|
using UnityEngine;
|
//修改成控制多个活动模块,如精彩活动模板1,精彩活动模板2
|
|
public class OpenServerActivityCenter : Singleton<OpenServerActivityCenter>
|
{
|
public event Action openServerActivityStateChange;
|
|
//{活动ID:活动接口}
|
Dictionary<int, IOpenServerActivity> GameServerActivitys = new Dictionary<int, IOpenServerActivity>();
|
|
public int selectFuncOrder = -1;
|
|
public OpenServerActivityCenter()
|
{
|
TimeUtility.OnServerOpenDayRefresh -= OnServerOpenDayRefresh;
|
TimeUtility.OnServerOpenDayRefresh += OnServerOpenDayRefresh;
|
}
|
|
public void Register(int funcOrder, IOpenServerActivity activity)
|
{
|
if (!GameServerActivitys.ContainsKey(funcOrder))
|
{
|
GameServerActivitys.Add(funcOrder, activity);
|
activity.onStateUpdate -= OnStateUpdate;
|
activity.onStateUpdate += OnStateUpdate;
|
}
|
}
|
|
private void OnStateUpdate(int _order)
|
{
|
if (openServerActivityStateChange != null)
|
{
|
openServerActivityStateChange();
|
}
|
}
|
|
private void OnServerOpenDayRefresh()
|
{
|
if (openServerActivityStateChange != null)
|
{
|
openServerActivityStateChange();
|
}
|
}
|
|
public bool IsAnyActivityOpen(out int _functionOrder)
|
{
|
_functionOrder = 0;
|
foreach (var _order in GameServerActivitys.Keys)
|
{
|
if (GameServerActivitys[_order].IsOpen || GameServerActivitys[_order].IsAdvance)
|
{
|
_functionOrder = _order;
|
return true;
|
}
|
}
|
return false;
|
}
|
|
public bool IsActivityOpen(int _funcOrder)
|
{
|
bool isOpen = false;
|
if (GameServerActivitys.ContainsKey(_funcOrder))
|
{
|
isOpen = GameServerActivitys[_funcOrder].IsOpen || GameServerActivitys[_funcOrder].IsAdvance;
|
}
|
|
return isOpen;
|
}
|
|
public bool IsPriorityOpenOpen(int _funcOrder)
|
{
|
if (GameServerActivitys.ContainsKey(_funcOrder))
|
{
|
return GameServerActivitys[_funcOrder].priorityOpen;
|
}
|
return false;
|
}
|
|
|
|
public void ProcessErrorTip()
|
{
|
SysNotifyMgr.Instance.ShowTip("ActiveOutTime");
|
}
|
}
|
|
public interface IOpenServerActivity
|
{
|
bool IsOpen { get; }
|
bool IsAdvance { get; }
|
bool priorityOpen { get; }
|
|
event Action<int> onStateUpdate;
|
}
|
|
public class ILOpenServerActivityProxy : IOpenServerActivity
|
{
|
public bool IsOpen => funcIsOpen();
|
|
public bool IsAdvance => funcIsAdvance();
|
|
public bool priorityOpen => funcPriorityOpen();
|
|
public event Action<int> onStateUpdate;
|
|
private Func<bool> funcIsOpen;
|
private Func<bool> funcIsAdvance;
|
private Func<bool> funcPriorityOpen;
|
|
public ILOpenServerActivityProxy(Func<bool> isOpen, Func<bool> isAdvance, Func<bool> priorityOpen)
|
{
|
funcIsOpen = isOpen;
|
funcIsAdvance = isAdvance;
|
funcPriorityOpen = priorityOpen;
|
}
|
|
|
public void StateUpdate(int id)
|
{
|
if (onStateUpdate != null)
|
{
|
onStateUpdate(id);
|
}
|
}
|
|
}
|