public void SpawnLootAtPoint(List <string> lootIds, Vector3 point) { foreach (string lootId in lootIds) { if (!database.ContainsKey(lootId)) { Debug.LogError("LootDatabase does not contain key: " + lootId); } Loot loot = database.Get(lootId); LootDrop chosen = loot.ChooseRandom(); //Debug.Log ("Loot roll: " + lootId + "... chose: " + chosen.prefabName); if (chosen.prefabName.Equals(LootDrop.NONE_PREFAB_NAME)) { continue; } List <GameObject> prefabs = PrefabManager.Instance.SpawnPrefabs(chosen.prefabName, chosen.quantity, point); foreach (GameObject instance in prefabs) { // TODO: parent should be room // set self as parent for now instance.transform.parent = transform; Rigidbody2D rigidbody = instance.GetComponent <Rigidbody2D>(); if (rigidbody != null) { Vector2 spawnForce = new Vector2(Random.Range(-SPAWN_FORCE / 2.0f, SPAWN_FORCE / 2.0f), Random.Range(SPAWN_FORCE / 2.0f, SPAWN_FORCE)); rigidbody.AddForce(spawnForce); } } } }
protected void LootDropGUI(string lootId, Loot l, LootDrop drop, int index) { string errorString; GUILayout.BeginVertical(); GUILayout.BeginHorizontal("Box"); // DROP ROW - REMOVE BUTTON if (GUILayout.Button("-", GUILayout.Width(15), GUILayout.Height(15))) { if (EditorUtility.DisplayDialog("Delete Drop Row", "Are you sure?", "Delete", "Cancel")) { l.dropTable.Remove(drop); } } // DROP ROW - PREFAB NAME drop.prefabName = GUILayout.TextField(drop.prefabName, GUILayout.Width(150)); // DROP ROW - QUANTITY bool quantityValid = false; string quantityKey = lootId + "Quantity" + index; if (!temporaryStrings.ContainsKey(quantityKey)) { temporaryStrings[quantityKey] = drop.quantity.ToString(); } GUILayout.Label("Quantity: "); temporaryStrings[quantityKey] = GUILayout.TextField(temporaryStrings[quantityKey], GUILayout.Width(25)); int result = 0; if (int.TryParse(temporaryStrings[quantityKey], out result)) { drop.quantity = (uint)Mathf.Max(0, result); quantityValid = true; } // DROP ROW - WEIGHT bool weightValid = false; string weightKey = lootId + "Weight" + index; if (!temporaryStrings.ContainsKey(weightKey)) { temporaryStrings[weightKey] = drop.weight.ToString(); } GUILayout.Label("Weight: "); temporaryStrings[weightKey] = GUILayout.TextField(temporaryStrings[weightKey], GUILayout.Width(40)); if (int.TryParse(temporaryStrings[weightKey], out result)) { drop.weight = (uint)Mathf.Max(0, result); weightValid = true; } if (weightValid && quantityValid && drop.IsValid(out errorString, prefabList)) { GUILayout.Label("✓"); } else { GUILayout.Label("✖"); } GUILayout.EndHorizontal(); if (errorString != null && !errorString.Trim().Equals("")) { GUILayout.Label("<color=red>" + errorString + "</color>", richTextStyle); } GUILayout.EndVertical(); }