2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

【Unity】Editor拡張をせずに簡易ボタンを実装する方法

Posted at

概要

今日のUnityでインスペクタ上にボタンを表示するのは何かと不便です。
Editor拡張する方法だと複数同時編集ができません。
Odin のようなアセットは有料だったりOSSできなかったりします。
そこで、Editor拡張を利用せずコンポーネント単体でボタンを実装する方法を考えました。

方法

image.png
[SerializeField] bool XXX で出現するチェックボックス✅を OnValidate() で制御すると、コンポーネント単体でボタンを実現できます。

using UnityEngine;

public class boolButton : MonoBehaviour
{
#if UNITY_EDITOR
    [SerializeField] bool _button;

    private void OnValidate()
    {
        if (_button)
        {
            _button = false;
            ButtonProcess();
        }
    }

    private void ButtonProcess()
    {
        Debug.Log("Pushed Button");
    }
#endif
}
2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?