迁移数据表到 Luban,移除 JsonNet、EnumUtility
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using SepCore.BuiltinData;
|
||||
using SepCore.BuiltinData;
|
||||
using SepCore.CustomComponent;
|
||||
using SepCore.DamageText;
|
||||
using SepCore.EnemyManager;
|
||||
using SepCore.HPBar;
|
||||
@@ -16,6 +17,8 @@ public partial class GameEntry
|
||||
{
|
||||
public static BuiltinDataComponent BuiltinData { get; private set; }
|
||||
|
||||
public static LubanComponent Luban { get; private set; }
|
||||
|
||||
public static HPBarComponent HPBar { get; private set; }
|
||||
|
||||
public static DamageTextComponent DamageText { get; private set; }
|
||||
@@ -37,6 +40,7 @@ public partial class GameEntry
|
||||
private static void InitCustomComponents()
|
||||
{
|
||||
BuiltinData = UnityGameFramework.Runtime.GameEntry.GetComponent<BuiltinDataComponent>();
|
||||
Luban = UnityGameFramework.Runtime.GameEntry.GetComponent<LubanComponent>();
|
||||
HPBar = UnityGameFramework.Runtime.GameEntry.GetComponent<HPBarComponent>();
|
||||
DamageText = UnityGameFramework.Runtime.GameEntry.GetComponent<DamageTextComponent>();
|
||||
EnemyManager = UnityGameFramework.Runtime.GameEntry.GetComponent<EnemyManagerComponent>();
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
+14
-32
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ namespace SepCore.Components
|
||||
private Collider[] _buffer;
|
||||
|
||||
private StatProperty _absorbRangeStat;
|
||||
private Action<StatModifier, bool> _absorbRangeStatCallback;
|
||||
private Action<modifier, bool> _absorbRangeStatCallback;
|
||||
|
||||
private float AbsorbRange => Mathf.Max(0f, (_absorbRangeBase + _absorbRangeStat.Value) * _absorbRangeStat.Percent);
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ namespace SepCore.Components
|
||||
public class BackpackComponent : MonoBehaviour
|
||||
{
|
||||
/// <summary>
|
||||
/// 武器槽容量,由DRRole决定。
|
||||
/// 武器槽容量,由 RoleConfig 决定。
|
||||
/// </summary>
|
||||
private int _weaponCapacity;
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using SepCore.Event;
|
||||
using SepCore.Definition;
|
||||
using UnityEngine;
|
||||
@@ -14,15 +14,15 @@ namespace SepCore.Components
|
||||
private StatComponent _statComponent;
|
||||
|
||||
private StatProperty _maxHealthStat;
|
||||
private Action<StatModifier, bool> _maxHealthStatCallback;
|
||||
private Action<modifier, bool> _maxHealthStatCallback;
|
||||
public StatProperty MaxHealthStat => _maxHealthStat;
|
||||
|
||||
private StatProperty _defenseStat;
|
||||
private Action<StatModifier, bool> _defenseStatCallback;
|
||||
private Action<modifier, bool> _defenseStatCallback;
|
||||
public StatProperty DefenseStat => _defenseStat;
|
||||
|
||||
private StatProperty _dodgeStat;
|
||||
private Action<StatModifier, bool> _dodgeStatCallback;
|
||||
private Action<modifier, bool> _dodgeStatCallback;
|
||||
public StatProperty DodgeStat => _dodgeStat;
|
||||
|
||||
private bool _isPlayer => _statComponent != null;
|
||||
|
||||
@@ -28,7 +28,7 @@ namespace SepCore.Components
|
||||
private StatComponent _statComponent;
|
||||
|
||||
private StatProperty _movementStat;
|
||||
private Action<StatModifier, bool> _movementStatCallback;
|
||||
private Action<modifier, bool> _movementStatCallback;
|
||||
|
||||
public void OnInit(float speed, Transform target, StatComponent statComponent = null,
|
||||
bool avoidEnemyOverlap = false, float enemyBodyRadius = 0.45f, int separationIterations = 2)
|
||||
|
||||
@@ -7,13 +7,13 @@ namespace SepCore.Components
|
||||
{
|
||||
public class StatComponent : MonoBehaviour
|
||||
{
|
||||
private Dictionary<StatType, List<StatModifier>> _statModifiers;
|
||||
private Dictionary<StatType, Action<StatModifier, bool>> _statModifierCallbacks;
|
||||
private Dictionary<StatType, List<modifier>> _statModifiers;
|
||||
private Dictionary<StatType, Action<modifier, bool>> _statModifierCallbacks;
|
||||
|
||||
public void OnInit()
|
||||
{
|
||||
_statModifiers = new Dictionary<StatType, List<StatModifier>>();
|
||||
_statModifierCallbacks = new Dictionary<StatType, Action<StatModifier, bool>>();
|
||||
_statModifiers = new Dictionary<StatType, List<modifier>>();
|
||||
_statModifierCallbacks = new Dictionary<StatType, Action<modifier, bool>>();
|
||||
}
|
||||
|
||||
public void OnReset()
|
||||
@@ -22,11 +22,11 @@ namespace SepCore.Components
|
||||
_statModifierCallbacks.Clear();
|
||||
}
|
||||
|
||||
public void AddModifier(StatModifier modifier)
|
||||
public void AddModifier(modifier modifier)
|
||||
{
|
||||
if (!_statModifiers.TryGetValue(modifier.StatType, out var modifiers))
|
||||
{
|
||||
_statModifiers.Add(modifier.StatType, modifiers = new List<StatModifier>());
|
||||
_statModifiers.Add(modifier.StatType, modifiers = new List<modifier>());
|
||||
modifiers.Add(modifier);
|
||||
}
|
||||
else
|
||||
@@ -38,7 +38,7 @@ namespace SepCore.Components
|
||||
callbacks?.Invoke(modifier, true);
|
||||
}
|
||||
|
||||
public void RemoveModifier(StatModifier modifier)
|
||||
public void RemoveModifier(modifier modifier)
|
||||
{
|
||||
if (_statModifiers.TryGetValue(modifier.StatType, out var modifiers))
|
||||
{
|
||||
@@ -49,7 +49,7 @@ namespace SepCore.Components
|
||||
callbacks?.Invoke(modifier, false);
|
||||
}
|
||||
|
||||
public void Subscribe(StatType statType, Action<StatModifier, bool> callback)
|
||||
public void Subscribe(StatType statType, Action<modifier, bool> callback)
|
||||
{
|
||||
if (!_statModifierCallbacks.TryAdd(statType, callback))
|
||||
{
|
||||
@@ -57,7 +57,7 @@ namespace SepCore.Components
|
||||
}
|
||||
}
|
||||
|
||||
public void Unsubscribe(StatType statType, Action<StatModifier, bool> callback)
|
||||
public void Unsubscribe(StatType statType, Action<modifier, bool> callback)
|
||||
{
|
||||
if (!_statModifierCallbacks.TryGetValue(statType, out var callbacks))
|
||||
{
|
||||
@@ -79,23 +79,23 @@ namespace SepCore.Components
|
||||
|
||||
foreach (var modifier in modifiers)
|
||||
{
|
||||
if (modifier.IsPercent) result.Percent += modifier.Value;
|
||||
else result.Value += modifier.Value;
|
||||
if (modifier.IsPercent) result.Percent += modifier.RealValue;
|
||||
else result.Value += modifier.RealValue;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public void UpdateStat(StatProperty stat, StatModifier modifier, bool isApply)
|
||||
public void UpdateStat(StatProperty stat, modifier modifier, bool isApply)
|
||||
{
|
||||
float coef = isApply ? 1f : -1f;
|
||||
if (modifier.IsPercent)
|
||||
{
|
||||
stat.Percent += modifier.Value * coef;
|
||||
stat.Percent += modifier.RealValue * coef;
|
||||
}
|
||||
else
|
||||
{
|
||||
stat.Value += modifier.Value * coef;
|
||||
stat.Value += modifier.RealValue * coef;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+1
-2
@@ -1,7 +1,6 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using SepCore.DataTable;
|
||||
using SepCore.Definition;
|
||||
using SepCore.Entity;
|
||||
using GameFramework.Event;
|
||||
@@ -70,7 +69,7 @@ namespace SepCore.EnemyManager
|
||||
_entity = null;
|
||||
}
|
||||
|
||||
public void OnInit(DRLevel level, Player player)
|
||||
public void OnInit(LevelConfig level, Player player)
|
||||
{
|
||||
_isStopped = false;
|
||||
|
||||
|
||||
+16
-7
@@ -1,5 +1,5 @@
|
||||
using System;
|
||||
using SepCore.DataTable;
|
||||
using SepCore.CustomUtility;
|
||||
using SepCore.Definition;
|
||||
using SepCore.Timer;
|
||||
using UnityEngine;
|
||||
@@ -22,18 +22,27 @@ namespace SepCore.EnemyManager
|
||||
public float ElapsedTime => _elapsedTime;
|
||||
public int WaveCount => _enemyTypes?.Length ?? 0;
|
||||
|
||||
public void Init(DRLevel level, Action<EnemyType, int> onSpawn)
|
||||
public void Init(LevelConfig level, Action<EnemyType, int> onSpawn)
|
||||
{
|
||||
GameEntry.Timer.CancelByOwner(this);
|
||||
|
||||
_onSpawn = onSpawn;
|
||||
_baseIntervals = (float[])level.Intervals.Clone();
|
||||
_enemyTypes = level.EntityTypes;
|
||||
_spawnCounts = level.EntityCounts;
|
||||
int count = level.EnemySpawnConfigs.Count;
|
||||
_baseIntervals = new float[count];
|
||||
_enemyTypes = new EnemyType[count];
|
||||
_spawnCounts = new int[count];
|
||||
_elapsedTime = 0f;
|
||||
|
||||
_waveHandles = new TimerHandle[_baseIntervals.Length];
|
||||
for (int i = 0; i < _baseIntervals.Length; i++)
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
var spawnConfig = level.EnemySpawnConfigs[i];
|
||||
_baseIntervals[i] = spawnConfig.Interval / 1000f;
|
||||
_enemyTypes[i] = EntityDataFactory.GetEnemyType(spawnConfig.EnemyName);
|
||||
_spawnCounts[i] = spawnConfig.EnemyCount;
|
||||
}
|
||||
|
||||
_waveHandles = new TimerHandle[count];
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
int waveIndex = i;
|
||||
float interval = GetScaledInterval(_baseIntervals[i], _spawnRateScale);
|
||||
|
||||
+2
-3
@@ -1,9 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 74fbdf043ed3bc141a0a0b09756bc7d2
|
||||
guid: d33e74ac49f622c43b614b17e23bc811
|
||||
folderAsset: yes
|
||||
timeCreated: 1528026153
|
||||
licenseType: Pro
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,329 @@
|
||||
using GameFramework.Resource;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Luban;
|
||||
using SepCore.Definition;
|
||||
using UnityEngine;
|
||||
using UnityGameFramework.Runtime;
|
||||
|
||||
namespace SepCore.CustomComponent
|
||||
{
|
||||
/// <summary>
|
||||
/// Luban 数据表组件。
|
||||
/// 生成的数据结构与枚举位于 Assets/GameMain/Scripts/Base/Gen。
|
||||
/// 负责加载 Luban 导出的二进制数据表(.bytes)并构建 SepCore.Definition.Tables。
|
||||
/// 注意:表名列表需与 SepCore.Definition.Tables 构造函数保持一致。
|
||||
/// </summary>
|
||||
public class LubanComponent : GameFrameworkComponent
|
||||
{
|
||||
private static readonly string[] TableNames = new string[]
|
||||
{
|
||||
"tbenemyconfig",
|
||||
"tbentityconfig",
|
||||
"tbglobalconfig",
|
||||
"tbgoodsconfig",
|
||||
"tblevelconfig",
|
||||
"tbleveldropconfig",
|
||||
"tblevelexperienceconfig",
|
||||
"tbleveluprewardconfig",
|
||||
"tbmusicconfig",
|
||||
"tbpropconfig",
|
||||
"tbroleconfig",
|
||||
"tbsceneconfig",
|
||||
"tbsoundconfig",
|
||||
"tbspriteconfig",
|
||||
"tbuiformconfig",
|
||||
"tbuisoundconfig",
|
||||
"tbweaponconfig"
|
||||
};
|
||||
|
||||
private sealed class TableAccessor
|
||||
{
|
||||
public Func<Tables, int, object> RowGetter;
|
||||
public Func<Tables, string, object> StringRowGetter;
|
||||
public Func<Tables, object> ListGetter;
|
||||
}
|
||||
|
||||
private static readonly Dictionary<Type, TableAccessor> TableAccessors =
|
||||
new()
|
||||
{
|
||||
{
|
||||
typeof(EnemyConfig),
|
||||
StringAccessor(tables => key => tables.TbEnemyConfig.GetOrDefault(key),
|
||||
tables => tables.TbEnemyConfig.DataList)
|
||||
},
|
||||
{
|
||||
typeof(EntityConfig),
|
||||
StringAccessor(tables => key => tables.TbEntityConfig.GetOrDefault(key),
|
||||
tables => tables.TbEntityConfig.DataList)
|
||||
},
|
||||
{
|
||||
typeof(GoodsConfig),
|
||||
Accessor(tables => id => tables.TbGoodsConfig.GetOrDefault(id),
|
||||
tables => tables.TbGoodsConfig.DataList)
|
||||
},
|
||||
{
|
||||
typeof(LevelConfig),
|
||||
Accessor(tables => id => tables.TbLevelConfig.GetOrDefault(id),
|
||||
tables => tables.TbLevelConfig.DataList)
|
||||
},
|
||||
{
|
||||
typeof(LevelDropConfig),
|
||||
Accessor(tables => id => tables.TbLevelDropConfig.GetOrDefault(id),
|
||||
tables => tables.TbLevelDropConfig.DataList)
|
||||
},
|
||||
{
|
||||
typeof(LevelExperienceConfig),
|
||||
StringAccessor(tables => key => tables.TbLevelExperienceConfig.GetOrDefault(key),
|
||||
tables => tables.TbLevelExperienceConfig.DataList)
|
||||
},
|
||||
{
|
||||
typeof(LevelUpRewardConfig),
|
||||
Accessor(tables => id => tables.TbLevelUpRewardConfig.GetOrDefault(id),
|
||||
tables => tables.TbLevelUpRewardConfig.DataList)
|
||||
},
|
||||
{
|
||||
typeof(MusicConfig),
|
||||
Accessor(tables => id => tables.TbMusicConfig.GetOrDefault(id),
|
||||
tables => tables.TbMusicConfig.DataList)
|
||||
},
|
||||
{
|
||||
typeof(PropConfig),
|
||||
Accessor(tables => id => tables.TbPropConfig.GetOrDefault(id),
|
||||
tables => tables.TbPropConfig.DataList)
|
||||
},
|
||||
{
|
||||
typeof(RoleConfig),
|
||||
StringAccessor(tables => key => tables.TbRoleConfig.GetOrDefault(key),
|
||||
tables => tables.TbRoleConfig.DataList)
|
||||
},
|
||||
{
|
||||
typeof(SceneConfig),
|
||||
Accessor(tables => id => tables.TbSceneConfig.GetOrDefault((SceneType)id),
|
||||
tables => tables.TbSceneConfig.DataList)
|
||||
},
|
||||
{
|
||||
typeof(SoundConfig),
|
||||
Accessor(tables => id => tables.TbSoundConfig.GetOrDefault(id),
|
||||
tables => tables.TbSoundConfig.DataList)
|
||||
},
|
||||
{
|
||||
typeof(SpriteConfig),
|
||||
StringAccessor(tables => key => tables.TbSpriteConfig.GetOrDefault(key),
|
||||
tables => tables.TbSpriteConfig.DataList)
|
||||
},
|
||||
{
|
||||
typeof(UIFormConfig),
|
||||
Accessor(tables => id => tables.TbUIFormConfig.GetOrDefault((UIFormType)id),
|
||||
tables => tables.TbUIFormConfig.DataList)
|
||||
},
|
||||
{
|
||||
typeof(UISoundConfig),
|
||||
Accessor(tables => id => tables.TbUISoundConfig.GetOrDefault(id),
|
||||
tables => tables.TbUISoundConfig.DataList)
|
||||
},
|
||||
{
|
||||
typeof(WeaponConfig),
|
||||
Accessor(tables => id => tables.TbWeaponConfig.GetOrDefault(id),
|
||||
tables => tables.TbWeaponConfig.DataList)
|
||||
},
|
||||
};
|
||||
|
||||
private static TableAccessor Accessor<TValue>(Func<Tables, Func<int, object>> rowGetterFactory,
|
||||
Func<Tables, List<TValue>> listGetter) where TValue : BeanBase
|
||||
{
|
||||
return new TableAccessor
|
||||
{
|
||||
RowGetter = (tables, id) => rowGetterFactory(tables)(id),
|
||||
ListGetter = tables => listGetter(tables)
|
||||
};
|
||||
}
|
||||
|
||||
private static TableAccessor StringAccessor<TValue>(Func<Tables, Func<string, object>> rowGetterFactory,
|
||||
Func<Tables, List<TValue>> listGetter) where TValue : BeanBase
|
||||
{
|
||||
return new TableAccessor
|
||||
{
|
||||
StringRowGetter = (tables, key) => rowGetterFactory(tables)(key),
|
||||
ListGetter = tables => listGetter(tables)
|
||||
};
|
||||
}
|
||||
|
||||
private Dictionary<string, byte[]> _tableBytes = null;
|
||||
private int _remainCount = 0;
|
||||
private Action _onLoadSuccess = null;
|
||||
private Action<string> _onLoadFailure = null;
|
||||
|
||||
/// <summary>
|
||||
/// 获取 Luban 数据表管理器,加载完成后可用。
|
||||
/// </summary>
|
||||
public Tables Tables { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取数据表是否已加载完成。
|
||||
/// </summary>
|
||||
public bool IsReady => Tables != null;
|
||||
|
||||
public TbGlobalConfig Global => Tables.TbGlobalConfig;
|
||||
|
||||
/// <summary>
|
||||
/// 按 id 获取数据行,未找到时返回 null。
|
||||
/// </summary>
|
||||
/// <typeparam name="T">数据行类型(对应生成的 xxxConfig 类)。</typeparam>
|
||||
/// <param name="id">数据行主键。</param>
|
||||
/// <returns>数据行,未找到时返回 null。</returns>
|
||||
public T Get<T>(int id) where T : class
|
||||
{
|
||||
if (Tables == null)
|
||||
{
|
||||
throw new InvalidOperationException("Luban data tables are not loaded yet.");
|
||||
}
|
||||
|
||||
TableAccessor accessor;
|
||||
if (!TableAccessors.TryGetValue(typeof(T), out accessor))
|
||||
{
|
||||
throw new NotSupportedException("No table getter is registered for type '" + typeof(T).FullName + "'.");
|
||||
}
|
||||
|
||||
if (accessor.RowGetter == null)
|
||||
{
|
||||
if (accessor.StringRowGetter != null)
|
||||
{
|
||||
return (T)accessor.StringRowGetter(Tables, id.ToString());
|
||||
}
|
||||
throw new NotSupportedException("Table for type '" + typeof(T).FullName + "' does not use an int key.");
|
||||
}
|
||||
|
||||
return (T)accessor.RowGetter(Tables, id);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 按字符串主键获取数据行,未找到时返回 null。
|
||||
/// </summary>
|
||||
/// <typeparam name="T">数据行类型(对应生成的 xxxConfig 类)。</typeparam>
|
||||
/// <param name="key">数据行字符串主键。</param>
|
||||
/// <returns>数据行,未找到时返回 null。</returns>
|
||||
public T Get<T>(string key) where T : class
|
||||
{
|
||||
if (Tables == null)
|
||||
{
|
||||
throw new InvalidOperationException("Luban data tables are not loaded yet.");
|
||||
}
|
||||
|
||||
TableAccessor accessor;
|
||||
if (!TableAccessors.TryGetValue(typeof(T), out accessor))
|
||||
{
|
||||
throw new NotSupportedException("No table getter is registered for type '" + typeof(T).FullName + "'.");
|
||||
}
|
||||
|
||||
if (accessor.StringRowGetter == null)
|
||||
{
|
||||
if (int.TryParse(key, out int parsedId) && accessor.RowGetter != null)
|
||||
{
|
||||
return (T)accessor.RowGetter(Tables, parsedId);
|
||||
}
|
||||
throw new NotSupportedException("Table for type '" + typeof(T).FullName + "' does not use a string key.");
|
||||
}
|
||||
|
||||
return (T)accessor.StringRowGetter(Tables, key);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取整个表的所有数据行。
|
||||
/// </summary>
|
||||
/// <typeparam name="T">数据行类型(对应生成的 xxxConfig 类)。</typeparam>
|
||||
/// <returns>表内全部数据行,可安全遍历。</returns>
|
||||
public IReadOnlyList<T> GetTable<T>() where T : class
|
||||
{
|
||||
if (Tables == null)
|
||||
{
|
||||
throw new InvalidOperationException("Luban data tables are not loaded yet.");
|
||||
}
|
||||
|
||||
TableAccessor accessor;
|
||||
if (!TableAccessors.TryGetValue(typeof(T), out accessor))
|
||||
{
|
||||
throw new NotSupportedException("No table getter is registered for type '" + typeof(T).FullName + "'.");
|
||||
}
|
||||
|
||||
return (IReadOnlyList<T>)accessor.ListGetter(Tables);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 异步加载所有数据表。
|
||||
/// </summary>
|
||||
/// <param name="onSuccess">加载成功回调。</param>
|
||||
/// <param name="onFailure">加载失败回调,参数为错误信息。</param>
|
||||
public void LoadTables(Action onSuccess, Action<string> onFailure)
|
||||
{
|
||||
if (IsReady)
|
||||
{
|
||||
onSuccess?.Invoke();
|
||||
return;
|
||||
}
|
||||
|
||||
_onLoadSuccess = onSuccess;
|
||||
_onLoadFailure = onFailure;
|
||||
_tableBytes = new Dictionary<string, byte[]>(TableNames.Length);
|
||||
_remainCount = TableNames.Length;
|
||||
|
||||
foreach (string tableName in TableNames)
|
||||
{
|
||||
GameEntry.Resource.LoadAsset(GetTableAssetPath(tableName), Constant.AssetPriority.DataTableAsset,
|
||||
new LoadAssetCallbacks(OnLoadTableSuccess, OnLoadTableFailure), tableName);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnLoadTableSuccess(string assetName, object asset, float duration, object userData)
|
||||
{
|
||||
string tableName = (string)userData;
|
||||
TextAsset textAsset = asset as TextAsset;
|
||||
if (textAsset == null)
|
||||
{
|
||||
OnLoadTableFailure(assetName, LoadResourceStatus.AssetError, "Table asset is invalid.", userData);
|
||||
return;
|
||||
}
|
||||
|
||||
_tableBytes[tableName] = textAsset.bytes;
|
||||
if (--_remainCount > 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
Tables = new SepCore.Definition.Tables(name => new Luban.ByteBuf(_tableBytes[name]));
|
||||
_tableBytes = null;
|
||||
Log.Info("Load Luban data tables OK.");
|
||||
Action onLoadSuccess = _onLoadSuccess;
|
||||
_onLoadSuccess = null;
|
||||
_onLoadFailure = null;
|
||||
onLoadSuccess?.Invoke();
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
Log.Error("Build Luban data tables failure with exception '{0}'.", exception);
|
||||
Action<string> onLoadFailure = _onLoadFailure;
|
||||
_onLoadSuccess = null;
|
||||
_onLoadFailure = null;
|
||||
onLoadFailure?.Invoke(exception.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
private void OnLoadTableFailure(string assetName, LoadResourceStatus status, string errorMessage,
|
||||
object userData)
|
||||
{
|
||||
Log.Error("Can not load data table '{0}' from '{1}' with error message '{2}'.", (string)userData, assetName,
|
||||
errorMessage);
|
||||
Action<string> onLoadFailure = _onLoadFailure;
|
||||
_onLoadSuccess = null;
|
||||
_onLoadFailure = null;
|
||||
onLoadFailure?.Invoke(errorMessage);
|
||||
}
|
||||
|
||||
private static string GetTableAssetPath(string tableName)
|
||||
{
|
||||
return GameFramework.Utility.Text.Format("Assets/GameMain/DataTables/{0}.bytes", tableName);
|
||||
}
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fd425f3318ddacb44a9c9468dcd434bf
|
||||
guid: 7686ced148554a92ba9da1fd22a26d01
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
+14
-8
@@ -3,7 +3,6 @@ using System.Threading;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using SepCore.Components;
|
||||
using SepCore.Event;
|
||||
using SepCore.DataTable;
|
||||
using SepCore.Definition;
|
||||
using SepCore.Entity.Weapon;
|
||||
using SepCore.CustomUtility;
|
||||
@@ -65,7 +64,7 @@ namespace SepCore.Entity
|
||||
get => _exp;
|
||||
set
|
||||
{
|
||||
if (value >= _expRequires[_currentLevel + 1])
|
||||
if (_expRequires != null && _currentLevel + 1 < _expRequires.Length && value >= _expRequires[_currentLevel + 1])
|
||||
{
|
||||
value -= _expRequires[_currentLevel + 1];
|
||||
_currentLevel++;
|
||||
@@ -73,7 +72,10 @@ namespace SepCore.Entity
|
||||
GameEntry.Event.Fire(this, PlayerLevelUpEventArgs.Create());
|
||||
}
|
||||
|
||||
GameEntry.Event.Fire(this, PlayerExpChangeEventArgs.Create(value, _expRequires[_currentLevel + 1]));
|
||||
int requiredExp = _expRequires != null && _currentLevel + 1 < _expRequires.Length
|
||||
? _expRequires[_currentLevel + 1]
|
||||
: 100;
|
||||
GameEntry.Event.Fire(this, PlayerExpChangeEventArgs.Create(value, requiredExp));
|
||||
_exp = value;
|
||||
}
|
||||
}
|
||||
@@ -151,7 +153,7 @@ namespace SepCore.Entity
|
||||
_backpackComponent?.SetWeaponState(_enable && _weaponEnabled);
|
||||
}
|
||||
|
||||
public void InitRole(DRRole role)
|
||||
public void InitRole(RoleConfig role, LevelExperienceConfig expConfig)
|
||||
{
|
||||
// MovementComponent
|
||||
_movementComponent.OnInit(role.Speed, this.CachedTransform, _statComponent);
|
||||
@@ -167,18 +169,22 @@ namespace SepCore.Entity
|
||||
WeaponType.WeaponKnife, Id, _playerData.Camp)).Forget();
|
||||
|
||||
// StatComponent
|
||||
foreach (var modifier in role.InitialProperties)
|
||||
if (role.Modifiers != null)
|
||||
{
|
||||
_statComponent.AddModifier(modifier);
|
||||
foreach (var modifier in role.Modifiers)
|
||||
{
|
||||
_statComponent.AddModifier(modifier);
|
||||
}
|
||||
}
|
||||
|
||||
_expRequires = role.ExpRequires;
|
||||
_expRequires = expConfig != null ? expConfig.ToTargetLevelArray() : null;
|
||||
|
||||
// Fire Events
|
||||
GameEntry.Event.Fire(this,
|
||||
PlayerHealthChangeEventArgs.Create(0, _healthComponent.CurrentHealth, _healthComponent.MaxHealth));
|
||||
|
||||
GameEntry.Event.Fire(this, PlayerExpChangeEventArgs.Create(0, 100));
|
||||
int initialTargetExp = _expRequires != null && _expRequires.Length > 1 ? _expRequires[1] : 100;
|
||||
GameEntry.Event.Fire(this, PlayerExpChangeEventArgs.Create(0, initialTargetExp));
|
||||
|
||||
GameEntry.Event.Fire(this, PlayerCoinChangeEventArgs.Create(Coin, Coin));
|
||||
}
|
||||
+1
-1
@@ -50,7 +50,7 @@ namespace SepCore.Entity.Weapon
|
||||
protected StatProperty AttackStat { get; private set; } = new();
|
||||
|
||||
private StatComponent _attackStatComponent;
|
||||
private System.Action<StatModifier, bool> _attackStatCallback;
|
||||
private System.Action<modifier, bool> _attackStatCallback;
|
||||
|
||||
private static readonly List<EntityBase> s_EmptyCandidates = new();
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user