Version: 2021.1
言語: 日本語

説明

ScriptableObject クラスのオブジェクトがスコープを外れるとき、この関数は呼び出されます。

これはオブジェクトを破棄し、任意なクリーンアップのコードを実行したいときにも呼び出されます。 コンパイルが完了した後にスクリプトがリロードされるとき OnDisable が呼び出され、スクリプトがロードされた後に OnEnable が呼び出されます。

// A ScriptableObject example script.
// The A and B members implement features which
// are unrelated to MonoBehaviour.

using UnityEngine;

public class ScriptObj : ScriptableObject { int a = 10; int[] b = new int[5] {0, 17, 34, 42, 67};

public int A { get {return a; } }

// return value in b array, or -1 if x is out-of-range public int B(int x) { if (x >= 0 &amp;&amp; x <= 5) return b[x]; else return -1; }

public void Awake() { Debug.Log("Awake"); }

public void OnEnable() { Debug.Log("OnEnable"); }

public void OnDisable() { Debug.Log("OnDisable"); }

public void OnDestroy() { Debug.Log("OnDestroy"); } }

The following script makes use of the above ScriptableObject script.

// create and access the ScriptObj

using UnityEngine;

public class ScriptObjExample : MonoBehaviour { ScriptObj test;

void Start() { test = (ScriptObj)ScriptableObject.CreateInstance(typeof(ScriptObj));

print(test.A); print(test.B(3)); print(test.B(-3)); } }

OnDisable はコルーチンにすることができません。