| | | 1 | | // Copyright (c) 2026 Sideline Authors. All rights reserved. |
| | | 2 | | // Licensed under GPL-3.0. |
| | | 3 | | |
| | | 4 | | using System; |
| | | 5 | | |
| | | 6 | | namespace Lattice.ECS.Core |
| | | 7 | | { |
| | | 8 | | /// <summary> |
| | | 9 | | /// 自动生成组件序列化代码的特性 |
| | | 10 | | /// |
| | | 11 | | /// 使用示例: |
| | | 12 | | /// [GenerateComponent] |
| | | 13 | | /// public struct Position : IComponent { |
| | | 14 | | /// public FP X; |
| | | 15 | | /// public FP Y; |
| | | 16 | | /// } |
| | | 17 | | /// |
| | | 18 | | /// Source Generator 会自动生成: |
| | | 19 | | /// - Serialize 方法 |
| | | 20 | | /// - OnAdded/OnRemoved 委托(可选) |
| | | 21 | | /// - 注册代码 |
| | | 22 | | /// </summary> |
| | | 23 | | [AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] |
| | | 24 | | public sealed class GenerateComponentAttribute : Attribute |
| | | 25 | | { |
| | | 26 | | /// <summary>组件标志</summary> |
| | 0 | 27 | | public ComponentFlags Flags { get; set; } = ComponentFlags.None; |
| | | 28 | | |
| | | 29 | | /// <summary>是否生成 OnAdded 回调</summary> |
| | 0 | 30 | | public bool GenerateOnAdded { get; set; } = false; |
| | | 31 | | |
| | | 32 | | /// <summary>是否生成 OnRemoved 回调</summary> |
| | 0 | 33 | | public bool GenerateOnRemoved { get; set; } = false; |
| | | 34 | | |
| | | 35 | | /// <summary>自定义序列化逻辑(如果为空则自动生成)</summary> |
| | 0 | 36 | | public string? CustomSerializer { get; set; } = null; |
| | | 37 | | |
| | 0 | 38 | | public GenerateComponentAttribute() |
| | | 39 | | { |
| | 0 | 40 | | } |
| | | 41 | | } |
| | | 42 | | |
| | | 43 | | /// <summary> |
| | | 44 | | /// 标记字段不参与序列化 |
| | | 45 | | /// </summary> |
| | | 46 | | [AttributeUsage(AttributeTargets.Field, Inherited = false, AllowMultiple = false)] |
| | | 47 | | public sealed class DontSerializeAttribute : Attribute |
| | | 48 | | { |
| | | 49 | | } |
| | | 50 | | |
| | | 51 | | /// <summary> |
| | | 52 | | /// 标记字段使用变长编码 |
| | | 53 | | /// </summary> |
| | | 54 | | [AttributeUsage(AttributeTargets.Field, Inherited = false, AllowMultiple = false)] |
| | | 55 | | public sealed class VarIntAttribute : Attribute |
| | | 56 | | { |
| | | 57 | | } |
| | | 58 | | |
| | | 59 | | /// <summary> |
| | | 60 | | /// 标记字段使用指定比特数(用于小范围值) |
| | | 61 | | /// </summary> |
| | | 62 | | [AttributeUsage(AttributeTargets.Field, Inherited = false, AllowMultiple = false)] |
| | | 63 | | public sealed class BitFieldAttribute : Attribute |
| | | 64 | | { |
| | | 65 | | public int Bits { get; } |
| | | 66 | | |
| | | 67 | | public BitFieldAttribute(int bits) |
| | | 68 | | { |
| | | 69 | | Bits = bits; |
| | | 70 | | } |
| | | 71 | | } |
| | | 72 | | } |