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

@@ -68,7 +68,7 @@ namespace GAS.Editor
[DisplayAsString]
[LabelWidth(75)]
[ShowIf("IsPlaying")]
public int IID;
public ulong IID;
[VerticalGroup(BOXGROUP_ASC_H_R_A_V)] [ReadOnly] [LabelWidth(75)] [ShowIf("IsPlaying")]
public GameObject instance;
@@ -247,7 +247,6 @@ namespace GAS.Editor
RefreshAttributesInfo();
RefreshGameplayEffectsInfo();
RefreshTagsInfo();
RefreshDamageInfo();
}
@@ -335,20 +334,6 @@ namespace GAS.Editor
}
}
}
private void RefreshDamageInfo()
{
DamageRecorder.Clear();
foreach (var kv in _selected.DamageList)
{
DamageRecorder.Add($"--对 {kv.asc.EntityId}@造成了{kv.atkValue}伤害");
DamageRecorder.Add($" 伤害来源 {kv.skillId}");
DamageRecorder.Add($" @{kv.damageType.Name}@{kv.other.ToString()}");
DamageRecorder.Add($" @闪避率:{kv.missRate}@暴击率{kv.criRate}");
DamageRecorder.Add($" @是否双倍{kv.isDouble}@双倍概率{kv.doubleRate}");
DamageRecorder.Add($" 当前时间戳{kv.time}");
}
}
}
}
#endif

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;
}
}
}

View File

@@ -289,7 +289,7 @@ GameObject:
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
m_IsActive: 0
--- !u!4 &1449950259
Transform:
m_ObjectHideFlags: 0
@@ -339,6 +339,9 @@ MonoBehaviour:
Box: {fileID: 7403693568755579174, guid: 2e5d0c510b71c714aaccc714aca99afc, type: 3}
Preset: {fileID: 11400000, guid: 7692a8d07949a5c46b6b5325ebb9a422, type: 2}
GE_JisolDemo1: {fileID: 11400000, guid: 25ef9a2206b693c4f9b93af896a038a8, type: 2}
AbilityAsset: {fileID: 4900000, guid: 55f106e119a6897439630e254550d8fd, type: 3}
GEAsset: {fileID: 4900000, guid: 8f64d28cf3a48454c9421439e97c85fe, type: 3}
ASCAsset: {fileID: 4900000, guid: 2a02b2265d30a464a989f2d4b3e9adac, type: 3}
--- !u!4 &1745439354
Transform:
m_ObjectHideFlags: 0

View File

@@ -13,7 +13,7 @@ MonoBehaviour:
m_Name: GE_Player
m_EditorClassIdentifier: JNGame.Runtime:GAS.Runtime:GameplayEffectAsset
description:
durationPolicy: 1
durationPolicy: 2
duration: 0
period: 0
periodExecutionId: 0

View File

@@ -1,8 +1,9 @@
using System;
using System.Collections.Generic;
using GAS.Runtime;
using GASSamples.Scripts.Game.GAS;
using JNGame.Runtime.Sync.System.Logic;
using JNGame.Sync.Entity.Component;
using UnityEngine;
namespace GASSamples.Scripts.Game.Entity.Nodes.Component.Components
{
@@ -32,7 +33,12 @@ namespace GASSamples.Scripts.Game.Entity.Nodes.Component.Components
ASC.SetPreset(ascPreset);
ASC.SetLevel(level);
if (ASC.Preset == null) return;
// ASC.Init(asc.PresetBaseTags(), asc.PresetAttributeSetTypes(), asc.Preset.LinkAbilities, entityId, level);
var attrSetTypes = new Type[ASC.Preset.AttributeSets.Length];
for (var i = 0; i < ASC.Preset.AttributeSets.Length; i++)
attrSetTypes[i] = GetSystem<JNGASSystem>().GetAttrSetTypeDict()[ASC.Preset.AttributeSets[i]];
ASC.Init(ASC.Preset.BaseTags, attrSetTypes, ASC.Preset.LinkAbilities, Entity.Id, level);
}
/// <summary>

View File

@@ -1,6 +1,7 @@
using Game.Logic.System.Usual;
using GAS.Runtime;
using GASSamples.Scripts.Game.Entity.Nodes.Component.Components;
using GASSamples.Scripts.Game.GAS;
using JNGame.Runtime.Sync.System.Logic;
using JNGame.Sync.Entity.Component;
@@ -17,13 +18,13 @@ namespace GASSamples.Scripts.Game.Entity.Nodes.Component.Controller
base.OnSyncStart();
//设置GAS 角色
// GAS.InitWithPreset(GetSystem<DDataSystem>().Preset,1);
GAS.InitWithPreset(GetSystem<DGASSystem>().GetASCPresetAsset("ASC_Demo1"),1);
//附加效果测试
// GAS.ApplyGameplayEffectToSelf(new GameplayEffect(GetSystem<DDataSystem>().GE_JisolDemo1));
//释放技能
// GAS.TryActivateAbility(GAbilityLib.JisolDemo1.Name);
GAS.TryActivateAbility(GAbilityLib.JisolDemo1.Name);
}

View File

@@ -0,0 +1,32 @@
using System;
using System.Collections.Generic;
using Game.Logic.System.Usual;
using GAS.Runtime;
using JNGame.Runtime.Sync.System.Logic;
namespace GASSamples.Scripts.Game.GAS
{
public class DGASSystem : JNGASSystem
{
public override void OnInitAbilityAssetData()
{
SetAbilityAssetData(ByteToAbility(GetSystem<DDataSystem>().Ability));
}
public override void OnInitGameplayEffectData()
{
SetGameplayEffectData(ByteToGE(GetSystem<DDataSystem>().GE));
}
public override void OnInitASCPresetAssetData()
{
SetASCPresetAssetData(ByteToASC(GetSystem<DDataSystem>().ASC));
}
public override Dictionary<string, Type> GetAttrSetTypeDict()
{
return GAttrSetLib.AttrSetTypeDict;
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: eebf87e24e6740be8f5013969bca0ca3
timeCreated: 1729652027

View File

@@ -1,4 +1,5 @@
using GAS.Runtime;
using JNGame.Runtime.Sync.System.Logic;
using JNGame.Sync.Entity;
using UnityEngine;
@@ -14,6 +15,7 @@ namespace GASSamples.Scripts.Game.GAS
public GAbilitySystemComponent(IJNEntity entity)
{
Entity = entity;
GASResService = Entity.GetContext().GetSync().GetSystem<JNGASSystem>();
}
public override void OnGExecute(GameplayEffectSpec geSpec)

View File

@@ -12,12 +12,21 @@ namespace Game.Logic.System.Usual
public AbilitySystemComponentPreset Preset { get; private set; }
public IGameplayEffectData GE_JisolDemo1 { get; private set; }
public byte[] Ability { get; private set; }
public byte[] GE { get; private set; }
public byte[] ASC { get; private set; }
public override void OnSyncStart()
{
base.OnSyncStart();
Preset = App.Resource.Preset;
GE_JisolDemo1 = App.Resource.GE_JisolDemo1;
Ability = App.Resource.Ability;
GE = App.Resource.GE;
ASC = App.Resource.ASC;
}
}
}

View File

@@ -0,0 +1,27 @@
///////////////////////////////////
//// This is a generated file. ////
//// Do not modify it. ////
///////////////////////////////////
using System;
using System.Collections.Generic;
namespace GAS.Runtime
{
public static class GASCPresetLib
{
public struct ASCPresetInfo
{
public string Name;
public string AssetPath;
}
public static ASCPresetInfo ASC_Demo1 = new ASCPresetInfo { Name = "ASC_Demo1", AssetPath = "Assets/Scripts/GASSamples/GAS/Config/AbilitySystemComponentLib/ASC_Demo1.asset"};
public static Dictionary<string, ASCPresetInfo> ASCPresetMap = new Dictionary<string, ASCPresetInfo>
{
["ASC_Demo1"] = ASC_Demo1,
};
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: ec7b55df34c66be4d933fd550a032c52
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,28 @@
///////////////////////////////////
//// This is a generated file. ////
//// Do not modify it. ////
///////////////////////////////////
using System;
using System.Collections.Generic;
namespace GAS.Runtime
{
public static class GAbilityLib
{
public struct AbilityInfo
{
public string Name;
public string AssetPath;
public Type AbilityClassType;
}
public static AbilityInfo JisolDemo1 = new AbilityInfo { Name = "JisolDemo1", AssetPath = "Assets/Scripts/GASSamples/GAS/Config/GameplayAbilityLib/JisolDemo1.asset",AbilityClassType = typeof(GAS.Runtime.TimelineAbility) };
public static Dictionary<string, AbilityInfo> AbilityMap = new Dictionary<string, AbilityInfo>
{
["JisolDemo1"] = JisolDemo1,
};
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 4f87dae0ef06e5b43a93fbe6c182c8c9
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,27 @@
///////////////////////////////////
//// This is a generated file. ////
//// Do not modify it. ////
///////////////////////////////////
using System;
using System.Collections.Generic;
namespace GAS.Runtime
{
public static class GGameplayEffectLib
{
public struct GameplayEffectAssetInfo
{
public string Name;
public string AssetPath;
}
public static GameplayEffectAssetInfo GE_Player = new GameplayEffectAssetInfo { Name = "GE_Player", AssetPath = "Assets/Scripts/GASSamples/GAS/Config/GameplayEffectLib/GE_Player.asset"};
public static Dictionary<string, GameplayEffectAssetInfo> GameplayEffectMap = new Dictionary<string, GameplayEffectAssetInfo>
{
["GE_Player"] = GE_Player,
};
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 1c5edef4175b8f54fab71d79979e19af
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -18,10 +18,14 @@ namespace GASSamples.Scripts
//GE_JisolDemo1
public IGameplayEffectData GE_JisolDemo1;
public byte[] Ability;
public byte[] GE;
public byte[] ASC;
public override Task OnInit()
{
return base.OnInit();
}

View File

@@ -13,6 +13,9 @@ namespace GASSamples.Scripts
public GameObject Box;
public AbilitySystemComponentPreset Preset;
public GameplayEffectAsset GE_JisolDemo1;
public TextAsset AbilityAsset;
public TextAsset GEAsset;
public TextAsset ASCAsset;
private JNGASFrameSystem _frameSystem;
@@ -28,6 +31,12 @@ namespace GASSamples.Scripts
App.Resource.Preset = Preset;
App.Resource.GE_JisolDemo1 = GE_JisolDemo1;
App.Resource.Ability = AbilityAsset.bytes;
App.Resource.GE = GEAsset.bytes;
App.Resource.ASC = ASCAsset.bytes;
_frameSystem = new JNGASFrameSystem();
_frameSystem.Initialize();
_frameSystem.TStartExecute();

View File

@@ -2,10 +2,10 @@ using Cysharp.Threading.Tasks;
using Game.Input;
using Game.Logic.System.Usual;
using GASSamples.Scripts.Game.Entity;
using GASSamples.Scripts.Game.GAS;
using GASSamples.Scripts.Game.Logic.Data;
using GASSamples.Scripts.Game.Logic.System;
using GASSamples.Scripts.Game.View;
using JNGame.Runtime.Sync.System.Logic;
using JNGame.Sync.Entity;
using JNGame.Sync.Frame;
using JNGame.Sync.System;
@@ -22,7 +22,7 @@ namespace DefaultNamespace
{
new DInputSystem(), //游戏输入
new DDataSystem(), //数据 系统
new JNGASSystem(), //GAS 系统
new DGASSystem(), //GAS 系统
new DWorldSystem(), //世界逻辑
};
}