注解
注解可以更好的分类class,再不用实例化类的情况下筛选需要的class
- 声明
[AttributeUsage( AttributeTargets.Class )]
public class NodeAttributes : Attribute
public NodeAttributes( string name, string category, string description,
System.Type castType = null, KeyCode shortcutKey = KeyCode.None,
bool available = true, bool deprecated = false, string deprecatedAlternative = null,
System.Type deprecatedAlternativeType = null, string community = null,
string customCategoryColor = null, int sortOrderPriority = -1, int nodeAvailabilityFlags = int.MaxValue )
- 使用
[NodeAttributes( "Vector From Matrix", "Matrix Operators", "Retrieve vector data from a matrix" )]
- 筛选
Type[] availableTypes = GetTypesInNamespace( Assembly.GetExecutingAssembly(), "AmplifyShaderEditor" );
foreach( System.Type type in availableTypes )
{
foreach( NodeAttributes attribute in Attribute.GetCustomAttributes( type ).OfType<NodeAttributes>() )
{
if( attribute.Available && !attribute.Deprecated )
private Type[] GetTypesInNamespace( Assembly assembly, string nameSpace )
{
return assembly.GetTypes().Where(
t => String.Equals( t.Namespace, nameSpace, StringComparison.Ordinal ) ).ToArray();
}