Why not login to Qiita and try out its useful features?

We'll deliver articles that match you.

You can read useful information later.

27
20

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 5 years have passed since last update.

[System.Serializable]を使ってEditor上に調整パラメータを出す

Posted at

処理を分割するためにクラスに分けたい、そして、そのクラスにはEditor上で調整したいパラメータがある。
けど、MonoBehaviourを増やしたくない。ってときは、
[System.Serializable]
を使えばOK。という話

例えば、こんなクラスがあって、

class GameManager : MonoBehaviour {
    public float myButtonWidth;
    public float myButtonHeight;
    ...
}

MyButtonクラスを新しく作ってbuttonWidthとbuttonHeightは、そっちに持たせたいなぁと思った時に、

class MyButton {
    public float myButtonWidth;
    public float myButtonHeight;

    ...
}

ってして、


class GameManager : MonoBehaviour {
    public MyButton myButton;

    ...
}

ってするだけだと、インスペクタに表示されません。

しかし、以下のように、MyButton クラスの頭に [System.Serializable] を記載しておけば、

[System.Serializable]
class MyButton {
    public float myButtonWidth;
    public float myButtonHeight;

    ...
}

インスペクタ上に表示されます。
Screenshot 2016-06-06 12.49.58.png

27
20
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

Qiita Conference 2025 will be held!: 4/23(wed) - 4/25(Fri)

Qiita Conference is the largest tech conference in Qiita!

Keynote Speaker

ymrl、Masanobu Naruse, Takeshi Kano, Junichi Ito, uhyo, Hiroshi Tokumaru, MinoDriven, Minorun, Hiroyuki Sakuraba, tenntenn, drken, konifar

View event details
27
20

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?