From 616e92279d0d9fa44c92ecd305cec5f8329c1b55 Mon Sep 17 00:00:00 2001 From: Laicasaane Date: Thu, 10 Oct 2024 13:03:18 +0700 Subject: [PATCH] Correct the use of FaceDirection --- Assets/Code/Components/Components.cs | 3 +++ Assets/Code/Systems.Presentation/SyncSpriteRendererSystem.cs | 2 +- .../MoveBackFromOutsideWorldBoundarySystem.cs | 2 +- Assets/Code/Systems.Simulation/MoveSystem.cs | 2 +- 4 files changed, 6 insertions(+), 3 deletions(-) diff --git a/Assets/Code/Components/Components.cs b/Assets/Code/Components/Components.cs index 76aaad9..f4e947f 100644 --- a/Assets/Code/Components/Components.cs +++ b/Assets/Code/Components/Components.cs @@ -102,6 +102,9 @@ public struct SpriteElapsedTime : IComponentData public struct FaceDirection : IComponentData { public sbyte value; + + public readonly int GetFace() + => math.select(-1, 1, value > 0); } public struct MoveSpeed : IComponentData diff --git a/Assets/Code/Systems.Presentation/SyncSpriteRendererSystem.cs b/Assets/Code/Systems.Presentation/SyncSpriteRendererSystem.cs index 6405f85..933432f 100644 --- a/Assets/Code/Systems.Presentation/SyncSpriteRendererSystem.cs +++ b/Assets/Code/Systems.Presentation/SyncSpriteRendererSystem.cs @@ -44,7 +44,7 @@ in SystemAPI.Query 0; + renderer.flipX = faceDirection.GetFace() > 0; } } } diff --git a/Assets/Code/Systems.Simulation/MoveBackFromOutsideWorldBoundarySystem.cs b/Assets/Code/Systems.Simulation/MoveBackFromOutsideWorldBoundarySystem.cs index f141ddd..f6c2557 100644 --- a/Assets/Code/Systems.Simulation/MoveBackFromOutsideWorldBoundarySystem.cs +++ b/Assets/Code/Systems.Simulation/MoveBackFromOutsideWorldBoundarySystem.cs @@ -58,7 +58,7 @@ private void Execute(in FaceDirection faceDirection, ref LocalTransform transfor var max = boundary.max; var xToTheRight = math.select(position.x, min.x - padding, position.x > max.x + padding); var xToTheLeft = math.select(position.x, max.x + padding, position.x < min.x - padding); - position.x = math.select(xToTheLeft, xToTheRight, faceDirection.value > 0); + position.x = math.select(xToTheLeft, xToTheRight, faceDirection.GetFace() > 0); transform.Position = position; } diff --git a/Assets/Code/Systems.Simulation/MoveSystem.cs b/Assets/Code/Systems.Simulation/MoveSystem.cs index 4313faa..fcb8824 100644 --- a/Assets/Code/Systems.Simulation/MoveSystem.cs +++ b/Assets/Code/Systems.Simulation/MoveSystem.cs @@ -47,7 +47,7 @@ in MoveSpeed moveSpeed , ref LocalTransform transform ) { - transform.Position += new float3(moveSpeed.value * deltaTime, 0f, 0f) * faceDirection.value; + transform.Position += new float3(moveSpeed.value * deltaTime, 0f, 0f) * faceDirection.GetFace(); } } }