//init the npc manager: public void InitNPCMgr() { //make sure there's a npc manager prefab set: if (npcMgr == null) { Debug.LogError("[Game Manager]: NPC Manager hasn't been set for NPC faction."); return; } npcMgrIns = Instantiate(npcMgr.gameObject).GetComponent <NPCManager>(); //set the faction manager: npcMgrIns.FactionMgr = FactionMgr; //init the npc manager: npcMgrIns.Init(); if (TypeInfo != null) //if this faction has a valid type. { //set the building center regulator (if there's any): if (TypeInfo.centerBuilding != null) { npcMgrIns.territoryManager_NPC.centerRegulator = npcMgrIns.GetBuildingRegulatorAsset(TypeInfo.centerBuilding); } //set the population building regulator (if there's any): if (TypeInfo.populationBuilding != null) { npcMgrIns.populationManager_NPC.populationBuilding = npcMgrIns.GetBuildingRegulatorAsset(TypeInfo.populationBuilding); } //is there extra buildings to add? if (TypeInfo.extraBuildings.Count > 0) { //go through them: foreach (Building b in TypeInfo.extraBuildings) { if (b != null) { npcMgrIns.buildingCreator_NPC.independentBuildingRegulators.Add(npcMgrIns.GetBuildingRegulatorAsset(b)); } else { Debug.LogError("[Game Manager]: Faction " + TypeInfo.Name + " (Code: " + TypeInfo.Code + ") has missing building regulator(s) in extra buildings."); } } } } }
//init the npc manager: public void InitNPCMgr(GameManager gameMgr) { //making sure there's a valid npc type and a valid NPCManager prefab for it: Assert.IsNotNull(npcType, $"[FactionSlot] NPC Faction of ID: {ID} does not have a NPCTypeInfo assigned, will be initiated as dummy faction."); NPCManager npcMgrPrefab = npcType.GetNPCManagerPrefab(typeInfo); Assert.IsNotNull(npcMgrPrefab, $"[FactionSlot] NPC Faction of ID: {ID} does not have a NPCManager prefab defined for its type, will be initiated as dummy faction."); npcMgrIns = Object.Instantiate(npcMgrPrefab.gameObject).GetComponent <NPCManager>(); //init the npc manager instance: npcMgrIns.Init(npcType, gameMgr, FactionMgr); }
//init the npc manager: public void InitNPCMgr(GameManager gameMgr) { //make sure there's a npc manager prefab set: if (npcMgr == null) { Debug.LogError("[Faction Slot]: NPC Manager hasn't been set for NPC faction."); return; } npcMgrIns = Object.Instantiate(npcMgr.gameObject).GetComponent <NPCManager>(); //set the faction manager: npcMgrIns.FactionMgr = FactionMgr; //init the npc manager: npcMgrIns.Init(gameMgr); if (typeInfo != null) //if this faction has a valid type. { //set the building center regulator (if there's any): if (typeInfo.GetCenterBuilding() != null) { npcMgrIns.territoryManager_NPC.centerRegulator = npcMgrIns.GetBuildingRegulatorAsset(typeInfo.GetCenterBuilding()); } //set the population building regulator (if there's any): if (typeInfo.GetPopulationBuilding() != null) { npcMgrIns.populationManager_NPC.populationBuilding = npcMgrIns.GetBuildingRegulatorAsset(typeInfo.GetPopulationBuilding()); } //is there extra buildings to add? foreach (Building b in typeInfo.GetExtraBuildings()) { if (b != null) { npcMgrIns.buildingCreator_NPC.independentBuildingRegulators.Add(npcMgrIns.GetBuildingRegulatorAsset(b)); } else { Debug.LogError($"[Game Manager]: Faction " + typeInfo.GetName() + " (Code: " + typeInfo.GetCode() + ") has missing Building fields in the 'Extra Buildings' list."); } } } }