// Start is called before the first frame update IEnumerator Start() { yield return(null); m_Click.AddListener(OnBtnClick); container.context = this; }
// Use this for initialization void Awake() { switchBtn = this.transform.GetComponent <Button>(); if (switchBtn != null) { UnityEngine.UI.Button.ButtonClickedEvent clickEvent = new UnityEngine.UI.Button.ButtonClickedEvent(); clickEvent.AddListener(() => { OnClickSwitch(); }); switchBtn.onClick = clickEvent; } }
public void Init(int chapterCount) { for (int i = 2; i <= chapterCount; i++) { int n = i; GameObject obj = Instantiate(Prefab, transform); string s = "Log Chapter" + n; obj.name = s; obj.GetComponentInChildren <Text>().text = s; UnityEngine.UI.Button.ButtonClickedEvent cce = new UnityEngine.UI.Button.ButtonClickedEvent(); cce.AddListener(() => { LearnMain.Instance.LogChapter(n); }); obj.GetComponent <Button>().onClick = cce; } }
/** * Ajoute ou modifie un listener à chaque champ de la ligne row * @row ligne à modifier * @fieldChangeMethod méthode à appeler lors de la modification d'un champ de type texte * @removeRowMethod méthode à appeler pour le dernier champ qui est le bouton de suppression d'une ligne * @decallage mettre cette valeur valeur à -1 si cette méthode est appelée depuis la méthode de suppression d'une ligne (décallant les indexs de la table de 1) */ public void addListenersToRow(Transform row, Action <int, int> fieldChangeMethod, Action <int> removeRowMethod, int decallage) { // Ajout du listener à chaque champs de type texte de la nouvelle ligne for (int i = 1; i < row.gameObject.transform.childCount - 1; i++) { int colnum = i; int rownum = row.GetSiblingIndex() + decallage; InputField.OnChangeEvent submitEvent = new InputField.OnChangeEvent(); submitEvent.AddListener(delegate { fieldChangeMethod(rownum, colnum); }); row.gameObject.transform.GetChild(i).gameObject.transform.GetChild(0).GetComponent <InputField> ().onValueChange = submitEvent; } //Ajout du listener du bouton de suppression d'une ligne int rownumButton = row.GetSiblingIndex() + decallage; UnityEngine.UI.Button.ButtonClickedEvent onclickEvent = new UnityEngine.UI.Button.ButtonClickedEvent(); onclickEvent.AddListener(delegate { removeRowMethod(rownumButton); }); row.gameObject.transform.GetChild(row.gameObject.transform.childCount - 1).gameObject.transform.GetChild(0).GetComponent <UnityEngine.UI.Button> ().onClick = onclickEvent; }
// Start is called before the first frame update void Start() { m_Click.AddListener(OnBtnClick); container.context = this; }