45 lines
1.6 KiB
C#
45 lines
1.6 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using MedievalParty.Entity;
|
|
using MedievalParty.Entity.AI;
|
|
using MedievalParty.Entity.Player;
|
|
using UnityEngine;
|
|
|
|
namespace MedievalParty.Core.Game
|
|
{
|
|
public class GameManager_SpawningEntityState: IState
|
|
{
|
|
private readonly PlayerObject _playerPrefab;
|
|
private readonly AIObject _AIPrefab;
|
|
private readonly List<Transform> _spawningPositions;
|
|
private readonly EntityListSO _entityList;
|
|
private readonly Action _onSpawnCompleted;
|
|
|
|
public GameManager_SpawningEntityState(PlayerObject playerPrefab, AIObject aiPrefab, List<Transform> spawningPositions, EntityListSO entityList, Action onSpawnCompleted)
|
|
{
|
|
_playerPrefab = playerPrefab;
|
|
_AIPrefab = aiPrefab;
|
|
_spawningPositions = spawningPositions;
|
|
_entityList = entityList;
|
|
_onSpawnCompleted = onSpawnCompleted;
|
|
}
|
|
|
|
public void OnEnter()
|
|
{
|
|
CreateEntity(_playerPrefab, _spawningPositions[0].position, _entityList.Characters[0]);
|
|
for (int i = 1; i < _spawningPositions.Count; i++)
|
|
CreateEntity(_AIPrefab, _spawningPositions[i].position, _entityList.Characters[i]);
|
|
|
|
_onSpawnCompleted();
|
|
}
|
|
|
|
public void OnExit() { }
|
|
public void OnUpdate() { }
|
|
|
|
private void CreateEntity(EntityObject prefab, Vector3 spawn, EntitySO entity)
|
|
{
|
|
EntityObject obj = GameObject.Instantiate(prefab, spawn, Quaternion.identity);
|
|
obj.SetCharacter(entity);
|
|
}
|
|
}
|
|
} |