Class: Mikunyan::Asset

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#add_idsArray<Mikunyan::Asset::LocalObjectEntry> (readonly)

?

Returns:



19
20
21
# File 'lib/mikunyan/asset.rb', line 19

def add_ids
  @add_ids
end

#endianSymbol (readonly)

data endianness (:little or :big)

Returns:

  • (Symbol)

    the current value of endian



19
20
21
# File 'lib/mikunyan/asset.rb', line 19

def endian
  @endian
end

#formatInteger (readonly)

file format number

Returns:

  • (Integer)

    the current value of format



19
20
21
# File 'lib/mikunyan/asset.rb', line 19

def format
  @format
end

#generator_versionString (readonly)

version string of generator

Returns:

  • (String)

    the current value of generator_version



19
20
21
# File 'lib/mikunyan/asset.rb', line 19

def generator_version
  @generator_version
end

#klassesArray<Mikunyan::Asset::Klass> (readonly)

defined classes

Returns:



19
20
21
# File 'lib/mikunyan/asset.rb', line 19

def klasses
  @klasses
end

#nameString (readonly)

Asset name

Returns:

  • (String)

    the current value of name



19
20
21
# File 'lib/mikunyan/asset.rb', line 19

def name
  @name
end

#objectsArray<Mikunyan::Asset::ObjectEntry> (readonly)

contained objects

Returns:



19
20
21
# File 'lib/mikunyan/asset.rb', line 19

def objects
  @objects
end

#referencesArray<Mikunyan::Asset::Reference> (readonly)

reference data

Returns:



19
20
21
# File 'lib/mikunyan/asset.rb', line 19

def references
  @references
end

#target_platformInteger (readonly)

target platform number

Returns:

  • (Integer)

    the current value of target_platform



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

Parameters:

  • file (String)

    file name

  • name (String) (defaults to: nil)

    Asset name (automatically generated if not specified)

Returns:



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

Parameters:

  • bin (String, IO)

    binary data

  • name (String)

    Asset name

  • parent_bundle (Mikunyan::AssetBundle) (defaults to: nil)

    Parent AssetBundle

Returns:



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

#containersArray<Hash>?

Returns list of containers

Returns:

  • (Array<Hash>, nil)

    list of all 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

Parameters:

Returns:

  • (String, nil)

    type name



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

Parameters:

Returns:



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

Parameters:

Returns:

  • (Hash, nil)

    parsed object



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

Returns:



108
109
110
# File 'lib/mikunyan/asset.rb', line 108

def path_id(id)
  @path_id_table[id]
end

#path_idsArray<Integer>

Returns list of all path IDs

Returns:

  • (Array<Integer>)

    list of all path IDs



114
115
116
# File 'lib/mikunyan/asset.rb', line 114

def path_ids
  @objects.map(&:path_id)
end