0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Unity コマンドラインからプロジェクトのUnityバージョンを取得する

Posted at

導入

CIツールを使用する時など、コマンドラインからUnityを実行したいことがあります。
例えばMac・Unity Hub経由でインストールすると以下のパスに実行ファイルが存在します。

/Applications/Unity/Hub/Editor/2021.1.20f1/Unity.app/Contents/MacOS/Unity

このパスの中にある2021.1.20f1というバージョンはプロジェクトによって異なりますから、
できれば決め打ちではなく、自動的に取得したいです。

コマンドライン経由でのバージョン取得

バージョン情報はプロジェクトディレクトリから見て

./ProjectSettings/ProjectVersion.txt

のファイル内に存在し

ProjectVersion.txt
m_EditorVersion: 2021.1.20f1
m_EditorVersionWithRevision: 2021.1.20f1 (be552157821d)

という形で記載されています。ですので、

cat ProjectSettings/ProjectVersion.txt | grep -Eo '[0-9]+\.[0-9]+\.[0-9]+[a-z]{1}[0-9]+' | head -1

というコマンドでバージョンを取得することができます。

さらにこれを利用することで、Unity実行パスを以下で取得することができます

UNITY_VERSION=$(cat ProjectSettings/ProjectVersion.txt | grep -Eo '[0-9]+\.[0-9]+\.[0-9]+[a-z]{1}[0-9]+' | head -1)
UNITY_PATH=/Applications/Unity/Hub/Editor/${UNITY_VERSION}/Unity.app/Contents/MacOS/Unity
0
1
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
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?