/// <summary> /// Spawns items from the equipment group /// </summary> /// <param name="selectedGroup"></param> /// <param name="position"></param> /// <param name="rotation"></param> /// <param name="callback"></param> /// <param name="tolerance"></param> /// <returns></returns> public static IEnumerator InstantiateFromEquipmentGroup(EquipmentGroup selectedGroup, Vector3 position, Quaternion rotation, Action <GameObject> callback = null, float tolerance = 1.3f) { float currentHeight = 0; foreach (EquipmentGroup group in selectedGroup.GetSpawnedEquipmentGroups()) { for (int i = 0; i < group.ItemsToSpawn; i++) { FVRObject selectedFVR; if (IM.OD.TryGetValue(group.GetObjects().GetRandom(), out selectedFVR)) { //First, async get the game object to spawn AnvilCallback <GameObject> objectCallback = selectedFVR.GetGameObjectAsync(); yield return(objectCallback); GameObject gameObject = objectCallback.Result; //Next calculate the height needed for this item float heightNeeded = gameObject.GetMaxBounds().size.y / 2 * tolerance; currentHeight += heightNeeded; //Finally spawn the item and call the callback if it's not null GameObject spawnedObject = UnityEngine.GameObject.Instantiate(gameObject, position + (Vector3.up * currentHeight), rotation); if (callback != null) { callback.Invoke(spawnedObject); } yield return(null); } } } }
void OnDestroy() { if (dontDrop) { return; } TNHTweakerLogger.Log("TNHTweaker -- Lootable link was destroyed!", TNHTweakerLogger.LogType.TNH); List <EquipmentGroup> selectedGroups = group.GetSpawnedEquipmentGroups(); string selectedItem; int spawnedItems = 0; foreach (EquipmentGroup selectedGroup in selectedGroups) { for (int itemIndex = 0; itemIndex < selectedGroup.ItemsToSpawn; itemIndex++) { if (selectedGroup.IsCompatibleMagazine) { FVRObject mag = FirearmUtils.GetAmmoContainerForEquipped(selectedGroup.MinAmmoCapacity, selectedGroup.MaxAmmoCapacity); if (mag != null) { selectedItem = mag.ItemID; } else { TNHTweakerLogger.Log( "TNHTweaker -- Spawning nothing, since group was compatible magazines, and could not find a compatible magazine for player", TNHTweakerLogger.LogType.TNH); return; } } else { selectedItem = selectedGroup.GetObjects().GetRandom(); } if (LoadedTemplateManager.LoadedVaultFiles.ContainsKey(selectedItem)) { AnvilManager.Run(TNHTweakerUtils.SpawnFirearm(LoadedTemplateManager.LoadedVaultFiles[selectedItem], transform.position + (Vector3.up * 0.1f * spawnedItems), transform.rotation)); } else { Instantiate(IM.OD[selectedItem].GetGameObject(), transform.position + (Vector3.up * 0.1f * spawnedItems), transform.rotation); } spawnedItems += 1; } } }