LoginSignup
27
20

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