示例
using UnityEngine;
using System;
using System.Linq;
using System.Reflection;
using System.Collections;
using System.Collections.Generic;
namespace my_test {
public class Test1 : MonoBehaviour {
void Start()
{
PrintExecutingAssembly();
}
private void PrintExecutingAssembly()
{
//得到当前执行代码所在程序集中命名空间为my_test中的类型定义
List<Type> types = (from type in Assembly.GetExecutingAssembly().GetTypes()
where type.Namespace == "my_test"
select type).ToList();
for (int i = 0; i < types.Count; i++)
Debug.Log(types[i].FullName);
}
}
public class Test2
{
private class Test2_2 { }
}
public struct Struct1 { }
public enum Enum1 { }
}
运行测试