/// <summary> /// Spawns the items into the scene. However, this can be overwritten by deserialization /// </summary> /// <param name="sceneName"></param> private static void SpawnGearForScene(string sceneName) { IEnumerable <GearSpawnInfo> sceneGearSpawnInfos = GetSpawnInfos(sceneName); if (sceneGearSpawnInfos is null) { return; } foreach (GearSpawnInfo eachGearSpawnInfo in sceneGearSpawnInfos) { string normalizedGearName = GetNormalizedGearName(eachGearSpawnInfo.PrefabName); Object prefab = Resources.Load(normalizedGearName); if (prefab is null) { Logger.LogWarning("Could not find prefab '{0}' to spawn in scene '{1}'.", eachGearSpawnInfo.PrefabName, sceneName); continue; } float spawnProbability = ProbabilityManager.GetAdjustedProbability(eachGearSpawnInfo); if (ModComponentUtils.RandomUtils.RollChance(spawnProbability)) { Object gear = Object.Instantiate(prefab, eachGearSpawnInfo.Position, eachGearSpawnInfo.Rotation); gear.name = prefab.name; DisableObjectForXPMode xpmode = gear.Cast <GameObject>().GetComponent <DisableObjectForXPMode>(); if (xpmode != null) { Object.Destroy(xpmode); } } } }
private static void PrepareScene() { if (ModComponentUtils.ModUtils.IsNonGameScene()) { return; } System.Diagnostics.Stopwatch stopwatch = new System.Diagnostics.Stopwatch(); stopwatch.Start(); SpawnGearForScene(GetNormalizedSceneName(GameManager.m_ActiveScene)); stopwatch.Stop(); Logger.Log("Spawned '{0}' items for scene '{1}' in {2} ms", ProbabilityManager.GetDifficultyLevel(), GameManager.m_ActiveScene, stopwatch.ElapsedMilliseconds); }