2021-04-08 20:09:59 +08:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
|
|
|
|
namespace ET
|
|
|
|
|
{
|
|
|
|
|
public class MainStoryAIComponentAwakeSystem : AwakeSystem<MainStoryAIComponent>
|
|
|
|
|
{
|
|
|
|
|
public override void Awake(MainStoryAIComponent self)
|
|
|
|
|
{
|
|
|
|
|
MainStoryAIComponent.instance = self;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
public static class MainStoryAIComponentSystem
|
|
|
|
|
{
|
|
|
|
|
public static MainStoryAI CreateAI(this MainStoryAIComponent self,Team team,int sceneId)
|
|
|
|
|
{
|
2021-04-11 19:50:39 +08:00
|
|
|
|
MainStoryAI ai = EntityFactory.CreateWithParentAndId<MainStoryAI>(self,team.LeaderId);
|
2021-04-08 20:09:59 +08:00
|
|
|
|
ai.Init(team, sceneId);
|
2021-04-11 19:50:39 +08:00
|
|
|
|
foreach (long item in team.GetUnitIds())
|
2021-04-08 20:09:59 +08:00
|
|
|
|
{
|
|
|
|
|
self.aiIdDic[item] = ai.Id;
|
|
|
|
|
}
|
|
|
|
|
return ai;
|
|
|
|
|
}
|
|
|
|
|
public static MainStoryAI GetAI(this MainStoryAIComponent self, long id)
|
|
|
|
|
{
|
2021-04-11 19:50:39 +08:00
|
|
|
|
MainStoryAI ai = self.GetChild<MainStoryAI>(id);
|
2021-04-08 20:09:59 +08:00
|
|
|
|
return ai;
|
|
|
|
|
}
|
|
|
|
|
public static MainStoryAI GetAI(this MainStoryAIComponent self, Unit unit)
|
|
|
|
|
{
|
2021-04-11 19:50:39 +08:00
|
|
|
|
if(!self.aiIdDic.TryGetValue(unit.Id,out long id))
|
2021-04-08 20:09:59 +08:00
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
2021-04-11 19:50:39 +08:00
|
|
|
|
MainStoryAI ai = self.GetChild<MainStoryAI>(id);
|
2021-04-08 20:09:59 +08:00
|
|
|
|
return ai;
|
|
|
|
|
}
|
|
|
|
|
public static bool DestoryAI(this MainStoryAIComponent self, MainStoryAI ai)
|
|
|
|
|
{
|
|
|
|
|
if (!ai) return false;
|
2021-04-11 19:50:39 +08:00
|
|
|
|
List<long> list = ai.team?.GetUnitIds();
|
2021-04-08 20:09:59 +08:00
|
|
|
|
if (list != null)
|
2021-04-11 19:50:39 +08:00
|
|
|
|
foreach (long item in list)
|
2021-04-08 20:09:59 +08:00
|
|
|
|
{
|
|
|
|
|
self.aiIdDic.Remove(item);
|
|
|
|
|
}
|
|
|
|
|
ai.Dispose();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
public static bool DestoryAI(this MainStoryAIComponent self, Unit unit)
|
|
|
|
|
{
|
2021-04-11 19:50:39 +08:00
|
|
|
|
MainStoryAI ai= self.GetAI(unit);
|
2021-04-08 20:09:59 +08:00
|
|
|
|
return DestoryAI(self, ai);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|