12
12
ASSETS = os .path .join (ROOT ,'assetbundle' )
13
13
# destination folder
14
14
DST = os .path .join (ROOT , 'extracted' )
15
+ # number of dirs to ignore
16
+ # e.g. IGNOR_DIR_COUNT = 2 will reduce
17
+ # 'assets/assetbundles/images/story_picture/small/15.png'
18
+ # to
19
+ # 'images/story_picture/small/15.png'
20
+
21
+ IGNOR_DIR_COUNT = 2
15
22
16
23
os .makedirs (DST , exist_ok = True )
17
24
18
25
debug = True
19
26
20
27
def main ():
21
28
for root , dirs , files in os .walk (ASSETS , topdown = False ):
29
+ if '.git' in root :
30
+ continue
22
31
for f in files :
23
32
print (f )
24
33
# load file
@@ -31,35 +40,36 @@ def main():
31
40
# assets without container / internal path will be ignored for now
32
41
if not asset .container :
33
42
continue
34
- extracted = []
35
- local_path = []
43
+
36
44
# check which mode we will have to use
37
45
num_cont = sum (1 for obj in asset .container .values () if obj .type in TYPES )
38
46
num_objs = sum (1 for obj in asset .objects .values () if obj .type in TYPES )
39
47
40
- # first we extract the assets in the container
41
- for asset_path , obj in asset .container .items ():
42
- fp = os .path .join (DST , * asset_path .split ('/' ))
43
- export_obj (obj , fp )
48
+ # check if container contains all important assets, if yes, just ignore the container
49
+ if num_objs <= num_cont * 2 :
50
+ for asset_path , obj in asset .container .items ():
51
+ fp = os .path .join (DST , * asset_path .split ('/' )[IGNOR_DIR_COUNT :])
52
+ export_obj (obj , fp )
53
+
54
+ # otherwise use the container to generate a path for the normal objects
55
+ else :
56
+ local_path = []
57
+ extracted = []
44
58
45
- local_path .append (
46
- os .path .splitext (asset_path )[0 ]
47
- if asset_path .endswith (".prefab" )
48
- else
49
- os .path .dirname (asset_path )
59
+ for asset_path in asset .container .keys ():
60
+ local_path .append (
61
+ os .path .splitext (asset_path )[0 ]
50
62
)
51
-
52
- # way more assets without path then with path,
53
- # therefore we get the general path from the container
54
- # and then extract all assets depending on that
55
- if num_objs > num_cont * 2 :
63
+
56
64
if len (local_path ) > 1 :
57
65
if len (set (local_path )) == 1 :
58
66
local_path = local_path [0 ]
59
67
else :
60
68
local_path = mode (local_path )
61
69
else :
62
- local_path = os .path .join (DST , * local_path [0 ].split ('/' ))
70
+ local_path = local_path [0 ]
71
+ local_path = os .path .join (DST , * local_path .split ('/' )[IGNOR_DIR_COUNT :])
72
+
63
73
64
74
for obj in asset .objects .values ():
65
75
if obj .path_id not in extracted :
@@ -75,30 +85,29 @@ def export_obj(obj, fp : str, append_name : bool = False) -> list:
75
85
76
86
fp , extension = os .path .splitext (fp )
77
87
os .makedirs (os .path .dirname (fp ), exist_ok = True )
78
- try :
79
- if obj .type == 'TextAsset' :
80
- if not extension :
81
- extension = '.txt'
82
- with open (f"{ fp } { extension } " , 'wb' ) as f :
83
- f .write (data .script )
84
-
85
- elif obj .type == "Sprite" :
86
- extension = ".png"
87
- data .image .save (f"{ fp } { extension } " )
88
-
89
- return [obj .path_id , data .m_RD .texture .path_id , getattr (data .m_RD .alphaTexture ,'path_id' , None )]
90
-
91
- elif obj .type == "Texture2D" :
92
- extension = ".png"
93
- fp = f"{ fp } { extension } "
94
- if not os .path .exists (fp ):
88
+
89
+ if obj .type == 'TextAsset' :
90
+ if not extension :
91
+ extension = '.txt'
92
+ with open (f"{ fp } { extension } " , 'wb' ) as f :
93
+ f .write (data .script )
94
+
95
+ elif obj .type == "Sprite" :
96
+ extension = ".png"
97
+ data .image .save (f"{ fp } { extension } " )
98
+
99
+ return [obj .path_id , data .m_RD .texture .path_id , getattr (data .m_RD .alphaTexture ,'path_id' , None )]
100
+
101
+ elif obj .type == "Texture2D" :
102
+ extension = ".png"
103
+ fp = f"{ fp } { extension } "
104
+ if not os .path .exists (fp ):
105
+ try :
95
106
data .image .save (fp )
96
-
97
- return [ obj . path_id ]
107
+ except EOFError :
108
+ pass
98
109
99
- except Exception as e :
100
- print (fp , e )
101
- return ([])
110
+ return [obj .path_id ]
102
111
103
112
104
113
if __name__ == '__main__' :
0 commit comments