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

Commit 18f8d88

Browse files
committed
Add AssetFilterEditor
1 parent b88cde3 commit 18f8d88

File tree

6 files changed

+215
-22
lines changed

6 files changed

+215
-22
lines changed

GameFramework/Editor/AssetBundleEditor/AssetBundleEditor.cs

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -17,24 +17,7 @@ public class AssetBundleEditor : EditorWindow
1717

1818
private Vector2 _scrollView = Vector2.zero;
1919

20-
public static string[] AssetFilter = new string[] { "AnimationClip",
21-
"AudioClip",
22-
"AudioMixer",
23-
"ComputeShader",
24-
"Font",
25-
"GUISkin",
26-
"Material",
27-
"Mesh",
28-
"Model",
29-
"PhysicMaterial",
30-
"Prefab",
31-
"Scene",
32-
"Script",
33-
"Shader",
34-
"Sprite",
35-
"Texture",
36-
"VideoClip","TextAsset","ScriptableObject","AnimatorController","SpriteAtlas"};
37-
20+
private static string[] _assetFilter;
3821
//窗口的位置
3922
private Rect _foldersWindowRect = Rect.zero;
4023
public bool _haspopupFoldersWindow
@@ -51,6 +34,8 @@ public bool _haspopupFoldersWindow
5134
[MenuItem("Tools/Asset Bundle/Asset Bundle Editor")]
5235
private static void MainWindow()
5336
{
37+
_assetFilter = AssetFilterEditor.GetAssetFilters().ToArray();
38+
5439
//GetWindowWithRect<AssetBundleEditor>(new Rect(100, 100, 1200, 600), false, "Asset Bundle Editor");
5540
GetWindow<AssetBundleEditor>("Asset Bundle Editor");
5641
}
@@ -162,19 +147,19 @@ private static List<AssetBundleBuild> JsonToABB(JsonData jsonData)
162147
StringBuilder filterBuilder = new StringBuilder();
163148
if (jsonFilter == -1)
164149
{
165-
foreach (var item in AssetFilter)
150+
foreach (var item in _assetFilter)
166151
{
167152
filterBuilder.Append($"t:{item} ");
168153
}
169154
}
170155
else
171156
{
172-
for (int i = 0; i < AssetFilter.Length; i++)
157+
for (int i = 0; i < _assetFilter.Length; i++)
173158
{
174159
int byteIndex = 1 << i;
175160
if ((jsonFilter & byteIndex) == byteIndex)
176161
{
177-
filterBuilder.Append($"t:{AssetFilter[i]} ");
162+
filterBuilder.Append($"t:{_assetFilter[i]} ");
178163
}
179164
}
180165
}
@@ -422,7 +407,7 @@ private void DrawJsonData(JsonData jsonData)
422407
jsonData[key] = 1024;
423408
}
424409
int filter = (int)jsonData[key];
425-
int newFilter = EditorGUILayout.MaskField(filter, AssetFilter, GUILayout.Width(100));
410+
int newFilter = EditorGUILayout.MaskField(filter, _assetFilter, GUILayout.Width(100));
426411
if (filter != newFilter)
427412
{
428413
jsonData[key] = newFilter;

GameFramework/Editor/AssetGroupEditor.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
using LitJson;
2+
using System.Collections;
3+
using System.Collections.Generic;
4+
using UnityEditor;
5+
using UnityEditorInternal;
6+
using UnityEngine;
7+
8+
namespace Wanderer.GameFramework
9+
{
10+
11+
public class AssetFilterEditor : EditorWindow
12+
{
13+
private const string _configName = "AssetFilterEditor.json";
14+
private static JsonData _config;
15+
private Vector2 _scrollView = Vector2.zero;
16+
17+
private static List<string> _listLabels = new List<string>(){ "AnimationClip",
18+
"AudioClip","AudioMixer","ComputeShader","Font","GUISkin","Material",
19+
"Mesh","Model","PhysicMaterial","Prefab","Scene","Script","Shader",
20+
"Sprite","Texture","VideoClip","TextAsset","ScriptableObject",
21+
"AnimatorController","SpriteAtlas"};
22+
private string _newLabel = "";
23+
24+
private ReorderableList _labelReorderableList;
25+
private bool _showAddItemWindow;
26+
27+
[MenuItem("Tools/Assets Management/Asset Filter")]
28+
private static void OpenWindow()
29+
{
30+
GetWindow<AssetFilterEditor>(true, "Asset Filter Editor",true).ShowModalUtility();
31+
}
32+
33+
public static List<string> GetAssetFilters()
34+
{
35+
_config = ProjectSettingsConfig.LoadJsonData(_configName);
36+
if (_config != null && _config.Count > 0)
37+
{
38+
_listLabels.Clear();
39+
for (int i = 0; i < _config.Count; i++)
40+
{
41+
string label = (string)_config[i];
42+
if (!_listLabels.Contains(label))
43+
{
44+
_listLabels.Add(label);
45+
}
46+
}
47+
}
48+
else
49+
{
50+
_config = new JsonData();
51+
_config.SetJsonType(JsonType.Array);
52+
}
53+
return _listLabels;
54+
}
55+
56+
private void OnEnable()
57+
{
58+
GetAssetFilters();
59+
SetReorderableList();
60+
}
61+
62+
private void OnDisable()
63+
{
64+
_labelReorderableList = null;
65+
}
66+
67+
private void SetReorderableList()
68+
{
69+
_labelReorderableList = new ReorderableList(_listLabels, typeof(string));
70+
_labelReorderableList.drawHeaderCallback = (rect) => { GUI.Label(rect, "Asset Filter"); };
71+
_labelReorderableList.drawElementCallback = (rect, index, isActive, isFocused) => {
72+
string label = _listLabels[index];
73+
GUI.Label(rect, label);
74+
};
75+
_labelReorderableList.onRemoveCallback = (list) => {
76+
if (EditorUtility.DisplayDialog("Warning", "Are you sure to delete the current data?", "Yes", "No"))
77+
{
78+
ReorderableList.defaultBehaviours.DoRemoveButton(list);
79+
SaveConfig();
80+
}
81+
};
82+
_labelReorderableList.onAddCallback = (list) =>
83+
{
84+
_showAddItemWindow = true;
85+
86+
};
87+
88+
//_labelReorderableList.drawElementBackgroundCallback = (rect, index, isActive, isFocused) => { };
89+
//_labelReorderableList.elementHeightCallback = (index) => { return 80.0f; };
90+
}
91+
92+
93+
private void OnGUI()
94+
{
95+
if (_config == null)
96+
return;
97+
_scrollView = EditorGUILayout.BeginScrollView(_scrollView);
98+
//GUILayout.BeginVertical("HelpBox");
99+
_labelReorderableList?.DoLayoutList();
100+
101+
if (_showAddItemWindow)
102+
{
103+
Rect lastRect = GUILayoutUtility.GetLastRect();
104+
lastRect.y += lastRect.height - 25;
105+
//lastRect.height = 60;
106+
107+
Rect newRect = new Rect(lastRect.x, lastRect.y, lastRect.width, 70);
108+
EditorGUI.DrawRect(newRect,new Color(0.2196079f, 0.2196079f, 0.2196079f,1.0f));
109+
newRect.y += 5;
110+
newRect.height = 25;
111+
GUI.Label(newRect,"New Filter");
112+
newRect.x = 65;
113+
newRect.width -= 70;
114+
_newLabel = EditorGUI.TextField(newRect, _newLabel);
115+
newRect.width = lastRect.width*0.5f;
116+
newRect.y += 35;
117+
newRect.x = 0;
118+
if (GUI.Button(newRect, "Cancel"))
119+
{
120+
_newLabel = "";
121+
_showAddItemWindow = false;
122+
}
123+
newRect.x = newRect.width;
124+
if (GUI.Button(newRect, "Save"))
125+
{
126+
if (!string.IsNullOrEmpty(_newLabel))
127+
{
128+
_newLabel = _newLabel.Trim();
129+
if (!_listLabels.Contains(_newLabel))
130+
{
131+
_listLabels.Add(_newLabel);
132+
SaveConfig();
133+
}
134+
}
135+
_newLabel = "";
136+
_showAddItemWindow = false;
137+
138+
}
139+
}
140+
141+
//GUILayout.EndVertical();
142+
EditorGUILayout.EndScrollView();
143+
}
144+
145+
146+
private void SaveConfig()
147+
{
148+
_config.Clear();
149+
foreach (var item in _listLabels)
150+
{
151+
_config.Add(item);
152+
}
153+
ProjectSettingsConfig.SaveJsonData(_configName,_config);
154+
}
155+
156+
}
157+
158+
}

GameFramework/Editor/AssetGroupEditor/AssetFilterEditor.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using LitJson;
2+
using System.Collections;
3+
using System.Collections.Generic;
4+
using UnityEditor;
5+
using UnityEngine;
6+
7+
namespace Wanderer.GameFramework
8+
{
9+
public class AssetGroupEditor:EditorWindow
10+
{
11+
private const string _configName = "AssetGroupEditor.json";
12+
private JsonData _config;
13+
private JsonData _newData;
14+
private JsonData _selectFoldersJsonData;
15+
private Vector2 _scrollView = Vector2.zero;
16+
17+
18+
}
19+
20+
}

GameFramework/Editor/AssetGroupEditor/AssetGroupEditor.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)