public bool OnEvent(IEvent e) { Type eventType = e.GetType(); // 자기 타일에 몬스터가 들어오거나 나갈 때 리스트에서 제거 if (eventType == typeof(TileEnterEvent)) { TileEnterEvent enterEvent = e as TileEnterEvent; if (enterEvent.EnterTilePos.x == tileTransform.position.x && enterEvent.EnterTilePos.z == tileTransform.position.z) { containMonsterUnitList.Add((MonsterUnit)enterEvent.EnterUnit); //Debug.Log(tileTransform.position + " 몬스터 IN " + containMonsterUnitList.Count); } return(true); } else if (eventType == typeof(TileLeaveEvent)) { TileLeaveEvent leaveEvent = e as TileLeaveEvent; if (leaveEvent.LeaveTilePos.x == tileTransform.position.x && leaveEvent.LeaveTilePos.z == tileTransform.position.z) { containMonsterUnitList.Remove((MonsterUnit)leaveEvent.LeaveUnit); //Debug.Log(tileTransform.position + " 몬스터 OUT " + containMonsterUnitList.Count); } return(true); } else if (eventType == typeof(MonsterDeadEvent)) { MonsterDeadEvent deadEvent = e as MonsterDeadEvent; if (deadEvent.DeadPos.x == tileTransform.position.x && deadEvent.DeadPos.z == tileTransform.position.z) { containMonsterUnitList.Remove(deadEvent.DeadUnit); //Debug.Log(tileTransform.position + " 몬스터 Dead " + containMonsterUnitList.Count); } return(true); } else if (eventType == typeof(PlayerUnitSummonEvent)) { PlayerUnitSummonEvent summonEvent = e as PlayerUnitSummonEvent; if (summonEvent.SummonTilePos.x == tileTransform.position.x && summonEvent.SummonTilePos.z == tileTransform.position.z) { containPlayerUnit = summonEvent.SummonUnit; //Debug.Log(tileTransform.position + " 유닛 Summon " + containPlayerUnit); } return(true); } else if (eventType == typeof(PlayerUnitDeadEvent)) { PlayerUnitDeadEvent deadEvent = e as PlayerUnitDeadEvent; if (deadEvent.DeadPos.x == tileTransform.position.x && deadEvent.DeadPos.z == tileTransform.position.z) { containPlayerUnit = null; //Debug.Log(tileTransform.position + " 유닛 Dead " + containPlayerUnit); } return(true); } return(false); }
public static TileLeaveEvent Create(Vector3Int tilePos, Unit unit) { TileLeaveEvent e = new TileLeaveEvent(); e.LeaveTilePos = tilePos; e.LeaveUnit = unit; return(e); }
protected void Walk(float dt) { monsterTransform.position = Vector3.MoveTowards(monsterTransform.position, pathList[0], dt * speed); // 거리가 특정 거리 이하 일때 발생 if (Vector3.Distance(monsterTransform.position, pathList[0]) <= 0.1) { currentState = MonsterUnitState.SetPath; } else if (Vector3.Distance(monsterTransform.position, pathList[0]) <= 0.5 && pathList[0] != UnitPosition) { // 절반정도 진입했으면 TileEnter, TileLeave발행하고 포함된 타일 변경 + 적이 있는지 체크 GameManager.Instance.MessageSystem.Publish(TileLeaveEvent.Create(UnitPosition, this)); UnitPosition = pathList[0]; GameManager.Instance.MessageSystem.Publish(TileEnterEvent.Create(UnitPosition, this)); if (CheckPlayerUnit()) { currentState = MonsterUnitState.Attack; } } }