2016-11-11 9 views
1

一般に、公開者のフィールドがインスペクタで公開されるようにスクリプトが記述されています。代わりにプロパティを使用するいくつかの方法はありますか?Unityでは、InspectorウィンドウでC#* Properties *を公開できますか?

// instead of this 
public GameObject wrongBall; 

// is there some way to do this (to trigger an event in the setter, for instance) 
// and have it show up in the inspector window? 
public GameObject WrongBallProperty 
{ 
    get; 
    set; 
} 
+0

非常に多くのバージョンの後でUnityがこれをサポートしていないことを信じられないほど素晴らしい。 –

+0

@RayKoopa問題はシリアル化です。問題を起こさずにプロパティよりもフィールドのシリアル化を行う方が簡単です。 –

答えて

0

並べ替え。

あなたが直接インスペクターでプロパティを使用することはできませんが、バッキングフィールドを使用してプロパティを作成することができます

public GameObject WrongBallProperty { 
    get { return this.wrongBallProperty; } 
    set { //do whatever } 
} 

[SerializeField] 
private gameObject wrongBallProperty; 

これはインスペクタでwrongBallPropertyを表示し、あなたがどんなロジックを行うことができますgetsetが必要です。詳細はSerializeField referenceを参照してください。

関連する問題