19 changed files with 256 additions and 17 deletions
@ -0,0 +1,20 @@ |
|||||||
|
using System.Reflection; |
||||||
|
|
||||||
|
namespace Tools.Editor |
||||||
|
{ |
||||||
|
public static class UnityEditorUtil |
||||||
|
{ |
||||||
|
static MethodInfo clearMethod; |
||||||
|
|
||||||
|
public static void ClearConsole() |
||||||
|
{ |
||||||
|
if (clearMethod == null) |
||||||
|
{ |
||||||
|
Assembly assembly = Assembly.GetAssembly(typeof(UnityEditor.Editor)); |
||||||
|
System.Type logEntries = assembly.GetType("UnityEditor.LogEntries"); |
||||||
|
clearMethod = logEntries.GetMethod("Clear"); |
||||||
|
} |
||||||
|
clearMethod.Invoke(new object(), null); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,3 @@ |
|||||||
|
fileFormatVersion: 2 |
||||||
|
guid: b4f042c2bcf24f2494edc41df37ff88f |
||||||
|
timeCreated: 1737803701 |
@ -0,0 +1,66 @@ |
|||||||
|
using System; |
||||||
|
using System.Collections; |
||||||
|
using System.Collections.Generic; |
||||||
|
|
||||||
|
namespace Tools.ExcelResolver.Editor |
||||||
|
{ |
||||||
|
internal class TDict : TType |
||||||
|
{ |
||||||
|
internal override Type RealType => typeof(Dictionary<,>).MakeGenericType(KeyType?.RealType ?? typeof(object), ValueType?.RealType ?? typeof(object)); |
||||||
|
internal override string FieldWriteFormat => $"Dictionary<{KeyType?.RealType.Name ?? "object"}, {ValueType?.RealType.Name ?? "object"}>"; |
||||||
|
internal override object DefaultValue => Activator.CreateInstance(typeof(Dictionary<,>).MakeGenericType(KeyType?.RealType ?? typeof(object), ValueType?.RealType ?? typeof(object))); |
||||||
|
|
||||||
|
// 键和值的类型 |
||||||
|
internal TType KeyType { get; set; } |
||||||
|
internal TType ValueType { get; set; } |
||||||
|
|
||||||
|
internal override bool String2TType(string typeText) |
||||||
|
{ |
||||||
|
var split = typeText.Split(',', StringSplitOptions.RemoveEmptyEntries); |
||||||
|
if (split.Length != 3 || !string.Equals(split[0], "dict", StringComparison.OrdinalIgnoreCase)) |
||||||
|
{ |
||||||
|
return false; |
||||||
|
} |
||||||
|
|
||||||
|
// 解析键和值的类型 |
||||||
|
KeyType = ExcelResolverUtil.GetTTypeByString(split[1]); |
||||||
|
ValueType = ExcelResolverUtil.GetTTypeByString(split[2]); |
||||||
|
|
||||||
|
return KeyType != null && ValueType != null; |
||||||
|
} |
||||||
|
|
||||||
|
internal override object TryParseFrom(string cellText) |
||||||
|
{ |
||||||
|
if (KeyType == null || ValueType == null) |
||||||
|
{ |
||||||
|
return null; // 如果未指定键和值类型,无法解析 |
||||||
|
} |
||||||
|
|
||||||
|
var dict = (IDictionary)Activator.CreateInstance(typeof(Dictionary<,>).MakeGenericType(KeyType.RealType, ValueType.RealType)); |
||||||
|
var entries = cellText.Split('|'); // 假定每个键值对用 "|" 分隔 |
||||||
|
|
||||||
|
foreach (var entry in entries) |
||||||
|
{ |
||||||
|
var keyValue = entry.Split(':'); // 假定键和值用 ":" 分隔 |
||||||
|
if (keyValue.Length != 2) |
||||||
|
{ |
||||||
|
return null; // 任意键值对格式不正确时,返回 null |
||||||
|
} |
||||||
|
|
||||||
|
var key = KeyType.TryParseFrom(keyValue[0]); |
||||||
|
var value = ValueType.TryParseFrom(keyValue[1]); |
||||||
|
|
||||||
|
if (key != null && value != null) |
||||||
|
{ |
||||||
|
dict.Add(key, value); |
||||||
|
} |
||||||
|
else |
||||||
|
{ |
||||||
|
return null; // 键或值解析失败时,返回 null |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
return dict; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,3 @@ |
|||||||
|
fileFormatVersion: 2 |
||||||
|
guid: ee795236344b4595bafcdb6222b93798 |
||||||
|
timeCreated: 1737802386 |
@ -1,6 +1,6 @@ |
|||||||
namespace Tools.ExcelResolver |
namespace Tools.ExcelResolver |
||||||
{ |
{ |
||||||
public interface IExcelData |
public interface IExcelSOData |
||||||
{ |
{ |
||||||
|
|
||||||
} |
} |
@ -1,6 +1,6 @@ |
|||||||
namespace Tools.ExcelResolver |
namespace Tools.ExcelResolver |
||||||
{ |
{ |
||||||
public interface IExcelSO |
public interface IExcelSOUtil |
||||||
{ |
{ |
||||||
|
|
||||||
} |
} |
Binary file not shown.
Loading…
Reference in new issue