using System.Collections.Generic;
using XGame.Framework.Asyncs;
using XGame.Framework.Loadable;

namespace XGame.Framework.Data
{
    /// <summary>
    /// 数据集合
    /// </summary>
    public class DataGroup : IDataGroup, ILoadAsyncHandle
    {
        private HashSet<IData> _datas;
        public DataGroup()
        {
            _datas = new HashSet<IData>();
        }
        void IDataGroup.AddData(IData data)
        {
            _datas.Add(data);
        }

        public void OnLoadAsync(IAsyncGroup group)
        {
            foreach (var data in _datas)
            {
                (data as ILoadAsyncHandle)?.OnLoadAsync(group);
            }
        }

        public void OnUnloadAsync(IAsyncGroup group)
        {
            foreach (var data in _datas)
            {
                (data as ILoadAsyncHandle)?.OnUnloadAsync(group);
            }
        }
    }
}
