Created
March 17, 2018 05:56
-
-
Save hecres/f594add4b38493fcf2f17317f3c88d32 to your computer and use it in GitHub Desktop.
Unityで割り当てられているクラスIDからクラス名を取得する処理
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Reflection; | |
using UnityEditor; | |
public static string GetClassName(int classId) | |
{ | |
var assembly = Assembly.GetAssembly(typeof(MonoScript)); | |
var unityType = assembly.GetType("UnityEditor.UnityType"); | |
var classObject = unityType.InvokeMember("FindTypeByPresistentTypeID", BindingFlags.InvokeMethod, null, null, new object[] { classId }); | |
if (classObject == null) | |
{ | |
return string.Empty; | |
} | |
var nameProperty = classObject.GetType().GetProperty("name"); | |
return nameProperty == null ? string.Empty : (string)nameProperty.GetValue(classObject); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment