module UniEnv

Constants

VERSION

Public Class Methods

check_config(config) click to toggle source
# File lib/unienv.rb, line 39
def self.check_config(config)
  cand = [ 'development', 'release', 'distribution' ]
  cand.select! { |c| c =~ /^#{config}/i }
  return cand[0] if cand.size == 1
  return nil
end
check_target(target) click to toggle source
# File lib/unienv.rb, line 33
def self.check_target(target)
  cand = [ 'ios', 'android' ]
  cand.select! { |c| c =~ /^#{target}/i }
  return cand[0] if cand.size == 1
  return nil
end
clean_tmpdir() click to toggle source
# File lib/unienv.rb, line 91
def self.clean_tmpdir
  FileUtils.remove_entry_secure(tmpdir, true)
end
download(uri, path) click to toggle source
# File lib/unienv.rb, line 138
  def self.download(uri, path)
=begin
    File.open(path, 'w') do |f|
      f.write(download_to_s(uri).read)
    end
=end
    http_client = HTTPClient.new
    uri = URI.parse(URI.encode(uri))
    header = http_client.head(uri, nil, nil)
    #p header
    #p header.headers
    totalsize = header.nil? ? 0 : header.headers["Content-Length"].to_i
    http_client.receive_timeout = 60 * 120
    size = 0
    readblock = 0
    File.open(path, 'w') do |file|
      http_client.get_content(uri, nil, nil) do |chunk|
        size += chunk.size
        file.write chunk
        blk = size / (100 * 1024 * 1024)
        if readblock < blk
          printf("Recv: %dMB\n", size / (1024 * 1024))
          readblock = blk
        end
      end
    end
    printf("Recv: %dMB\n", size / (1024 * 1024))
  end
download_to_s(uri) click to toggle source
# File lib/unienv.rb, line 113
def self.download_to_s(uri)
  totalsize = nil
  size = 0
  progress = 0
  print "download: #{uri}\n"
  OpenURI.open_uri(
    uri,
    {
      :content_length_proc => lambda { |sz|
        totalsize = sz
        print "total: #{sz / 1024}KB\n"
      },
      :progress_proc => lambda { |sz|
        unless totalsize.nil?
          size = sz
          rate = ((size.to_f / totalsize.to_f) * 10).to_i
          if rate > progress
            print ". #{sz / 1024}KB\n"
            progress = rate
          end
        end
      },
    }
  )
end
editor_path() click to toggle source
# File lib/unienv.rb, line 17
def self.editor_path
  "#{$project_path}/Assets/Editor"
end
editor_uri(config, version) click to toggle source
# File lib/unienv.rb, line 78
def self.editor_uri(config, version)
  url(config, 'editor', version)
end
enum_installed() click to toggle source
# File lib/unienv.rb, line 56
def self.enum_installed
  unis = Dir.glob('/Applications/Unity*')
  list = {}
  unis.each do |uni|
    if File.basename(uni) =~ /\AUnity(.+)\Z/
      ver = $1
      list[ver] = uni
    end
  end
  list
end
find_cache(type, version) click to toggle source
# File lib/unienv.rb, line 103
def self.find_cache(type, version)
  Dir.glob(make_cache_path(type, version))
end
find_editor_cache(version) click to toggle source
# File lib/unienv.rb, line 106
def self.find_editor_cache(version)
  find_cache("Unity", version)
end
find_project() click to toggle source
# File lib/unienv.rb, line 23
def self.find_project
  return unless $project_path.nil?
  dirs = Dir.glob("**/Assets")
  dirs.each do |d|
    d = d.sub(/(\/)?Assets$/, '')
    if Dir.exist?("#{d}/ProjectSettings")
      $project_path = File.expand_path(d)
    end
  end
end
find_standard_assets_cache(version) click to toggle source
# File lib/unienv.rb, line 109
def self.find_standard_assets_cache(version)
  find_cache("StandardAssets", version)
end
get_projversion() click to toggle source
# File lib/unienv.rb, line 166
def self.get_projversion
  Dir.glob("**/ProjectVersion.txt") do |e|
    File.open(e, "r").readlines.each do |t|
      if t.strip.chomp =~ /\Am_EditorVersion:\s+(.+)\Z/
        return $1
      end
    end
  end
  ''
end
has_editor?() click to toggle source
# File lib/unienv.rb, line 20
def self.has_editor?
  Dir.exist?(self.editor_path)
end
load_config() click to toggle source
# File lib/unienv.rb, line 50
def self.load_config
  txt = File.read("#{ASSETS_PATH}/unity_versions.yml")
  YAML.load(txt)
end
make_cache_path(type, version) click to toggle source
# File lib/unienv.rb, line 94
def self.make_cache_path(type, version)
  "#{tmpdir}/#{type}-#{version}.pkg"
end
make_editor_cache_path(version) click to toggle source
# File lib/unienv.rb, line 97
def self.make_editor_cache_path(version)
  make_cache_path("Unity", version)
end
make_standard_assets_cache_path(version) click to toggle source
# File lib/unienv.rb, line 100
def self.make_standard_assets_cache_path(version)
  make_cache_path("StandardAssets", version)
end
make_tmpdir() click to toggle source
# File lib/unienv.rb, line 88
def self.make_tmpdir
  FileUtils.mkdir_p(tmpdir)
end
search_version(config, name) click to toggle source
# File lib/unienv.rb, line 68
def self.search_version(config, name)
  vers = []
  config['version'].each do |k, v|
    vers << k if k.include?(name)
  end
  vers
end
sh(cmd) click to toggle source
# File lib/unienv.rb, line 10
def self.sh(cmd)
  print "exec: #{cmd}\n"
  system cmd
  if $? != 0
    raise "ERROR: #{$?.to_i}"
  end
end
standard_assets_uri(config, version) click to toggle source
# File lib/unienv.rb, line 81
def self.standard_assets_uri(config, version)
  url(config, 'standard_assets', version)
end
tmpdir() click to toggle source
# File lib/unienv.rb, line 85
def self.tmpdir
  Dir.tmpdir + "/unienv"
end
uri(config, type, version) click to toggle source
# File lib/unienv.rb, line 75
def self.uri(config, type, version)
  config['version'][version][type]
end