Ejemplo n.º 1
0
 /// <summary>
 /// 帆布显示运行消息事件
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="msg"></param>
 public static void ShowInfo(object sender, string msg)
 {
     if (ShowInfoEvent != null)
     {
         ShowInfoEvent.Invoke(sender, new ShowInfoEventArgs()
         {
             Msg = msg
         });
     }
 }
    void Start()
    {
        // 参照するイベントのインスタンス

        /*  MonoBehaviour を 継承してるクラスは参照できない
         *  You are trying to create a MonoBehaviour using the 'new' keyword.
         *  This is not allowed.  MonoBehaviours can only be added using AddComponent().
         *  buttonEvents = new Button_event(); だめ!!
         */
        showInfoEvent = new ShowInfoEvent("hiro", 302);
        // ボタンの取得
        showInfoButton.GetComponent <Button>();
        // ボタンが押された時、実行するイベントを加える
        showInfoButton.onClick.AddListener(showInfoEvent.ShowInfo);
    }