50
44

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Unity C# Callbackパターンの書き方

Last updated at Posted at 2014-08-06

delegateを使う。

呼び出し側

using UnityEngine;

public class SampleMain {

    public void Start () {

        SampleSub sub = new SampleSub();
        sub.hoge(Callback);
    }

    public void Callback ( string msg ) {

        Debug.Log("Callback : " + msg); // Callback : おわったよ
    }
}

呼び出され側

using UnityEngine;

public class SampleSub {

	public delegate void onComplete( string msg );

    public void hoge ( onComplete callback ) {

        // 処理が終わったら
        callback("おわったよ");
    }
}
50
44
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
50
44

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?