Skip to content

Instantly share code, notes, and snippets.

@hecres
Created March 17, 2018 05:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hecres/f594add4b38493fcf2f17317f3c88d32 to your computer and use it in GitHub Desktop.
Save hecres/f594add4b38493fcf2f17317f3c88d32 to your computer and use it in GitHub Desktop.
Unityで割り当てられているクラスIDからクラス名を取得する処理
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