Browse Source

Ball Recycle System

master
Xiao Bai 1 month ago
parent
commit
05221b3a44
  1. 9
      client/client/Assets/Scripts/CoreGame/AFramSync/Logic/Component/Ball/BallRecycleComponent.cs
  2. 3
      client/client/Assets/Scripts/CoreGame/AFramSync/Logic/Component/Ball/BallRecycleComponent.cs.meta
  3. 56
      client/client/Assets/Scripts/CoreGame/AFramSync/Logic/EntitasGen/Components/LogicBallRecycleComponent.cs
  4. 11
      client/client/Assets/Scripts/CoreGame/AFramSync/Logic/EntitasGen/Components/LogicBallRecycleComponent.cs.meta
  5. 49
      client/client/Assets/Scripts/CoreGame/AFramSync/Logic/EntitasGen/LogicComponentsLookup.cs
  6. 3
      client/client/Assets/Scripts/CoreGame/AFramSync/Logic/Service/Matcher/MatcherSvc.cs
  7. 2
      client/client/Assets/Scripts/CoreGame/AFramSync/Logic/System/Ball/BallFeature.cs
  8. 11
      client/client/Assets/Scripts/CoreGame/AFramSync/Logic/System/Ball/BallHitTriggerSystem.cs
  9. 36
      client/client/Assets/Scripts/CoreGame/AFramSync/Logic/System/Ball/BallRecycleSystem.cs
  10. 3
      client/client/Assets/Scripts/CoreGame/AFramSync/Logic/System/Ball/BallRecycleSystem.cs.meta

9
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
{
}
}

3
client/client/Assets/Scripts/CoreGame/AFramSync/Logic/Component/Ball/BallRecycleComponent.cs.meta

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 32996adfddf44fb7ac495e72b5ab4c52
timeCreated: 1753759848

56
client/client/Assets/Scripts/CoreGame/AFramSync/Logic/EntitasGen/Components/LogicBallRecycleComponent.cs

@ -0,0 +1,56 @@
//------------------------------------------------------------------------------
// <auto-generated>
// 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.
// </auto-generated>
//------------------------------------------------------------------------------
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);
}
}
}
}
}
//------------------------------------------------------------------------------
// <auto-generated>
// 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.
// </auto-generated>
//------------------------------------------------------------------------------
public sealed partial class LogicMatcher {
static Entitas.IMatcher<LogicEntity> _matcherBallRecycle;
public static Entitas.IMatcher<LogicEntity> BallRecycle {
get {
if (_matcherBallRecycle == null) {
var matcher = (Entitas.Matcher<LogicEntity>)Entitas.Matcher<LogicEntity>.AllOf(LogicComponentsLookup.BallRecycle);
matcher.componentNames = LogicComponentsLookup.componentNames;
_matcherBallRecycle = matcher;
}
return _matcherBallRecycle;
}
}
}

11
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:

49
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 ActionBuffer = 0;
public const int BallBag = 1; public const int BallBag = 1;
public const int BallData = 2; public const int BallData = 2;
public const int Dead = 3; public const int BallRecycle = 3;
public const int FCollision = 4; public const int Dead = 4;
public const int FrameCommands = 5; public const int FCollision = 5;
public const int GaCtxTransfer = 6; public const int FrameCommands = 6;
public const int LevelWave = 7; public const int GaCtxTransfer = 7;
public const int LogicTransform = 8; public const int LevelWave = 8;
public const int MoveDirection = 9; public const int LogicTransform = 9;
public const int Nav = 10; public const int MoveDirection = 10;
public const int NeedSyncBody = 11; public const int Nav = 11;
public const int Property = 12; public const int NeedSyncBody = 12;
public const int ShootBall = 13; public const int Property = 13;
public const int Ball = 14; public const int ShootBall = 14;
public const int Bullet = 15; public const int Ball = 15;
public const int DestroyEnt = 16; public const int Bullet = 16;
public const int DirectBullet = 17; public const int DestroyEnt = 17;
public const int Faction = 18; public const int DirectBullet = 18;
public const int Hero = 19; public const int Faction = 19;
public const int Monster = 20; public const int Hero = 20;
public const int Obstacle = 21; public const int Monster = 21;
public const int Summon = 22; public const int Obstacle = 22;
public const int SyncData = 23; public const int Summon = 23;
public const int AbilitySystem = 24; 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 = { public static readonly string[] componentNames = {
"ActionBuffer", "ActionBuffer",
"BallBag", "BallBag",
"BallData", "BallData",
"BallRecycle",
"Dead", "Dead",
"FCollision", "FCollision",
"FrameCommands", "FrameCommands",
@ -68,6 +70,7 @@ public static class LogicComponentsLookup {
typeof(CoreGame.Logic.ActionBufferComponent), typeof(CoreGame.Logic.ActionBufferComponent),
typeof(CoreGame.Logic.BallBagComponent), typeof(CoreGame.Logic.BallBagComponent),
typeof(CoreGame.Logic.BallDataComponent), typeof(CoreGame.Logic.BallDataComponent),
typeof(CoreGame.Logic.BallRecycleComponent),
typeof(CoreGame.Logic.DeadComponent), typeof(CoreGame.Logic.DeadComponent),
typeof(CoreGame.Logic.FCollisionComponent), typeof(CoreGame.Logic.FCollisionComponent),
typeof(CoreGame.Logic.FrameCommandsComponent), typeof(CoreGame.Logic.FrameCommandsComponent),

3
client/client/Assets/Scripts/CoreGame/AFramSync/Logic/Service/Matcher/MatcherSvc.cs

@ -16,5 +16,8 @@ namespace CoreGame.Logic
public static Matcher<LogicEntity> s_ShootBall = public static Matcher<LogicEntity> s_ShootBall =
(Matcher<LogicEntity>)Matcher<LogicEntity>.AllOf(Lookup.ShootBall, Lookup.BallBag); (Matcher<LogicEntity>)Matcher<LogicEntity>.AllOf(Lookup.ShootBall, Lookup.BallBag);
public static Matcher<LogicEntity> s_BallRecycle =
(Matcher<LogicEntity>)Matcher<LogicEntity>.AllOf(Lookup.BallRecycle);
} }
} }

2
client/client/Assets/Scripts/CoreGame/AFramSync/Logic/System/Ball/BallFeature.cs

@ -9,10 +9,12 @@ namespace CoreGame.Logic
Add(new PhysicsWorldTimeSetSystem(ctx)); Add(new PhysicsWorldTimeSetSystem(ctx));
Add(new PhysicsWorldRefreshSystem(ctx)); Add(new PhysicsWorldRefreshSystem(ctx));
Add(new BallHitTriggerSystem(ctx)); Add(new BallHitTriggerSystem(ctx));
Add(new BallRecycleSystem(ctx));
Add(new PhysicBodySyncTransformSystem(ctx)); Add(new PhysicBodySyncTransformSystem(ctx));
Add(new PhysicsWorldRefreshSystem(ctx)); Add(new PhysicsWorldRefreshSystem(ctx));
Add(new BallHitTriggerSystem(ctx)); Add(new BallHitTriggerSystem(ctx));
Add(new BallRecycleSystem(ctx));
Add(new PhysicBodySyncTransformSystem(ctx)); Add(new PhysicBodySyncTransformSystem(ctx));
} }

11
client/client/Assets/Scripts/CoreGame/AFramSync/Logic/System/Ball/BallHitTriggerSystem.cs

@ -35,16 +35,7 @@ namespace CoreGame.Logic
{ {
if (enemy.logicTransform.position.y < -1) if (enemy.logicTransform.position.y < -1)
{ {
var casterEid = ballComp.casterEid; enemy.isBallRecycle = true;
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;
}
} }
continue; continue;
} }

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

3
client/client/Assets/Scripts/CoreGame/AFramSync/Logic/System/Ball/BallRecycleSystem.cs.meta

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 74206916e76b4c09ae9d066000d5ad1a
timeCreated: 1753759310
Loading…
Cancel
Save