Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1.x #47

Merged
merged 3 commits into from
Jan 13, 2024
Merged

1.x #47

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Editor/Windows/ASConfigEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ protected override void OnGUI()
if (GELayout.Button("Clean Sandbox"))
{
var sandbox = Path.Combine(EHelper.Path.Project, "Sandbox");
if (Directory.Exists(sandbox)) AHelper.IO.DeleteFolder(sandbox, SearchOption.AllDirectories, true);
if (Directory.Exists(sandbox)) AHelper.IO.DeleteDir(sandbox, SearchOption.AllDirectories, true);
}

if (GELayout.Button("Clean Bundles"))
{
var sandbox = Path.Combine(EHelper.Path.Project, "Bundles");
if (Directory.Exists(sandbox)) AHelper.IO.DeleteFolder(sandbox, SearchOption.AllDirectories, true);
if (Directory.Exists(sandbox)) AHelper.IO.DeleteDir(sandbox, SearchOption.AllDirectories, true);
}
}

Expand Down
6 changes: 5 additions & 1 deletion Editor/Windows/AssetCollectWindow.Data.cs
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,9 @@ private class DependenciesInfo
#region Common

private Hashtable TempTable = new Hashtable();

private GUILayoutOption GP_MAX_Width_100;
private GUILayoutOption GP_MIN_Width_50;

private GUILayoutOption GP_Width_100;
private GUILayoutOption GP_Width_120;
private GUILayoutOption GP_Width_150;
Expand Down Expand Up @@ -533,6 +535,8 @@ private class DependenciesInfo

private void GPInit()
{
GP_MAX_Width_100 = GUILayout.MaxWidth(100);
GP_MIN_Width_50 = GUILayout.MinWidth(50);
GP_Width_EXPAND = GUILayout.ExpandWidth(true);
GP_Width_120 = GUILayout.Width(120);
GP_Width_150 = GUILayout.Width(150);
Expand Down
55 changes: 51 additions & 4 deletions Editor/Windows/Data/AssetCollectItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using AIO.UEngine;
using UnityEditor;
Expand Down Expand Up @@ -174,39 +173,87 @@
/// </summary>
/// <param name="data">数据</param>
/// <returns>Ture:忽略 False:需要过滤</returns>
public bool IsCollectAsset(AssetRuleData data)
{
// 判断是否为Resources目录下的资源
var rootPath = data.AssetPath.Substring(0, data.AssetPath.LastIndexOf('/'));
if (rootPath.Contains("Resources/") || rootPath.EndsWith("Resources"))
{
Debug.LogWarningFormat("Resources 目录下的资源不允许打包 !!! 已自动过滤 !!! -> {0}", data.AssetPath);
return false;
}

// 判断收集规则是否符合条件 如果不符合则跳过
if (RuleCollects.Count != 0 &&
!RuleCollects.Any(filter => filter.IsCollectAsset(data))
!RuleCollects.Exists(filter => filter.IsCollectAsset(data))
) return false;

// 判断自定义收集规则等
if (RuleUseCollectCustom && RuleCustomCollect?.Length > 0 &&
!UEditor.RuleCollect.IsCollectAssetCustom(RuleCustomCollect, data.Extension)
) return false;

// 判断过滤规则是否符合条件 如果符合则跳过
if (RuleFilters.Count != 0 &&
RuleFilters.Any(filter => filter.IsCollectAsset(data))
RuleFilters.Exists(filter => filter.IsCollectAsset(data))
) return false;

// 判断自定义过滤规则等
if (RuleUseFilterCustom && RuleCustomFilter?.Length > 0 &&
UEditor.RuleCollect.IsCollectAssetCustom(RuleCustomFilter, data.Extension)
) return false;

return true;
}

Check notice on line 208 in Editor/Windows/Data/AssetCollectItem.cs

View check run for this annotation

codefactor.io / CodeFactor

Editor/Windows/Data/AssetCollectItem.cs#L176-L208

Complex Method
public string GetAddress(string assetPath)
{
UpdateCollect();
UpdateFilter();
var data = new AssetRuleData
{
Tags = Tags,
UserData = UserData,
PackageName = PackageName,
GroupName = GroupName,
CollectPath = CollectPath,
};
var index = assetPath.LastIndexOf('.');
if (index >= 0)
{
data.Extension = assetPath.Substring(index).Replace(".", "").ToLower();
}

data.AssetPath = assetPath.Substring(0, assetPath.Length - data.Extension.Length - 1);
return IsCollectAsset(data) ? GetAssetAddress(data, ASConfig.GetOrCreate().LoadPathToLower) : string.Empty;
}

/// <summary>
/// 是否存在指定资源
/// </summary>
/// <param name="assetPath">资源相对路径</param>
/// <returns>Ture:存在 False:不存在</returns>
public bool Exist(string assetPath)
{
UpdateFilter();
var data = new AssetRuleData
{
Tags = Tags,
UserData = UserData,
PackageName = PackageName,
GroupName = GroupName,
CollectPath = CollectPath,
};
var index = assetPath.LastIndexOf('.');
if (index >= 0)
{
data.Extension = assetPath.Substring(index).Replace(".", "").ToLower();
}

data.AssetPath = assetPath.Substring(0, assetPath.Length - data.Extension.Length - 1);
return IsCollectAsset(data);
}

public string GetAssetAddress(AssetRuleData data, bool pathToLower = false)
{
var rule = AssetCollectSetting.MapAddress.GetValue(Address);
Expand Down Expand Up @@ -337,7 +384,7 @@
}
}

public async void CollectAssetTask(string package, string group,
public async Task CollectAssetTask(string package, string group,
Action<Dictionary<string, AssetDataInfo>> cb = null)
{
AssetDataInfos.Clear();
Expand Down
54 changes: 52 additions & 2 deletions Editor/Windows/Data/AssetCollectRoot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using UnityEditor;
using UnityEngine;
Expand All @@ -20,7 +19,7 @@ namespace AIO.UEditor
[HelpURL(
"https://github.com/AIO-GAME/Unity.Asset.CLI/blob/main/.github/API_USAGE/ToolWindow.md#asset-system-%E5%B7%A5%E5%85%B7%E8%AF%B4%E6%98%8E")]
#if UNITY_2021_1_OR_NEWER
[Icon( "Packages/com.aio.package/Resources/Editor/Setting/icon_interests.png")]
[Icon("Packages/com.aio.package/Resources/Editor/Setting/icon_interests.png")]
#else
[ScriptIcon(IconRelative = "Packages/com.aio.package/Resources/Editor/Setting/icon_interests.png")]
#endif
Expand Down Expand Up @@ -374,5 +373,56 @@ public void FoldoutOff()
}
}
}

[MenuItem("Assets/Asset System Find Address", true, 1000)]
private static bool IsSelectAsset()
{
return Selection.activeObject != null &&
AssetDatabase.Contains(Selection.activeObject) &&
!AssetDatabase.IsValidFolder(AssetDatabase.GetAssetPath(Selection.activeObject)); // 不能是文件夹
}

/// <summary>
/// 根据GUID查找资源可寻址路径
/// </summary>
[MenuItem("Assets/Asset System Find Address", false, 1000)]
public static void FindAssetLocal()
{
var obj = Selection.activeObject;
var path = AssetDatabase.GetAssetPath(obj);
var guid = AssetDatabase.AssetPathToGUID(path);
if (string.IsNullOrEmpty(guid)) return;
var root = GetOrCreate();
var list = new List<(string, string, string)>();
foreach (var package in root.Packages)
{
if (package is null) continue;
foreach (var group in package.Groups)
{
if (group is null) continue;
foreach (var item in group.Collectors)
{
if (item is null) continue;
if (item.Type != EAssetCollectItemType.MainAssetCollector) continue;
if (!path.StartsWith(item.CollectPath)) continue;
// 是否是否被过滤
var address = item.GetAddress(path);
if (string.IsNullOrEmpty(address)) continue;
list.Add((package.Name, group.Name, address));
}
}
}

if (list.Count == 0) Debug.Log($"未找到资源{path}的可寻址路径");
else
{
var str = string.Join("\n", list.Select(tuple => @$"
Package : {tuple.Item1}
Group : {tuple.Item2}
Address : {tuple.Item3}
"));
Debug.Log($"资源{path}的可寻址路径:\n{str}");
}
}
}
}
4 changes: 2 additions & 2 deletions Editor/Windows/Interface/AssetInfoData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public long Size
}
else if (Directory.Exists(AssetPath))
{
_size = AHelper.IO.GetFolderLength(AssetPath);
_size = AHelper.IO.GetDirLength(AssetPath);
}
else _size = -1;
}
Expand Down Expand Up @@ -101,7 +101,7 @@ public DateTime LastWriteTime
if (File.Exists(AssetPath))
_lastWriteTime = AHelper.IO.GetFileLastWriteTimeUtc(AssetPath);
else if (Directory.Exists(AssetPath))
_lastWriteTime = AHelper.IO.GetFolderLastWriteTimeUtc(AssetPath);
_lastWriteTime = AHelper.IO.GetDirLastWriteTimeUtc(AssetPath);
else _lastWriteTime = DateTime.MinValue;
}

Expand Down
4 changes: 2 additions & 2 deletions Editor/Windows/Mode/AssetCollectWindow.OnDrawConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -127,14 +127,14 @@ partial void OnDrawASConfig()
{
var sandbox = Path.Combine(EHelper.Path.Project, "Sandbox");
if (Directory.Exists(sandbox))
AHelper.IO.DeleteFolder(sandbox, SearchOption.AllDirectories, true);
AHelper.IO.DeleteDir(sandbox, SearchOption.AllDirectories, true);
}

if (GELayout.Button("Clean Bundles", GEStyle.toolbarbuttonRight, GP_Width_100))
{
var sandbox = Path.Combine(EHelper.Path.Project, "Bundles");
if (Directory.Exists(sandbox))
AHelper.IO.DeleteFolder(sandbox, SearchOption.AllDirectories, true);
AHelper.IO.DeleteDir(sandbox, SearchOption.AllDirectories, true);
}
}

Expand Down
47 changes: 22 additions & 25 deletions Editor/Windows/Mode/AssetCollectWindow.OnDrawLookMode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ LookModeDisplayPackages is null ||
}

Data.CurrentPackageIndex = EditorGUILayout.Popup(Data.CurrentPackageIndex, LookModeDisplayPackages,
GEStyle.PreDropDown,
GP_Width_100);
GEStyle.PreDropDown, GP_MAX_Width_100, GP_MIN_Width_50);

if (!Data.IsGroupValid())
{
Expand Down Expand Up @@ -60,7 +59,7 @@ LookModeDisplayPackages is null ||

Data.CurrentGroupIndex = EditorGUILayout.Popup(
Data.CurrentGroupIndex, LookModeDisplayGroups[packageName],
GEStyle.PreDropDown, GP_Width_100);
GEStyle.PreDropDown, GP_MAX_Width_100, GP_MIN_Width_50);

if (!Data.IsCollectValid())
{
Expand Down Expand Up @@ -93,19 +92,19 @@ LookModeDisplayPackages is null ||
LookModeDisplayCollectorsIndex = 0;
EditorGUILayout.Popup(0,
LookModeDisplayCollectors[(Data.CurrentPackageIndex, Data.CurrentGroupIndex)],
GEStyle.PreDropDown, GP_Width_100);
GEStyle.PreDropDown, GP_MAX_Width_100, GP_MIN_Width_50);
}
else if (LookModeDisplayCollectors[(Data.CurrentPackageIndex, Data.CurrentGroupIndex)].Length >= 31)
{
LookModeDisplayCollectorsIndex = EditorGUILayout.Popup(LookModeDisplayCollectorsIndex,
LookModeDisplayCollectors[(Data.CurrentPackageIndex, Data.CurrentGroupIndex)],
GEStyle.PreDropDown, GP_Width_100);
GEStyle.PreDropDown, GP_MAX_Width_100, GP_MIN_Width_50);
}
else
{
LookModeDisplayCollectorsIndex = EditorGUILayout.MaskField(LookModeDisplayCollectorsIndex,
LookModeDisplayCollectors[(Data.CurrentPackageIndex, Data.CurrentGroupIndex)],
GEStyle.PreDropDown, GP_Width_100);
GEStyle.PreDropDown, GP_MAX_Width_100, GP_MIN_Width_50);
}
}
else LookModeDisplayCollectorsIndex = 0;
Expand All @@ -117,13 +116,13 @@ LookModeDisplayPackages is null ||
LookModeDisplayTypeIndex = 0;
EditorGUILayout.Popup(0,
LookModeDisplayTypes[(Data.CurrentPackageIndex, Data.CurrentGroupIndex)],
GEStyle.PreDropDown, GP_Width_100);
GEStyle.PreDropDown, GP_MAX_Width_100, GP_MIN_Width_50);
}
else
{
LookModeDisplayTypeIndex = EditorGUILayout.MaskField(LookModeDisplayTypeIndex,
LookModeDisplayTypes[(Data.CurrentPackageIndex, Data.CurrentGroupIndex)],
GEStyle.PreDropDown, GP_Width_100);
GEStyle.PreDropDown, GP_MAX_Width_100, GP_MIN_Width_50);
}
}
else LookModeDisplayTypeIndex = 0;
Expand All @@ -135,13 +134,13 @@ LookModeDisplayPackages is null ||
LookModeDisplayTagsIndex = 0;
EditorGUILayout.Popup(0,
LookModeDisplayTags[(Data.CurrentPackageIndex, Data.CurrentGroupIndex)],
GEStyle.PreDropDown, GP_Width_100);
GEStyle.PreDropDown, GP_MAX_Width_100, GP_MIN_Width_50);
}
else
{
LookModeDisplayTagsIndex = EditorGUILayout.MaskField(LookModeDisplayTagsIndex,
LookModeDisplayTags[(Data.CurrentPackageIndex, Data.CurrentGroupIndex)],
GEStyle.PreDropDown, GP_Width_100);
GEStyle.PreDropDown, GP_MAX_Width_100, GP_MIN_Width_50);
}
}
else LookModeDisplayTagsIndex = 0;
Expand Down Expand Up @@ -182,6 +181,14 @@ LookModeDisplayPackages is null ||
}

OnDrawHeaderLookPageSetting();

if (GUILayout.Button(GC_REFRESH, GEStyle.TEtoolbarbutton, GP_Width_25))
{
LookModeCurrentSelectAsset = null;
SearchText = string.Empty;
LookModeDisplayTagsIndex = LookModeDisplayTypeIndex = LookModeDisplayCollectorsIndex = 0;
UpdateDataLookMode();
}
}

/// <summary>
Expand Down Expand Up @@ -228,14 +235,6 @@ private void OnDrawHeaderLookPageSetting()
{
LookDataPageSizeMenu.ShowAsContext();
}

if (GUILayout.Button(GC_REFRESH, GEStyle.TEtoolbarbutton, GP_Width_25))
{
LookModeCurrentSelectAsset = null;
SearchText = string.Empty;
LookModeDisplayTagsIndex = LookModeDisplayTypeIndex = LookModeDisplayCollectorsIndex = 0;
UpdateDataLookMode();
}
}

/// <summary>
Expand Down Expand Up @@ -397,29 +396,24 @@ private void OnDrawLookModeAssetDetail()
EditorGUILayout.LabelField(GC_LookMode_Detail_Asset, GP_Width_100);
EditorGUILayout.ObjectField(LookModeCurrentSelectAsset, LookModeCurrentSelectAsset.GetType(),
false);
if (GELayout.Button(GC_OPEN_FOLDER, GEStyle.IconButton, 16))
EditorUtility.RevealInFinder(LookModeCurrentSelectAssetDataInfo.AssetPath);
}

using (new EditorGUILayout.HorizontalScope(GEStyle.toolbarbuttonLeft))
{
EditorGUILayout.LabelField(GC_LookMode_Detail_GUID, GP_Width_100);
EditorGUILayout.LabelField(LookModeCurrentSelectAssetDataInfo.GUID);
GELayout.ButtonCopy(GC_COPY, LookModeCurrentSelectAssetDataInfo.GUID, 16, GEStyle.IconButton);
}

using (new EditorGUILayout.HorizontalScope(GEStyle.toolbarbuttonLeft))
{
EditorGUILayout.LabelField(GC_LookMode_Detail_Type, GP_Width_100);
EditorGUILayout.LabelField(LookModeCurrentSelectAssetDataInfo.Type);
GELayout.ButtonCopy(GC_COPY, LookModeCurrentSelectAssetDataInfo.Type, 16, GEStyle.IconButton);
}

using (new EditorGUILayout.HorizontalScope(GEStyle.toolbarbuttonLeft))
{
EditorGUILayout.LabelField(GC_LookMode_Detail_Path, GP_Width_100);
EditorGUILayout.LabelField(LookModeCurrentSelectAssetDataInfo.AssetPath);
GELayout.ButtonCopy(GC_COPY, LookModeCurrentSelectAssetDataInfo.AssetPath, 16, GEStyle.IconButton);
}

using (new EditorGUILayout.HorizontalScope(GEStyle.toolbarbuttonLeft))
Expand All @@ -428,7 +422,6 @@ private void OnDrawLookModeAssetDetail()
var timer =
LookModeCurrentSelectAssetDataInfo.LastWriteTime.ToString("yyyy-MM-dd hh:mm:ss");
EditorGUILayout.LabelField(timer);
GELayout.ButtonCopy(GC_COPY, timer, 16, GEStyle.IconButton);
}

if (!string.IsNullOrEmpty(LookModeCurrentSelectAssetDataInfo.Tags))
Expand Down Expand Up @@ -626,6 +619,10 @@ private void OnDrawLookDataItem(Rect rect, AssetDataInfo data, int index)
{
GUI.FocusControl(null);
onDrawLookDataItemMenu = new GenericMenu();
onDrawLookDataItemMenu.AddItem(new GUIContent("Open Default Asset"), false,
() => { EditorUtility.OpenWithDefaultApp(data.AssetPath); });
onDrawLookDataItemMenu.AddItem(new GUIContent("Open Local Folder"), false,
() => { EditorUtility.RevealInFinder(data.AssetPath); });
onDrawLookDataItemMenu.AddItem(new GUIContent("Select Asset"), false,
() => { Selection.activeObject = AssetDatabase.LoadMainAssetAtPath(data.AssetPath); });
onDrawLookDataItemMenu.AddItem(new GUIContent("Copy Address"), false,
Expand Down Expand Up @@ -712,7 +709,7 @@ private void UpdateDataLookModeCollector(int packageIndex, int groupIndex)
var listTypes = new List<string>();
for (var k = 0; k < Data.Packages[i].Groups[j].Collectors.Length; k++)
{
Data.Packages[i].Groups[j].Collectors[k].CollectAssetTask(
_ = Data.Packages[i].Groups[j].Collectors[k].CollectAssetTask(
Data.Packages[i].Name,
Data.Packages[i].Groups[j].Name,
dic =>
Expand Down
Loading
Loading