调整服务器逻辑

1、调整Entity.AddComponent方法添加的组件Id为父组件的Id。
2、增加了ISupportedSingleCollection和ISingleCollectionRoot接口.
3、增加了SingleCollection、用于把子组件保存到单独的数据库表的功能,配合ISupportedSingleCollection和ISingleCollectionRoot。
This commit is contained in:
ALEXTANG
2023-07-24 16:49:23 +08:00
parent 846dc4d4bc
commit f8056aef32
11 changed files with 224 additions and 29 deletions

View File

@@ -321,7 +321,7 @@ namespace TEngine
public T AddComponent<T>() where T : Entity, new()
{
var entity = Create<T>(Scene.RouteId, false);
var entity = Create<T>(Id, Scene.RouteId, false);
AddComponent(entity);
EntitiesSystem.Instance.Awake(entity);
EntitiesSystem.Instance.StartUpdate(entity);
@@ -367,6 +367,12 @@ namespace TEngine
}
else
{
#if TENGINE_NET
if (component is ISupportedSingleCollection && component.Id != Id)
{
Log.Error($"component type :{component.GetType().FullName} for implementing ISupportedSingleCollection, it is required that the Id must be the same as the parent");
}
#endif
if (_tree == null)
{
_tree = DictionaryPool<Type, Entity>.Create();
@@ -404,6 +410,8 @@ namespace TEngine
#endregion
#region GetComponent
public DictionaryPool<Type, Entity> GetTree => _tree;
public T GetComponent<T>() where T : Entity, new()
{

View File

@@ -0,0 +1,8 @@
#if TENGINE_NET
namespace TEngine;
/// <summary>
/// Entity保存到数据库的时候会根据子组件设置分离存储特性分表存储在不同的集合表中
/// </summary>
public interface ISingleCollectionRoot { }
#endif

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 3dfa22a9da7a76b41bf6511e45b22b53
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,23 @@
#if TENGINE_NET
namespace TEngine;
/// <summary>
/// Entity是单一集合、保存到数据库的时候不会跟随父组件保存在一个集合里、会单独保存在一个集合里
/// 需要配合SingleCollectionAttribute一起使用、如在Entity类头部定义SingleCollectionAttribute(typeOf(Unit))
/// SingleCollectionAttribute用来定义这个Entity是属于哪个Entity的子集
/// </summary>
public interface ISupportedSingleCollection { }
[AttributeUsage(AttributeTargets.Class, Inherited = true, AllowMultiple = false)]
public class SingleCollectionAttribute : Attribute
{
public readonly Type RootType;
public readonly string CollectionName;
public SingleCollectionAttribute(Type rootType, string collectionName)
{
RootType = rootType;
CollectionName = collectionName;
}
}
#endif

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: d9654cddb77221d4eaa991df735b12c2
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: