Skip to content

Component

jiepengtan edited this page Nov 20, 2019 · 4 revisions
  • 需要在文件 __DllSourceFiles/Tools.UnsafeECS.ECDefine/Src/Unsafe/Component.cs 中进行定义
  1. Component 中可以使用的类型
   bool
   float  //注意不支持double 
   byte
   sbyte
   short
   ushort
   int
   uint
   long
   ulong
   Vector2 
   Vector3 
   Quaternion 
   Vector2Int 
   Vctor3Int
   EntityRef
   Entity 
  1. 同时需要继承自 IGameComponent
    public partial class AssetData : IGameComponent {
        public int AssetId;
    }
  1. 可以使用继承
     public partial class TestCompBase1 : IGameComponent {
        public int Count;
    }
    public partial class TestCompChild2 : TestCompBase1 {
        public float Radius;
    }
  • 生成的代码的主体可以在 __DllSourceFiles/Game.Model/Src/__UnsafeECS/Generated/CodeGen_Component.cs 看到
  • 其他细碎的代码在其他文件中可能掺杂
   [StructLayoutAttribute(LayoutKind.Sequential)]
    [System.Serializable]
    public unsafe partial struct TestCompBase1 {
        public int Count; 
        public override Int32 GetHashCode() {
            unchecked {
                var hash = 7;
                hash = hash * 37 +Count.GetHashCode();  
                return hash;
            }
        }
    }
    [StructLayoutAttribute(LayoutKind.Sequential)]
    [System.Serializable]
    public unsafe partial struct TestCompChild2 {
        public LFloat Radius;
        public int Count; 
        public override Int32 GetHashCode() {
            unchecked {
                var hash = 7;
                hash = hash * 37 +Radius.GetHashCode();
                hash = hash * 37 +Count.GetHashCode();  
                return hash;
            }
        }
    }

Clone this wiki locally