diff --git a/Assets/TEngine/Scripts/Runtime/Entity/Core/Entity/EntityExtension.cs b/Assets/TEngine/Scripts/Runtime/Entity/Core/Entity/EntityExtension.cs index 50e6a1d3..d756ee2d 100644 --- a/Assets/TEngine/Scripts/Runtime/Entity/Core/Entity/EntityExtension.cs +++ b/Assets/TEngine/Scripts/Runtime/Entity/Core/Entity/EntityExtension.cs @@ -5,7 +5,7 @@ private static int _serialId = 0; /// - /// 生成客户端序列化ID,服务器默认不用 + /// 生成客户端序列化ID/EntityID,服务器默认不用 /// /// /// @@ -14,14 +14,71 @@ return ++_serialId; } - public static void ShowEntity(this EntityComponent entityComponent, int serialId, int entityId, + /// + /// 创建实体 + /// + /// EntityComponent + /// 实体资源路径 + /// EntityData实体数据 + /// 实体实例对象池自动释放可释放对象的间隔秒数 + /// 实体实例对象池容量 + /// 实体实例对象池对象过期秒数 + /// 实体实例对象池的优先级 + /// 实体类型 + public static void CreateEntity(this EntityComponent entityComponent, string assetPath, + EntityData userData = null, float autoReleaseInterval = 60f, + int capacity = 60, float expireTime = 60f, int priority = 0) + { + if (userData == null) + { + userData = EntityData.Create(); + } + + entityComponent.CreateEntity(typeof(T), assetPath, userData, autoReleaseInterval, capacity, expireTime, + priority); + } + + /// + /// 创建实体 + /// + /// + /// + /// + /// + /// + /// + /// + /// + public static void CreateEntity(this EntityComponent entityComponent, System.Type logicType, string assetPath, + object userData = null, float autoReleaseInterval = 60f, + int capacity = 60, + float expireTime = 60f, int priority = 0) + { + var entityId = entityComponent.GenerateSerialId(); + entityComponent.CreateEntity(entityId, logicType, assetPath, userData, autoReleaseInterval, capacity, + expireTime, priority); + } + + /// + /// 创建实体 + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + public static void CreateEntity(this EntityComponent entityComponent, int entityId, System.Type logicType, string assetPath, object userData = null, float autoReleaseInterval = 60f, int capacity = 60, float expireTime = 60f, int priority = 0) { - if (serialId < 0) + if (entityId < 0) { - Log.Error("Can not load entity id '{0}' from data table.", entityId.ToString()); + Log.Error("Can not load entity id '{0}'.", entityId.ToString()); return; } @@ -32,7 +89,7 @@ expireTime, priority); } - entityComponent.ShowEntity(serialId, logicType, assetPath, logicType.Name, + entityComponent.ShowEntity(entityId, logicType, assetPath, logicType.Name, Constant.DefaultPriority, userData); } }