Skip to content

Commit 53421e3

Browse files
committed
fixing build tab serialization and stability.
1 parent 8cc47c2 commit 53421e3

File tree

1 file changed

+50
-18
lines changed

1 file changed

+50
-18
lines changed

UnityEngine.AssetBundles/Editor/AssetBundleBrowser/AssetBundleBuildTab.cs

Lines changed: 50 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,12 @@ public class AssetBundleBuildTab
1212
{
1313
const string k_BuildPrefPrefix = "ABBBuild:";
1414
// gui vars
15+
[SerializeField]
1516
private ValidBuildTarget m_BuildTarget = ValidBuildTarget.StandaloneWindows;
17+
[SerializeField]
1618
private CompressOptions m_Compression = CompressOptions.StandardCompression;
1719
private string m_OutputPath = string.Empty;
20+
[SerializeField]
1821
private bool m_UseDefaultPath = true;
1922
private string m_streamingPath = "Assets/StreamingAssets";
2023

@@ -24,20 +27,31 @@ public class AssetBundleBuildTab
2427
[SerializeField]
2528
private Vector2 m_ScrollPosition;
2629

30+
2731
class ToggleData
2832
{
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)
3038
{
39+
if (onToggles.Contains(title))
40+
state = true;
41+
else
42+
state = s;
3143
content = new GUIContent(title, tooltip);
32-
state = EditorPrefs.GetBool(prefsKey, s);
3344
option = opt;
3445
}
35-
public string prefsKey
36-
{ get { return k_BuildPrefPrefix + content.text; } }
46+
//public string prefsKey
47+
//{ get { return k_BuildPrefPrefix + content.text; } }
3748
public bool state;
3849
public GUIContent content;
3950
public BuildAssetBundleOptions option;
4051
}
52+
53+
[SerializeField]
54+
private List<string> m_OnToggles;
4155
List<ToggleData> m_ToggleData;
4256
ToggleData m_ForceRebuild;
4357
ToggleData m_CopyToStreaming;
@@ -61,57 +75,69 @@ public enum CompressOptions
6175
public AssetBundleBuildTab()
6276
{
6377
m_AdvancedSettings = false;
78+
m_OnToggles = new List<string>();
79+
m_UseDefaultPath = true;
6480
}
81+
6582
public void OnEnable(Rect pos, EditorWindow parent)
6683
{
67-
m_BuildTarget = (ValidBuildTarget)EditorPrefs.GetInt(k_BuildPrefPrefix + "BuildTarget", (int)m_BuildTarget);
68-
m_Compression = (CompressOptions)EditorPrefs.GetInt(k_BuildPrefPrefix + "Compression", (int)m_Compression);
6984
m_ToggleData = new List<ToggleData>();
7085
m_ToggleData.Add(new ToggleData(
7186
false,
7287
"Exclude Type Information",
7388
"Do not include type information within the asset bundle (don't write type tree).",
89+
m_OnToggles,
7490
BuildAssetBundleOptions.DisableWriteTypeTree));
7591
m_ToggleData.Add(new ToggleData(
7692
false,
7793
"Force Rebuild",
7894
"Force rebuild the asset bundles",
95+
m_OnToggles,
7996
BuildAssetBundleOptions.ForceRebuildAssetBundle));
8097
m_ToggleData.Add(new ToggleData(
8198
false,
8299
"Ignore Type Tree Changes",
83100
"Ignore the type tree changes when doing the incremental build check.",
101+
m_OnToggles,
84102
BuildAssetBundleOptions.IgnoreTypeTreeChanges));
85103
m_ToggleData.Add(new ToggleData(
86104
false,
87105
"Append Hash",
88106
"Append the hash to the assetBundle name.",
107+
m_OnToggles,
89108
BuildAssetBundleOptions.AppendHashToAssetBundleName));
90109
m_ToggleData.Add(new ToggleData(
91110
false,
92111
"Strict Mode",
93112
"Do not allow the build to succeed if any errors are reporting during it.",
113+
m_OnToggles,
94114
BuildAssetBundleOptions.StrictMode));
95115
m_ToggleData.Add(new ToggleData(
96116
false,
97117
"Dry Run Build",
98118
"Do a dry run build.",
119+
m_OnToggles,
99120
BuildAssetBundleOptions.DryRunBuild));
100121

101122

102123
m_ForceRebuild = new ToggleData(
103124
false,
104125
"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);
106128
m_CopyToStreaming = new ToggleData(
107129
false,
108130
"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);
110133

111134
m_TargetContent = new GUIContent("Build Target", "Choose target platform to build for.");
112135
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+
}
115141
}
116142

117143
public void OnGUI(Rect pos)
@@ -129,7 +155,6 @@ public void OnGUI(Rect pos)
129155
if (tgt != m_BuildTarget)
130156
{
131157
m_BuildTarget = tgt;
132-
EditorPrefs.SetInt(k_BuildPrefPrefix + "BuildTarget", (int)m_BuildTarget);
133158
if(m_UseDefaultPath)
134159
{
135160
m_OutputPath = "AssetBundles/";
@@ -168,15 +193,21 @@ public void OnGUI(Rect pos)
168193
m_ForceRebuild.content);
169194
if (newState != m_ForceRebuild.state)
170195
{
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);
172200
m_ForceRebuild.state = newState;
173201
}
174202
newState = GUILayout.Toggle(
175203
m_CopyToStreaming.state,
176204
m_CopyToStreaming.content);
177205
if (newState != m_CopyToStreaming.state)
178206
{
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);
180211
m_CopyToStreaming.state = newState;
181212
}
182213
}
@@ -198,7 +229,6 @@ public void OnGUI(Rect pos)
198229
if (cmp != m_Compression)
199230
{
200231
m_Compression = cmp;
201-
EditorPrefs.SetInt(k_BuildPrefPrefix + "Compression", (int)m_Compression);
202232
}
203233
foreach (var tog in m_ToggleData)
204234
{
@@ -207,7 +237,11 @@ public void OnGUI(Rect pos)
207237
tog.state);
208238
if (newState != tog.state)
209239
{
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);
211245
tog.state = newState;
212246
}
213247
}
@@ -324,13 +358,12 @@ private static void DirectoryCopy(string sourceDirName, string destDirName)
324358
private void BrowseForFolder()
325359
{
326360
m_UseDefaultPath = false;
327-
EditorPrefs.SetBool(k_BuildPrefPrefix + "DefaultOutputBuildPath", m_UseDefaultPath);
328361
var newPath = EditorUtility.OpenFolderPanel("Bundle Folder", m_OutputPath, string.Empty);
329362
if (!string.IsNullOrEmpty(newPath))
330363
{
331364
var gamePath = System.IO.Path.GetFullPath(".");
332365
gamePath = gamePath.Replace("\\", "/");
333-
if (newPath.StartsWith(gamePath))
366+
if (newPath.StartsWith(gamePath) && newPath.Length > gamePath.Length)
334367
newPath = newPath.Remove(0, gamePath.Length+1);
335368
m_OutputPath = newPath;
336369
EditorUserBuildSettings.SetPlatformSettings(EditorUserBuildSettings.activeBuildTarget.ToString(), "AssetBundleOutputPath", m_OutputPath);
@@ -339,7 +372,6 @@ private void BrowseForFolder()
339372
private void ResetPathToDefault()
340373
{
341374
m_UseDefaultPath = true;
342-
EditorPrefs.SetBool(k_BuildPrefPrefix + "DefaultOutputBuildPath", m_UseDefaultPath);
343375
m_OutputPath = "AssetBundles/";
344376
m_OutputPath += m_BuildTarget.ToString();
345377
EditorUserBuildSettings.SetPlatformSettings(EditorUserBuildSettings.activeBuildTarget.ToString(), "AssetBundleOutputPath", m_OutputPath);

0 commit comments

Comments
 (0)