Skip to content

Instantly share code, notes, and snippets.

@miyazakiyuma
Created February 5, 2025 01:30
Show Gist options
  • Save miyazakiyuma/ae5928747a60d3382a058ff396024872 to your computer and use it in GitHub Desktop.
Save miyazakiyuma/ae5928747a60d3382a058ff396024872 to your computer and use it in GitHub Desktop.
nyagos.alias.unityopen = function(args)
-- ProjectSettings/ProjectVersion.txt のパスを取得
local project_version_path = "ProjectSettings/ProjectVersion.txt"
local file = io.open(project_version_path, "r")
if not file then
print("Error: Could not find " .. project_version_path)
return
end
-- ProjectVersion.txt の内容を読み取る
local version_line = file:read("*l")
file:close()
if not version_line then
print("Error: Could not read Unity version from " .. project_version_path)
return
end
-- Unity バージョンを抽出
local version = version_line:match("m_EditorVersion: (.+)")
if not version then
print("Error: Could not parse Unity version from " .. version_line)
return
end
print("Detected Unity version: " .. version)
-- Unity のインストールパスを設定(例: Unity Hub 経由でインストールされている場合)
local unity_path = string.format([[C:\Program Files\Unity\Hub\Editor\%s\Editor\Unity.exe]], version)
-- Unity 実行ファイルが存在するか確認
local f = io.open(unity_path, "r")
if not f then
print("Error: Unity version " .. version .. " not found at " .. unity_path)
return
end
f:close()
-- Unity を起動
command = string.format([["%s" -projectPath %s]], unity_path , nyagos.eval("pwd") )
print("Executing: " .. command)
nyagos.exec(command)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment