public void SetLearnSkillsMenu(System.Action <int> confirmFunc, System.Action refuseFunc) { //set refuse skill button refuseSkillButton.onClick.RemoveAllListeners(); refuseSkillButton.onClick.AddListener(() => refuseFunc()); //deactive every button in the pooling and add if there are not enough buttons in pool skillsToReplacePooling.DeactiveAll(); skillsToReplacePooling.InitCycle(prefabSimpleButton, GameManager.instance.MaxSkillForPokemon); //get current skills of the pokemon List <SkillModel> currentSkills = fightManager.currentPlayerPokemon.CurrentSkills; int quantity = Mathf.Min(currentSkills.Count + 1, GameManager.instance.MaxSkillForPokemon); for (int i = 0; i < quantity; i++) { //instantiate button from pool and set parent Button button = skillsToReplacePooling.Instantiate(prefabSimpleButton, contentLearnSkillMenu, false); //be sure to not have listeners button.onClick.RemoveAllListeners(); //add new listener to button int indexForLambda = i; //for some reason, need to make a copy of anything you want to access for the lambda button.onClick.AddListener(() => confirmFunc(indexForLambda)); //set text (name of the skill or empty) button.GetComponentInChildren <Text>().text = i < currentSkills.Count ? currentSkills[i].GetObjectName() : "-"; } skillsToReplacePooling.EndCycle(quantity); }
public void SetCatchPokemonMenu(System.Action <int> confirmFunc, System.Action refuseFunc) { //set refuse pokemon button refuseCatchPokemonButton.onClick.RemoveAllListeners(); refuseCatchPokemonButton.onClick.AddListener(() => refuseFunc()); //deactive every button in the pooling and add if there are not enough buttons in pool pokemonCatchPooling.DeactiveAll(); pokemonCatchPooling.InitCycle(prefabSimpleButton, GameManager.instance.MaxPokemonInTeam); //get current player pokemons List <PokemonModel> playerPokemons = GameManager.instance.Player.PlayerPokemons; int quantity = Mathf.Min(playerPokemons.Count + 1, GameManager.instance.MaxPokemonInTeam); for (int i = 0; i < quantity; i++) { //instantiate button from pool and set parent Button button = pokemonCatchPooling.Instantiate(prefabSimpleButton, contentCatchPokemonMenu, false); //be sure to not have listeners button.onClick.RemoveAllListeners(); //add new listener to button int indexForLambda = i; //for some reason, need to make a copy of anything you want to access for the lambda button.onClick.AddListener(() => confirmFunc(indexForLambda)); //set text (name of the pokemon or empty) button.GetComponentInChildren <Text>().text = i < playerPokemons.Count ? playerPokemons[i].GetObjectName() : "-"; //set not interactable button of pokemon in arena if (i < playerPokemons.Count && playerPokemons[i] == fightManager.currentPlayerPokemon) { button.interactable = false; } //be sure other buttons are interactable, or when start another fight can be a button not interactable from previous battle else if (button.interactable == false) { button.interactable = true; } } pokemonCatchPooling.EndCycle(quantity); }
void SetList <T>(Pooling <Button> poolingList, List <T> valueArray, Transform parent, System.Action <Button, T> function) where T : IGetName { //deactive every button poolingList.DeactiveAll(); //add if there are not enough buttons in pool poolingList.InitCycle(prefabSimpleButton, valueArray.Count); //foreach value foreach (T value in valueArray) { //instantiate button from pool and set parent Button button = poolingList.Instantiate(prefabSimpleButton, parent, false); //and set it SetButton(button, value, function); } poolingList.EndCycle(valueArray.Count); }