@@ -199,7 +199,7 @@ All object types can be found in [UnityPy/classes](UnityPy/classes/).
199199
200200### [ Texture2D] ( UnityPy/classes/Texture2D.py )
201201
202- - ` .name `
202+ - ` .m_Name `
203203- ` .image ` converts the texture into a ` PIL.Image `
204204- ` .m_Width ` - texture width (int)
205205- ` .m_Height ` - texture height (int)
@@ -212,9 +212,10 @@ for obj in env.objects:
212212 if obj.type.name == " Texture2D" :
213213 # export texture
214214 data = obj.read()
215+ path = os.path.join(export_dir, f " { data.m_Name} .png " )
215216 data.image.save(path)
216217 # edit texture
217- fp = os.path.join(replace_dir, data.name )
218+ fp = os.path.join(replace_dir, f " { data.m_Name } .png " )
218219 pil_img = Image.open(fp)
219220 data.image = pil_img
220221 data.save()
@@ -225,7 +226,7 @@ for obj in env.objects:
225226Sprites are part of a texture and can have a separate alpha-image as well.
226227Unlike most other extractors (including AssetStudio), UnityPy merges those two images by itself.
227228
228- - ` .name `
229+ - ` .m_Name `
229230- ` .image ` - converts the merged texture part into a ` PIL.Image `
230231- ` .m_Width ` - sprite width (int)
231232- ` .m_Height ` - sprite height (int)
@@ -236,16 +237,16 @@ Unlike most other extractors (including AssetStudio), UnityPy merges those two i
236237for obj in env.objects:
237238 if obj.type.name == " Sprite" :
238239 data = obj.read()
240+ path = os.path.join(export_dir, f " { data.m_Name} .png " )
239241 data.image.save(path)
240242```
241243
242244### [ TextAsset] ( UnityPy/classes/TextAsset.py )
243245
244246TextAssets are usually normal text files.
245247
246- - ` .name `
247- - ` .script ` - binary data (bytes)
248- - ` .text ` - script decoded via UTF8 (str)
248+ - ` .m_Name `
249+ - ` .m_Script ` - str
249250
250251Some games save binary data as TextFile, so it's usually better to use ` .script ` .
251252
@@ -256,12 +257,13 @@ for obj in env.objects:
256257 if obj.type.name == " TextAsset" :
257258 # export asset
258259 data = obj.read()
260+ path = os.path.join(export_dir, f " { data.m_Name} .txt " )
259261 with open (path, " wb" ) as f:
260- f.write(bytes ( data.script ))
262+ f.write(data.m_Script.encode( " utf-8 " , " surrogateescape " ))
261263 # edit asset
262- fp = os.path.join(replace_dir, data.name )
264+ fp = os.path.join(replace_dir, f " { data.m_Name } .txt " )
263265 with open (fp, " rb" ) as f:
264- data.script = f.read()
266+ data.m_Script = f.read().decode( " utf-8 " , " surrogateescape " ) )
265267 data.save()
266268```
267269
@@ -272,9 +274,8 @@ If a type tree exists, it can be used to read the whole data,
272274but if it doesn't exist, then it is usually necessary to investigate the class that loads the specific MonoBehaviour to extract the data.
273275([ example] ( examples/CustomMonoBehaviour/get_scriptable_texture.py ) )
274276
275- - ` .name `
276- - ` .script `
277- - ` .raw_data ` - data after the basic initialisation
277+ - ` .m_Name `
278+ - ` .m_Script `
278279
279280** Export**
280281
@@ -290,12 +291,6 @@ for obj in env.objects:
290291 fp = os.path.join(extract_dir, f " { tree[' m_Name' ]} .json " )
291292 with open (fp, " wt" , encoding = " utf8" ) as f:
292293 json.dump(tree, f, ensure_ascii = False , indent = 4 )
293- else :
294- # save raw relevant data (without Unity MonoBehaviour header)
295- data = obj.read()
296- fp = os.path.join(extract_dir, f " { data.name} .bin " )
297- with open (fp, " wb" ) as f:
298- f.write(data.raw_data)
299294
300295 # edit
301296 if obj.serialized_type.node:
@@ -304,7 +299,7 @@ for obj in env.objects:
304299 obj.save_typetree(tree)
305300 else :
306301 data = obj.read()
307- with open (os.path.join(replace_dir, data.name )) as f:
302+ with open (os.path.join(replace_dir, data.m_Name )) as f:
308303 data.save(raw_data = f.read())
309304```
310305
@@ -332,7 +327,7 @@ if obj.type.name == "Font":
332327 if font.m_FontData[0 :4 ] == b " OTTO" :
333328 extension = " .otf"
334329
335- with open (os.path.join(path, font.name + extension), " wb" ) as f:
330+ with open (os.path.join(path, font.m_Name + extension), " wb" ) as f:
336331 f.write(font.m_FontData)
337332```
338333
@@ -344,7 +339,7 @@ The mesh will be converted to the Wavefront .obj file format.
344339
345340``` python
346341mesh : Mesh
347- with open (f " { mesh.name } .obj " , " wt" , newline = " " ) as f:
342+ with open (f " { mesh.m_Name } .obj " , " wt" , newline = " " ) as f:
348343 # newline = "" is important
349344 f.write(mesh.export())
350345```
@@ -364,15 +359,15 @@ export_dir: str
364359if mesh_renderer.m_GameObject:
365360 # get the name of the model
366361 game_object = mesh_renderer.m_GameObject.read()
367- export_dir = os.path.join(export_dir, game_object.name )
362+ export_dir = os.path.join(export_dir, game_object.m_Name )
368363mesh_renderer.export(export_dir)
369364```
370365
371366### [ Texture2DArray] ( UnityPy/classes/Texture2DArray.py )
372367
373368WARNING - not well tested
374369
375- - ` .name `
370+ - ` .m_Name `
376371- ` .image ` converts the texture2darray into a ` PIL.Image `
377372- ` .m_Width ` - texture width (int)
378373- ` .m_Height ` - texture height (int)
0 commit comments