Update EcsTypeCodeManager.cs

This commit is contained in:
DCFApixels 2025-03-21 19:52:34 +08:00
parent a580adffa2
commit aeb0977d74

View File

@ -12,46 +12,6 @@ using Unity.IL2CPP.CompilerServices;
namespace DCFApixels.DragonECS.Internal namespace DCFApixels.DragonECS.Internal
{ {
#if ENABLE_IL2CPP
[Il2CppSetOption(Option.NullChecks, false)]
[Il2CppSetOption(Option.ArrayBoundsChecks, false)]
#endif
[DebuggerDisplay("{" + nameof(GetDebuggerDisplay) + "(),nq}")]
internal readonly struct EcsTypeCodeKey : IEquatable<EcsTypeCodeKey>
{
public readonly Type Type;
public readonly string NameKey;
public EcsTypeCodeKey(Type type, string nameKey)
{
Type = type;
NameKey = nameKey;
}
public bool Equals(EcsTypeCodeKey other)
{
return Type == other.Type && NameKey == other.NameKey;
}
public override bool Equals(object obj)
{
return obj is EcsTypeCodeKey other && Equals(other);
}
public override int GetHashCode()
{
return HashCode.Combine(Type, NameKey);
}
public override string ToString()
{
if (string.IsNullOrEmpty(NameKey))
{
return Type.ToString();
}
return $"{Type} {NameKey}";
}
public static implicit operator EcsTypeCodeKey(Type type) { return new EcsTypeCodeKey(type, string.Empty); }
private string GetDebuggerDisplay()
{
return ToString();
}
}
//TODO разработать возможность ручного устанавливания ID типам. //TODO разработать возможность ручного устанавливания ID типам.
//это может быть полезно как детерминированность для сети //это может быть полезно как детерминированность для сети
#if ENABLE_IL2CPP #if ENABLE_IL2CPP
@ -83,7 +43,6 @@ namespace DCFApixels.DragonECS.Internal
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
public static EcsTypeCode Get<T>() { return EcsTypeCodeCache<T>.code; } public static EcsTypeCode Get<T>() { return EcsTypeCodeCache<T>.code; }
public static bool Has(Type type) { return _codes.ContainsKey(type); } public static bool Has(Type type) { return _codes.ContainsKey(type); }
public static bool Has<T>() { return _codes.ContainsKey(typeof(T)); }
public static EcsTypeCodeKey FindTypeOfCode(EcsTypeCode typeCode) public static EcsTypeCodeKey FindTypeOfCode(EcsTypeCode typeCode)
{ {
foreach (var item in _codes) foreach (var item in _codes)
@ -123,4 +82,40 @@ namespace DCFApixels.DragonECS.Internal
return this.AutoToString(false); return this.AutoToString(false);
} }
} }
#if ENABLE_IL2CPP
[Il2CppSetOption(Option.NullChecks, false)]
[Il2CppSetOption(Option.ArrayBoundsChecks, false)]
#endif
[DebuggerDisplay("{" + nameof(ToString) + "()}")]
internal readonly struct EcsTypeCodeKey : IEquatable<EcsTypeCodeKey>
{
public readonly Type Type;
public readonly string NameKey;
public EcsTypeCodeKey(Type type, string nameKey)
{
Type = type;
NameKey = nameKey;
}
public bool Equals(EcsTypeCodeKey other)
{
return Type == other.Type && NameKey == other.NameKey;
}
public override bool Equals(object obj)
{
return obj is EcsTypeCodeKey other && Equals(other);
}
public override int GetHashCode()
{
return HashCode.Combine(Type, NameKey);
}
public override string ToString()
{
if (string.IsNullOrEmpty(NameKey))
{
return Type.ToString();
}
return $"{Type} {NameKey}";
}
public static implicit operator EcsTypeCodeKey(Type type) { return new EcsTypeCodeKey(type, string.Empty); }
}
} }