From 05221b3a44c754f1bc152058f3130f140c81044a Mon Sep 17 00:00:00 2001 From: Xiao Bai Date: Tue, 29 Jul 2025 11:53:35 +0800 Subject: [PATCH] Ball Recycle System --- .../Component/Ball/BallRecycleComponent.cs | 9 +++ .../Ball/BallRecycleComponent.cs.meta | 3 + .../Components/LogicBallRecycleComponent.cs | 56 +++++++++++++++++++ .../LogicBallRecycleComponent.cs.meta | 11 ++++ .../Logic/EntitasGen/LogicComponentsLookup.cs | 49 ++++++++-------- .../Logic/Service/Matcher/MatcherSvc.cs | 3 + .../Logic/System/Ball/BallFeature.cs | 2 + .../Logic/System/Ball/BallHitTriggerSystem.cs | 11 +--- .../Logic/System/Ball/BallRecycleSystem.cs | 36 ++++++++++++ .../System/Ball/BallRecycleSystem.cs.meta | 3 + 10 files changed, 150 insertions(+), 33 deletions(-) create mode 100644 client/client/Assets/Scripts/CoreGame/AFramSync/Logic/Component/Ball/BallRecycleComponent.cs create mode 100644 client/client/Assets/Scripts/CoreGame/AFramSync/Logic/Component/Ball/BallRecycleComponent.cs.meta create mode 100644 client/client/Assets/Scripts/CoreGame/AFramSync/Logic/EntitasGen/Components/LogicBallRecycleComponent.cs create mode 100644 client/client/Assets/Scripts/CoreGame/AFramSync/Logic/EntitasGen/Components/LogicBallRecycleComponent.cs.meta create mode 100644 client/client/Assets/Scripts/CoreGame/AFramSync/Logic/System/Ball/BallRecycleSystem.cs create mode 100644 client/client/Assets/Scripts/CoreGame/AFramSync/Logic/System/Ball/BallRecycleSystem.cs.meta diff --git a/client/client/Assets/Scripts/CoreGame/AFramSync/Logic/Component/Ball/BallRecycleComponent.cs b/client/client/Assets/Scripts/CoreGame/AFramSync/Logic/Component/Ball/BallRecycleComponent.cs new file mode 100644 index 00000000..02d0c45d --- /dev/null +++ b/client/client/Assets/Scripts/CoreGame/AFramSync/Logic/Component/Ball/BallRecycleComponent.cs @@ -0,0 +1,9 @@ +using Entitas; + +namespace CoreGame.Logic +{ + [Logic] + public class BallRecycleComponent : IComponent + { + } +} \ No newline at end of file diff --git a/client/client/Assets/Scripts/CoreGame/AFramSync/Logic/Component/Ball/BallRecycleComponent.cs.meta b/client/client/Assets/Scripts/CoreGame/AFramSync/Logic/Component/Ball/BallRecycleComponent.cs.meta new file mode 100644 index 00000000..a58bea50 --- /dev/null +++ b/client/client/Assets/Scripts/CoreGame/AFramSync/Logic/Component/Ball/BallRecycleComponent.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 32996adfddf44fb7ac495e72b5ab4c52 +timeCreated: 1753759848 \ No newline at end of file diff --git a/client/client/Assets/Scripts/CoreGame/AFramSync/Logic/EntitasGen/Components/LogicBallRecycleComponent.cs b/client/client/Assets/Scripts/CoreGame/AFramSync/Logic/EntitasGen/Components/LogicBallRecycleComponent.cs new file mode 100644 index 00000000..45a21a52 --- /dev/null +++ b/client/client/Assets/Scripts/CoreGame/AFramSync/Logic/EntitasGen/Components/LogicBallRecycleComponent.cs @@ -0,0 +1,56 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by Entitas.CodeGeneration.Plugins.ComponentEntityApiGenerator. +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ +public partial class LogicEntity { + + static readonly CoreGame.Logic.BallRecycleComponent ballRecycleComponent = new CoreGame.Logic.BallRecycleComponent(); + + public bool isBallRecycle { + get { return HasComponent(LogicComponentsLookup.BallRecycle); } + set { + if (value != isBallRecycle) { + var index = LogicComponentsLookup.BallRecycle; + if (value) { + var componentPool = GetComponentPool(index); + var component = componentPool.Count > 0 + ? componentPool.Pop() + : ballRecycleComponent; + + AddComponent(index, component); + } else { + RemoveComponent(index); + } + } + } + } +} + +//------------------------------------------------------------------------------ +// +// This code was generated by Entitas.CodeGeneration.Plugins.ComponentMatcherApiGenerator. +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ +public sealed partial class LogicMatcher { + + static Entitas.IMatcher _matcherBallRecycle; + + public static Entitas.IMatcher BallRecycle { + get { + if (_matcherBallRecycle == null) { + var matcher = (Entitas.Matcher)Entitas.Matcher.AllOf(LogicComponentsLookup.BallRecycle); + matcher.componentNames = LogicComponentsLookup.componentNames; + _matcherBallRecycle = matcher; + } + + return _matcherBallRecycle; + } + } +} diff --git a/client/client/Assets/Scripts/CoreGame/AFramSync/Logic/EntitasGen/Components/LogicBallRecycleComponent.cs.meta b/client/client/Assets/Scripts/CoreGame/AFramSync/Logic/EntitasGen/Components/LogicBallRecycleComponent.cs.meta new file mode 100644 index 00000000..bb61eabc --- /dev/null +++ b/client/client/Assets/Scripts/CoreGame/AFramSync/Logic/EntitasGen/Components/LogicBallRecycleComponent.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 873be48d947f2f14b91f618722d08b60 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/client/client/Assets/Scripts/CoreGame/AFramSync/Logic/EntitasGen/LogicComponentsLookup.cs b/client/client/Assets/Scripts/CoreGame/AFramSync/Logic/EntitasGen/LogicComponentsLookup.cs index 16bf4853..3027c1d6 100644 --- a/client/client/Assets/Scripts/CoreGame/AFramSync/Logic/EntitasGen/LogicComponentsLookup.cs +++ b/client/client/Assets/Scripts/CoreGame/AFramSync/Logic/EntitasGen/LogicComponentsLookup.cs @@ -11,35 +11,37 @@ public static class LogicComponentsLookup { public const int ActionBuffer = 0; public const int BallBag = 1; public const int BallData = 2; - public const int Dead = 3; - public const int FCollision = 4; - public const int FrameCommands = 5; - public const int GaCtxTransfer = 6; - public const int LevelWave = 7; - public const int LogicTransform = 8; - public const int MoveDirection = 9; - public const int Nav = 10; - public const int NeedSyncBody = 11; - public const int Property = 12; - public const int ShootBall = 13; - public const int Ball = 14; - public const int Bullet = 15; - public const int DestroyEnt = 16; - public const int DirectBullet = 17; - public const int Faction = 18; - public const int Hero = 19; - public const int Monster = 20; - public const int Obstacle = 21; - public const int Summon = 22; - public const int SyncData = 23; - public const int AbilitySystem = 24; + public const int BallRecycle = 3; + public const int Dead = 4; + public const int FCollision = 5; + public const int FrameCommands = 6; + public const int GaCtxTransfer = 7; + public const int LevelWave = 8; + public const int LogicTransform = 9; + public const int MoveDirection = 10; + public const int Nav = 11; + public const int NeedSyncBody = 12; + public const int Property = 13; + public const int ShootBall = 14; + public const int Ball = 15; + public const int Bullet = 16; + public const int DestroyEnt = 17; + public const int DirectBullet = 18; + public const int Faction = 19; + public const int Hero = 20; + public const int Monster = 21; + public const int Obstacle = 22; + public const int Summon = 23; + public const int SyncData = 24; + public const int AbilitySystem = 25; - public const int TotalComponents = 25; + public const int TotalComponents = 26; public static readonly string[] componentNames = { "ActionBuffer", "BallBag", "BallData", + "BallRecycle", "Dead", "FCollision", "FrameCommands", @@ -68,6 +70,7 @@ public static class LogicComponentsLookup { typeof(CoreGame.Logic.ActionBufferComponent), typeof(CoreGame.Logic.BallBagComponent), typeof(CoreGame.Logic.BallDataComponent), + typeof(CoreGame.Logic.BallRecycleComponent), typeof(CoreGame.Logic.DeadComponent), typeof(CoreGame.Logic.FCollisionComponent), typeof(CoreGame.Logic.FrameCommandsComponent), diff --git a/client/client/Assets/Scripts/CoreGame/AFramSync/Logic/Service/Matcher/MatcherSvc.cs b/client/client/Assets/Scripts/CoreGame/AFramSync/Logic/Service/Matcher/MatcherSvc.cs index 0422cc05..c4303c1a 100644 --- a/client/client/Assets/Scripts/CoreGame/AFramSync/Logic/Service/Matcher/MatcherSvc.cs +++ b/client/client/Assets/Scripts/CoreGame/AFramSync/Logic/Service/Matcher/MatcherSvc.cs @@ -16,5 +16,8 @@ namespace CoreGame.Logic public static Matcher s_ShootBall = (Matcher)Matcher.AllOf(Lookup.ShootBall, Lookup.BallBag); + + public static Matcher s_BallRecycle = + (Matcher)Matcher.AllOf(Lookup.BallRecycle); } } \ No newline at end of file diff --git a/client/client/Assets/Scripts/CoreGame/AFramSync/Logic/System/Ball/BallFeature.cs b/client/client/Assets/Scripts/CoreGame/AFramSync/Logic/System/Ball/BallFeature.cs index a30c38e6..e87ca7de 100644 --- a/client/client/Assets/Scripts/CoreGame/AFramSync/Logic/System/Ball/BallFeature.cs +++ b/client/client/Assets/Scripts/CoreGame/AFramSync/Logic/System/Ball/BallFeature.cs @@ -9,10 +9,12 @@ namespace CoreGame.Logic Add(new PhysicsWorldTimeSetSystem(ctx)); Add(new PhysicsWorldRefreshSystem(ctx)); Add(new BallHitTriggerSystem(ctx)); + Add(new BallRecycleSystem(ctx)); Add(new PhysicBodySyncTransformSystem(ctx)); Add(new PhysicsWorldRefreshSystem(ctx)); Add(new BallHitTriggerSystem(ctx)); + Add(new BallRecycleSystem(ctx)); Add(new PhysicBodySyncTransformSystem(ctx)); } diff --git a/client/client/Assets/Scripts/CoreGame/AFramSync/Logic/System/Ball/BallHitTriggerSystem.cs b/client/client/Assets/Scripts/CoreGame/AFramSync/Logic/System/Ball/BallHitTriggerSystem.cs index 9362e72c..5c9e9e14 100644 --- a/client/client/Assets/Scripts/CoreGame/AFramSync/Logic/System/Ball/BallHitTriggerSystem.cs +++ b/client/client/Assets/Scripts/CoreGame/AFramSync/Logic/System/Ball/BallHitTriggerSystem.cs @@ -35,16 +35,7 @@ namespace CoreGame.Logic { if (enemy.logicTransform.position.y < -1) { - var casterEid = ballComp.casterEid; - var logicContext = entity.logicContext; - var heroEntity = logicContext.GetEntity(casterEid); - if (heroEntity) - { - var transform = heroEntity.logicTransform; - var dir = transform.position - fCollisionBody.Position; - fCollisionBody.LinearVelocityNormalized = FixedMath.Normalize(dir); - fCollisionBody.LinearVelocity = fCollisionBody.LinearVelocityNormalized * fCollisionBody.Velocity; - } + enemy.isBallRecycle = true; } continue; } diff --git a/client/client/Assets/Scripts/CoreGame/AFramSync/Logic/System/Ball/BallRecycleSystem.cs b/client/client/Assets/Scripts/CoreGame/AFramSync/Logic/System/Ball/BallRecycleSystem.cs new file mode 100644 index 00000000..ba391c8f --- /dev/null +++ b/client/client/Assets/Scripts/CoreGame/AFramSync/Logic/System/Ball/BallRecycleSystem.cs @@ -0,0 +1,36 @@ +using Entitas; +using Sog; + +namespace CoreGame.Logic +{ + public class BallRecycleSystem : ITickSystem + { + private readonly IGroup m_BallRecycleGroup; + + public BallRecycleSystem(LogicContext logicContext) + { + m_BallRecycleGroup = logicContext.GetGroup(MatcherSvc.s_BallRecycle); + } + + public void Tick() + { + var tmpBuffer = m_BallRecycleGroup.GetEntitiesWithTmpBuffer(); + for (int i = 0; i < tmpBuffer.Count; i++) + { + var entity = tmpBuffer.Buffer[i]; + var ballComp = entity.ballData; + var fCollisionBody = entity.fCollision.body; + var casterEid = ballComp.casterEid; + var logicContext = entity.logicContext; + var heroEntity = logicContext.GetEntity(casterEid); + if (heroEntity) + { + var transform = heroEntity.logicTransform; + var dir = transform.position - fCollisionBody.Position; + fCollisionBody.LinearVelocityNormalized = FixedMath.Normalize(dir); + fCollisionBody.LinearVelocity = fCollisionBody.LinearVelocityNormalized * fCollisionBody.Velocity; + } + } + } + } +} \ No newline at end of file diff --git a/client/client/Assets/Scripts/CoreGame/AFramSync/Logic/System/Ball/BallRecycleSystem.cs.meta b/client/client/Assets/Scripts/CoreGame/AFramSync/Logic/System/Ball/BallRecycleSystem.cs.meta new file mode 100644 index 00000000..7447343c --- /dev/null +++ b/client/client/Assets/Scripts/CoreGame/AFramSync/Logic/System/Ball/BallRecycleSystem.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 74206916e76b4c09ae9d066000d5ad1a +timeCreated: 1753759310 \ No newline at end of file