58 lines
1.7 KiB
C#
58 lines
1.7 KiB
C#
|
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)
|
|||
|
{
|
|||
|
var ai = EntityFactory.CreateWithParentAndId<MainStoryAI>(self,team.LeaderId);
|
|||
|
ai.Init(team, sceneId);
|
|||
|
foreach (var item in team.GetUnitIds())
|
|||
|
{
|
|||
|
self.aiIdDic[item] = ai.Id;
|
|||
|
}
|
|||
|
return ai;
|
|||
|
}
|
|||
|
public static MainStoryAI GetAI(this MainStoryAIComponent self, long id)
|
|||
|
{
|
|||
|
var ai = self.GetChild<MainStoryAI>(id);
|
|||
|
return ai;
|
|||
|
}
|
|||
|
public static MainStoryAI GetAI(this MainStoryAIComponent self, Unit unit)
|
|||
|
{
|
|||
|
if(!self.aiIdDic.TryGetValue(unit.Id,out var id))
|
|||
|
{
|
|||
|
return null;
|
|||
|
}
|
|||
|
var ai = self.GetChild<MainStoryAI>(id);
|
|||
|
return ai;
|
|||
|
}
|
|||
|
public static bool DestoryAI(this MainStoryAIComponent self, MainStoryAI ai)
|
|||
|
{
|
|||
|
if (!ai) return false;
|
|||
|
var list = ai.team?.GetUnitIds();
|
|||
|
if (list != null)
|
|||
|
foreach (var item in list)
|
|||
|
{
|
|||
|
self.aiIdDic.Remove(item);
|
|||
|
}
|
|||
|
ai.Dispose();
|
|||
|
return true;
|
|||
|
}
|
|||
|
public static bool DestoryAI(this MainStoryAIComponent self, Unit unit)
|
|||
|
{
|
|||
|
var ai= self.GetAI(unit);
|
|||
|
return DestoryAI(self, ai);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|