以下のコードなのですがこれはunityのリファレンス
https://docs.unity3d.com/jp/540/ScriptReference/UI.InputField-onEndEdit.html
にあるコードなのですが
問題なのは
mainInputField.onEndEdit.AddListener(delegate{LockInput(mainInputField)}
ここの部分です。
AddListenerの引数Events.UnityAction callとあり中身はpublic delegate void UnityAction()
なのですが、
delegate{LockInput(mainInputField)}のような書き方は調べても見たことがありません。
普通delegateは登録したいメソッドをそのままで移入するか new delegate(メソッドの名前)の形にするか匿名メソッドで書くかラムダ式で登録するのですが
このような書き方は最新の描き方なのでしょうか?
C#
1 using UnityEngine; 2using System.Collections; 3using UnityEngine.UI; // Required when Using UI elements. 4 5public class Example : MonoBehaviour 6{ 7 public InputField mainInputField; 8 9 void LockInput(InputField input) 10 { 11 if (input.text.Length > 0) 12 { 13 Debug.Log("Text has been entered"); 14 } 15 else if (input.text.Length == 0) 16 { 17 Debug.Log("Main Input Empty"); 18 } 19 } 20 21 public void Start() 22 { 23 mainInputField.onEndEdit.AddListener(delegate{LockInput(mainInputField);}); 24 } 25}
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/09/24 05:13