【m】框架大更新

This commit is contained in:
2025-10-31 11:18:23 +08:00
parent ae6e7c804b
commit 8e1d52ddbf
1883 changed files with 213934 additions and 640 deletions

View File

@@ -0,0 +1,229 @@
#if UNITY_2019_4_OR_NEWER
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using UnityEngine;
namespace YooAsset.Editor
{
public static class DefaultSearchSystem
{
/// <summary>
/// 解析搜索命令
/// </summary>
public static List<ISearchCommand> ParseCommand(string commandContent)
{
if (string.IsNullOrEmpty(commandContent))
return new List<ISearchCommand>();
List<ISearchCommand> results = new List<ISearchCommand>(10);
string[] commands = Regex.Split(commandContent, @"\s+");
foreach (var command in commands)
{
if (command.Contains("!="))
{
var splits = command.Split(new string[] { "!=" }, StringSplitOptions.None);
if (CheckSplitsValid(command, splits) == false)
continue;
var cmd = new SearchCompare();
cmd.HeaderTitle = splits[0];
cmd.CompareValue = splits[1];
cmd.CompareOperator = "!=";
results.Add(cmd);
}
else if (command.Contains(">="))
{
var splits = command.Split(new string[] { ">=" }, StringSplitOptions.None);
if (CheckSplitsValid(command, splits) == false)
continue;
var cmd = new SearchCompare();
cmd.HeaderTitle = splits[0];
cmd.CompareValue = splits[1];
cmd.CompareOperator = ">=";
results.Add(cmd);
}
else if (command.Contains("<="))
{
var splits = command.Split(new string[] { "<=" }, StringSplitOptions.None);
if (CheckSplitsValid(command, splits) == false)
continue;
var cmd = new SearchCompare();
cmd.HeaderTitle = splits[0];
cmd.CompareValue = splits[1];
cmd.CompareOperator = "<=";
results.Add(cmd);
}
else if (command.Contains(">"))
{
var splits = command.Split('>');
if (CheckSplitsValid(command, splits) == false)
continue;
var cmd = new SearchCompare();
cmd.HeaderTitle = splits[0];
cmd.CompareValue = splits[1];
cmd.CompareOperator = ">";
results.Add(cmd);
}
else if (command.Contains("<"))
{
var splits = command.Split('<');
if (CheckSplitsValid(command, splits) == false)
continue;
var cmd = new SearchCompare();
cmd.HeaderTitle = splits[0];
cmd.CompareValue = splits[1];
cmd.CompareOperator = "<";
results.Add(cmd);
}
else if (command.Contains("="))
{
var splits = command.Split('=');
if (CheckSplitsValid(command, splits) == false)
continue;
var cmd = new SearchCompare();
cmd.HeaderTitle = splits[0];
cmd.CompareValue = splits[1];
cmd.CompareOperator = "=";
results.Add(cmd);
}
else if (command.Contains(":"))
{
var splits = command.Split(':');
if (CheckSplitsValid(command, splits) == false)
continue;
var cmd = new SearchKeyword();
cmd.SearchTag = splits[0];
cmd.Keyword = splits[1];
results.Add(cmd);
}
else
{
var cmd = new SearchKeyword();
cmd.SearchTag = string.Empty;
cmd.Keyword = command;
results.Add(cmd);
}
}
return results;
}
private static bool CheckSplitsValid(string command, string[] splits)
{
if (splits.Length != 2)
{
Debug.LogWarning($"Invalid search command : {command}");
return false;
}
if (string.IsNullOrEmpty(splits[0]))
return false;
if (string.IsNullOrEmpty(splits[1]))
return false;
return true;
}
/// <summary>
/// 搜索匹配
/// </summary>
public static void Search(List<ITableData> sourceDatas, string command)
{
var searchCmds = ParseCommand(command);
foreach (var tableData in sourceDatas)
{
tableData.Visible = Search(tableData, searchCmds);
}
}
private static bool Search(ITableData tableData, List<ISearchCommand> commands)
{
if (commands.Count == 0)
return true;
// 先匹配字符串
var searchKeywordCmds = commands.Where(cmd => cmd is SearchKeyword).ToList();
if (SearchKeyword(tableData, searchKeywordCmds) == false)
return false;
// 后匹配数值
var searchCompareCmds = commands.Where(cmd => cmd is SearchCompare).ToList();
if (SearchCompare(tableData, searchCompareCmds) == false)
return false;
return true;
}
private static bool SearchKeyword(ITableData tableData, List<ISearchCommand> commands)
{
if (commands.Count == 0)
return true;
// 匹配规则:任意字符串列匹配成果
foreach (var tableCell in tableData.Cells)
{
foreach (var cmd in commands)
{
var searchKeywordCmd = cmd as SearchKeyword;
if (tableCell is StringValueCell stringValueCell)
{
if (string.IsNullOrEmpty(searchKeywordCmd.SearchTag) == false)
{
if (searchKeywordCmd.SearchTag == stringValueCell.SearchTag)
{
if (searchKeywordCmd.CompareTo(stringValueCell.StringValue))
return true;
}
}
else
{
if (searchKeywordCmd.CompareTo(stringValueCell.StringValue))
return true;
}
}
}
}
// 匹配失败
return false;
}
private static bool SearchCompare(ITableData tableData, List<ISearchCommand> commands)
{
if (commands.Count == 0)
return true;
// 匹配规则:任意指定数值列匹配成果
foreach (var tableCell in tableData.Cells)
{
foreach (var cmd in commands)
{
var searchCompareCmd = cmd as SearchCompare;
if (tableCell is IntegerValueCell integerValueCell)
{
if (searchCompareCmd.HeaderTitle == integerValueCell.SearchTag)
{
if (searchCompareCmd.CompareTo(integerValueCell.IntegerValue))
return true;
}
}
else if (tableCell is SingleValueCell singleValueCell)
{
if (searchCompareCmd.HeaderTitle == singleValueCell.SearchTag)
{
if (searchCompareCmd.CompareTo(singleValueCell.SingleValue))
return true;
}
}
}
}
// 匹配失败
return false;
}
}
}
#endif

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: c74188ff4fc442a429e138c980b51a90
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,9 @@
#if UNITY_2019_4_OR_NEWER
namespace YooAsset.Editor
{
public interface ISearchCommand
{
}
}
#endif

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 8ab518ab477549849888cd722b80738a
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,133 @@
#if UNITY_2019_4_OR_NEWER
using System;
using UnityEditor;
using UnityEngine;
namespace YooAsset.Editor
{
/// <summary>
/// 指定标题的比较搜索
/// </summary>
public class SearchCompare : ISearchCommand
{
public string HeaderTitle;
public string CompareValue;
public string CompareOperator;
/// <summary>
/// 转换的整形数值
/// </summary>
private bool _isConvertedIntegerNum = false;
private long _convertedIntegerNumber = 0;
public long IntegerNumberValue
{
get
{
if (_isConvertedIntegerNum == false)
{
_isConvertedIntegerNum = true;
_convertedIntegerNumber = long.Parse(CompareValue.ToString());
}
return _convertedIntegerNumber;
}
}
/// <summary>
/// 转换的浮点数值
/// </summary>
private bool _isConvertedSingleNum = false;
private double _convertedSingleNumber = 0;
public double SingleNumberValue
{
get
{
if (_isConvertedSingleNum == false)
{
_isConvertedSingleNum = true;
_convertedSingleNumber = double.Parse(CompareValue.ToString());
}
return _convertedSingleNumber;
}
}
public bool CompareTo(long value)
{
if (CompareOperator == ">")
{
if (value > SingleNumberValue)
return true;
}
else if (CompareOperator == ">=")
{
if (value >= SingleNumberValue)
return true;
}
else if (CompareOperator == "<")
{
if (value < SingleNumberValue)
return true;
}
else if (CompareOperator == "<=")
{
if (value <= SingleNumberValue)
return true;
}
else if (CompareOperator == "=")
{
if (value == SingleNumberValue)
return true;
}
else if (CompareOperator == "!=")
{
if (value != SingleNumberValue)
return true;
}
else
{
Debug.LogWarning($"Can not support operator : {CompareOperator}");
}
return false;
}
public bool CompareTo(double value)
{
if (CompareOperator == ">")
{
if (value > IntegerNumberValue)
return true;
}
else if (CompareOperator == ">=")
{
if (value >= IntegerNumberValue)
return true;
}
else if (CompareOperator == "<")
{
if (value < IntegerNumberValue)
return true;
}
else if (CompareOperator == "<=")
{
if (value <= IntegerNumberValue)
return true;
}
else if (CompareOperator == "=")
{
if (value == IntegerNumberValue)
return true;
}
else if (CompareOperator == "!=")
{
if (value != IntegerNumberValue)
return true;
}
else
{
Debug.LogWarning($"Can not support operator : {CompareOperator}");
}
return false;
}
}
}
#endif

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 91546dbdc522a3f408bf85882ef9d1a2
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,19 @@
#if UNITY_2019_4_OR_NEWER
namespace YooAsset.Editor
{
/// <summary>
/// 搜索关键字
/// </summary>
public class SearchKeyword : ISearchCommand
{
public string SearchTag;
public string Keyword;
public bool CompareTo(string value)
{
return value.Contains(Keyword);
}
}
}
#endif

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 7fb8c1af236290449af442e0ab746ffa
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: