반응형
FactionManager.cs
public class FactionManager : MonoBehaviour {
// ...
//The lists below hold all different types of units.
private List<Unit> units = new List<Unit>(); //list containing all the units that this faction owns.
// ...
FactionManager에 다 있음.
CustomEvent에서 Unit이 Create되거나, Destroy될때 리스너를 받아서 자체적으로 업데이트.
GameDataManager.cs
private bool InitSinglePlayerGame()
{
// ...
//This where we will set the NPC settings using the info from the single player manager:
//First check if we have enough faction slots available:
if (LobbyManager.instance.LobbyFactions.Count <= factions.Count)
{
defeatCondition = LobbyManager.instance.UIMgr.defeatConditionMenu.GetValue(); //set defeat condition
speedModifier = LobbyManager.instance.UIMgr.speedModifierMenu.GetValue(); //set speed modifier
//loop through the factions slots of this map:
for (int i = 0; i < LobbyManager.instance.LobbyFactions.Count; i++)
{
factions[i].Init(
LobbyManager.instance.LobbyFactions[i].GetFactionName(),
LobbyManager.instance.LobbyFactions[i].GetFactionType(),
LobbyManager.instance.LobbyFactions[i].GetFactionColor(),
LobbyManager.instance.LobbyFactions[i].PlayerControlled,
LobbyManager.instance.GetCurrentMap().GetInitialPopulation(),
LobbyManager.instance.LobbyFactions[i].GetNPCType(),
gameObject.AddComponent<FactionManager>(), i, this);
}
// ...
gameObject.AddComponent<FactionManager>(), i, this);
1.
FactionManager는 Faction당 1개씩 Scene에 AddComponent를 통해 생성된다.
Scene을 Play했을 때 GameManager 게임오브젝트를 보면 밑에 추가되어 있음.
2.
FactonManager는 FactionSlot안에 들어있음.
GameManager를 통해 가져오면 되고, 이를 통해 모든 unit들의 instance에 접근가능.
Example
IEnumerable<Unit> units = gameMgr.GetFaction(0).FactionMgr.GetUnits();
foreach(Unit unit in units) {
Debug.Log($"유닛: {unit.name}");
}
반응형
'Unity > Asset 분석' 카테고리의 다른 글
[RTS Engine] [GridSearchHandler] No search cell has been defined to contain position: {position}! (0) | 2022.03.12 |
---|---|
[RTS Engine] Attack시 자폭판정이 쓰는 버그 (0) | 2022.01.25 |
[RTS Engine] Attack, AttackObjectLauncher 구조 (0) | 2022.01.05 |
Mesh Backer (0) | 2021.07.30 |
[RTS Engine] Terrain크기 수정하기 (0) | 2021.07.17 |