はじめに
Inspectorから設定できるものでいいから、とにかくIconをセットしたいと思って調べました。
コード
以下のように書くと実装できます。
public void Create()
{
var obj = new GameObject();
var texture = UnityEditor.EditorGUIUtility.IconContent("sv_label_0").image as Texture2D;
UnityEditor.EditorGUIUtility.SetIconForObject(obj, texture);
}
![](https://mut-kon.com/wp-content/uploads/2023/05/image.png)
おわりに
UnityEditor名前空間なのでビルドする際はプリプロセッサで囲んでください。
また、別の色や画像にしたい場合は以下を参考に好みのものを探してみてください。
![](https://cdn.sstatic.net/Sites/stackoverflow/Img/apple-touch-icon.png?v=c78bd457575a)
Where's location of the unity's default icon for scripts
Anyone know about location of the (default) icons of assets.
For example script icon that unity use for all .cs scripts
コメント