Version: 2022.1

InitializeOnLoadMethodAttribute

class in UnityEditor

切换到手册

描述

允许在 Unity 加载时初始化编辑器类方法,无需用户操作。

using UnityEngine;
using UnityEditor;

class MyClass { [InitializeOnLoadMethod] static void OnProjectLoadedInEditor() { Debug.Log("Project loaded in Unity Editor"); } }