Skip to content
This repository was archived by the owner on Jul 11, 2023. It is now read-only.

Commit 4ecf0f9

Browse files
committed
完善AssetGroup,基本没什么问题
1 parent 43f3947 commit 4ecf0f9

File tree

3 files changed

+253
-26
lines changed

3 files changed

+253
-26
lines changed

GameFramework/Editor/AssetGroupEditor/AssetFilterEditor.cs

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public class AssetFilterEditor : EditorWindow
1414
private static JsonData _config;
1515
private Vector2 _scrollView = Vector2.zero;
1616

17-
private static List<string> _listLabels = new List<string>(){ "AnimationClip",
17+
private static List<string> _listLabels = new List<string>(){"Object", "AnimationClip",
1818
"AudioClip","AudioMixer","ComputeShader","Font","GUISkin","Material",
1919
"Mesh","Model","PhysicMaterial","Prefab","Scene","Script","Shader",
2020
"Sprite","Texture","VideoClip","TextAsset","ScriptableObject",
@@ -24,7 +24,7 @@ public class AssetFilterEditor : EditorWindow
2424
private ReorderableList _labelReorderableList;
2525
private bool _showAddItemWindow;
2626

27-
[MenuItem("Tools/Assets Management/Asset Filter")]
27+
[MenuItem("Tools/Asset Management/Asset Filter")]
2828
private static void OpenWindow()
2929
{
3030
GetWindow<AssetFilterEditor>(true, "Asset Filter Editor",true);
@@ -47,7 +47,7 @@ public static List<string> GetAssetFilters()
4747
}
4848
else
4949
{
50-
AutomaticRefresh();
50+
//AutomaticRefresh();
5151

5252
_config = new JsonData();
5353
_config.SetJsonType(JsonType.Array);
@@ -99,7 +99,8 @@ private static void AutomaticRefresh()
9999
{
100100
if (!string.IsNullOrEmpty(itemType.Namespace))
101101
{
102-
if (itemType.Namespace.Contains("UnityEditor"))
102+
if (itemType.Namespace.Contains("UnityEditor")
103+
|| itemType.Namespace.Contains("UnityEngine"))
103104
{
104105
continue;
105106
}
@@ -118,10 +119,16 @@ private void OnGUI()
118119
{
119120
if (_config == null)
120121
return;
122+
GUILayout.BeginHorizontal();
121123
if (GUILayout.Button("Automatic refresh of system type"))
122124
{
123125
AutomaticRefresh();
124126
}
127+
if (GUILayout.Button("Save Config"))
128+
{
129+
SaveConfig();
130+
}
131+
GUILayout.EndHorizontal();
125132
_scrollView = EditorGUILayout.BeginScrollView(_scrollView);
126133
//GUILayout.BeginVertical("HelpBox");
127134
_labelReorderableList?.DoLayoutList();
@@ -165,7 +172,8 @@ private void OnGUI()
165172

166173
}
167174
}
168-
175+
176+
GUILayout.Space(100);
169177
//GUILayout.EndVertical();
170178
EditorGUILayout.EndScrollView();
171179
}
@@ -178,7 +186,8 @@ private void SaveConfig()
178186
{
179187
_config.Add(item);
180188
}
181-
ProjectSettingsConfig.SaveJsonData(_configName,_config);
189+
ProjectSettingsConfig.SaveJsonData(_configName, _config);
190+
182191
}
183192

184193
}

GameFramework/Editor/AssetGroupEditor/AssetGroupEditor.cs

Lines changed: 235 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
using LitJson;
22
using System.Collections;
33
using System.Collections.Generic;
4+
using System.Text;
45
using UnityEditor;
6+
using UnityEditor.AddressableAssets;
7+
using UnityEditor.AddressableAssets.Build;
8+
using UnityEditor.AddressableAssets.Settings.GroupSchemas;
59
using UnityEditor.EditorTools;
610
using UnityEngine;
711

@@ -15,11 +19,13 @@ public class AssetGroupEditor:EditorWindow
1519

1620
private Vector2 _scrollView = Vector2.zero;
1721
private string[] _assetFilter;
22+
private string[] _labels = new string[] { "none" };
23+
private List<string> _profileVariables = new List<string> { "LocalBuildPath","LocalLoadPath" };
1824

1925
private EditorMenuItemView _menuItem;
2026
private EditorFormView _editorForm;
2127

22-
[MenuItem("Tools/Assets Management/Asset Group #&G")]
28+
[MenuItem("Tools/Asset Management/Asset Group #&G")]
2329
private static void OpenWindow()
2430
{
2531
GetWindow<AssetGroupEditor>("Asset Group Editor");
@@ -28,6 +34,12 @@ private static void OpenWindow()
2834
private void OnFocus()
2935
{
3036
_assetFilter = AssetFilterEditor.GetAssetFilters().ToArray();
37+
var settings = AddressableAssetSettingsDefaultObject.Settings;
38+
if (settings != null)
39+
{
40+
_labels = settings.GetLabels().ToArray();
41+
_profileVariables = settings.profileSettings.GetVariableNames();
42+
}
3143
}
3244

3345
private void OnEnable()
@@ -39,48 +51,182 @@ private void OnEnable()
3951
_config.SetJsonType(JsonType.Array);
4052
}
4153

54+
//var settings = AddressableAssetSettingsDefaultObject.Settings;
55+
//if (settings != null)
56+
//{
57+
// _labels = settings.GetLabels().ToArray();
58+
// _profileVariables = settings.profileSettings.GetVariableNames();
59+
//}
60+
4261
OnMenuInit();
43-
_assetFilter = AssetFilterEditor.GetAssetFilters().ToArray();
62+
//_assetFilter = AssetFilterEditor.GetAssetFilters().ToArray();
4463
_editorForm = new EditorFormView(_config);
4564
OnFormInit();
4665
}
4766

4867
private void OnMenuInit()
4968
{
5069
_menuItem = new EditorMenuItemView();
51-
_menuItem.SetMenuItem("File", new string[] { "Save Config", "Exit" }, (itemIndex) => {
52-
if (itemIndex==0)
70+
_menuItem.SetMenuItem("File", new string[] { "Save Config","Set Addressables", "Exit" }, (itemIndex) => {
71+
if (itemIndex == 0)
5372
{
5473
ProjectSettingsConfig.SaveJsonData(_configName, _config);
5574
EditorUtility.DisplayDialog("Save Config", "Data saved successfully!", "OK");
5675
}
76+
else if (itemIndex == 1)
77+
{
78+
var settings = AddressableAssetSettingsDefaultObject.Settings;
79+
if (settings != null)
80+
{
81+
string binPath = ContentUpdateScript.GetContentStateDataPath(false);
82+
if (_config != null && _config.Count > 0)
83+
{
84+
for (int i = 0; i < _config.Count; i++)
85+
{
86+
JsonData item = _config[i];
87+
string groupName = item["GroupName"].ToString();
88+
var group = settings.FindGroup(groupName);
89+
if (group == null)
90+
{
91+
group = settings.CreateGroup(groupName,false,false,false,null);
92+
}
93+
BundledAssetGroupSchema bagSchema=group.GetSchema<BundledAssetGroupSchema>();
94+
if (bagSchema == null)
95+
{
96+
bagSchema= group.AddSchema<BundledAssetGroupSchema>();
97+
}
98+
bagSchema.BuildPath.SetVariableByName(settings, item["BuildPath"].ToString());
99+
bagSchema.LoadPath.SetVariableByName(settings, item["LoadPath"].ToString());
100+
101+
ContentUpdateGroupSchema cugSchema =group.GetSchema<ContentUpdateGroupSchema>();
102+
if (cugSchema == null)
103+
{
104+
cugSchema= group.AddSchema<ContentUpdateGroupSchema>();
105+
}
106+
cugSchema.StaticContent = ((int)item["UpdateRestriction"]==1);
107+
108+
//Filter
109+
StringBuilder filterBuilder = new StringBuilder();
110+
for (int filterIndex = 0; filterIndex < item["Filter"].Count; filterIndex++)
111+
{
112+
filterBuilder.Append($"t:{item["Filter"][filterIndex].ToString()} ");
113+
}
114+
//SearchInFolders
115+
List<string> folders = new List<string>();
116+
for (int folderIndex = 0; folderIndex < item["SearchInFolders"].Count; folderIndex++)
117+
{
118+
folders.Add(item["SearchInFolders"][folderIndex].ToString());
119+
}
120+
//Labels
121+
List<string> labels = new List<string>();
122+
for (int labelIndex = 0; labelIndex < item["Labels"].Count; labelIndex++)
123+
{
124+
labels.Add(item["Labels"][labelIndex].ToString());
125+
}
126+
127+
//Find All Asset
128+
var findAssets = AssetDatabase.FindAssets(filterBuilder.ToString(), folders.ToArray());
129+
for (int findIndex = 0; findIndex < findAssets.Length; findIndex++)
130+
{
131+
string guid = findAssets[findIndex];
132+
string assetPath = AssetDatabase.GUIDToAssetPath(guid);
133+
if (AssetDatabase.IsValidFolder(assetPath)|| assetPath.EndsWith(".cs"))
134+
{
135+
continue;
136+
}
137+
if (group.GetAssetEntry(guid) == null)
138+
{
139+
var entry = settings.CreateOrMoveEntry(guid, group);
140+
foreach (var itemLabel in labels)
141+
{
142+
entry.SetLabel(itemLabel, true);
143+
}
144+
}
145+
}
146+
}
147+
}
148+
EditorUtility.SetDirty(settings);
149+
AssetDatabase.Refresh();
150+
151+
EditorApplication.ExecuteMenuItem("Window/Asset Management/Addressables/Groups");
152+
}
153+
}
154+
else
155+
{
156+
Close();
157+
}
57158
},50)
58-
.SetMenuItem("Tools",new string[] { "Filter Edit" },(itemIndex) => { EditorApplication.ExecuteMenuItem("Tools/Assets Management/Asset Filter"); });
159+
.SetMenuItem("Tools",new string[] { "Filter Edit","Labels Edit" },(itemIndex) =>
160+
{
161+
if (itemIndex == 0)
162+
{
163+
EditorApplication.ExecuteMenuItem("Tools/Asset Management/Asset Filter");
164+
}
165+
else if (itemIndex == 1)
166+
{
167+
EditorApplication.ExecuteMenuItem("Window/Asset Management/Addressables/Groups");
168+
}
169+
});
59170
}
60171

61172
private void OnFormInit()
62173
{
63174
_editorForm.SetTitle("GroupName", 150, JsonType.String, null)
64175
.SetTitle("Description", 100, JsonType.String, null)
65176
//.SetTitle("Variant", 100, JsonType.String, null)
66-
.SetTitle("Filter", 100, JsonType.Int, (jsonData,width)=> {
67-
int filter = (int)jsonData;
68-
int newFilter = EditorGUILayout.MaskField(filter, _assetFilter, GUILayout.Width(100));
69-
if (filter != newFilter)
70-
{
71-
(jsonData as IJsonWrapper).SetInt(newFilter);
72-
}
177+
.SetTitle("Filter", 100, JsonType.Array, (jsonData,width)=> {
178+
string buttonText = "None";
179+
HashSet<string> selectFilter = new HashSet<string>();
180+
if (jsonData!=null && jsonData.Count>0)
181+
{
182+
if (jsonData.Count == 1)
183+
{
184+
buttonText = jsonData[0].ToString();
185+
}
186+
else
187+
{
188+
buttonText = "Mixed...";
189+
}
190+
for (int i = 0; i < jsonData.Count; i++)
191+
{
192+
selectFilter.Add(jsonData[i].ToString());
193+
}
194+
}
195+
if (GUILayout.Button(buttonText, EditorStyles.toolbarDropDown,GUILayout.Width(width)))
196+
{
197+
GenericMenu gm = new GenericMenu();
198+
for (int i = 0; i < _assetFilter.Length; i++)
199+
{
200+
string itemFilter = _assetFilter[i];
201+
bool filterOn = selectFilter.Contains(itemFilter);
202+
gm.AddItem(new GUIContent(itemFilter), filterOn, () => {
203+
if (filterOn)
204+
{
205+
jsonData.Remove(itemFilter);
206+
selectFilter.Remove(itemFilter);
207+
}
208+
else
209+
{
210+
selectFilter.Add(itemFilter);
211+
jsonData.Add(itemFilter);
212+
}
213+
});
214+
}
215+
gm.ShowAsContext();
216+
}
73217
})
74218
.SetTitle("SearchInFolders", 120, JsonType.Array, (jsonData, width) => {
75219
string buttonText = "No folder selected";
76220
if (jsonData != null && jsonData.Count > 0)
77221
{
78-
buttonText = $"[{jsonData.Count}]{jsonData[0].ToString()}";
79-
if (buttonText.Length > 13)
222+
if (jsonData.Count == 1)
80223
{
81-
buttonText = buttonText.Substring(0, 13);
224+
buttonText = jsonData[0].ToString();
225+
}
226+
else
227+
{
228+
buttonText = "Mixed...";
82229
}
83-
buttonText += "...|...";
84230
}
85231
if (GUILayout.Button(buttonText, EditorStyles.toolbarDropDown, GUILayout.Width(width)))
86232
{
@@ -100,8 +246,79 @@ private void OnFormInit()
100246
}
101247
});
102248
}
103-
});
104-
}
249+
})
250+
.SetTitle("Labels",100,JsonType.Array,(jsonData,width)=> {
251+
string buttonText = "None";
252+
HashSet<string> selectLabels = new HashSet<string>();
253+
if (jsonData != null && jsonData.Count > 0)
254+
{
255+
if (jsonData.Count == 1)
256+
{
257+
buttonText = jsonData[0].ToString();
258+
}
259+
else
260+
{
261+
buttonText = "Mixed...";
262+
}
263+
for (int i = 0; i < jsonData.Count; i++)
264+
{
265+
selectLabels.Add(jsonData[i].ToString());
266+
}
267+
}
268+
if (GUILayout.Button(buttonText, EditorStyles.toolbarDropDown, GUILayout.Width(width)))
269+
{
270+
GenericMenu gm = new GenericMenu();
271+
for (int i = 0; i < _labels.Length; i++)
272+
{
273+
string itemLabel = _labels[i];
274+
bool labelOn = selectLabels.Contains(itemLabel);
275+
gm.AddItem(new GUIContent(itemLabel), labelOn, () => {
276+
if (labelOn)
277+
{
278+
jsonData.Remove(itemLabel);
279+
selectLabels.Remove(itemLabel);
280+
}
281+
else
282+
{
283+
selectLabels.Add(itemLabel);
284+
jsonData.Add(itemLabel);
285+
}
286+
});
287+
}
288+
gm.ShowAsContext();
289+
}
290+
291+
})
292+
.SetTitle("BuildPath",150,JsonType.String,(jsonData,width)=> {
293+
string buildPath = jsonData.ToString();
294+
int buildPathIndex = _profileVariables.IndexOf(buildPath);
295+
int newBuildPathIndex = EditorGUILayout.Popup(buildPathIndex, _profileVariables.ToArray(),GUILayout.Width(width));
296+
if (newBuildPathIndex != buildPathIndex)
297+
{
298+
buildPath = _profileVariables[newBuildPathIndex];
299+
(jsonData as IJsonWrapper).SetString(buildPath);
300+
}
301+
})
302+
.SetTitle("LoadPath", 150, JsonType.String, (jsonData, width) => {
303+
string loadPath = jsonData.ToString();
304+
int loadPathIndex = _profileVariables.IndexOf(loadPath);
305+
int newLoadPathIndex = EditorGUILayout.Popup(loadPathIndex, _profileVariables.ToArray(),GUILayout.Width(width));
306+
if (newLoadPathIndex != loadPathIndex)
307+
{
308+
loadPath = _profileVariables[newLoadPathIndex];
309+
(jsonData as IJsonWrapper).SetString(loadPath);
310+
}
311+
})
312+
.SetTitle("UpdateRestriction",200,JsonType.Int,(jsonData,width)=> {
313+
int updateType = (int)jsonData;
314+
int newUpdateType =EditorGUILayout.Popup(updateType,new string[] {"Can Change Post Release", "Cannot Change Post Release" },GUILayout.Width(width));
315+
if (newUpdateType != updateType)
316+
{
317+
(jsonData as IJsonWrapper).SetInt(newUpdateType);
318+
}
319+
})
320+
;
321+
}
105322

106323
private void OnDisable()
107324
{

0 commit comments

Comments
 (0)