public override void OnCreated(ILoading loading) { Logger.logInfo(LOG_BASE, "DormitoryMod Created"); instance = this; base.OnCreated(loading); if (this.dormitoryInitializerObj != null) { return; } this.dormitoryInitializerObj = new GameObject("DormitoryMod Dormitories"); this.dormitoryInitializer = this.dormitoryInitializerObj.AddComponent <DormitoryInitializer>(); }
public void updateCapacity(float targetValue) { try { DormitoryMod seniorCitizenCenterMod = DormitoryMod.getInstance(); if (seniorCitizenCenterMod == null || seniorCitizenCenterMod.getDormitoryInitializer() == null) { Logger.logInfo(Logger.LOG_OPTIONS, "OptionsManager.updateCapacity -- Skipping capacity update because a game is not loaded yet"); return; } DormitoryInitializer dormitoryInitializer = DormitoryMod.getInstance().getDormitoryInitializer(); if (dormitoryInitializer.getLoadedLevel() != DormitoryInitializer.LOADED_LEVEL_GAME) { Logger.logInfo(Logger.LOG_OPTIONS, "OptionsManager.updateCapacity -- Skipping capacity update because a game is not loaded yet"); return; } } catch (Exception e) { Logger.logError(Logger.LOG_OPTIONS, "OptionsManager.updateCapacity -- Skipping capacity update because a game is not loaded yet -- Exception: {0}", e.Message); } Logger.logInfo(Logger.LOG_OPTIONS, "OptionsManager.updateCapacity -- Updating capacity with modifier: {0}", targetValue); for (uint index = 0; PrefabCollection <BuildingInfo> .LoadedCount() > index; ++index) { BuildingInfo buildingInfo = PrefabCollection <BuildingInfo> .GetLoaded(index); if (buildingInfo != null && buildingInfo.m_buildingAI is DormitoryAi) { ((DormitoryAi)buildingInfo.m_buildingAI).updateCapacity(targetValue); } } BuildingManager buildingManager = Singleton <BuildingManager> .instance; for (ushort i = 0; i < buildingManager.m_buildings.m_buffer.Length; i++) { if (buildingManager.m_buildings.m_buffer[i].Info != null && buildingManager.m_buildings.m_buffer[i].Info.m_buildingAI != null && buildingManager.m_buildings.m_buffer[i].Info.m_buildingAI is DormitoryAi) { ((DormitoryAi)buildingManager.m_buildings.m_buffer[i].Info.m_buildingAI).validateCapacity(i, ref buildingManager.m_buildings.m_buffer[i], true); } } }