提交GAS 打算做一个帧同步的GAS

This commit is contained in:
DESKTOP-5RP3AKU\Jisol
2024-10-18 03:16:09 +08:00
parent b0a2e4a900
commit d9b0c78827
726 changed files with 76601 additions and 0 deletions

View File

@@ -0,0 +1,18 @@
using System;
using GAS.Runtime;
using UnityEngine;
namespace GAS.Runtime
{
[Serializable]
public abstract class CatchAreaBase : TargetCatcherBase
{
public LayerMask checkLayer;
public void Init(AbilitySystemComponent owner, LayerMask checkLayer)
{
base.Init(owner);
this.checkLayer = checkLayer;
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 58b4935f7a5a43d69506e28666032462
timeCreated: 1709451834

View File

@@ -0,0 +1,75 @@
using System;
using System.Collections.Generic;
using GAS.General;
using UnityEngine;
namespace GAS.Runtime
{
[Serializable]
public sealed class CatchAreaBox2D : CatchAreaBase
{
public Vector2 offset;
public float rotation;
public Vector2 size;
public EffectCenterType centerType;
public void Init(AbilitySystemComponent owner, LayerMask tCheckLayer, Vector2 offset, Vector2 size,
float rotation)
{
base.Init(owner, tCheckLayer);
this.offset = offset;
this.size = size;
this.rotation = rotation;
}
private static readonly Collider2D[] Collider2Ds = new Collider2D[32];
protected override void CatchTargetsNonAlloc(AbilitySystemComponent mainTarget, List<AbilitySystemComponent> results)
{
int count = centerType switch
{
EffectCenterType.SelfOffset => Owner.OverlapBox2DNonAlloc(offset, size, rotation, Collider2Ds, checkLayer),
EffectCenterType.WorldSpace => Physics2D.OverlapBoxNonAlloc(offset, size, rotation, Collider2Ds, checkLayer),
EffectCenterType.TargetOffset => mainTarget.OverlapBox2DNonAlloc(offset, size, rotation, Collider2Ds, checkLayer),
_ => 0
};
for (var i = 0; i < count; ++i)
{
var targetUnit = Collider2Ds[i].GetComponent<AbilitySystemComponent>();
if (targetUnit != null)
{
results.Add(targetUnit);
}
}
}
#if UNITY_EDITOR
public override void OnEditorPreview(GameObject previewObject)
{
// 使用Debug 绘制box预览
float showTime = 1;
Color color = Color.green;
var relativeTransform = previewObject.transform;
var center = offset;
var angle = rotation + relativeTransform.eulerAngles.z;
switch (centerType)
{
case EffectCenterType.SelfOffset:
center = relativeTransform.position;
center.y += relativeTransform.lossyScale.y > 0 ? offset.y : -offset.y;
center.x += relativeTransform.lossyScale.x > 0 ? offset.x : -offset.x;
break;
case EffectCenterType.WorldSpace:
center = offset;
break;
case EffectCenterType.TargetOffset:
//center = _spec.Target.transform.position + (Vector3)_task.Offset;
break;
}
DebugExtension.DebugBox(center, size, angle, color, showTime);
}
#endif
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: e6b866d9cbaa44caa47f9dfc06bd9855
timeCreated: 1709451757

View File

@@ -0,0 +1,68 @@
using System.Collections.Generic;
using GAS.General;
using UnityEngine;
namespace GAS.Runtime
{
public sealed class CatchAreaCircle2D : CatchAreaBase
{
public float radius;
public Vector2 offset;
public EffectCenterType centerType;
public void Init(AbilitySystemComponent owner, LayerMask tCheckLayer, Vector2 offset, float radius)
{
base.Init(owner, tCheckLayer);
this.offset = offset;
this.radius = radius;
}
private static readonly Collider2D[] Collider2Ds = new Collider2D[32];
protected override void CatchTargetsNonAlloc(AbilitySystemComponent mainTarget, List<AbilitySystemComponent> results)
{
int count = centerType switch
{
EffectCenterType.SelfOffset => Owner.OverlapCircle2DNonAlloc(offset, radius, Collider2Ds, checkLayer),
EffectCenterType.WorldSpace => Physics2D.OverlapCircleNonAlloc(offset, radius, Collider2Ds, checkLayer),
EffectCenterType.TargetOffset => mainTarget.OverlapCircle2DNonAlloc(offset, radius, Collider2Ds, checkLayer),
_ => 0
};
for (var i = 0; i < count; ++i)
{
var targetUnit = Collider2Ds[i].GetComponent<AbilitySystemComponent>();
if (targetUnit != null)
{
results.Add(targetUnit);
}
}
}
#if UNITY_EDITOR
public override void OnEditorPreview(GameObject previewObject)
{
// 使用Debug 绘制box预览
float showTime = 1;
Color color = Color.green;
var relativeTransform = previewObject.transform;
var center = offset;
switch (centerType)
{
case EffectCenterType.SelfOffset:
center = relativeTransform.position;
center.y += relativeTransform.lossyScale.y > 0 ? offset.y : -offset.y;
center.x += relativeTransform.lossyScale.x > 0 ? offset.x : -offset.x;
break;
case EffectCenterType.WorldSpace:
center = offset;
break;
case EffectCenterType.TargetOffset:
//center = _targetCatcher.Target.transform.position;
break;
}
DebugExtension.DebugDrawCircle(center, radius, color, showTime);
}
#endif
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: e60fe4199379464da56e2d33224b98b5
timeCreated: 1709889749

View File

@@ -0,0 +1,12 @@
using System.Collections.Generic;
namespace GAS.Runtime
{
public sealed class CatchSelf : TargetCatcherBase
{
protected override void CatchTargetsNonAlloc(AbilitySystemComponent mainTarget, List<AbilitySystemComponent> results)
{
results.Add(Owner);
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: be9321649ff24febb2f8a1c8e0ec2e4c
timeCreated: 1709451646

View File

@@ -0,0 +1,12 @@
using System.Collections.Generic;
namespace GAS.Runtime
{
public sealed class CatchTarget : TargetCatcherBase
{
protected override void CatchTargetsNonAlloc(AbilitySystemComponent mainTarget, List<AbilitySystemComponent> results)
{
results.Add(mainTarget);
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 42c991b40b9d414fb7b87d2c7d44c078
timeCreated: 1709534433

View File

@@ -0,0 +1,45 @@
using System;
using System.Collections.Generic;
using UnityEngine;
namespace GAS.Runtime
{
public abstract class TargetCatcherBase
{
public AbilitySystemComponent Owner;
protected TargetCatcherBase()
{
}
public virtual void Init(AbilitySystemComponent owner)
{
Owner = owner;
}
[Obsolete("请使用CatchTargetsNonAlloc方法来避免产生垃圾收集GC。")]
public List<AbilitySystemComponent> CatchTargets(AbilitySystemComponent mainTarget)
{
var result = new List<AbilitySystemComponent>();
CatchTargetsNonAlloc(mainTarget, result);
return result;
}
public void CatchTargetsNonAllocSafe(AbilitySystemComponent mainTarget, List<AbilitySystemComponent> results)
{
results.Clear();
CatchTargetsNonAlloc(mainTarget, results);
}
protected abstract void CatchTargetsNonAlloc(AbilitySystemComponent mainTarget, List<AbilitySystemComponent> results);
#if UNITY_EDITOR
public virtual void OnEditorPreview(GameObject obj)
{
}
#endif
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 7720c3db62774f24943b28e0160c291c
timeCreated: 1709451499