public void GenerateLoot(GameObject holder) { Holder chipHolder = holder.GetComponent <Holder>(); chipHolder.ClearChips(); //Easiest to get stats chips, medium to get attack chips, hard to get UI chips int StatsChipWeightage = ChipLibraryStats.Count * 3; int AttackChipsWeightage = ChipLibraryAttacks.Count * 2; //For this demo set Attack Chip Weightage to 0 int UIChipWeightage = ChipLibraryUI.Count * 1 * 0; //For this demo set UI Chip Weightage to 0 int MaxWeightage = StatsChipWeightage + AttackChipsWeightage + UIChipWeightage; int NumberOfChips = Random.Range(1, 4); for (int i = 0; i < NumberOfChips; ++i) { int ID = 0; int ChipWeightage = Random.Range(0, MaxWeightage); if (ChipWeightage >= StatsChipWeightage) { ChipWeightage -= StatsChipWeightage; ++ID; if (ChipWeightage >= UIChipWeightage) { ChipWeightage -= UIChipWeightage; ++ID; } } //Debug.Log("CHIP WEIGHTAGE" + ChipWeightage); //Debug.Log("TYPE" + ID); Chip newChip = new Chip(); switch (ID) { //Stats Chip case 0: newChip.CopyChip(ChipLibraryStats[ChipWeightage / 3]); break; case 1: newChip.CopyChip(ChipLibraryUI[ChipWeightage / 1]); break; case 2: newChip.CopyChip(ChipLibraryAttacks[ChipWeightage / 2]); break; default: break; } chipHolder.AddChip(newChip); } //chipHolder.AddChip(ChipLibraryStats[0]); //chipHolder.AddChip(ChipLibraryStats[1]); LootChips = chipHolder.Chips; }
public void DisplayLoot(GameObject holder) { foreach (GameObject go in DisplayedLootChips) { Destroy(go); } DisplayedLootChips.Clear(); float xDiff = LootBackground.GetComponent <RectTransform>().rect.width * 0.525f; //* 3 / 5; float yDiff = LootBackground.GetComponent <RectTransform>().rect.width * 0.525f; //* 3 / 5; Holder chipHolder = holder.GetComponent <Holder>(); int loop = 0; foreach (Chip c in chipHolder.Chips /*LootChips*/) { GameObject toInstantiate = LootChipTemplate; switch (c.ChipType) { case Chip.CType.ATK: toInstantiate.GetComponent <Image>().color = new Color(0.55f, 0.21f, 0.25f); break; case Chip.CType.UI: toInstantiate.GetComponent <Image>().color = new Color(0.5f, 0.55f, 0.47f); break; case Chip.CType.STAT: toInstantiate.GetComponent <Image>().color = new Color(0.45f, 0.41f, 0.27f); break; default: toInstantiate.GetComponent <Image>().color = Color.white; break; } int tempInt = loop; toInstantiate.GetComponent <RectTransform>().sizeDelta = new Vector3(xDiff * 0.6f, yDiff * 0.6f); Vector3 curPos = LootBackground.GetComponent <RectTransform>().position + new Vector3(0.0f, xDiff * 0.44f, 0.0f) //Original Position - new Vector3(-xDiff * (loop % 3 - 1) * 0.6f, yDiff * (loop / 3 - 1) * 0.6f, -1.0f); //Offset for individual chips GameObject instance = Instantiate(toInstantiate, curPos, Quaternion.identity); instance.transform.GetChild(0).GetComponent <Text>().text = c.ChipName; instance.transform.SetParent(LootBackground.transform); instance.tag = "LootChip"; instance.GetComponent <Button>().onClick.AddListener(() => HandleLootChip(tempInt)); instance.SetActive(true); DisplayedLootChips.Add(instance); ++loop; } }