12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 |
- using System.Collections.Generic;
- using XGame.Framework.Asyncs;
- using XGame.Framework.Interfaces;
- using XGame.Framework.Loadable;
- namespace XGame.Framework.Nodes
- {
- public class BusinessGroup : IBusinessGroup, ILoadAsyncHandle
- {
- private List<IBusiness> _businesses;
- private List<IUpdate> _updates;
- private List<ILateUpdate> _lateUpdates;
- protected NodeContext _context;
- public BusinessGroup(NodeContext context)
- {
- _context = context;
- _businesses = new List<IBusiness>();
- _updates = new List<IUpdate>();
- _lateUpdates = new List<ILateUpdate>();
- }
- #region 接口实现
- public void AddBusiness(IBusiness business)
- {
- _businesses.Add(business);
- if (business is IContextSetter setter){
- setter.Context = _context;
- }
- if (business is IUpdate update)
- {
- _updates.Add(update);
- }
- if (business is ILateUpdate lateUpdate)
- {
- _lateUpdates.Add(lateUpdate);
- }
- }
- #endregion
- #region public
- public void Enable(object intent)
- {
- foreach(var business in _businesses)
- {
- business?.OnEnable(intent);
- }
- }
- public void Disable()
- {
- foreach(var business in _businesses)
- {
- business?.OnDisable();
- }
- }
- public void Update(int millisecond)
- {
- foreach(var update in _updates)
- {
- update?.Update(millisecond);
- }
- }
- public void LateUpdate(int millisecond)
- {
- foreach(var lateUpdate in _lateUpdates)
- {
- lateUpdate?.LateUpdate(millisecond);
- }
- }
- public void Dispose()
- {
- }
- #endregion
- public void OnLoadAsync(IAsyncGroup group)
- {
- foreach(var business in _businesses)
- {
- (business as ILoadAsyncHandle)?.OnLoadAsync(group);
- }
- }
- public void OnUnloadAsync(IAsyncGroup group)
- {
- foreach(var business in _businesses)
- {
- (business as ILoadAsyncHandle)?.OnUnloadAsync(group);
- }
- }
- }
- }
|