はなちるのマイノート

Unityをメインとした技術ブログ。自分らしくまったりやっていきたいと思いますー!

【Unity】エディタ上でBuilt-inに存在するアイコンのTextureを取得する方法

はじめに

今回はUnityEditorにビルドインで存在するアイコンのTextureを取得する方法を紹介したいと思います。

アイコンを使用している様子

やり方

EditorGUIUtility.Loadを用いてbuilt-inリソースを読み込みます。

public static Object Load(string path);

Load a built-in resource.

This function will look in Assets/Editor Default Resources/ + path for the resource. If not there, it will try the built-in editor resources by name.

// DeepL翻訳
組み込みリソースをロードする。

この関数は Assets/Editor Default Resources/ + path でリソースを探します。そこにない場合は、名前から組み込みのエディタリソースを探します。

docs.unity3d.com

具体的には以下のように書けばOKで

Texture icon = (Texture)EditorGUIUtility.Load("_Help@2x");

またどのiconがどのpathかは分からないかと思いますが、GitHubにまとめてくれていた人がいらっしゃたので載せておきます。

github.com

GitHubNameをそのままpathに書き込んであげればOKです。

やり方