17
16

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.

InitializeOnLoadのメソッド版! - InitializeOnLoadMethod

Last updated at Posted at 2015-03-08

InitializeOnLoad と InitializeOnLoadMethod

InitializeOnLoad の使い方はクラスに付けて使う方法でした。

using UnityEngine;
using UnityEditor;

[InitializeOnLoad]
public class NewBehaviourScript
{
	static NewBehaviourScript ()
	{
		Debug.Log("スクリプトコンパイル後に呼び出される");
	}
}

これのメソッド版になります。

using UnityEngine;
using UnityEditor;

public class NewBehaviourScript
{
	[InitializeOnLoadMethod]
	static void Hoge ()
	{
		Debug.Log ("スクリプトコンパイル後に呼び出される");
	}
}

ランタイム版の RuntimeInitializeOnLoadMethod もあるよ

ゲーム再生直後に呼び出される RuntimeInitializeOnLoadMethod もあります。

using UnityEngine;
using UnityEditor;

public class NewBehaviourScript
{
	[RuntimeInitializeOnLoadMethod]
	static void Hoge ()
	{
		Debug.Log ("ゲーム再生直後に呼び出される");
	}
}
17
16
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
17
16

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?