Texture2D 返回将与导入的 MonoScript 关联的自定义图标。如果没有自定义图标与导入的 MonoScript 关联,则返回 null。
获取与导入的 MonoScript 关联的图标。
using UnityEngine; using UnityEditor;
class Example { [MenuItem("Examples/Get Icon for MonoScript from MonoImporter")] public static void GetIconForMonoScriptFromMonoImporter() { var assetPath = "Assets/MyMonoBehaviour.cs"; var monoImporter = AssetImporter.GetAtPath(assetPath) as MonoImporter; var icon = monoImporter.GetIcon(); Debug.Log($"Icon for {assetPath} is {icon}"); } }