com.alicizax.unity.framework/Runtime/ABase/Event/EventRuntimeHandle.cs
2025-12-24 14:34:26 +08:00

44 lines
1.3 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using Unity.IL2CPP.CompilerServices;
namespace AlicizaX
{
[AttributeUsage(AttributeTargets.Struct)]
public sealed class PrewarmAttribute : Attribute
{
public int Capacity { get; }
public PrewarmAttribute(int capacity) => Capacity = capacity;
}
[Il2CppSetOption(Option.NullChecks, false)]
[Il2CppSetOption(Option.DivideByZeroChecks, false)]
[Il2CppSetOption(Option.ArrayBoundsChecks, false)]
[StructLayout(LayoutKind.Sequential)]
public readonly struct EventRuntimeHandle : IDisposable
{
private readonly long _data; // 高32位=index, 低32位=version
private readonly int _typeId; // 类型ID避免泛型委托
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal EventRuntimeHandle(int typeId, int index, int version)
{
_typeId = typeId;
_data = ((long)index << 32) | (uint)version;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Dispose()
{
if (_typeId != 0)
{
int index = (int)(_data >> 32);
int version = (int)_data;
UnsubscribeRegistry.Invoke(_typeId, index, version);
}
}
}
}