< Summary

Information
Class: Lattice.ECS.Core.GenerateComponentAttribute
Assembly: Lattice
File(s): /home/runner/work/Sideline/Sideline/godot/scripts/lattice/ECS/Core/GenerateComponentAttribute.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 6
Coverable lines: 6
Total lines: 72
Line coverage: 0%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
get_Flags()100%210%
get_GenerateOnAdded()100%210%
get_GenerateOnRemoved()100%210%
get_CustomSerializer()100%210%
.ctor()100%210%

File(s)

/home/runner/work/Sideline/Sideline/godot/scripts/lattice/ECS/Core/GenerateComponentAttribute.cs

#LineLine coverage
 1// Copyright (c) 2026 Sideline Authors. All rights reserved.
 2// Licensed under GPL-3.0.
 3
 4using System;
 5
 6namespace 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>
 027        public ComponentFlags Flags { get; set; } = ComponentFlags.None;
 28
 29        /// <summary>是否生成 OnAdded 回调</summary>
 030        public bool GenerateOnAdded { get; set; } = false;
 31
 32        /// <summary>是否生成 OnRemoved 回调</summary>
 033        public bool GenerateOnRemoved { get; set; } = false;
 34
 35        /// <summary>自定义序列化逻辑(如果为空则自动生成)</summary>
 036        public string? CustomSerializer { get; set; } = null;
 37
 038        public GenerateComponentAttribute()
 39        {
 040        }
 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}