71 lines
1.6 KiB
C#
71 lines
1.6 KiB
C#
using ET;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
|
|
namespace ET
|
|
{
|
|
public class TeamDestroySystem : DestroySystem<Team>
|
|
{
|
|
public override void Destroy(Team self)
|
|
{
|
|
self.teamMemberDic.Clear();
|
|
}
|
|
}
|
|
public class Team:Entity
|
|
{
|
|
public long leaderId;
|
|
public Dictionary<long, Unit> teamMemberDic = new Dictionary<long, Unit>();
|
|
|
|
public int MemberCount => teamMemberDic.Count;
|
|
public void Add(Unit unit)
|
|
{
|
|
teamMemberDic.Add(unit.Id, unit);
|
|
UpdateTeamUI();
|
|
}
|
|
public Unit Get(long id)
|
|
{
|
|
teamMemberDic.TryGetValue(id, out Unit unit);
|
|
return unit;
|
|
}
|
|
|
|
public IEnumerable<Unit> GetAll()
|
|
{
|
|
return teamMemberDic.Values;
|
|
}
|
|
public int GetIndex(long unitId)
|
|
{
|
|
int index = 0;
|
|
foreach (Unit u in GetAll())
|
|
{
|
|
if (u.Id == unitId)
|
|
return index;
|
|
index++;
|
|
}
|
|
return -1;
|
|
}
|
|
public bool Contains(long id)
|
|
{
|
|
return GetIndex(id) != -1;
|
|
}
|
|
|
|
public void Remove(long id)
|
|
{
|
|
teamMemberDic.Remove(id);
|
|
UpdateTeamUI();
|
|
}
|
|
public void RemoveAll()
|
|
{
|
|
teamMemberDic.Clear();
|
|
UpdateTeamUI();
|
|
}
|
|
private void UpdateTeamUI()
|
|
{
|
|
Game.EventSystem.Publish(new ET.EventType.UpdateTeamHeadInfo
|
|
{
|
|
zoneScene = this.ZoneScene(),
|
|
team = this,
|
|
}).Coroutine();
|
|
}
|
|
}
|
|
}
|