Version: 2022.2
public Texture2D GetIcon ();

返回

Texture2D Returns the custom icon that will be associated with the imported MonoScript. If no custom icon will be associated with the imported MonoScript, returns null.

描述

Gets the icon to associate with the imported 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}"); } }