一.MissionBehavior
Mission任务中发生的事件,AgentSpawn,AgentRemove,BeforeMissionStart等统称为MissionBehavior.
通过在Mission中添加属于自己的MissionBehavior实现对游戏任务事件的捕捉
<1.在MBSubModuleBase中重写OnBeforeMissionBehaviorInitialize(Mission mission)
<2.获取Mission添加MyMissionBehavior事件捕捉
<3.实现MyMissionBehavior继承MissionBehavior重写OnAgentSpawn,OnMissionTick等回调
public override void OnMissionBehaviorInitialize(Mission mission)
{base.OnMissionBehaviorInitialize(mission);mission.AddMissionBehavior(new MissionSoundTimer(mission));
}public class MissionSoundTimer : BasicMissionHandler
{public override void OnAgentCreated(Agent agent){base.OnAgentCreated(agent);}public override void OnMissionTick(float dt){}
}
二.CampaignBehavior
大地图中发生的事件,PartyEncounter,DaliyTick等统称为CampaignBehavior.
通过在Campaign中添加属于自己的Behavior实现对大地图事件的捕捉.
<1.在MBSubModuleBase中重写OnGameStart(Game game, IGameStarter gameStarterObject)
<2.在CampaignGameStarter中添加MyCampaignBehavior
<3.MyCampaignBehavior继承CampaignBehavior重写RegisterEvents,捕捉大地图事件
protected override void OnGameStart(Game game, IGameStarter gameStarterObject)
{base.OnGameStart(game, gameStarterObject);if (gameStarterObject is CampaignGameStarter){CampaignGameStarter starter = (CampaignGameStarter)gameStarterObject;starter.AddBehavior(new WorldMapBehavior());}
}public class WorldMapBehavior : CampaignBehaviorBase {public override void RegisterEvents(){CampaignEvents.OnMainPartyStarvingEvent.AddNonSerializedListener(this, PlayMusic);CampaignEvents.DailyTickEvent.AddNonSerializedListener(this, PlayMusic);}public void PlayMusic(){MBMusicManager.Current.StartTheme(MusicTheme.MainTheme, 10, false);}public override void SyncData(IDataStore dataStore){}
}