Add File Patterns to Resource Rule Editor
This commit is contained in:
parent
70b610c9e5
commit
301b54d8cb
@ -243,6 +243,10 @@ namespace StarForce.Editor.ResourceTools
|
||||
r.xMax = r.xMin + 120;
|
||||
rule.searchPatterns = EditorGUI.TextField(r, rule.searchPatterns);
|
||||
|
||||
r.xMin = r.xMax + GAP;
|
||||
r.xMax = r.xMin + 120;
|
||||
rule.filePatterns = EditorGUI.TextField(r, rule.filePatterns);
|
||||
|
||||
r.xMin = r.xMax + GAP;
|
||||
r.xMax = rect.xMax;
|
||||
rule.folderPatterns = EditorGUI.TextField(r, rule.folderPatterns);
|
||||
@ -342,6 +346,10 @@ namespace StarForce.Editor.ResourceTools
|
||||
r.xMax = r.xMin + 85;
|
||||
EditorGUI.TextField(r, "Filter Type");
|
||||
|
||||
r.xMin = r.xMax + GAP;
|
||||
r.xMax = r.xMin + 120;
|
||||
EditorGUI.TextField(r, "Search Patterns");
|
||||
|
||||
r.xMin = r.xMax + GAP;
|
||||
r.xMax = r.xMin + 120;
|
||||
EditorGUI.TextField(r, "File Patterns");
|
||||
@ -483,6 +491,10 @@ namespace StarForce.Editor.ResourceTools
|
||||
if (file.Extension.Contains("meta"))
|
||||
continue;
|
||||
|
||||
// 检查文件名是否匹配 filePatterns
|
||||
if (!string.IsNullOrEmpty(resourceRule.filePatterns) && !MatchFilePattern(file.Name, resourceRule.filePatterns))
|
||||
continue;
|
||||
|
||||
// 检查文件夹是否匹配 folderPatterns
|
||||
if (!string.IsNullOrEmpty(resourceRule.folderPatterns) && !MatchFolderPattern(file.DirectoryName, resourceRule.folderPatterns))
|
||||
continue;
|
||||
@ -545,7 +557,10 @@ namespace StarForce.Editor.ResourceTools
|
||||
{
|
||||
if (file.Extension.Contains("meta"))
|
||||
continue;
|
||||
|
||||
|
||||
// 检查文件名是否匹配 filePatterns
|
||||
if (!string.IsNullOrEmpty(resourceRule.filePatterns) && !MatchFilePattern(file.Name, resourceRule.filePatterns))
|
||||
continue;
|
||||
// 检查文件所在文件夹是否匹配 folderPatterns
|
||||
if (!string.IsNullOrEmpty(resourceRule.folderPatterns) && !MatchFolderPattern(file.DirectoryName, resourceRule.folderPatterns))
|
||||
continue;
|
||||
@ -638,6 +653,9 @@ namespace StarForce.Editor.ResourceTools
|
||||
if (file.Extension.Contains("meta"))
|
||||
continue;
|
||||
|
||||
// 检查文件名是否匹配 filePatterns
|
||||
if (!string.IsNullOrEmpty(resourceRule.filePatterns) && !MatchFilePattern(file.Name, resourceRule.filePatterns))
|
||||
continue;
|
||||
// 检查文件所在文件夹是否匹配 folderPatterns
|
||||
if (!string.IsNullOrEmpty(resourceRule.folderPatterns) && !MatchFolderPattern(file.DirectoryName, resourceRule.folderPatterns))
|
||||
continue;
|
||||
@ -672,6 +690,51 @@ namespace StarForce.Editor.ResourceTools
|
||||
{
|
||||
return m_ResourceCollection.Save();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 检查文件名是否匹配指定的模式
|
||||
/// </summary>
|
||||
private bool MatchFilePattern(string fileName, string patterns)
|
||||
{
|
||||
if (string.IsNullOrEmpty(patterns))
|
||||
return true;
|
||||
|
||||
string[] patternArray = patterns.Split(';', ',', '|');
|
||||
|
||||
bool hasIncludePattern = false;
|
||||
bool includeMatched = false;
|
||||
|
||||
foreach (string pattern in patternArray)
|
||||
{
|
||||
string trimmedPattern = pattern.Trim();
|
||||
if (string.IsNullOrEmpty(trimmedPattern))
|
||||
continue;
|
||||
|
||||
if (trimmedPattern.StartsWith("!"))
|
||||
{
|
||||
// 排除模式:如果文件名包含排除关键字,直接返回 false
|
||||
string excludePattern = trimmedPattern.Substring(1).ToLower();
|
||||
if (fileName.ToLower().Contains(excludePattern))
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
// 包含模式
|
||||
hasIncludePattern = true;
|
||||
if (MatchWildcard(fileName, trimmedPattern))
|
||||
{
|
||||
includeMatched = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 如果有包含模式,需要匹配到才返回 true
|
||||
// 如果只有排除模式,默认返回 true(除非上面已经被排除)
|
||||
if (hasIncludePattern)
|
||||
return includeMatched;
|
||||
else
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 检查文件夹路径是否匹配指定的模式
|
||||
|
||||
@ -23,6 +23,7 @@ namespace StarForce.Editor.ResourceTools
|
||||
public bool packed = true;
|
||||
public ResourceFilterType filterType = ResourceFilterType.Root;
|
||||
public string searchPatterns = "*.*";
|
||||
public string filePatterns = "*.*";
|
||||
public string folderPatterns = "*.*";
|
||||
}
|
||||
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "com.bywaystudios.gameframework",
|
||||
"displayName": "GameFramework",
|
||||
"version": "0.1.2",
|
||||
"version": "0.1.3",
|
||||
"description": "Custom GameFramework code"
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user