2015-09-15 12 views
5

私は最近、カスタムインスペクタを作成しました。インスペクタで変数を編集するときに、OnValidate()が呼び出されていないことがわかりました。私が使ったカスタムインスペクタを維持しながら、私のコールを再びOnValidate()に戻す方法に関するアイデアはありますか?Unity - カスタムインスペクタを使用しているときにOnValidate()にアクセスできますか?

答えて

1

答えはシリアル化とプロパティフィールドで行われました。

私のコードでは、ここの最初の部分は、私のメインスクリプトでこれを宣言していることを示しています。覚えておいてください。パブリック変数はすでにシリアル化されているため、その必要はありません。

pubilc class Original_Editor : Editor{ 
     public override void OnInspectorGUI(){ 
       serializedObject.Update(); 
       // Get the camera width. 
       SerializedProperty width = serializedObject.FindProperty("cameraWidth"); 
       // Set the layout. 
       EditorGUILayout.PropertyField(width); 
       // Clamp the desired values 
       width.floatValue = Mathf.Clamp((int)width.floatValue, 0, 9999); 
       // apply 
       serializedObject.ApplyModifiedProperties(); 
     } 
    } 
:私はこれを持って私のカスタムインスペクタで今すぐ

public class Original : MonoBehaviour { 

// Used for the user to input their board section width and height. 
[Tooltip("The desired Camera Width.")] 
public float cameraWidth; 
} 

関連する問題