第十一章 地图动作与地图事件(Map Action and Map Event)
我们已经有了剧本,而且可以运行剧本,但我们还缺少对地图的操作控制。
我们这一章来完成地图上的操作,地图的操作将全部由MapAction
控制。
文章目录
九 触发事件与切换回合(Trigger Events and Change Turn)
光有地图事件是不行的,我们还需要知道如何触发它们。
1 触发事件方法(Trigger Events Method)
我们同样的使用一个Coroutine
来触发事件:
protected Coroutine m_EventCoroutine = null;
/// <summary>
/// 触发地图事件
/// </summary>
/// <param name="type"></param>
/// <param name="onTriggerEnd"></param>
public void TriggerEvents(MapEventConditionType type, Action onTriggerEnd)
{
mapStatus = MapStatus.Event;
if (m_EventCoroutine != null)
{
error = "MapAction TriggerEvents -> event is running.";
status = ActionStatus.Error;
Debug.LogError(error);
if (onTriggerEnd != null)
{
onTriggerEnd();
}
return;
}
m_EventCoroutine = GameDirector.instance.StartCoroutine(EventsTriggering(type, onTriggerEnd));
}
public IEnumerator EventsTriggering(MapEventConditionType type, Action onTriggerEnd)
{
yield return null;
// TODO
}
关于触发事件,我们只用可以当做入口的条件来触发相应的事件:
switch (type)
{
case MapEventConditionType.NoneCondition:
yield return m_MapEvents.TriggerStartEvents(
this, onError: eventError => error = eventError);
break;
case MapEventConditionType.TurnCondition:
yield return m_MapEvents.TriggerTurnEvents(
this, onError: eventError => error = eventError);
break;
case MapEventConditionType.PositionCondition:
if (movingEndCell != null)
{
yield return m_MapEvents.TriggerPositionEvents(
this, movingEndCell.position, onError: eventError => error = eventError);
}
break;
case MapEventConditionType.RoleDeadCondition:
if (selectedUnit != null && selectedUnit.role.isDead)
{
yield return m_MapEvents.TriggerDeadEvents(
this, selectedUnit.role.characterId, onError: eventError => error = eventError);
}
if (targetUnit != null && targetUnit.role.isDead)
{
yield return m_MapEvents.TriggerDeadEvents(
this, targetUnit.role.characterId, onError: eventError => error = eventError);
}
break;
case MapEventConditionType.RoleTalkCondition:
if