土屋つかさの技術ブログは今か無しか

土屋つかさが主にプログラミングについて語るブログです。

#unity TMP_Text.alignmentに設定する値と内部的に保存される値の対応

 TMP_Text.alignmentという、文字描画時のアラインメントをTextAlignmentOptions列挙体で設定するプロパティがあるんですが、この列挙体はデータ個数が37個(!)もあって、しかもインスペクタのUIと直接対応しておらず把握が大変だったのでここでまとめておきます。

 TMP_Text.alignmentを更新すると、内部的にTMP_Text.horizontalAlignmentとTMP_Text.VerticalAlignmentを変更します*1。処理速度を稼ぐためのか非常にトリッキーなコードになっていて、ここまでするならTMP_Text.alignmentプロパティ自体廃止してしまえばいいのにと思うのですが、そうも行かない理由があるのでしょう。

前置きが長くなりましたが、TMP_Text.alignmentプロパティに設定した値によってTMP_Text.horizontalAlignmentプロパティ/TMP_Text.VerticalAlignmentプロパティに設定される値*2は以下のようになります。個々のパラメータの意味もまた複雑なんですが、近いうちに追記できればと思っています。

TextAlignment VerticalAlignment HorizontalAlignment
TopLeft Top Left
Top Top Center
TopRight Top Right
TopJustified Top Justified
TopFlush Top Flush
TopGeoAligned Top Geometry
Left Middle Left
Center Middle Center
Right Middle Right
Justified Middle Justified
Flush Middle Flush
CenterGeoAligned Middle Geometry
BottomLeft Bottom Left
Bottom Bottom Center
BottomRight Bottom Right
BottomJustified Bottom Justified
BottomFlush Bottom Flush
BottomGeoAligned Bottom Geometry
BaselineLeft Baseline Left
Baseline Baseline Center
BaselineRight Baseline Right
BaselineJustified Baseline Justified
BaselineFlush Baseline Flush
BaselineGeoAligned Baseline Geometry
MidlineLeft Geometry Left
Midline Geometry Center
MidlineRight Geometry Right
MidlineJustified Geometry Justified
MidlineFlush Geometry Flush
MidlineGeoAligned Geometry Geometry
CaplineLeft Capline Left
Capline Capline Center
CaplineRight Capline Right
CaplineJustified Capline Justified
CaplineFlush Capline Flush
CaplineGeoAligned Capline Geometry
Converted=0xFFFF

*1:alignmentプロパティに直接相当するメンバ変数はありません

*2:正確には、それぞれのプロパティに対応するメンバ変数