获取自定义特性的类

  • Post author:
  • Post category:其他


using System;

using System.Reflection;

using UnityEngine;

public class SHY : Attribute

{

}

[SHY]

public class SHYTest

{


public int test = 10;

}

public class TestAttribute : MonoBehaviour

{


void Start()

{


var types = Assembly.GetCallingAssembly().GetTypes();

foreach (var item in types)

{


var attribute = item.GetCustomAttribute(typeof(SHY));

if (attribute != null)

{


Debug.LogError(item.Name);

FieldInfo[] fields = item.GetFields();

foreach (var field in fields)

{


Debug.LogError(field.Name);

}

}

}

}

}



版权声明:本文为douniwan08原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。