Version: 2021.2

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"); } }