Class: Mikunyan::Asset
- Inherits:
-
Object
- Object
- Mikunyan::Asset
- Defined in:
- lib/mikunyan/asset.rb
Overview
Class for representing Unity Asset
Defined Under Namespace
Classes: ContainerInfo, Klass, LocalObjectEntry, ObjectEntry, Reference
Instance Attribute Summary collapse
-
#add_ids ⇒ Array<Mikunyan::Asset::LocalObjectEntry>
readonly
?.
-
#endian ⇒ Symbol
readonly
data endianness (:little or :big).
-
#format ⇒ Integer
readonly
file format number.
-
#generator_version ⇒ String
readonly
version string of generator.
-
#klasses ⇒ Array<Mikunyan::Asset::Klass>
readonly
defined classes.
-
#name ⇒ String
readonly
Asset name.
-
#objects ⇒ Array<Mikunyan::Asset::ObjectEntry>
readonly
contained objects.
-
#references ⇒ Array<Mikunyan::Asset::Reference>
readonly
reference data.
-
#target_platform ⇒ Integer
readonly
target platform number.
Class Method Summary collapse
-
.file(file, name = nil) ⇒ Mikunyan::Asset
Load Asset from file.
-
.load(bin, name, parent_bundle = nil) ⇒ Mikunyan::Asset
Load Asset from binary string.
-
.object_simplify(obj) ⇒ Object
Alias to ObjectValue#simplify (for compatibility).
Instance Method Summary collapse
-
#containers ⇒ Array<Hash>?
Returns list of containers.
-
#each_object(&block) ⇒ Enumerator<Mikunyan::Asset::ObjectEntry>, Array<Mikunyan::Asset::ObjectEntry>
Same as objects.each.
-
#object_type(obj) ⇒ String?
Returns object type name string.
-
#parse_object(obj) ⇒ Mikunyan::BaseObject?
Parse object of given path ID.
-
#parse_object_simple(obj) ⇒ Hash?
Parse object of given path ID and simplify it.
-
#path_id(id) ⇒ ObjectEntry?
Returns object with specified path ID.
-
#path_ids ⇒ Array<Integer>
Returns list of all path IDs.
Instance Attribute Details
#add_ids ⇒ Array<Mikunyan::Asset::LocalObjectEntry> (readonly)
?
19 20 21 |
# File 'lib/mikunyan/asset.rb', line 19 def add_ids @add_ids end |
#endian ⇒ Symbol (readonly)
data endianness (:little or :big)
19 20 21 |
# File 'lib/mikunyan/asset.rb', line 19 def endian @endian end |
#format ⇒ Integer (readonly)
file format number
19 20 21 |
# File 'lib/mikunyan/asset.rb', line 19 def format @format end |
#generator_version ⇒ String (readonly)
version string of generator
19 20 21 |
# File 'lib/mikunyan/asset.rb', line 19 def generator_version @generator_version end |
#klasses ⇒ Array<Mikunyan::Asset::Klass> (readonly)
defined classes
19 20 21 |
# File 'lib/mikunyan/asset.rb', line 19 def klasses @klasses end |
#name ⇒ String (readonly)
Asset name
19 20 21 |
# File 'lib/mikunyan/asset.rb', line 19 def name @name end |
#objects ⇒ Array<Mikunyan::Asset::ObjectEntry> (readonly)
contained objects
19 20 21 |
# File 'lib/mikunyan/asset.rb', line 19 def objects @objects end |
#references ⇒ Array<Mikunyan::Asset::Reference> (readonly)
reference data
19 20 21 |
# File 'lib/mikunyan/asset.rb', line 19 def references @references end |
#target_platform ⇒ Integer (readonly)
target platform number
19 20 21 |
# File 'lib/mikunyan/asset.rb', line 19 def target_platform @target_platform end |
Class Method Details
.file(file, name = nil) ⇒ Mikunyan::Asset
Load Asset from file
93 94 95 96 97 98 |
# File 'lib/mikunyan/asset.rb', line 93 def self.file(file, name = nil) name ||= File.basename(name, '.*') File.open(file, 'rb') do |io| Asset.load(io, name) end end |
.load(bin, name, parent_bundle = nil) ⇒ Mikunyan::Asset
Load Asset from binary string
83 84 85 86 87 |
# File 'lib/mikunyan/asset.rb', line 83 def self.load(bin, name, parent_bundle = nil) r = Asset.new(name, parent_bundle) r.send(:load, bin) r end |
.object_simplify(obj) ⇒ Object
Alias to ObjectValue#simplify (for compatibility)
159 160 161 |
# File 'lib/mikunyan/asset.rb', line 159 def self.object_simplify(obj) obj.is_a?(ObjectValue) ? obj.simplify : obj end |
Instance Method Details
#containers ⇒ Array<Hash>?
Returns list of containers
120 121 122 123 124 125 126 127 128 |
# File 'lib/mikunyan/asset.rb', line 120 def containers obj = @path_id_table[1] return nil unless obj.klass&.type_tree&.tree&.type == 'AssetBundle' parse_object(obj).m_Container.value.map do |e| ContainerInfo.new(e.first.value, e.second.preloadIndex.value, e.second.preloadSize.value, e.second.asset.m_FileID.value, e.second.asset.m_PathID.value) end end |
#each_object(&block) ⇒ Enumerator<Mikunyan::Asset::ObjectEntry>, Array<Mikunyan::Asset::ObjectEntry>
Same as objects.each
102 103 104 |
# File 'lib/mikunyan/asset.rb', line 102 def each_object(&block) @objects.each(&block) end |
#object_type(obj) ⇒ String?
Returns object type name string
153 154 155 156 |
# File 'lib/mikunyan/asset.rb', line 153 def object_type(obj) obj = @path_id_table[obj] if obj.instance_of?(Integer) obj&.type end |
#parse_object(obj) ⇒ Mikunyan::BaseObject?
Parse object of given path ID
133 134 135 136 137 138 139 140 141 |
# File 'lib/mikunyan/asset.rb', line 133 def parse_object(obj) obj = @path_id_table[obj] if obj.instance_of?(Integer) return nil unless obj.klass&.type_tree value_klass = Mikunyan::CustomTypes.get_custom_type(obj.klass.type_tree.tree.type, obj.class_id) ret = parse_object_private(BinaryReader.new(obj.data, @endian), obj.klass.type_tree.tree, value_klass) ret.object_entry = obj ret end |
#parse_object_simple(obj) ⇒ Hash?
Parse object of given path ID and simplify it
146 147 148 |
# File 'lib/mikunyan/asset.rb', line 146 def parse_object_simple(obj) parse_object(obj)&.simplify end |
#path_id(id) ⇒ ObjectEntry?
Returns object with specified path ID
108 109 110 |
# File 'lib/mikunyan/asset.rb', line 108 def path_id(id) @path_id_table[id] end |
#path_ids ⇒ Array<Integer>
Returns list of all path IDs
114 115 116 |
# File 'lib/mikunyan/asset.rb', line 114 def path_ids @objects.map(&:path_id) end |