70 lines
2.3 KiB
C#
70 lines
2.3 KiB
C#
//------------------------------------------------------------
|
|
// Game Framework
|
|
// Copyright © 2013-2021 Jiang Yin. All rights reserved.
|
|
// Homepage: https://gameframework.cn/
|
|
// Feedback: mailto:ellan@gameframework.cn
|
|
//------------------------------------------------------------
|
|
|
|
using GameFramework.DataTable;
|
|
using System;
|
|
using CustomUtility;
|
|
using DataTable;
|
|
using Entity;
|
|
using Entity.EntityData;
|
|
using UnityGameFramework.Runtime;
|
|
|
|
namespace StarForce
|
|
{
|
|
public static class EntityExtension
|
|
{
|
|
private static int s_SerialId = 0;
|
|
|
|
public static EntityBase GetGameEntity(this EntityComponent entityComponent, int entityId)
|
|
{
|
|
UnityGameFramework.Runtime.Entity entity = entityComponent.GetEntity(entityId);
|
|
if (entity == null)
|
|
{
|
|
return null;
|
|
}
|
|
|
|
return (EntityBase)entity.Logic;
|
|
}
|
|
|
|
public static void HideEntity(this EntityComponent entityComponent, EntityBase entity)
|
|
{
|
|
entityComponent.HideEntity(entity.Entity);
|
|
}
|
|
|
|
public static void AttachEntity(this EntityComponent entityComponent, EntityBase entityBase, int ownerId,
|
|
string parentTransformPath = null, object userData = null)
|
|
{
|
|
entityComponent.AttachEntity(entityBase.Entity, ownerId, parentTransformPath, userData);
|
|
}
|
|
|
|
private static void ShowEntity(this EntityComponent entityComponent, Type logicType, string entityGroup,
|
|
int priority, EntityDataBase data)
|
|
{
|
|
if (data == null)
|
|
{
|
|
Log.Warning("Data is invalid.");
|
|
return;
|
|
}
|
|
|
|
IDataTable<DREntity> dtEntity = GameEntry.DataTable.GetDataTable<DREntity>();
|
|
DREntity drEntity = dtEntity.GetDataRow(data.TypeId);
|
|
if (drEntity == null)
|
|
{
|
|
Log.Warning("Can not load entity id '{0}' from data table.", data.TypeId.ToString());
|
|
return;
|
|
}
|
|
|
|
entityComponent.ShowEntity(data.Id, logicType, AssetUtility.GetEntityAsset(drEntity.AssetName), entityGroup,
|
|
priority, data);
|
|
}
|
|
|
|
public static int GenerateSerialId(this EntityComponent entityComponent)
|
|
{
|
|
return --s_SerialId;
|
|
}
|
|
}
|
|
} |