This commit is contained in:
PC-20230316NUNE\Administrator
2024-10-23 15:30:22 +08:00
parent a3257421ad
commit 1953e7c25f
34 changed files with 3751 additions and 512 deletions

View File

@@ -169,7 +169,7 @@ namespace GAS.Runtime
}
public void UpdateCurrentValueWhenBaseValueIsDirty(AttributeBase attribute, int sourceId, int oldBaseValue, int newBaseValue)
public void UpdateCurrentValueWhenBaseValueIsDirty(AttributeBase attribute, ulong sourceId, int oldBaseValue, int newBaseValue)
{
if (oldBaseValue == newBaseValue) return;

View File

@@ -15,9 +15,9 @@ namespace GAS.Runtime
// Changed 是提供属性变化后的回调
protected event Action<AttributeBase, int, int> _onCurrentValueChanged;
protected event Action<AttributeBase, int, int, int> _onBaseValueChanged;
protected event Action<AttributeBase, ulong, int, int> _onBaseValueChanged;
protected event Action<AttributeBase, int, int> _onPostCurrentValueChange;
protected event Action<AttributeBase, int, int, int> _onPostBaseValueChange;
protected event Action<AttributeBase, ulong, int, int> _onPostBaseValueChange;
protected event Action<AttributeBase, int> _onPreCurrentValueChange;
@@ -86,7 +86,7 @@ namespace GAS.Runtime
int lenght = strValue.Length;
}
public void SetBaseValue(int sourceId, int value)
public void SetBaseValue(ulong sourceId, int value)
{
if (_onPreBaseValueChangeList.Count > 0)
{
@@ -121,12 +121,12 @@ namespace GAS.Runtime
// _onPreBaseValueChange?.GetInvocationList().Cast<Func<AttributeBase, int, int>>();
}
public void RegisterPostBaseValueChange(Action<AttributeBase, int, int, int> action)
public void RegisterPostBaseValueChange(Action<AttributeBase, ulong, int, int> action)
{
_onPostBaseValueChange += action;
}
public void RegisterBaseValueChanged(Action<AttributeBase, int, int, int> action)
public void RegisterBaseValueChanged(Action<AttributeBase, ulong, int, int> action)
{
_onBaseValueChanged += action;
}
@@ -154,12 +154,12 @@ namespace GAS.Runtime
// _onPreBaseValueChange?.GetInvocationList().Cast<Func<AttributeBase, int, int>>();
}
public void UnregisterPostBaseValueChange(Action<AttributeBase, int, int, int> action)
public void UnregisterPostBaseValueChange(Action<AttributeBase, ulong, int, int> action)
{
_onPostBaseValueChange -= action;
}
public void UnregisterBaseValueChanged(Action<AttributeBase, int, int, int> action)
public void UnregisterBaseValueChanged(Action<AttributeBase, ulong, int, int> action)
{
_onBaseValueChanged -= action;
}
@@ -202,7 +202,7 @@ namespace GAS.Runtime
return value;
}
private void InvokeOnPostBaseValueChange(AttributeBase attribute, int sourceId, int oldBaseValue, int newBaseValue)
private void InvokeOnPostBaseValueChange(AttributeBase attribute, ulong sourceId, int oldBaseValue, int newBaseValue)
{
_onPostBaseValueChange?.Invoke(attribute, sourceId, oldBaseValue, newBaseValue);
_owner.AttributeSetContainer.UpdateCurrentValueWhenBaseValueIsDirty(attribute, sourceId, oldBaseValue, newBaseValue);

View File

@@ -10,7 +10,7 @@ namespace GAS.Runtime
public abstract AttributeBase this[string key] { get; }
public abstract string[] AttributeNames { get; }
public abstract void SetOwner(AbilitySystemComponent owner);
public void ChangeAttributeBase(int sourceId, string attributeShortName, LFloat value)
public void ChangeAttributeBase(ulong sourceId, string attributeShortName, LFloat value)
{
if (this[attributeShortName] != null)
{

View File

@@ -164,7 +164,7 @@ namespace GAS.Runtime
}
}
public void UpdateCurrentValueWhenBaseValueIsDirty(AttributeBase attribute, int sourceId, int oldBaseValue, int newBaseValue)
public void UpdateCurrentValueWhenBaseValueIsDirty(AttributeBase attribute, ulong sourceId, int oldBaseValue, int newBaseValue)
{
if (_attributeAggregators.TryGetValue(attribute.Name, out var aagt))
{

View File

@@ -15,7 +15,7 @@ namespace GAS.Runtime
private IAbilitySystemComponentPreset preset;
public bool enabled { get; protected set; }
public IAbilitySystemComponentPreset Preset => preset;
public int EntityId { get; protected set; }
public ulong EntityId { get; protected set; }
public string EntityName { get; protected set; }
public int Level { get; protected set; }
@@ -72,9 +72,10 @@ namespace GAS.Runtime
preset = ascPreset;
}
public void Init(GameplayTag[] baseTags, Type[] attrSetTypes, string[] baseAbilities, int entityId,
public void Init(GameplayTag[] baseTags, Type[] attrSetTypes, string[] baseAbilities, ulong entityId,
int level)
{
EntityId = entityId;
Prepare();
SetLevel(level);
if (baseTags != null) GameplayTagAggregator.Init(baseTags);

View File

@@ -6,7 +6,7 @@ namespace GAS.Runtime
public interface IAbilitySystemComponent
{
void SetPreset(IAbilitySystemComponentPreset ascPreset);
void Init(GameplayTag[] baseTags, Type[] attrSetTypes, string[] baseAbilities, int entityId, int level);
void Init(GameplayTag[] baseTags, Type[] attrSetTypes, string[] baseAbilities, ulong entityId, int level);
void SetLevel(int level);
bool HasTag(GameplayTag tag);
bool HasAllTags(GameplayTagSet tags);

View File

@@ -1,14 +1,20 @@
using System;
using System.Collections.Generic;
using GAS.Runtime;
using JNGame.GAS;
using JNGame.Math;
using JNGame.Runtime.GAS.Runtime;
using JNGame.Serialization;
using JNGame.Sync.System;
using UnityEngine;
using NotImplementedException = System.NotImplementedException;
namespace JNGame.Runtime.Sync.System.Logic
{
/// <summary>
/// GAS 系统
/// </summary>
public class JNGASSystem : SLogicSystem
public class JNGASSystem : SLogicSystem,IGASResourceService
{
/// <summary>
@@ -16,6 +22,29 @@ namespace JNGame.Runtime.Sync.System.Logic
/// </summary>
private JexGasManager _gas = new();
public JexGasManager GAS => _gas;
/// <summary>
/// 所有的GE配置数据
/// </summary>
private Dictionary<string, IGameplayEffectData> m_AllGEAssets;
/// <summary>
/// 所有的GA配置数据
/// </summary>
private Dictionary<string, PureTimelineAbilityAsset> m_AllAbilityAssets;
/// <summary>
/// 所有的ASC预设配置
/// </summary>
private Dictionary<string, PureASCPresetAsset> m_AllASCAssets;
public override void OnSyncStart()
{
base.OnSyncStart();
OnInitAbilityAssetData();
OnInitASCPresetAssetData();
OnInitGameplayEffectData();
GASBindAsset();
}
public override void OnSyncUpdate(int dt)
{
@@ -32,6 +61,183 @@ namespace JNGame.Runtime.Sync.System.Logic
return GAS.Unregister(abilitySystemComponent);
}
/// <summary>
/// 初始化 Ability 数据
/// </summary>
public virtual void OnInitAbilityAssetData()
{
m_AllGEAssets = new();
}
/// <summary>
/// 初始化 ASC 数据
/// </summary>
public virtual void OnInitASCPresetAssetData()
{
m_AllAbilityAssets = new();
}
/// <summary>
/// 初始化 GE 数据
/// </summary>
public virtual void OnInitGameplayEffectData()
{
m_AllASCAssets = new();
}
/// <summary>
/// 返回属性类型
/// </summary>
/// <returns></returns>
public virtual Dictionary<string, Type> GetAttrSetTypeDict()
{
return new Dictionary<string, Type>();
}
public void GASBindAsset()
{
foreach (var iter in m_AllAbilityAssets)
{
iter.Value.BindLinkAsset(this);
}
foreach (var iter in m_AllGEAssets)
{
if (iter.Value is ILinkAssetBinder linkAssetBinder)
{
linkAssetBinder.BindLinkAsset(this);
}
}
}
public void SetGameplayEffectData(Dictionary<string, IGameplayEffectData> dictGEAssets)
{
m_AllGEAssets = dictGEAssets;
}
public void SetAbilityAssetData(Dictionary<string, PureTimelineAbilityAsset> dictGAAssets)
{
m_AllAbilityAssets = dictGAAssets;
}
public void SetASCPresetAssetData(Dictionary<string, PureASCPresetAsset> dictASCAssets)
{
m_AllASCAssets = dictASCAssets;
}
public IGameplayEffectData GetGameplayEffectData(string geAssetLocation)
{
if (m_AllGEAssets.TryGetValue(geAssetLocation, out IGameplayEffectData geAssetData))
{
return geAssetData;
}
Debug.LogWarning($"没有找到GE资源资源名:{geAssetLocation}");
return null;
}
public PureTimelineAbilityAsset GetTimelineAbilityAsset(string gaAssetLocation)
{
if (m_AllAbilityAssets.TryGetValue(gaAssetLocation, out PureTimelineAbilityAsset gaAssetData))
{
return gaAssetData;
}
Debug.LogWarning($"没有找到GA资源资源名:{gaAssetLocation}");
return null;
}
public PureASCPresetAsset GetASCPresetAsset(string ascAssetLocation)
{
if (m_AllASCAssets.TryGetValue(ascAssetLocation, out PureASCPresetAsset ascPresetData))
{
return ascPresetData;
}
Debug.LogWarning($"没有找到ASC预设资源资源名:{ascAssetLocation}");
return null;
}
public GameplayEffect CreateRuntimeGE(string key)
{
IGameplayEffectData staticData = GetGameplayEffectData(key);
if (staticData != null)
{
return new GameplayEffect(staticData, 0);
}
return null;
}
public GameplayEffect CreateRuntimeGE(string key, LFloat value)
{
IGameplayEffectData staticData = GetGameplayEffectData(key);
if (staticData != null)
{
var runtimeGE = new GameplayEffect(staticData, 0);
runtimeGE.ModifiersValue[0] = value;
return runtimeGE;
}
return null;
}
public GameplayEffect CreateRuntimeGE(string key, int valueId)
{
IGameplayEffectData staticData = GetGameplayEffectData(key);
if (staticData != null)
{
return new GameplayEffect(staticData, valueId);
}
return null;
}
/// <summary>
/// 字节转GE
/// </summary>
public Dictionary<string, IGameplayEffectData> ByteToGE(byte[] byteData)
{
var geDic = new Dictionary<string, IGameplayEffectData>();
var reader = new Deserializer(byteData);
var size = reader.ReadUInt16();
for (int i = 0; i < size; i++)
{
PureGameplayEffectAsset asset = new PureGameplayEffectAsset();
asset.Deserialize(reader);
geDic.Add(asset.Name, asset);
}
return geDic;
}
/// <summary>
/// 字节转ASC
/// </summary>
public Dictionary<string, PureASCPresetAsset> ByteToASC(byte[] byteData)
{
var ascDic = new Dictionary<string, PureASCPresetAsset>();
var reader = new Deserializer(byteData);
var size = reader.ReadUInt16();
for (int i = 0; i < size; i++)
{
PureASCPresetAsset asset = new PureASCPresetAsset();
asset.Deserialize(reader);
ascDic.Add(asset.Name, asset);
}
return ascDic;
}
/// <summary>
/// 字节转Ability
/// </summary>
public Dictionary<string, PureTimelineAbilityAsset> ByteToAbility(byte[] byteData)
{
var abDic = new Dictionary<string, PureTimelineAbilityAsset>();
Deserializer reader = new Deserializer(byteData);
// Ability
int size = reader.ReadUInt16();
for (int i = 0; i < size; i++)
{
PureTimelineAbilityAsset asset = new PureTimelineAbilityAsset();
asset.Deserialize(reader);
abDic.Add(asset.Name, asset);
}
return abDic;
}
}
}