ソースコード
using System;
using System.Collections.Generic;
<summary>
</summary>
public static class TypeExtensions
{
<summary>
</summary>
public static IEnumerable<Type> GetBaseTypes(this Type self)
{
for (var baseType = self.BaseType; null != baseType; baseType = baseType.BaseType)
{
yield return baseType;
}
}
}
使い方
class Character
{
}
class Player : Character
{
}
class Hero : Player
{
}
void Awake()
{
var type = typeof(Hero);
foreach (var n in type.GetBaseTypes())
{
Debug.Log(n.Name);
}
}
Player
Character
Object
関連記事