@@ -12,9 +12,12 @@ public class AssetBundleBuildTab
12
12
{
13
13
const string k_BuildPrefPrefix = "ABBBuild:" ;
14
14
// gui vars
15
+ [ SerializeField ]
15
16
private ValidBuildTarget m_BuildTarget = ValidBuildTarget . StandaloneWindows ;
17
+ [ SerializeField ]
16
18
private CompressOptions m_Compression = CompressOptions . StandardCompression ;
17
19
private string m_OutputPath = string . Empty ;
20
+ [ SerializeField ]
18
21
private bool m_UseDefaultPath = true ;
19
22
private string m_streamingPath = "Assets/StreamingAssets" ;
20
23
@@ -24,20 +27,31 @@ public class AssetBundleBuildTab
24
27
[ SerializeField ]
25
28
private Vector2 m_ScrollPosition ;
26
29
30
+
27
31
class ToggleData
28
32
{
29
- public ToggleData ( bool s , string title , string tooltip , BuildAssetBundleOptions opt = BuildAssetBundleOptions . None )
33
+ public ToggleData ( bool s ,
34
+ string title ,
35
+ string tooltip ,
36
+ List < string > onToggles ,
37
+ BuildAssetBundleOptions opt = BuildAssetBundleOptions . None )
30
38
{
39
+ if ( onToggles . Contains ( title ) )
40
+ state = true ;
41
+ else
42
+ state = s ;
31
43
content = new GUIContent ( title , tooltip ) ;
32
- state = EditorPrefs . GetBool ( prefsKey , s ) ;
33
44
option = opt ;
34
45
}
35
- public string prefsKey
36
- { get { return k_BuildPrefPrefix + content . text ; } }
46
+ // public string prefsKey
47
+ // { get { return k_BuildPrefPrefix + content.text; } }
37
48
public bool state ;
38
49
public GUIContent content ;
39
50
public BuildAssetBundleOptions option ;
40
51
}
52
+
53
+ [ SerializeField ]
54
+ private List < string > m_OnToggles ;
41
55
List < ToggleData > m_ToggleData ;
42
56
ToggleData m_ForceRebuild ;
43
57
ToggleData m_CopyToStreaming ;
@@ -61,57 +75,69 @@ public enum CompressOptions
61
75
public AssetBundleBuildTab ( )
62
76
{
63
77
m_AdvancedSettings = false ;
78
+ m_OnToggles = new List < string > ( ) ;
79
+ m_UseDefaultPath = true ;
64
80
}
81
+
65
82
public void OnEnable ( Rect pos , EditorWindow parent )
66
83
{
67
- m_BuildTarget = ( ValidBuildTarget ) EditorPrefs . GetInt ( k_BuildPrefPrefix + "BuildTarget" , ( int ) m_BuildTarget ) ;
68
- m_Compression = ( CompressOptions ) EditorPrefs . GetInt ( k_BuildPrefPrefix + "Compression" , ( int ) m_Compression ) ;
69
84
m_ToggleData = new List < ToggleData > ( ) ;
70
85
m_ToggleData . Add ( new ToggleData (
71
86
false ,
72
87
"Exclude Type Information" ,
73
88
"Do not include type information within the asset bundle (don't write type tree)." ,
89
+ m_OnToggles ,
74
90
BuildAssetBundleOptions . DisableWriteTypeTree ) ) ;
75
91
m_ToggleData . Add ( new ToggleData (
76
92
false ,
77
93
"Force Rebuild" ,
78
94
"Force rebuild the asset bundles" ,
95
+ m_OnToggles ,
79
96
BuildAssetBundleOptions . ForceRebuildAssetBundle ) ) ;
80
97
m_ToggleData . Add ( new ToggleData (
81
98
false ,
82
99
"Ignore Type Tree Changes" ,
83
100
"Ignore the type tree changes when doing the incremental build check." ,
101
+ m_OnToggles ,
84
102
BuildAssetBundleOptions . IgnoreTypeTreeChanges ) ) ;
85
103
m_ToggleData . Add ( new ToggleData (
86
104
false ,
87
105
"Append Hash" ,
88
106
"Append the hash to the assetBundle name." ,
107
+ m_OnToggles ,
89
108
BuildAssetBundleOptions . AppendHashToAssetBundleName ) ) ;
90
109
m_ToggleData . Add ( new ToggleData (
91
110
false ,
92
111
"Strict Mode" ,
93
112
"Do not allow the build to succeed if any errors are reporting during it." ,
113
+ m_OnToggles ,
94
114
BuildAssetBundleOptions . StrictMode ) ) ;
95
115
m_ToggleData . Add ( new ToggleData (
96
116
false ,
97
117
"Dry Run Build" ,
98
118
"Do a dry run build." ,
119
+ m_OnToggles ,
99
120
BuildAssetBundleOptions . DryRunBuild ) ) ;
100
121
101
122
102
123
m_ForceRebuild = new ToggleData (
103
124
false ,
104
125
"Clear Folders" ,
105
- "Will wipe out all contents of build directory as well as StreamingAssets/AssetBundles if you are choosing to copy build there." ) ;
126
+ "Will wipe out all contents of build directory as well as StreamingAssets/AssetBundles if you are choosing to copy build there." ,
127
+ m_OnToggles ) ;
106
128
m_CopyToStreaming = new ToggleData (
107
129
false ,
108
130
"Copy to StreamingAssets" ,
109
- "After build completes, will copy all build content to " + m_streamingPath + " for use in stand-alone player." ) ;
131
+ "After build completes, will copy all build content to " + m_streamingPath + " for use in stand-alone player." ,
132
+ m_OnToggles ) ;
110
133
111
134
m_TargetContent = new GUIContent ( "Build Target" , "Choose target platform to build for." ) ;
112
135
m_CompressionContent = new GUIContent ( "Compression" , "Choose no compress, standard (LZMA), or chunk based (LZ4)" ) ;
113
-
114
- m_UseDefaultPath = EditorPrefs . GetBool ( k_BuildPrefPrefix + "DefaultOutputBuildPath" , m_UseDefaultPath ) ;
136
+
137
+ if ( m_UseDefaultPath )
138
+ {
139
+ ResetPathToDefault ( ) ;
140
+ }
115
141
}
116
142
117
143
public void OnGUI ( Rect pos )
@@ -129,7 +155,6 @@ public void OnGUI(Rect pos)
129
155
if ( tgt != m_BuildTarget )
130
156
{
131
157
m_BuildTarget = tgt ;
132
- EditorPrefs . SetInt ( k_BuildPrefPrefix + "BuildTarget" , ( int ) m_BuildTarget ) ;
133
158
if ( m_UseDefaultPath )
134
159
{
135
160
m_OutputPath = "AssetBundles/" ;
@@ -168,15 +193,21 @@ public void OnGUI(Rect pos)
168
193
m_ForceRebuild . content ) ;
169
194
if ( newState != m_ForceRebuild . state )
170
195
{
171
- EditorPrefs . SetBool ( m_ForceRebuild . prefsKey , newState ) ;
196
+ if ( newState )
197
+ m_OnToggles . Add ( m_ForceRebuild . content . text ) ;
198
+ else
199
+ m_OnToggles . Remove ( m_ForceRebuild . content . text ) ;
172
200
m_ForceRebuild . state = newState ;
173
201
}
174
202
newState = GUILayout . Toggle (
175
203
m_CopyToStreaming . state ,
176
204
m_CopyToStreaming . content ) ;
177
205
if ( newState != m_CopyToStreaming . state )
178
206
{
179
- EditorPrefs . SetBool ( m_CopyToStreaming . prefsKey , newState ) ;
207
+ if ( newState )
208
+ m_OnToggles . Add ( m_CopyToStreaming . content . text ) ;
209
+ else
210
+ m_OnToggles . Remove ( m_CopyToStreaming . content . text ) ;
180
211
m_CopyToStreaming . state = newState ;
181
212
}
182
213
}
@@ -198,7 +229,6 @@ public void OnGUI(Rect pos)
198
229
if ( cmp != m_Compression )
199
230
{
200
231
m_Compression = cmp ;
201
- EditorPrefs . SetInt ( k_BuildPrefPrefix + "Compression" , ( int ) m_Compression ) ;
202
232
}
203
233
foreach ( var tog in m_ToggleData )
204
234
{
@@ -207,7 +237,11 @@ public void OnGUI(Rect pos)
207
237
tog . state ) ;
208
238
if ( newState != tog . state )
209
239
{
210
- EditorPrefs . SetBool ( tog . prefsKey , newState ) ;
240
+
241
+ if ( newState )
242
+ m_OnToggles . Add ( tog . content . text ) ;
243
+ else
244
+ m_OnToggles . Remove ( tog . content . text ) ;
211
245
tog . state = newState ;
212
246
}
213
247
}
@@ -324,13 +358,12 @@ private static void DirectoryCopy(string sourceDirName, string destDirName)
324
358
private void BrowseForFolder ( )
325
359
{
326
360
m_UseDefaultPath = false ;
327
- EditorPrefs . SetBool ( k_BuildPrefPrefix + "DefaultOutputBuildPath" , m_UseDefaultPath ) ;
328
361
var newPath = EditorUtility . OpenFolderPanel ( "Bundle Folder" , m_OutputPath , string . Empty ) ;
329
362
if ( ! string . IsNullOrEmpty ( newPath ) )
330
363
{
331
364
var gamePath = System . IO . Path . GetFullPath ( "." ) ;
332
365
gamePath = gamePath . Replace ( "\\ " , "/" ) ;
333
- if ( newPath . StartsWith ( gamePath ) )
366
+ if ( newPath . StartsWith ( gamePath ) && newPath . Length > gamePath . Length )
334
367
newPath = newPath . Remove ( 0 , gamePath . Length + 1 ) ;
335
368
m_OutputPath = newPath ;
336
369
EditorUserBuildSettings . SetPlatformSettings ( EditorUserBuildSettings . activeBuildTarget . ToString ( ) , "AssetBundleOutputPath" , m_OutputPath ) ;
@@ -339,7 +372,6 @@ private void BrowseForFolder()
339
372
private void ResetPathToDefault ( )
340
373
{
341
374
m_UseDefaultPath = true ;
342
- EditorPrefs . SetBool ( k_BuildPrefPrefix + "DefaultOutputBuildPath" , m_UseDefaultPath ) ;
343
375
m_OutputPath = "AssetBundles/" ;
344
376
m_OutputPath += m_BuildTarget . ToString ( ) ;
345
377
EditorUserBuildSettings . SetPlatformSettings ( EditorUserBuildSettings . activeBuildTarget . ToString ( ) , "AssetBundleOutputPath" , m_OutputPath ) ;
0 commit comments