迁移数据表到 Luban,移除 JsonNet、EnumUtility

This commit is contained in:
2026-09-13 14:08:14 +08:00
parent 4003b3aaba
commit de53890de6
607 changed files with 18515 additions and 3257 deletions
@@ -1,64 +0,0 @@
using System;
using Cysharp.Threading.Tasks;
using GameFramework;
using GameFramework.DataTable;
using SepCore.DataTable;
using UnityGameFramework.Runtime;
namespace SepCore.AsyncTask
{
/// <summary>
/// DataTable 异步扩展方法
/// </summary>
public static class DataTableAsyncExtension
{
/// <summary>
/// 异步加载数据表
/// </summary>
/// <param name="dataTableComponent">数据表组件</param>
/// <param name="dataTableAssetName">数据表资源名称</param>
/// <param name="userData">用户自定义数据</param>
/// <param name="timeout">超时时间(秒),0表示不超时</param>
/// <returns>加载成功事件</returns>
public static UniTask<LoadDataTableSuccessEventArgs> LoadDataTableAsync(this DataTableComponent dataTableComponent,
string dataTableAssetName,
object userData = null,
float timeout = 30f)
{
UniTask<LoadDataTableSuccessEventArgs> waitTask = AsyncTaskHelper.WaitSuccessOrFailureAsync<LoadDataTableSuccessEventArgs, LoadDataTableFailureEventArgs>(
LoadDataTableSuccessEventArgs.EventId,
LoadDataTableFailureEventArgs.EventId,
successArgs => successArgs.DataTableAssetName == dataTableAssetName && ReferenceEquals(successArgs.UserData, userData),
failureArgs => failureArgs.DataTableAssetName == dataTableAssetName && ReferenceEquals(failureArgs.UserData, userData),
timeout
);
string dataTableName = System.IO.Path.GetFileNameWithoutExtension(dataTableAssetName);
dataTableComponent.LoadDataTable(dataTableName, dataTableAssetName, userData);
return waitTask;
}
/// <summary>
/// 异步加载数据表(泛型版本)
/// </summary>
/// <typeparam name="T">数据行类型</typeparam>
/// <param name="dataTableComponent">数据表组件</param>
/// <param name="dataTableAssetName">数据表资源名称</param>
/// <param name="userData">用户自定义数据</param>
/// <param name="timeout">超时时间(秒),0表示不超时</param>
/// <returns>加载的数据表</returns>
public static UniTask<IDataTable<T>> LoadDataTableAsync<T>(this DataTableComponent dataTableComponent,
string dataTableAssetName,
object userData = null,
float timeout = 30f) where T : IDataRow
{
return LoadDataTableAsync(dataTableComponent, dataTableAssetName, userData, timeout)
.ContinueWith(successArgs =>
{
// 获取数据表名称(去掉路径和扩展名)
string dataTableName = System.IO.Path.GetFileNameWithoutExtension(dataTableAssetName);
return dataTableComponent.GetDataTable<T>(dataTableName);
});
}
}
}
@@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: fd425f3318ddacb44a9c9468dcd434bf
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -3,7 +3,6 @@ using System.Collections.Generic;
using System.Threading;
using Cysharp.Threading.Tasks;
using SepCore.CustomUtility;
using SepCore.DataTable;
using SepCore.Definition;
using SepCore.Entity;
using SepCore.Entity.Weapon;
@@ -22,7 +21,6 @@ namespace SepCore.AsyncTask
private const string EntityNamespace = "SepCore.Entity.";
private static readonly Dictionary<string, Type> _typeDict = new();
private static readonly Dictionary<int, string> _assetNameDict = new();
/// <summary>
/// 异步显示实体
@@ -171,15 +169,16 @@ namespace SepCore.AsyncTask
}
Type enemyType = TryGetType(data.EnemyType.ToString());
string assetName = TryGetAssetName(data.EntityTypeId);
if (enemyType == null || string.IsNullOrEmpty(assetName))
EntityConfig entityConfig = GameEntry.Luban.Get<EntityConfig>(data.AssetName);
if (enemyType == null || entityConfig == null)
{
Log.Warning("Can not load enemy logic type or entity config for assetName '{0}'.", data.AssetName);
return UniTask.FromResult<EnemyBase>(null);
}
return entityComponent
.ShowEntityAsync(data.Id, enemyType, AssetUtility.GetEntityAsset(assetName), "Enemy",
Constant.AssetPriority.BulletAsset, data, timeout, cancellationToken)
.ShowEntityAsync(data.Id, enemyType, AssetUtility.GetEntityAsset(entityConfig.PrefabPath), "Enemy",
Constant.AssetPriority.EnemyAsset, data, timeout, cancellationToken)
.ContinueWith(entity => entity?.Logic as EnemyBase);
}
@@ -198,15 +197,16 @@ namespace SepCore.AsyncTask
}
Type weaponType = TryGetType("Weapon." + data.WeaponType);
string assetName = TryGetAssetName(data.EntityTypeId);
if (weaponType == null || string.IsNullOrEmpty(assetName))
EntityConfig entityConfig = GameEntry.Luban.Get<EntityConfig>(data.AssetName);
if (weaponType == null || entityConfig == null)
{
Log.Warning("Can not load weapon logic type or entity config for assetName '{0}'.", data.AssetName);
return UniTask.FromResult<WeaponBase>(null);
}
return entityComponent
.ShowEntityAsync(data.Id, weaponType, AssetUtility.GetEntityAsset(assetName), "Weapon",
Constant.AssetPriority.BulletAsset, data, timeout, cancellationToken)
.ShowEntityAsync(data.Id, weaponType, AssetUtility.GetEntityAsset(entityConfig.PrefabPath), "Weapon",
Constant.AssetPriority.WeaponAsset, data, timeout, cancellationToken)
.ContinueWith(entity => entity?.Logic as WeaponBase);
}
@@ -304,14 +304,14 @@ namespace SepCore.AsyncTask
return UniTask.FromResult<T>(null);
}
DREntity drEntity = GameEntry.DataTable.GetDataTableRow<DREntity>(data.TypeId);
if (drEntity == null)
EntityConfig entityConfig = GameEntry.Luban.Get<EntityConfig>(data.AssetName);
if (entityConfig == null)
{
Log.Warning("Can not load entity id '{0}' from data table.", data.TypeId.ToString());
Log.Warning("Can not load entity assetName '{0}' from data table.", data.AssetName);
return UniTask.FromResult<T>(null);
}
return entityComponent.ShowEntityAsync<T>(data.Id, AssetUtility.GetEntityAsset(drEntity.AssetName),
return entityComponent.ShowEntityAsync<T>(data.Id, AssetUtility.GetEntityAsset(entityConfig.PrefabPath),
entityGroupName, priority, data, timeout, cancellationToken);
}
@@ -332,23 +332,5 @@ namespace SepCore.AsyncTask
return type;
}
private static string TryGetAssetName(int entityId)
{
if (!_assetNameDict.TryGetValue(entityId, out string assetName))
{
DREntity drEntity = GameEntry.DataTable.GetDataTableRow<DREntity>(entityId);
if (drEntity == null)
{
Log.Warning("Can not load entity id '{0}' from data table.", entityId.ToString());
return null;
}
assetName = drEntity.AssetName;
_assetNameDict.Add(entityId, assetName);
}
return assetName;
}
}
}
@@ -1,9 +1,7 @@
using System;
using System;
using System.Collections.Generic;
using SepCore.Definition;
using SepCore.Entity;
using UnityGameFramework.Runtime;
using SepCore.DataTable;
using SepCore.CustomUtility;
namespace SepCore.Entity
@@ -11,15 +9,14 @@ namespace SepCore.Entity
public static class EntityExtension
{
private static int s_SerialId = -10;
private static int _serialId = 0;
private const string EntityNamespace = "SepCore.Entity.";
private static readonly Dictionary<string, Type> _typeDict;
private static readonly Dictionary<int, string> _assetNameDict;
static EntityExtension()
{
_typeDict = new Dictionary<string, Type>();
_assetNameDict = new Dictionary<int, string>();
}
public static EntityBase GetGameEntity(this EntityComponent entityComponent, int entityId)
@@ -44,6 +41,26 @@ namespace SepCore.Entity
entityComponent.AttachEntity(entityBase.Entity, ownerId, parentTransformPath, userData);
}
public static void ShowEntity<T>(this EntityComponent entityComponent, EntityDataBase data, string group,
int priority) where T : EntityBase
{
if (data == null)
{
Log.Warning("Data is invalid.");
return;
}
EntityConfig entityConfig = GameEntry.Luban.Get<EntityConfig>(data.AssetName);
if (entityConfig == null)
{
Log.Warning("Can not load entity assetName '{0}' from data table.", data.AssetName);
return;
}
entityComponent.ShowEntity(data.Id, typeof(T), AssetUtility.GetEntityAsset(entityConfig.PrefabPath), group,
priority, data);
}
public static void ShowPlayer(this EntityComponent entityComponent, PlayerData data)
{
entityComponent.ShowEntity(typeof(Player), "Player", Constant.AssetPriority.PlayerAsset, data);
@@ -58,15 +75,7 @@ namespace SepCore.Entity
}
var enemyType = TryGetType(data.EnemyType.ToString());
var assetName = TryGetAssetName(data.EntityTypeId);
entityComponent.ShowEntity(
entityId: data.Id,
entityLogicType: enemyType,
entityAssetName: AssetUtility.GetEntityAsset(assetName),
entityGroupName: "Enemy",
priority: Constant.AssetPriority.BulletAsset,
userData: data);
entityComponent.ShowEntity(enemyType, "Enemy", Constant.AssetPriority.EnemyAsset, data);
}
public static void ShowWeapon(this EntityComponent entityComponent, WeaponData data)
@@ -78,37 +87,9 @@ namespace SepCore.Entity
}
var weaponType = TryGetType("Weapon." + data.WeaponType);
var assetName = TryGetAssetName(data.EntityTypeId);
entityComponent.ShowEntity(
entityId: data.Id,
entityLogicType: weaponType,
entityAssetName: AssetUtility.GetEntityAsset(assetName),
entityGroupName: "Weapon",
priority: Constant.AssetPriority.BulletAsset,
userData: data);
entityComponent.ShowEntity(weaponType, "Weapon", Constant.AssetPriority.WeaponAsset, data);
}
// public static void ShowBullet(this EntityComponent entityComponent, BulletData data)
// {
// if (data == null)
// {
// Log.Warning("Bullet data is invalid.");
// return;
// }
//
// var bulletType = TryGetType(data.BulletType.ToString());
// string assetName = TryGetAssetName(data.EntityTypeId);
//
// entityComponent.ShowEntity(
// entityId: data.Id,
// entityLogicType: bulletType,
// entityAssetName: AssetUtility.GetEntityAsset(assetName),
// entityGroupName: "Bullet",
// priority: Constant.AssetPriority.BulletAsset,
// userData: data);
// }
public static void ShowEffect(this EntityComponent entityComponent, EffectData data)
{
entityComponent.ShowEntity(typeof(Effect), "Effect", Constant.AssetPriority.EffectAsset, data);
@@ -133,14 +114,14 @@ namespace SepCore.Entity
return;
}
DREntity drEntity = GameEntry.DataTable.GetDataTableRow<DREntity>(data.TypeId);
if (drEntity == null)
EntityConfig entityConfig = GameEntry.Luban.Get<EntityConfig>(data.AssetName);
if (entityConfig == null)
{
Log.Warning("Can not load entity id '{0}' from data table.", data.TypeId.ToString());
Log.Warning("Can not load entity assetName '{0}' from data table.", data.AssetName);
return;
}
entityComponent.ShowEntity(data.Id, logicType, AssetUtility.GetEntityAsset(drEntity.AssetName), entityGroup,
entityComponent.ShowEntity(data.Id, logicType, AssetUtility.GetEntityAsset(entityConfig.PrefabPath), entityGroup,
priority, data);
}
@@ -162,27 +143,14 @@ namespace SepCore.Entity
return type;
}
private static string TryGetAssetName(int entityId)
{
if (!_assetNameDict.TryGetValue(entityId, out string assetName))
{
DREntity drEntity = GameEntry.DataTable.GetDataTableRow<DREntity>(entityId);
if (drEntity == null)
{
Log.Warning("Can not load bullet entity id '{0}' from data table.", entityId.ToString());
return null;
}
assetName = drEntity.AssetName;
_assetNameDict.Add(entityId, assetName);
}
return assetName;
}
public static int NextId(this EntityComponent entityComponent)
{
return --s_SerialId;
}
public static int SerialId(this EntityComponent entityComponent)
{
return ++_serialId;
}
}
}
@@ -1,8 +1,6 @@
using GameFramework;
using SepCore.DataTable;
using GameFramework;
using SepCore.Definition;
using SepCore.Entity;
using GameFramework.DataTable;
using GameFramework.Sound;
using UnityGameFramework.Runtime;
using SepCore.CustomUtility;
@@ -18,13 +16,7 @@ namespace SepCore.Sound
{
soundComponent.StopMusic();
IDataTable<DRMusic> dtMusic = GameEntry.DataTable.GetDataTable<DRMusic>();
DRMusic drMusic = dtMusic.GetDataRow(musicId);
if (drMusic == null)
{
Log.Warning("Can not load music '{0}' from data table.", musicId.ToString());
return null;
}
MusicConfig musicConfig = GameEntry.Luban.Get<MusicConfig>(musicId);
PlaySoundParams playSoundParams = PlaySoundParams.Create();
playSoundParams.Priority = 64;
@@ -32,7 +24,7 @@ namespace SepCore.Sound
playSoundParams.VolumeInSoundGroup = 1f;
playSoundParams.FadeInSeconds = FadeVolumeDuration;
playSoundParams.SpatialBlend = 0f;
s_MusicSerialId = soundComponent.PlaySound(AssetUtility.GetMusicAsset(drMusic.AssetName), "Music", Constant.AssetPriority.MusicAsset, playSoundParams, null, userData);
s_MusicSerialId = soundComponent.PlaySound(AssetUtility.GetMusicAsset(musicConfig.AssetName), "Music", Constant.AssetPriority.MusicAsset, playSoundParams, null, userData);
return s_MusicSerialId;
}
@@ -49,38 +41,26 @@ namespace SepCore.Sound
public static int? PlaySound(this SoundComponent soundComponent, int soundId, EntityBase bindingEntity = null, object userData = null)
{
IDataTable<DRSound> dtSound = GameEntry.DataTable.GetDataTable<DRSound>();
DRSound drSound = dtSound.GetDataRow(soundId);
if (drSound == null)
{
Log.Warning("Can not load sound '{0}' from data table.", soundId.ToString());
return null;
}
SoundConfig soundConfig = GameEntry.Luban.Get<SoundConfig>(soundId);
PlaySoundParams playSoundParams = PlaySoundParams.Create();
playSoundParams.Priority = drSound.Priority;
playSoundParams.Loop = drSound.Loop;
playSoundParams.VolumeInSoundGroup = drSound.Volume;
playSoundParams.SpatialBlend = drSound.SpatialBlend;
return soundComponent.PlaySound(AssetUtility.GetSoundAsset(drSound.AssetName), "Sound", Constant.AssetPriority.SoundAsset, playSoundParams, bindingEntity != null ? bindingEntity.Entity : null, userData);
playSoundParams.Priority = soundConfig.Priority;
playSoundParams.Loop = soundConfig.Loop;
playSoundParams.VolumeInSoundGroup = soundConfig.Volume;
playSoundParams.SpatialBlend = soundConfig.SpatialBlend;
return soundComponent.PlaySound(AssetUtility.GetSoundAsset(soundConfig.AssetName), "Sound", Constant.AssetPriority.SoundAsset, playSoundParams, bindingEntity != null ? bindingEntity.Entity : null, userData);
}
public static int? PlayUISound(this SoundComponent soundComponent, int uiSoundId, object userData = null)
{
IDataTable<DRUISound> dtUISound = GameEntry.DataTable.GetDataTable<DRUISound>();
DRUISound drUISound = dtUISound.GetDataRow(uiSoundId);
if (drUISound == null)
{
Log.Warning("Can not load UI sound '{0}' from data table.", uiSoundId.ToString());
return null;
}
UISoundConfig uiSoundConfig = GameEntry.Luban.Get<UISoundConfig>(uiSoundId);
PlaySoundParams playSoundParams = PlaySoundParams.Create();
playSoundParams.Priority = drUISound.Priority;
playSoundParams.Priority = uiSoundConfig.Priority;
playSoundParams.Loop = false;
playSoundParams.VolumeInSoundGroup = drUISound.Volume;
playSoundParams.VolumeInSoundGroup = uiSoundConfig.Volume;
playSoundParams.SpatialBlend = 0f;
return soundComponent.PlaySound(AssetUtility.GetUISoundAsset(drUISound.AssetName), "UISound", Constant.AssetPriority.UISoundAsset, playSoundParams, userData);
return soundComponent.PlaySound(AssetUtility.GetUISoundAsset(uiSoundConfig.AssetName), "UISound", Constant.AssetPriority.UISoundAsset, playSoundParams, userData);
}
public static bool IsMuted(this SoundComponent soundComponent, string soundGroupName)
@@ -1,6 +1,4 @@
using GameFramework.DataTable;
using GameFramework.UI;
using SepCore.DataTable;
using SepCore.Definition;
using SepCore.CustomUtility;
using UnityGameFramework.Runtime;
@@ -16,14 +14,8 @@ namespace SepCore.UI
public static bool HasUIForm(this UIComponent uiComponent, int uiFormId, string uiGroupName = null)
{
IDataTable<DRUIForm> dtUIForm = GameEntry.DataTable.GetDataTable<DRUIForm>();
DRUIForm drUIForm = dtUIForm.GetDataRow(uiFormId);
if (drUIForm == null)
{
return false;
}
string assetName = AssetUtility.GetUIFormAsset(drUIForm.AssetName);
UIFormConfig formConfig = GameEntry.Luban.Get<UIFormConfig>(uiFormId);
string assetName = AssetUtility.GetUIFormAsset(formConfig.AssetName);
if (string.IsNullOrEmpty(uiGroupName))
{
return uiComponent.HasUIForm(assetName);
@@ -45,14 +37,8 @@ namespace SepCore.UI
public static UGuiForm GetUIForm(this UIComponent uiComponent, int uiFormId, string uiGroupName = null)
{
IDataTable<DRUIForm> dtUIForm = GameEntry.DataTable.GetDataTable<DRUIForm>();
DRUIForm drUIForm = dtUIForm.GetDataRow(uiFormId);
if (drUIForm == null)
{
return null;
}
string assetName = AssetUtility.GetUIFormAsset(drUIForm.AssetName);
UIFormConfig formConfig = GameEntry.Luban.Get<UIFormConfig>(uiFormId);
string assetName = AssetUtility.GetUIFormAsset(formConfig.AssetName);
UIForm uiForm = null;
if (string.IsNullOrEmpty(uiGroupName))
{
@@ -92,16 +78,9 @@ namespace SepCore.UI
public static int? OpenUIForm(this UIComponent uiComponent, int uiFormId, object userData = null)
{
IDataTable<DRUIForm> dtUIForm = GameEntry.DataTable.GetDataTable<DRUIForm>();
DRUIForm drUIForm = dtUIForm.GetDataRow(uiFormId);
if (drUIForm == null)
{
Log.Warning("Can not load UI form '{0}' from data table.", uiFormId.ToString());
return null;
}
string assetName = AssetUtility.GetUIFormAsset(drUIForm.AssetName);
if (!drUIForm.AllowMultiInstance)
UIFormConfig formConfig = GameEntry.Luban.Get<UIFormConfig>(uiFormId);
string assetName = AssetUtility.GetUIFormAsset(formConfig.AssetName);
if (!formConfig.AllowMultiInstance)
{
if (uiComponent.IsLoadingUIForm(assetName))
{
@@ -114,8 +93,8 @@ namespace SepCore.UI
}
}
return uiComponent.OpenUIForm(assetName, drUIForm.UIGroupName, Constant.AssetPriority.UIFormAsset,
drUIForm.PauseCoveredUIForm, userData);
return uiComponent.OpenUIForm(assetName, formConfig.UIGroupName, Constant.AssetPriority.UIFormAsset,
formConfig.PauseCoveredUIForm, userData);
}
}
}