Skip to content

Instantly share code, notes, and snippets.

@yaegaki
Created October 8, 2015 20:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yaegaki/aaffc97bb9804bc6f3b9 to your computer and use it in GitHub Desktop.
Save yaegaki/aaffc97bb9804bc6f3b9 to your computer and use it in GitHub Desktop.
require "yaml"
require "pp"
h = []
hash = {}
File.read("unitychan_dynamic.prefab").each_line do |line|
match = line.match(/--- !u!\d+ &(\d+)/)
if match.nil?
h << line
else
h = hash[match[1]] = []
end
end
i = 0
nh = {}
hash.each do |k, v|
nh[k] = YAML.load(v.join)
end
th = {}
rootObj = nil
nh.each do |k, v|
key = v.keys.first
unless key.match(/(Rect)?Transform/).nil?
h = v[key]
name = nh[h["m_GameObject"]["fileID"].to_s]["GameObject"]["m_Name"]
children = h["m_Children"].map {|hoge| hoge["fileID"] }
th[k] = {
name: name,
children: children,
}
rootObj = th[k] if h["m_Father"]["fileID"] == 0
end
end
def resolve(o, prefix, th)
o[:name] = to_camel(o[:name])
o[:fullname] = "#{prefix}#{o[:name]}"
o[:children] = o[:children].map {|c| resolve(th[c.to_s], o[:fullname], th); th[c.to_s]; }
end
def to_camel(s)
result = []
hoge = true
first = true
s.chars.each do |c|
if c.match(/[a-zA-Z0-9]/).nil?
hoge = true
else
if !c.match(/[0-9]/).nil? && first
result << "N"
end
first = false
c.upcase! if hoge
result << c
hoge = false
end
end
result.join
end
resolve(rootObj, "", th)
pp rootObj
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment