LoginSignup
9
5

More than 5 years have passed since last update.

Unity2017のバージョンディレクティブ

Last updated at Posted at 2017-10-30

残念ながらUnityはバージョンが変わるたびにそれなりに非互換が発生するため、リリースバージョンによってdefineディレクティブがいろいろ定義されています。が、公式ドキュメントでは説明がそっけない。

Unity - マニュアル: プラットフォーム依存コンパイル
https://docs.unity3d.com/ja/current/Manual/PlatformDependentCompilation.html

ということで、こんなスクリプトを貼り付けて2017.1.1f1と5.6.1f1でコンパイルしてみました。

#if UNITY_2017
        Debug.Log("Unity2017");
#endif
#if UNITY_2017_1
        Debug.Log("Unity2017.1");
#endif
#if UNITY_2017_1_1
        Debug.Log("Unity2017.1.1");
#endif
#if UNITY_2017_OR_NEWER
        Debug.Log("Unity2017 or newer");
#endif
#if UNITY_2017_1_OR_NEWER
        Debug.Log("Unity2017.1 or newer");
#endif
#if UNITY_2017_1_1_OR_NEWER
        Debug.Log("Unity2017.1.1 or newer");
#endif
#if UNITY_5
        Debug.Log("Unity5");
#endif
#if UNITY_5_OR_NEWER
        Debug.Log("Unity5 or newer");
#endif
#if UNITY_5_2_OR_NEWER
        Debug.Log("Unity5.2 or newer");
#endif
#if UNITY_5_3_OR_NEWER
        Debug.Log("Unity5.3 or newer");
#endif
#if UNITY_5_6_OR_NEWER
        Debug.Log("Unity5.6 or newer");
#endif
#if UNITY_5_7
        Debug.Log("Unity5.7");
#endif

結果 (左が2017.1.1f1 右が5.6.1f1)

Unity2017.1.png Unity5.6.png

ここから分かることは、

  • "OR_NEWER"にはリリースバージョン番号のみ付けられる。
    • マイナーバージョン番号(ex. 5.6.1の".1")は付けられない。
    • リリースバージョン番号の小数点以上(ex. 5.6.1の"5")だけでもダメ。
  • 5.3未満のバージョンに"OR_NEWER"はない。
    • Unity5.2までは"OR_NEWER"がなかった?
  • パッチリリースは判別できない。
  • "UNITY_5"にUnity2017は入らない。
    • 2017が実は内部バージョン5.7だったりはしない。 ← これが知りたかった。

です。困るのは、"UNITY_5"を使ったサードパーティ製の古いスクリプトが案外たくさんあることで、どうしたものかと…。各社にとっては「Unity、勝手にバージョン番号増やすな!!」というところなんでしょうけども。

ちなみに、ビルドログにはmcsでのコンパイル時に渡されるdefineが出力されています。って、最初からこっち見ればよかった…。

Unity2017.1.1f1
-define:UNITY_5_3_OR_NEWER
-define:UNITY_5_4_OR_NEWER
-define:UNITY_5_5_OR_NEWER
-define:UNITY_5_6_OR_NEWER
-define:UNITY_2017_1_OR_NEWER
-define:UNITY_2017_1_1
-define:UNITY_2017_1
-define:UNITY_2017
9
5
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
9
5