うにてぃブログ

主にUnityとC#に関する記事を書いていきます

CustomPropertyDrawer

【Unity】Inspector に GetComponentInChildren を行うボタンを追加する

Inspector にオブジェクトをアタッチするのが面倒なことがあるので、 ボタンひとつで GetComponentInChildren してくれる拡張を作成 コード using System.Linq; using System.Reflection; using UnityEditor; using UnityEditor.IMGUI.Controls; using Unity…

【Unity】Inspector で使える検索できる enum 入力欄 【CustomPropertyDrawer】

enumPopup は数が多い場合探すのが面倒なので、検索窓付きの enum field を利用できる拡張を作成 コード using System.Linq; using UnityEditor; using UnityEditor.IMGUI.Controls; using UnityEngine; public class SearchableEnumAttribute : PropertyAtt…

【Unity】自動で GetCompoent をする Attribute【PropertyAttribute】

コンポーネントが必要な場合 RequireComponent か Reset() で コンポーネントの取得処理を書く必要がありますが、毎度書くのが面倒だというときがあり、 PropertyAttribute で解決できるのではと思い作成してみました using UnityEngine; [RequireComponent(…

【Unity】【CustomPropertyDrawer】Inspector の Color フィールドを拡張する

using UnityEditor; using UnityEngine; [CustomPropertyDrawer(typeof(Color))] public class ColorPropertyDrawer : PropertyDrawer { private const int ColorMax = 4; private SerializedProperty[] _rgba; private Color _color = new Color(); private…

【Unity】【CustomPropertyDrawer】Inspector に Preview を表示する

PropertyAttribute を作成して Inspector で アセットの Preview を表示できるように拡張する Editor.DrawPreview を呼び出せば Preview が表示できるようになります しかしながら、高さに関しては適当にしてるので利用する際は適切に処理を変えてください u…

【Unity】CustomPropertyDrawer を利用している Type 一覧の取得

CustomPropertyDrawer を利用しているクラスは描画方法を変えたかったことがあったが 自分で取得する必要があったので、そのとき利用した方法を記述する。 CustomPropertyDrawer github.com CustomPropertyDrawer のクラスは上記のようになっており、"m_Type…