Version: 2023.2

TypeCache.GetMethodsWithAttribute

切换到手册
public static TypeCache.MethodCollection GetMethodsWithAttribute ();
public static TypeCache.MethodCollection GetMethodsWithAttribute (Type attrType);
public static TypeCache.MethodCollection GetMethodsWithAttribute (string assemblyName);
public static TypeCache.MethodCollection GetMethodsWithAttribute (Type attrType, string assemblyName);

参数

attrType 属性类型。
assemblyName Optional assembly name.

返回

MethodCollection Returns an unordered MethodInfo collection of methods marked with the T attribute. If assemblyName is specified, returns only methods defined in this assembly.

描述

Retrieves an unordered collection of methods marked with the T attribute.

This method provides fast access to all methods loaded from a given assembly or all Unity domain assemblies and marked with a specific attribute. Methods marked with ancestors of the specified attribute are also included in the result. The order of results is undefined.

using UnityEditor;
using System.Collections.Generic;

public class Example { static void ScanInitializeOnLoadMethods() { var extractedMethods = TypeCache.GetMethodsWithAttribute<InitializeOnLoadMethodAttribute>(); foreach (var m in extractedMethods) { if (m.IsPrivate) continue; //... }

for (int i = 0; i < extractedMethods.Count; ++i) { if (extractedMethods[i].IsPublic) continue; //... } } }

Note: The returned MethodCollection is read-only and thread-safe. The order of MethodInfo in the collection is undefined.

Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961