mirror of
https://gitee.com/jisol/jisol-game/
synced 2025-09-27 02:36:14 +00:00
提交
This commit is contained in:
@@ -37,14 +37,5 @@
|
||||
|
||||
// private static int _frameRate = 60;
|
||||
// public static int FrameRate => _frameRate;
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
private static int _TimeLineAbilityTickTime = 20;
|
||||
|
||||
public static int TimeLineAbilityTickTime => _TimeLineAbilityTickTime;
|
||||
|
||||
public static int FrameRateValue => 1000 / _TimeLineAbilityTickTime;
|
||||
}
|
||||
}
|
@@ -12,26 +12,13 @@ namespace GAS.General
|
||||
bool IsFromPool { get; set; }
|
||||
}
|
||||
|
||||
public class ObjectPool
|
||||
public class JexGasObjectPool
|
||||
{
|
||||
private static ObjectPool _singleton;
|
||||
public static ObjectPool Instance => _singleton ??= new ObjectPool();
|
||||
|
||||
|
||||
private readonly ConcurrentDictionary<Type, Pool> _objPool = new();
|
||||
|
||||
private readonly Func<Type, Pool> _addPoolFunc = type => new Pool(type, 1024);
|
||||
|
||||
public static void Init()
|
||||
{
|
||||
_singleton = null;
|
||||
_singleton = new ObjectPool();
|
||||
}
|
||||
|
||||
public static void Destroy()
|
||||
{
|
||||
_singleton = null;
|
||||
}
|
||||
|
||||
public T Fetch<T>() where T : class
|
||||
{
|
||||
var type = typeof(T);
|
@@ -1,6 +1,7 @@
|
||||
|
||||
using System.Collections.Generic;
|
||||
using GAS.General;
|
||||
using JNGame.Runtime.GAS.Runtime;
|
||||
using UnityEngine;
|
||||
|
||||
namespace GAS.Runtime
|
||||
@@ -68,7 +69,7 @@ namespace GAS.Runtime
|
||||
}
|
||||
|
||||
WorkingContext.TotalRunTime += deltaTime;
|
||||
var targetFrame = WorkingContext.TotalRunTime / GASTimer.TimeLineAbilityTickTime;
|
||||
var targetFrame = WorkingContext.TotalRunTime / JexGasManager.TimeLineAbilityTickTime;
|
||||
while (WorkingContext.CurrentFrame < targetFrame)
|
||||
{
|
||||
++WorkingContext.CurrentFrame;
|
||||
|
@@ -82,7 +82,7 @@ namespace GAS.Runtime
|
||||
var modifier = geSpec.Modifiers[i];
|
||||
if (modifier.attributeName == _processedAttribute.Name)
|
||||
{
|
||||
var modifierSpec = ObjectPool.Instance.Fetch<ModifierSpec>();
|
||||
var modifierSpec = _owner.GetManager().ObjectPool.Fetch<ModifierSpec>();
|
||||
modifierSpec.Init(geSpec, modifier, i);
|
||||
_modifierCache.Add(modifierSpec);
|
||||
TryRegisterAttributeChangedListen(geSpec, modifier);
|
||||
@@ -120,7 +120,7 @@ namespace GAS.Runtime
|
||||
foreach (var modifierSpec in _cached)
|
||||
{
|
||||
modifierSpec.Release();
|
||||
ObjectPool.Instance.Recycle(modifierSpec);
|
||||
_owner.GetManager().ObjectPool.Recycle(modifierSpec);
|
||||
}
|
||||
|
||||
_cached.Clear();
|
||||
|
@@ -61,13 +61,6 @@ namespace GAS.Runtime
|
||||
public static void TickEventAttackAfterRecord(this AbilitySystemComponent asc, AbilitySystemComponent source, AbilitySystemComponent receive, GameplayTag damageType,
|
||||
DamageOther other, LFloat atkValue,int skillId)
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
asc.DamageList.Enqueue((receive, atkValue, damageType, other, 0, 0, false, 0, skillId,(long)(DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalMilliseconds));
|
||||
if (asc.DamageList.Count > 10)
|
||||
{
|
||||
asc.DamageList.Dequeue();
|
||||
}
|
||||
#endif
|
||||
// asc.TickEventContainer.TickEventAttackAfter(source, receive, damageType, other, atkValue);
|
||||
}
|
||||
|
||||
|
@@ -3,6 +3,7 @@ using System.Collections.Generic;
|
||||
using GAS.General;
|
||||
using JNGame.Math;
|
||||
using JNGame.GAS;
|
||||
using JNGame.Runtime.GAS.Runtime;
|
||||
using UnityEngine;
|
||||
|
||||
namespace GAS.Runtime
|
||||
@@ -34,14 +35,6 @@ namespace GAS.Runtime
|
||||
/// </summary>
|
||||
public IGASResourceService GASResService { get; protected set; }
|
||||
|
||||
#if UNITY_EDITOR
|
||||
public Queue<(AbilitySystemComponent asc, int atkValue, GameplayTag damageType, DamageOther other, int missRate, int criRate, bool isDouble, int doubleRate,int skillId, long time)> DamageList
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
} = new();
|
||||
#endif
|
||||
|
||||
private bool _ready;
|
||||
|
||||
/// <summary>
|
||||
@@ -49,12 +42,12 @@ namespace GAS.Runtime
|
||||
/// </summary>
|
||||
public LFloat BoundRadius { get; protected set; } = LFloat.One;
|
||||
|
||||
protected void OnAwake()
|
||||
public void OnAwake()
|
||||
{
|
||||
Prepare();
|
||||
enabled = true;
|
||||
#if UNITY_EDITOR
|
||||
GameplayAbilitySystem.GAS.Register(this);
|
||||
JexGasManager.Editor.Register(this);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -72,9 +65,6 @@ namespace GAS.Runtime
|
||||
AttributeSetContainer.Awake(this);
|
||||
GameplayTagAggregator.Awake(this);
|
||||
TickEventContainer.Awake(this);
|
||||
#if UNITY_EDITOR
|
||||
DamageList.Clear();
|
||||
#endif
|
||||
}
|
||||
|
||||
public void SetPreset(IAbilitySystemComponentPreset ascPreset)
|
||||
@@ -364,12 +354,20 @@ namespace GAS.Runtime
|
||||
/// <param name="abilitySpec"></param>
|
||||
public abstract void OnAbilityEnd(AbilitySpec abilitySpec);
|
||||
|
||||
public JexGasManager Manager;
|
||||
public JexGasManager GetManager()
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
return JexGasManager.Editor;
|
||||
#else
|
||||
return Manager;
|
||||
#endif
|
||||
}
|
||||
|
||||
public virtual void Release()
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
GameplayAbilitySystem.GAS.Unregister(this);
|
||||
DamageList.Clear();
|
||||
JexGasManager.Editor.Unregister(this);
|
||||
#endif
|
||||
enabled = default;
|
||||
preset = default;
|
||||
|
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using JNGame.Runtime.GAS.Runtime;
|
||||
|
||||
namespace GAS.Runtime
|
||||
{
|
||||
@@ -29,5 +30,11 @@ namespace GAS.Runtime
|
||||
bool TryActivateAbility(string abilityName, params object[] args);
|
||||
void TryEndAbility(string abilityName);
|
||||
T AttrSet<T>() where T : AttributeSet;
|
||||
|
||||
/// <summary>
|
||||
/// 获取管理器
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
JexGasManager GetManager();
|
||||
}
|
||||
}
|
@@ -91,7 +91,7 @@ namespace GAS.Runtime
|
||||
public GameplayEffectSpec CreateSpec(int skillID, AbilitySystemComponent creator, AbilitySystemComponent owner,
|
||||
int level = 1)
|
||||
{
|
||||
var spec = GameplayEffectSpec.GetItem();
|
||||
var spec = owner.GetManager().ObjectPool.Fetch<GameplayEffectSpec>();
|
||||
spec.Init(this, creator, owner, skillID, level);
|
||||
return spec;
|
||||
}
|
||||
@@ -99,7 +99,7 @@ namespace GAS.Runtime
|
||||
public GameplayEffectSpec CreateSpec(int skillID, GameplayEffectSpec sourceSpec, AbilitySystemComponent creator,
|
||||
AbilitySystemComponent owner, int level = 1)
|
||||
{
|
||||
var spec = GameplayEffectSpec.GetItem();
|
||||
var spec = owner.GetManager().ObjectPool.Fetch<GameplayEffectSpec>();
|
||||
spec.Init(this, creator, owner, skillID, level);
|
||||
spec.SetSourceGESpec(sourceSpec);
|
||||
return spec;
|
||||
|
@@ -19,7 +19,7 @@ namespace GAS.Runtime
|
||||
|
||||
public List<GameplayEffectSpec> FetchGameplayEffects()
|
||||
{
|
||||
var list = ObjectPool.Instance.Fetch<List<GameplayEffectSpec>>();
|
||||
var list = _owner.GetManager().ObjectPool.Fetch<List<GameplayEffectSpec>>();
|
||||
list.AddRange(_gameplayEffectSpecs);
|
||||
return list;
|
||||
}
|
||||
@@ -27,7 +27,7 @@ namespace GAS.Runtime
|
||||
public void ReturnGameplayEffects(List<GameplayEffectSpec> list)
|
||||
{
|
||||
list.Clear();
|
||||
ObjectPool.Instance.Recycle(list);
|
||||
_owner.GetManager().ObjectPool.Recycle(list);
|
||||
}
|
||||
|
||||
public void Tick(int deltaTime)
|
||||
@@ -50,7 +50,7 @@ namespace GAS.Runtime
|
||||
foreach (var spec in _recycleTask)
|
||||
{
|
||||
spec.Release();
|
||||
GameplayEffectSpec.RecycleItem(spec);
|
||||
_owner.GetManager().ObjectPool.Recycle(spec);
|
||||
}
|
||||
|
||||
_recycleTask.Clear();
|
||||
@@ -61,7 +61,7 @@ namespace GAS.Runtime
|
||||
{
|
||||
if (tags.Empty) return;
|
||||
|
||||
var removeList = ObjectPool.Instance.Fetch<List<GameplayEffectSpec>>();
|
||||
var removeList = _owner.GetManager().ObjectPool.Fetch<List<GameplayEffectSpec>>();
|
||||
|
||||
foreach (var gameplayEffectSpec in _gameplayEffectSpecs)
|
||||
{
|
||||
@@ -85,7 +85,7 @@ namespace GAS.Runtime
|
||||
}
|
||||
|
||||
removeList.Clear();
|
||||
ObjectPool.Instance.Recycle(removeList);
|
||||
_owner.GetManager().ObjectPool.Recycle(removeList);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -334,7 +334,7 @@ namespace GAS.Runtime
|
||||
foreach (var spec in _recycleTask)
|
||||
{
|
||||
spec.Release();
|
||||
GameplayEffectSpec.RecycleItem(spec);
|
||||
_owner.GetManager().ObjectPool.Recycle(spec);
|
||||
}
|
||||
|
||||
_recycleTask.Clear();
|
||||
|
@@ -15,17 +15,6 @@ namespace GAS.Runtime
|
||||
SelfNumber = GameplayEffectSpec.Count;
|
||||
}
|
||||
|
||||
public static GameplayEffectSpec GetItem()
|
||||
{
|
||||
var item = ObjectPool.Instance.Fetch<GameplayEffectSpec>();
|
||||
return item;
|
||||
}
|
||||
|
||||
public static void RecycleItem(GameplayEffectSpec obj)
|
||||
{
|
||||
ObjectPool.Instance.Recycle(obj);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The execution type of onImmunity is one shot.
|
||||
/// </summary>
|
||||
|
@@ -1,10 +0,0 @@
|
||||
namespace JNGame.Runtime.GAS.Runtime
|
||||
{
|
||||
/// <summary>
|
||||
/// GAS 管理器
|
||||
/// </summary>
|
||||
public class JNGasManager
|
||||
{
|
||||
|
||||
}
|
||||
}
|
@@ -0,0 +1,81 @@
|
||||
using System.Collections.Generic;
|
||||
using GAS.General;
|
||||
using GAS.Runtime;
|
||||
using JNGame.Runtime.Util;
|
||||
|
||||
namespace JNGame.Runtime.GAS.Runtime
|
||||
{
|
||||
/// <summary>
|
||||
/// GAS 管理器
|
||||
/// </summary>
|
||||
public class JexGasManager
|
||||
{
|
||||
|
||||
|
||||
#if UNITY_EDITOR
|
||||
//编辑器专用的单例 用于预览GAS
|
||||
public static JexGasManager Editor = new JexGasManager();
|
||||
#endif
|
||||
|
||||
//---------------- 全局信息 ------------------------------------------------------------------------------------------
|
||||
private static int _TimeLineAbilityTickTime = 20;
|
||||
public static int TimeLineAbilityTickTime => _TimeLineAbilityTickTime;
|
||||
public static int FrameRateValue => 1000 / _TimeLineAbilityTickTime;
|
||||
|
||||
/// <summary>
|
||||
/// GAS 专用对象池 (只限制当前管理器)
|
||||
/// </summary>
|
||||
public JexGasObjectPool ObjectPool { get; private set; }
|
||||
|
||||
public List<AbilitySystemComponent> AbilitySystemComponents = new();
|
||||
|
||||
public JexGasManager()
|
||||
{
|
||||
ObjectPool = new JexGasObjectPool();
|
||||
#if UNITY_EDITOR
|
||||
Editor = this;
|
||||
#endif
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 委托 AbilitySystemComponent
|
||||
/// </summary>
|
||||
public void Register(AbilitySystemComponent abilitySystemComponent)
|
||||
{
|
||||
if (AbilitySystemComponents.Contains(abilitySystemComponent)) return;
|
||||
AbilitySystemComponents.Add(abilitySystemComponent);
|
||||
abilitySystemComponent.OnAwake();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 取消委托 AbilitySystemComponent
|
||||
/// </summary>
|
||||
public bool Unregister(AbilitySystemComponent abilitySystemComponent)
|
||||
{
|
||||
abilitySystemComponent.Release();
|
||||
return AbilitySystemComponents.Remove(abilitySystemComponent);
|
||||
}
|
||||
|
||||
//GAS 更新
|
||||
public void Update(int dt)
|
||||
{
|
||||
|
||||
Profiler.BeginSample($"{nameof(JexGasManager)}::Tick()");
|
||||
|
||||
var abilitySystemComponents = ObjectPool.Fetch<List<AbilitySystemComponent>>();
|
||||
abilitySystemComponents.AddRange(AbilitySystemComponents);
|
||||
|
||||
foreach (var abilitySystemComponent in abilitySystemComponents)
|
||||
{
|
||||
abilitySystemComponent.Tick(dt);
|
||||
}
|
||||
|
||||
abilitySystemComponents.Clear();
|
||||
ObjectPool.Recycle(abilitySystemComponents);
|
||||
|
||||
Profiler.EndSample();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@@ -141,7 +141,7 @@ namespace GAS.Runtime
|
||||
}
|
||||
else
|
||||
{
|
||||
var list = ObjectPool.Instance.Fetch<List<object>>();
|
||||
var list = _owner.GetManager().ObjectPool.Fetch<List<object>>();
|
||||
list.Add(source);
|
||||
_dynamicAddedTags.Add(tag, list);
|
||||
}
|
||||
@@ -156,7 +156,7 @@ namespace GAS.Runtime
|
||||
if (_dynamicAddedTags.TryGetValue(tag, out var addedTag))
|
||||
{
|
||||
addedTag.Clear();
|
||||
ObjectPool.Instance.Recycle(addedTag);
|
||||
_owner.GetManager().ObjectPool.Recycle(addedTag);
|
||||
dirty = _dynamicAddedTags.Remove(tag);
|
||||
}
|
||||
|
||||
@@ -168,7 +168,7 @@ namespace GAS.Runtime
|
||||
}
|
||||
else
|
||||
{
|
||||
var list = ObjectPool.Instance.Fetch<List<object>>();
|
||||
var list = _owner.GetManager().ObjectPool.Fetch<List<object>>();
|
||||
list.Add(source);
|
||||
_dynamicRemovedTags.Add(tag, list);
|
||||
}
|
||||
@@ -190,7 +190,7 @@ namespace GAS.Runtime
|
||||
dirty = tagList.Count == 0;
|
||||
if (dirty)
|
||||
{
|
||||
ObjectPool.Instance.Recycle(tagList);
|
||||
_owner.GetManager().ObjectPool.Recycle(tagList);
|
||||
dynamicTag.Remove(tag);
|
||||
}
|
||||
}
|
||||
|
@@ -2,6 +2,7 @@
|
||||
|
||||
using System.Collections.Generic;
|
||||
using GAS.General;
|
||||
using JNGame.Runtime.GAS.Runtime;
|
||||
|
||||
namespace GAS.Runtime
|
||||
{
|
||||
@@ -308,7 +309,7 @@ namespace GAS.Runtime
|
||||
return;
|
||||
}
|
||||
_playTotalTime += deltaTime;
|
||||
var targetFrame = (int)(_playTotalTime / GASTimer.TimeLineAbilityTickTime);
|
||||
var targetFrame = (int)(_playTotalTime / JexGasManager.TimeLineAbilityTickTime);
|
||||
|
||||
// 追帧
|
||||
while (_currentFrame < targetFrame)
|
||||
|
@@ -1,4 +1,5 @@
|
||||
using GAS.Runtime;
|
||||
using JNGame.Runtime.GAS.Runtime;
|
||||
using JNGame.Sync.System;
|
||||
using UnityEngine;
|
||||
|
||||
@@ -9,27 +10,26 @@ namespace JNGame.Runtime.Sync.System.Logic
|
||||
/// </summary>
|
||||
public class JNGASSystem : SLogicSystem
|
||||
{
|
||||
//
|
||||
// /// <summary>
|
||||
// /// GAS 管理器
|
||||
// /// </summary>
|
||||
// private JexGasManager _gas = new();
|
||||
// public JexGasManager GAS => _gas;
|
||||
|
||||
/// <summary>
|
||||
/// GAS 管理器
|
||||
/// </summary>
|
||||
private JexGasManager _gas = new();
|
||||
public JexGasManager GAS => _gas;
|
||||
|
||||
public override void OnSyncUpdate(int dt)
|
||||
{
|
||||
// GAS.Update(dt);
|
||||
GAS.Update(dt);
|
||||
}
|
||||
|
||||
public void Register(AbilitySystemComponent abilitySystemComponent)
|
||||
{
|
||||
// GAS.Register(abilitySystemComponent);
|
||||
GAS.Register(abilitySystemComponent);
|
||||
}
|
||||
|
||||
public bool Unregister(AbilitySystemComponent abilitySystemComponent)
|
||||
{
|
||||
// return GAS.Unregister(abilitySystemComponent);
|
||||
return false;
|
||||
return GAS.Unregister(abilitySystemComponent);
|
||||
}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user