Version: 2017.3

RuntimeInitializeOnLoadMethodAttributeConstructor

切换到手册
public RuntimeInitializeOnLoadMethodAttribute ();
public RuntimeInitializeOnLoadMethodAttribute (RuntimeInitializeLoadType loadType);

参数

loadType 确定是在场景加载之前还是之后 调用这些方法。

描述

加载场景时使用的运行时类的创建。

// Demonstration of RuntimeInitializeOnLoadMethod and the argument it can take.
using UnityEngine;

class MyClass { [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)] static void OnBeforeSceneLoadRuntimeMethod() { Debug.Log("Before first scene loaded"); }

[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.AfterSceneLoad)] static void OnAfterSceneLoadRuntimeMethod() { Debug.Log("After first scene loaded"); }

[RuntimeInitializeOnLoadMethod] static void OnRuntimeMethodLoad() { Debug.Log("RuntimeMethodLoad: After first scene loaded"); } }