Last active
April 16, 2017 14:33
-
-
Save tmr111116/ba08bcdbcb615bd83c81 to your computer and use it in GitHub Desktop.
ProjectVersion によって起動する Unity を変えるやつコマンドライン引数対応版。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require "yaml" | |
UNITY_DIR_PREFIX = ENV.fetch("UNITY_DIR_PREFIX", "/Applications/Unity") | |
unity_args = ARGV.dup | |
project_path = Dir.getwd | |
path_arg = ARGV.index("-projectPath") | |
if path_arg | |
project_path = ARGV[path_arg + 1] | |
else | |
unity_args.unshift("-projectPath", project_path) | |
end | |
project_settings = File.join(project_path, "ProjectSettings") | |
raise "#{project_path} は Unity プロジェクトじゃない!" unless Dir.exists?(project_settings) | |
version_file = File.join(project_settings, "ProjectVersion.txt") | |
def get_project_version(version_file) | |
# ProjectVersion.txt がなかったら 4 系として扱う。 | |
return "4" unless File.exists?(version_file) | |
yaml = YAML.load_file(version_file) | |
yaml["m_EditorVersion"] | |
end | |
version = get_project_version(version_file) | |
unity_dir = UNITY_DIR_PREFIX + version | |
raise "Version #{version} の Unity が #{unity_dir} にインストールされていない!" unless Dir.exists?(unity_dir) | |
exe_path = File.join(unity_dir, "Unity.app", "Contents", "MacOS", "Unity") | |
puts "exec '#{exe_path}' #{unity_args}" | |
exit(system(exe_path, *unity_args)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
github に移した。 https://github.com/tmr111116/urun