Commit b4e7688f by alsunj

Add slime target and moving system

parent 752a165c
Showing with 185 additions and 211 deletions
using Unity.Entities; using Unity.Entities;
using UnityEngine; using UnityEngine;
public class DamageOnTriggerAuthoring : MonoBehaviour public class DamageOnCollisionAuthoring : MonoBehaviour
{ {
public int DamageOnTrigger; public int DamageOnTrigger;
public class DamageOnTriggerBaker : Baker<DamageOnTriggerAuthoring> public class DamageOnCollisionBaker : Baker<DamageOnCollisionAuthoring>
{ {
public override void Bake(DamageOnTriggerAuthoring authoring) public override void Bake(DamageOnCollisionAuthoring authoring)
{ {
var entity = GetEntity(TransformUsageFlags.Dynamic); var entity = GetEntity(TransformUsageFlags.Dynamic);
AddComponent(entity, new DamageOnTrigger { Value = authoring.DamageOnTrigger }); AddComponent(entity, new DamageOnCollision { Value = authoring.DamageOnTrigger });
AddBuffer<AlreadyDamagedEntity>(entity); AddBuffer<AlreadyDamagedEntity>(entity);
} }
} }
......
...@@ -25,6 +25,7 @@ public class SlimeTargetAuthoring : MonoBehaviour ...@@ -25,6 +25,7 @@ public class SlimeTargetAuthoring : MonoBehaviour
}); });
AddComponent<NpcTargetEntity>(entity); AddComponent<NpcTargetEntity>(entity);
AddComponent<SlimeTag>(entity); AddComponent<SlimeTag>(entity);
AddComponent<SlimeTargetDirection>(entity);
AddBuffer<NpcAttackCooldown>(entity); AddBuffer<NpcAttackCooldown>(entity);
} }
} }
......
...@@ -23,10 +23,6 @@ public class EntitiesReferencesAuthoring : MonoBehaviour ...@@ -23,10 +23,6 @@ public class EntitiesReferencesAuthoring : MonoBehaviour
SlimeEnemyEntity = GetEntity(authoring.SlimeEnemyGameObject, TransformUsageFlags.Dynamic), SlimeEnemyEntity = GetEntity(authoring.SlimeEnemyGameObject, TransformUsageFlags.Dynamic),
RespawnEntity = GetEntity(authoring.RespawnEntity, TransformUsageFlags.None) RespawnEntity = GetEntity(authoring.RespawnEntity, TransformUsageFlags.None)
}); });
AddComponentObject(entity, new UIPrefabs
{
HealthBar = authoring.HealthBarPrefab,
});
} }
} }
} }
...@@ -37,11 +33,5 @@ public struct EntititesReferences : IComponentData ...@@ -37,11 +33,5 @@ public struct EntititesReferences : IComponentData
public Entity PlayerPrefabEntity; public Entity PlayerPrefabEntity;
public Entity RougeEnemyEntity; public Entity RougeEnemyEntity;
public Entity SlimeEnemyEntity; public Entity SlimeEnemyEntity;
public Entity RespawnEntity; public Entity RespawnEntity;
}
public class UIPrefabs : IComponentData
{
public GameObject HealthBar;
} }
\ No newline at end of file
...@@ -46,7 +46,7 @@ public struct AbilityMoveSpeed : IComponentData ...@@ -46,7 +46,7 @@ public struct AbilityMoveSpeed : IComponentData
public float Value; public float Value;
} }
public struct DamageOnTrigger : IComponentData public struct DamageOnCollision : IComponentData
{ {
public int Value; public int Value;
} }
...@@ -81,4 +81,9 @@ public struct CurrentHitPoints : IComponentData ...@@ -81,4 +81,9 @@ public struct CurrentHitPoints : IComponentData
public struct SlimeTag : IComponentData public struct SlimeTag : IComponentData
{ {
}
public struct SlimeTargetDirection : IComponentData
{
public float3 Value;
} }
\ No newline at end of file
using Unity.NetCode;
//[UnityEngine.Scripting.Preserve]
// public class GameBootstrap : ClientServerBootstrap
// {
// public override bool Initialize(string defaultWorldName)
// {
// AutoConnectPort = 7970;
// return base.Initialize(defaultWorldName);
// }
// }
\ No newline at end of file
...@@ -20,32 +20,10 @@ public struct PlayerSprintData : IComponentData ...@@ -20,32 +20,10 @@ public struct PlayerSprintData : IComponentData
public float sprintCooldownReset; public float sprintCooldownReset;
} }
public struct PlayerAttackData : IComponentData
{
public float attackCooldownTimer;
}
public struct PlayerDefenceData : IComponentData
{
public float defenceCooldownTimer;
}
public struct PlayerTag : IComponentData public struct PlayerTag : IComponentData
{ {
} }
[GhostComponent(PrefabType = GhostPrefabType.AllPredicted, OwnerSendType = SendToOwnerType.SendToOwner)]
public struct PlayerCameraBind : IComponentData
{
public int ClientNetworkId;
}
public struct CameraFollow : IComponentData
{
public Entity PlayerEntity;
public float3 Offset;
}
public struct TeamTypes : IComponentData public struct TeamTypes : IComponentData
{ {
[GhostField] public TeamType Value; [GhostField] public TeamType Value;
......
...@@ -4,10 +4,6 @@ public struct GoInGameRequestRpc : IRpcCommand ...@@ -4,10 +4,6 @@ public struct GoInGameRequestRpc : IRpcCommand
{ {
} }
public struct ClientConnectionRpc : IRpcCommand
{
}
public struct PlayersRemainingToStart : IRpcCommand public struct PlayersRemainingToStart : IRpcCommand
{ {
public int Value; public int Value;
......
...@@ -5,11 +5,11 @@ using UnityEngine; ...@@ -5,11 +5,11 @@ using UnityEngine;
public class NetcodePlayerInputAuthoring : MonoBehaviour public class NetcodePlayerInputAuthoring : MonoBehaviour
{ {
public float sprintRemaining = 5f; public float sprintRemaining;
public float sprintDuration = 5f; public float sprintDuration;
public float sprintSpeed = 12f; public float sprintSpeed;
public float walkSpeed = 9f; public float walkSpeed;
public float sprintCooldownReset = 2f; public float sprintCooldownReset;
public class Baker : Baker<NetcodePlayerInputAuthoring> public class Baker : Baker<NetcodePlayerInputAuthoring>
{ {
...@@ -20,19 +20,13 @@ public class NetcodePlayerInputAuthoring : MonoBehaviour ...@@ -20,19 +20,13 @@ public class NetcodePlayerInputAuthoring : MonoBehaviour
AddComponent(entity, new PlayerSprintData AddComponent(entity, new PlayerSprintData
{ {
isSprinting = false, isSprinting = false,
isSprintCooldown = false,
sprintRemaining = authoring.sprintRemaining, sprintRemaining = authoring.sprintRemaining,
sprintDuration = authoring.sprintDuration, sprintDuration = authoring.sprintDuration,
sprintSpeed = authoring.sprintSpeed, sprintSpeed = authoring.sprintSpeed,
walkSpeed = authoring.walkSpeed, walkSpeed = authoring.walkSpeed,
sprintCooldown = 0f,
sprintCooldownReset = authoring.sprintCooldownReset, sprintCooldownReset = authoring.sprintCooldownReset,
}); });
AddComponent(entity, new PlayerAttackData());
AddComponent(entity, new PlayerDefenceData());
AddComponent<PlayerTag>(entity); AddComponent<PlayerTag>(entity);
} }
} }
} }
\ No newline at end of file
...@@ -11,6 +11,7 @@ public partial struct ApplyDamageSystem : ISystem ...@@ -11,6 +11,7 @@ public partial struct ApplyDamageSystem : ISystem
public void OnCreate(ref SystemState state) public void OnCreate(ref SystemState state)
{ {
state.RequireForUpdate<NetworkTime>(); state.RequireForUpdate<NetworkTime>();
state.RequireForUpdate<GamePlayingTag>();
} }
[BurstCompile] [BurstCompile]
......
...@@ -8,6 +8,8 @@ public partial struct CalculateFrameDamageSystem : ISystem ...@@ -8,6 +8,8 @@ public partial struct CalculateFrameDamageSystem : ISystem
public void OnCreate(ref SystemState state) public void OnCreate(ref SystemState state)
{ {
state.RequireForUpdate<NetworkTime>(); state.RequireForUpdate<NetworkTime>();
state.RequireForUpdate<GamePlayingTag>();
state.RequireForUpdate<DamageBufferElement>();
} }
[BurstCompile] [BurstCompile]
......
...@@ -12,6 +12,7 @@ public partial struct DamageOnCollisionSystem : ISystem ...@@ -12,6 +12,7 @@ public partial struct DamageOnCollisionSystem : ISystem
{ {
state.RequireForUpdate<SimulationSingleton>(); state.RequireForUpdate<SimulationSingleton>();
state.RequireForUpdate<EndSimulationEntityCommandBufferSystem.Singleton>(); state.RequireForUpdate<EndSimulationEntityCommandBufferSystem.Singleton>();
state.RequireForUpdate<GamePlayingTag>();
} }
[BurstCompile] [BurstCompile]
...@@ -20,7 +21,7 @@ public partial struct DamageOnCollisionSystem : ISystem ...@@ -20,7 +21,7 @@ public partial struct DamageOnCollisionSystem : ISystem
var ecbSingleton = SystemAPI.GetSingleton<EndSimulationEntityCommandBufferSystem.Singleton>(); var ecbSingleton = SystemAPI.GetSingleton<EndSimulationEntityCommandBufferSystem.Singleton>();
var damageOnCollisionJob = new DamageOnCollisionJob var damageOnCollisionJob = new DamageOnCollisionJob
{ {
DamageOnTriggerLookup = SystemAPI.GetComponentLookup<DamageOnTrigger>(true), DamageOnCollisionLookup = SystemAPI.GetComponentLookup<DamageOnCollision>(true),
TeamLookup = SystemAPI.GetComponentLookup<TeamTypes>(true), TeamLookup = SystemAPI.GetComponentLookup<TeamTypes>(true),
AlreadyDamagedLookup = SystemAPI.GetBufferLookup<AlreadyDamagedEntity>(true), AlreadyDamagedLookup = SystemAPI.GetBufferLookup<AlreadyDamagedEntity>(true),
DamageBufferLookup = SystemAPI.GetBufferLookup<DamageBufferElement>(true), DamageBufferLookup = SystemAPI.GetBufferLookup<DamageBufferElement>(true),
...@@ -34,7 +35,7 @@ public partial struct DamageOnCollisionSystem : ISystem ...@@ -34,7 +35,7 @@ public partial struct DamageOnCollisionSystem : ISystem
public struct DamageOnCollisionJob : ICollisionEventsJob public struct DamageOnCollisionJob : ICollisionEventsJob
{ {
[ReadOnly] public ComponentLookup<DamageOnTrigger> DamageOnTriggerLookup; [ReadOnly] public ComponentLookup<DamageOnCollision> DamageOnCollisionLookup;
[ReadOnly] public ComponentLookup<TeamTypes> TeamLookup; [ReadOnly] public ComponentLookup<TeamTypes> TeamLookup;
public BufferLookup<AlreadyDamagedEntity> AlreadyDamagedLookup; public BufferLookup<AlreadyDamagedEntity> AlreadyDamagedLookup;
public BufferLookup<DamageBufferElement> DamageBufferLookup; public BufferLookup<DamageBufferElement> DamageBufferLookup;
...@@ -49,12 +50,12 @@ public struct DamageOnCollisionJob : ICollisionEventsJob ...@@ -49,12 +50,12 @@ public struct DamageOnCollisionJob : ICollisionEventsJob
Entity damageReceivingEntity = Entity.Null; Entity damageReceivingEntity = Entity.Null;
if (DamageBufferLookup.HasBuffer(entityA) && if (DamageBufferLookup.HasBuffer(entityA) &&
DamageOnTriggerLookup.HasComponent(entityB)) DamageOnCollisionLookup.HasComponent(entityB))
{ {
damageReceivingEntity = entityA; damageReceivingEntity = entityA;
damageDealingEntity = entityB; damageDealingEntity = entityB;
} }
else if (DamageOnTriggerLookup.HasComponent(entityA) && else if (DamageOnCollisionLookup.HasComponent(entityA) &&
DamageBufferLookup.HasBuffer(entityB)) DamageBufferLookup.HasBuffer(entityB))
{ {
damageDealingEntity = entityA; damageDealingEntity = entityA;
...@@ -84,7 +85,7 @@ public struct DamageOnCollisionJob : ICollisionEventsJob ...@@ -84,7 +85,7 @@ public struct DamageOnCollisionJob : ICollisionEventsJob
if (damageDealingTeam.Value == damageReceivingTeam.Value) return; if (damageDealingTeam.Value == damageReceivingTeam.Value) return;
} }
if (DamageOnTriggerLookup.TryGetComponent(damageDealingEntity, out var damageOnTrigger)) if (DamageOnCollisionLookup.TryGetComponent(damageDealingEntity, out var damageOnTrigger))
{ {
ECB.AddComponent<DestroyEntityTag>(damageDealingEntity); ECB.AddComponent<DestroyEntityTag>(damageDealingEntity);
ECB.AppendToBuffer(damageReceivingEntity, new DamageBufferElement { Value = damageOnTrigger.Value }); ECB.AppendToBuffer(damageReceivingEntity, new DamageBufferElement { Value = damageOnTrigger.Value });
......
...@@ -6,6 +6,11 @@ using Unity.Transforms; ...@@ -6,6 +6,11 @@ using Unity.Transforms;
[UpdateInGroup(typeof(PredictedSimulationSystemGroup))] [UpdateInGroup(typeof(PredictedSimulationSystemGroup))]
public partial struct MoveAbilitySystem : ISystem public partial struct MoveAbilitySystem : ISystem
{ {
public void OnCreate(ref SystemState state)
{
state.RequireForUpdate<AbilityMoveSpeed>();
}
public void OnUpdate(ref SystemState state) public void OnUpdate(ref SystemState state)
{ {
var deltaTime = SystemAPI.Time.DeltaTime; var deltaTime = SystemAPI.Time.DeltaTime;
......
using Unity.Burst;
using Unity.Entities; using Unity.Entities;
using Unity.Mathematics;
using Unity.NetCode; using Unity.NetCode;
using Unity.Transforms; using Unity.Transforms;
...@@ -8,29 +8,34 @@ public partial struct MoveSlimeSystem : ISystem ...@@ -8,29 +8,34 @@ public partial struct MoveSlimeSystem : ISystem
{ {
public void OnCreate(ref SystemState state) public void OnCreate(ref SystemState state)
{ {
state.RequireForUpdate<AbilityMoveSpeed>(); state.RequireForUpdate<NetworkTime>();
state.RequireForUpdate<TeamTypes>(); state.RequireForUpdate<EndSimulationEntityCommandBufferSystem.Singleton>();
state.RequireForUpdate<NpcTargetEntity>(); state.RequireForUpdate<SlimeTargetDirection>();
state.RequireForUpdate<SlimeTag>();
} }
[BurstCompile]
public void OnUpdate(ref SystemState state) public void OnUpdate(ref SystemState state)
{ {
var deltaTime = SystemAPI.Time.DeltaTime; var deltaTime = SystemAPI.Time.DeltaTime;
var localTransformLookup = SystemAPI.GetComponentLookup<LocalTransform>(true);
foreach (var (transform, moveSpeed, teamType, targetEntity) in SystemAPI state.Dependency = new MoveSlimeJob
.Query<RefRW<LocalTransform>, RefRO<AbilityMoveSpeed>, RefRO<TeamTypes>, RefRO<NpcTargetEntity>>()
.WithAny<SlimeTag>())
{ {
if (teamType.ValueRO.Value == TeamType.Enemy && targetEntity.ValueRO.Value != Entity.Null) DeltaTime = deltaTime
{ }.ScheduleParallel(state.Dependency);
if (localTransformLookup.HasComponent(targetEntity.ValueRO.Value)) }
{ }
var targetPosition = localTransformLookup[targetEntity.ValueRO.Value].Position;
var direction = math.normalize(targetPosition - transform.ValueRW.Position); [BurstCompile]
transform.ValueRW.Position += direction * moveSpeed.ValueRO.Value * deltaTime; [WithAll(typeof(SlimeTargetDirection))]
} public partial struct MoveSlimeJob : IJobEntity
} {
} public float DeltaTime;
[BurstCompile]
private void Execute(ref LocalTransform transform, in AbilityMoveSpeed moveSpeed,
in SlimeTargetDirection targetDirection)
{
transform.Position += targetDirection.Value * moveSpeed.Value * DeltaTime;
} }
} }
\ No newline at end of file
...@@ -16,6 +16,7 @@ public partial struct NpcTargetingSystem : ISystem ...@@ -16,6 +16,7 @@ public partial struct NpcTargetingSystem : ISystem
public void OnCreate(ref SystemState state) public void OnCreate(ref SystemState state)
{ {
state.RequireForUpdate<PhysicsWorldSingleton>(); state.RequireForUpdate<PhysicsWorldSingleton>();
state.RequireForUpdate<GamePlayingTag>();
_npcAttackFilter = new CollisionFilter _npcAttackFilter = new CollisionFilter
{ {
BelongsTo = 1 << 6, //Target Cast BelongsTo = 1 << 6, //Target Cast
......
...@@ -6,12 +6,13 @@ using Unity.NetCode; ...@@ -6,12 +6,13 @@ using Unity.NetCode;
using Unity.Transforms; using Unity.Transforms;
[UpdateInGroup(typeof(PredictedSimulationSystemGroup))] [UpdateInGroup(typeof(PredictedSimulationSystemGroup))]
public partial struct NpcAttackSystem : ISystem public partial struct RogueAttackSystem : ISystem
{ {
public void OnCreate(ref SystemState state) public void OnCreate(ref SystemState state)
{ {
state.RequireForUpdate<NetworkTime>(); state.RequireForUpdate<NetworkTime>();
state.RequireForUpdate<BeginSimulationEntityCommandBufferSystem.Singleton>(); state.RequireForUpdate<BeginSimulationEntityCommandBufferSystem.Singleton>();
state.RequireForUpdate<GamePlayingTag>();
} }
public void OnUpdate(ref SystemState state) public void OnUpdate(ref SystemState state)
......
using Unity.Burst;
using Unity.Collections;
using Unity.Entities;
using Unity.Mathematics;
using Unity.NetCode;
using Unity.Transforms;
[UpdateInGroup(typeof(PredictedSimulationSystemGroup), OrderLast = true)]
[UpdateBefore(typeof(MoveSlimeSystem))]
public partial struct SetTargetSlimeSystem : ISystem
{
public void OnCreate(ref SystemState state)
{
state.RequireForUpdate<BeginSimulationEntityCommandBufferSystem.Singleton>();
state.RequireForUpdate<SlimeTag>();
state.RequireForUpdate<GamePlayingTag>();
}
[BurstCompile]
public void OnUpdate(ref SystemState state)
{
var ecbSingleton = SystemAPI.GetSingleton<BeginSimulationEntityCommandBufferSystem.Singleton>();
var teamLookup = SystemAPI.GetComponentLookup<TeamTypes>(true);
var transformLookup = SystemAPI.GetComponentLookup<LocalTransform>(true);
state.Dependency = new SetSlimeTargetDirectionJob
{
TeamLookup = teamLookup,
TransformLookup = transformLookup,
Ecb = ecbSingleton.CreateCommandBuffer(state.WorldUnmanaged).AsParallelWriter()
}.ScheduleParallel(state.Dependency);
}
}
[BurstCompile]
public partial struct SetSlimeTargetDirectionJob : IJobEntity
{
[ReadOnly] public ComponentLookup<TeamTypes> TeamLookup;
[ReadOnly] public ComponentLookup<LocalTransform> TransformLookup;
public EntityCommandBuffer.ParallelWriter Ecb;
[BurstCompile]
private void Execute(in LocalTransform transform, in TeamTypes slimeTeam, in NpcTargetEntity targetEntity,
in Entity entity)
{
if (targetEntity.Value == Entity.Null || !TransformLookup.HasComponent(targetEntity.Value) ||
!TeamLookup.HasComponent(targetEntity.Value))
{
Ecb.RemoveComponent<SlimeTargetDirection>(entity.Index, entity);
return;
}
var targetTeam = TeamLookup[targetEntity.Value].Value;
if (targetTeam != TeamType.Enemy)
{
var targetPosition = TransformLookup[targetEntity.Value].Position;
var direction = math.normalize(targetPosition - transform.Position);
Ecb.AddComponent(entity.Index, entity, new SlimeTargetDirection { Value = direction });
}
else
{
Ecb.RemoveComponent<SlimeTargetDirection>(entity.Index, entity);
}
}
}
\ No newline at end of file
fileFormatVersion: 2 fileFormatVersion: 2
guid: 6236f73d74af5b04da99a398ca41c536 guid: 86f8c4a7fca9c2244981a82be26b0c7d
\ No newline at end of file \ No newline at end of file
...@@ -32,7 +32,7 @@ public partial struct ClientRequestGameEntrySystem : ISystem ...@@ -32,7 +32,7 @@ public partial struct ClientRequestGameEntrySystem : ISystem
GameObject playerCameraGO = new GameObject($"Camera{networkId.ValueRO.Value}"); GameObject playerCameraGO = new GameObject($"Camera{networkId.ValueRO.Value}");
playerCameraGO.AddComponent<Camera>(); playerCameraGO.AddComponent<Camera>();
FollowPlayer followScript = playerCameraGO.AddComponent<FollowPlayer>(); FollowPlayer followScript = playerCameraGO.AddComponent<FollowPlayer>();
followScript.networkId = networkId.ValueRO.Value; // Store networkId instead of dire followScript.networkId = networkId.ValueRO.Value;
entityCommandBuffer.AddComponent<GoInGameRequestRpc>(requestGameConnection); entityCommandBuffer.AddComponent<GoInGameRequestRpc>(requestGameConnection);
entityCommandBuffer.AddComponent<SendRpcCommandRequest>(requestGameConnection); entityCommandBuffer.AddComponent<SendRpcCommandRequest>(requestGameConnection);
......
// using Unity.Burst;
// using Unity.Collections;
// using Unity.Entities;
// using Unity.NetCode;
// using UnityEngine;
//
// [WorldSystemFilter(WorldSystemFilterFlags.ClientSimulation | WorldSystemFilterFlags.ThinClientSimulation)]
// partial struct GoInGameClientSystem : ISystem
// {
// [BurstCompile]
// public void OnCreate(ref SystemState state)
// {
// EntityQueryBuilder entityQueryBuilder = new EntityQueryBuilder(Allocator.Temp)
// .WithAll<NetworkId>()
// .WithNone<NetworkStreamInGame>();
// state.RequireForUpdate(state.GetEntityQuery(entityQueryBuilder));
// entityQueryBuilder.Dispose();
// }
//
// public void OnUpdate(ref SystemState state)
// {
// EntityCommandBuffer entityCommandBuffer = new EntityCommandBuffer(Unity.Collections.Allocator.Temp);
// foreach ((
// RefRO<NetworkId> networkId,
// Entity entity)
// in SystemAPI.Query
// <RefRO<NetworkId>>().WithNone<NetworkStreamInGame>().WithEntityAccess())
// {
// entityCommandBuffer.AddComponent<NetworkStreamInGame>(entity);
//
// Entity rpcEntity = entityCommandBuffer.CreateEntity();
// GameObject playerCameraGO = new GameObject($"Camera{networkId.ValueRO.Value}");
// playerCameraGO.AddComponent<Camera>();
//
// // Assign the player entity to FollowPlayer script
// FollowPlayer followScript = playerCameraGO.AddComponent<FollowPlayer>();
// followScript.networkId = networkId.ValueRO.Value; // Store networkId instead of dire
//
// entityCommandBuffer.AddComponent<GoInGameRequestRpc>(rpcEntity);
// entityCommandBuffer.AddComponent<SendRpcCommandRequest>(rpcEntity);
// }
//
// entityCommandBuffer.Playback(state.EntityManager);
// }
//
// [BurstCompile]
// public void OnDestroy(ref SystemState state)
// {
// }
// }
fileFormatVersion: 2
guid: fba7b32c8a6f16243985cbaa18fe1c44
\ No newline at end of file
using Unity.Burst;
using Unity.Collections;
using Unity.Entities;
using Unity.NetCode;
[WorldSystemFilter(WorldSystemFilterFlags.ServerSimulation)]
partial struct ServerStartGameSystem : ISystem
{
public void OnCreate(ref SystemState state)
{
state.RequireForUpdate<NetworkTime>();
state.RequireForUpdate<GameStartProperties>();
state.RequireForUpdate<EntititesReferences>();
state.RequireForUpdate<GamePlayingTag>();
}
}
\ No newline at end of file
fileFormatVersion: 2
guid: 4b9f0553ae9c13c4a8e2e6161fdca969
\ No newline at end of file
...@@ -14,6 +14,8 @@ public partial struct DestroyEntitySystem : ISystem ...@@ -14,6 +14,8 @@ public partial struct DestroyEntitySystem : ISystem
state.RequireForUpdate<RespawnEntityTag>(); state.RequireForUpdate<RespawnEntityTag>();
state.RequireForUpdate<BeginSimulationEntityCommandBufferSystem.Singleton>(); state.RequireForUpdate<BeginSimulationEntityCommandBufferSystem.Singleton>();
state.RequireForUpdate<NetworkTime>(); state.RequireForUpdate<NetworkTime>();
state.RequireForUpdate<GamePlayingTag>();
state.RequireForUpdate<DestroyEntityTag>();
} }
public void OnUpdate(ref SystemState state) public void OnUpdate(ref SystemState state)
...@@ -67,10 +69,6 @@ public partial struct DestroyEntitySystem : ISystem ...@@ -67,10 +69,6 @@ public partial struct DestroyEntitySystem : ISystem
ecb.DestroyEntity(entity); // Destroy non-player entities ecb.DestroyEntity(entity); // Destroy non-player entities
} }
} }
else
{
transform.ValueRW.Position = new float3(1000f, 1000f, 1000f);
}
} }
} }
} }
\ No newline at end of file
...@@ -9,6 +9,8 @@ public partial struct DestroyOnTimerSystem : ISystem ...@@ -9,6 +9,8 @@ public partial struct DestroyOnTimerSystem : ISystem
{ {
state.RequireForUpdate<NetworkTime>(); state.RequireForUpdate<NetworkTime>();
state.RequireForUpdate<EndSimulationEntityCommandBufferSystem.Singleton>(); state.RequireForUpdate<EndSimulationEntityCommandBufferSystem.Singleton>();
state.RequireForUpdate<DestroyAtTick>();
state.RequireForUpdate<GamePlayingTag>();
} }
[BurstCompile] [BurstCompile]
...@@ -19,10 +21,10 @@ public partial struct DestroyOnTimerSystem : ISystem ...@@ -19,10 +21,10 @@ public partial struct DestroyOnTimerSystem : ISystem
var currentTick = SystemAPI.GetSingleton<NetworkTime>().ServerTick; var currentTick = SystemAPI.GetSingleton<NetworkTime>().ServerTick;
foreach (var (destroyAtTick, entity) in SystemAPI.Query<DestroyAtTick>().WithAll<Simulate>() foreach (var (destroyAtTick, entity) in SystemAPI.Query<RefRW<DestroyAtTick>>().WithAll<Simulate>()
.WithNone<DestroyEntityTag>().WithEntityAccess()) .WithNone<DestroyEntityTag>().WithEntityAccess())
{ {
if (currentTick.Equals(destroyAtTick.Value) || currentTick.IsNewerThan(destroyAtTick.Value)) if (currentTick.Equals(destroyAtTick.ValueRW.Value) || currentTick.IsNewerThan(destroyAtTick.ValueRW.Value))
{ {
ecb.AddComponent<DestroyEntityTag>(entity); ecb.AddComponent<DestroyEntityTag>(entity);
} }
......
...@@ -7,6 +7,8 @@ public partial struct InitializeDestroyOnTimerSystem : ISystem ...@@ -7,6 +7,8 @@ public partial struct InitializeDestroyOnTimerSystem : ISystem
public void OnCreate(ref SystemState state) public void OnCreate(ref SystemState state)
{ {
state.RequireForUpdate<NetworkTime>(); state.RequireForUpdate<NetworkTime>();
state.RequireForUpdate<DestroyOnTimer>();
state.RequireForUpdate<GamePlayingTag>();
} }
public void OnUpdate(ref SystemState state) public void OnUpdate(ref SystemState state)
...@@ -15,10 +17,10 @@ public partial struct InitializeDestroyOnTimerSystem : ISystem ...@@ -15,10 +17,10 @@ public partial struct InitializeDestroyOnTimerSystem : ISystem
var simulationTickRate = NetCodeConfig.Global.ClientServerTickRate.SimulationTickRate; var simulationTickRate = NetCodeConfig.Global.ClientServerTickRate.SimulationTickRate;
var currentTick = SystemAPI.GetSingleton<NetworkTime>().ServerTick; var currentTick = SystemAPI.GetSingleton<NetworkTime>().ServerTick;
foreach (var (destroyOnTimer, entity) in SystemAPI.Query<DestroyOnTimer>().WithNone<DestroyAtTick>() foreach (var (destroyOnTimer, entity) in SystemAPI.Query<RefRW<DestroyOnTimer>>().WithNone<DestroyAtTick>()
.WithEntityAccess()) .WithEntityAccess())
{ {
var lifetimeInTicks = (uint)(destroyOnTimer.Value * simulationTickRate); var lifetimeInTicks = (uint)(destroyOnTimer.ValueRW.Value * simulationTickRate);
var targetTick = currentTick; var targetTick = currentTick;
targetTick.Add(lifetimeInTicks); targetTick.Add(lifetimeInTicks);
ecb.AddComponent(entity, new DestroyAtTick { Value = targetTick }); ecb.AddComponent(entity, new DestroyAtTick { Value = targetTick });
......
...@@ -17,6 +17,7 @@ public partial class RespawnPlayerSystem : SystemBase ...@@ -17,6 +17,7 @@ public partial class RespawnPlayerSystem : SystemBase
{ {
RequireForUpdate<NetworkTime>(); RequireForUpdate<NetworkTime>();
RequireForUpdate<TeamTypes>(); RequireForUpdate<TeamTypes>();
RequireForUpdate<GamePlayingTag>();
} }
protected override void OnStartRunning() protected override void OnStartRunning()
......
...@@ -36,7 +36,7 @@ partial struct EnemySpawnerSystem : ISystem ...@@ -36,7 +36,7 @@ partial struct EnemySpawnerSystem : ISystem
float randomValue = aspect.RandomSpawnOffset; float randomValue = aspect.RandomSpawnOffset;
float3 spawnPosition = float3 spawnPosition =
spawnPoints[slimeSpawnIndex].SpawnPoint + new float3(randomValue, 0, -randomValue); spawnPoints[slimeSpawnIndex].SpawnPoint + new float3(randomValue, 0, -randomValue);
SpawnEnemy(ecb, enemySlimeEntity, spawnPosition); SpawnEnemy(ecb, enemySlimeEntity, spawnPosition);
aspect.IncreaseSlimeCounter(); aspect.IncreaseSlimeCounter();
aspect.ResetSlimeTimer(); aspect.ResetSlimeTimer();
} }
......
using System;
using Unity.Burst; using Unity.Burst;
using Unity.Entities; using Unity.Entities;
using Unity.Mathematics; using Unity.Mathematics;
...@@ -15,15 +16,19 @@ public partial class NetcodePlayerInputSystem : SystemBase ...@@ -15,15 +16,19 @@ public partial class NetcodePlayerInputSystem : SystemBase
_inputActions = new InputSystem_Actions(); _inputActions = new InputSystem_Actions();
_inputActions.Enable(); _inputActions.Enable();
RequireForUpdate<NetworkStreamInGame>(); RequireForUpdate<NetworkStreamInGame>();
RequireForUpdate<GamePlayingTag>();
RequireForUpdate<NetcodePlayerInput>(); RequireForUpdate<NetcodePlayerInput>();
RequireForUpdate<PlayerSprintData>();
} }
protected override void OnUpdate() protected override void OnUpdate()
{ {
foreach (RefRW<NetcodePlayerInput> netcodePlayerInput in SystemAPI.Query<RefRW<NetcodePlayerInput>>() foreach ((RefRW<NetcodePlayerInput> netcodePlayerInput, RefRW<PlayerSprintData> playerSprintData)
in SystemAPI.Query<RefRW<NetcodePlayerInput>, RefRW<PlayerSprintData>>()
.WithAll<GhostOwnerIsLocal>()) .WithAll<GhostOwnerIsLocal>())
{ {
netcodePlayerInput.ValueRW.inputVector = _inputActions.Player.Move.ReadValue<Vector2>(); netcodePlayerInput.ValueRW.inputVector = _inputActions.Player.Move.ReadValue<Vector2>();
playerSprintData.ValueRW.isSprinting = true;
} }
} }
......
...@@ -4,11 +4,22 @@ using Unity.Mathematics; ...@@ -4,11 +4,22 @@ using Unity.Mathematics;
using Unity.NetCode; using Unity.NetCode;
using Unity.Physics; using Unity.Physics;
using Unity.Transforms; using Unity.Transforms;
using UnityEngine;
[UpdateInGroup(typeof(PredictedSimulationSystemGroup))] [UpdateInGroup(typeof(PredictedSimulationSystemGroup))]
partial struct NetcodePlayerMovementSystem : ISystem partial struct NetcodePlayerMovementSystem : ISystem
{ {
[BurstCompile] [BurstCompile]
public void OnCreate(ref SystemState state)
{
state.RequireForUpdate<NetcodePlayerInput>();
state.RequireForUpdate<PhysicsVelocity>();
state.RequireForUpdate<LocalTransform>();
state.RequireForUpdate<PlayerSprintData>();
state.RequireForUpdate<GamePlayingTag>();
}
[BurstCompile]
public void OnUpdate(ref SystemState state) public void OnUpdate(ref SystemState state)
{ {
float deltaTime = SystemAPI.Time.DeltaTime; float deltaTime = SystemAPI.Time.DeltaTime;
...@@ -22,41 +33,37 @@ partial struct NetcodePlayerMovementSystem : ISystem ...@@ -22,41 +33,37 @@ partial struct NetcodePlayerMovementSystem : ISystem
{ {
float3 moveVector = new float3(netcodePlayerInput.ValueRO.inputVector.x, 0, float3 moveVector = new float3(netcodePlayerInput.ValueRO.inputVector.x, 0,
netcodePlayerInput.ValueRO.inputVector.y); netcodePlayerInput.ValueRO.inputVector.y);
float moveSpeed = sprintData.ValueRO.isSprinting float moveSpeed;
? sprintData.ValueRO.sprintSpeed if (sprintData.ValueRO.isSprinting)
: sprintData.ValueRO.walkSpeed; moveSpeed = sprintData.ValueRO.walkSpeed;
else
moveSpeed = sprintData.ValueRO.sprintSpeed;
// Update sprinting logic if (sprintData.ValueRO.isSprinting)
if (sprintData.ValueRO.isSprinting && !sprintData.ValueRO.isSprintCooldown)
{ {
sprintData.ValueRW.sprintRemaining -= deltaTime; if (!sprintData.ValueRO.isSprintCooldown)
if (sprintData.ValueRW.sprintRemaining <= 0)
{ {
sprintData.ValueRW.isSprinting = false; sprintData.ValueRW.sprintRemaining -= deltaTime;
sprintData.ValueRW.isSprintCooldown = true; if (sprintData.ValueRW.sprintRemaining <= 0)
{
sprintData.ValueRW.isSprintCooldown = true;
sprintData.ValueRW.sprintCooldown = sprintData.ValueRO.sprintCooldownReset;
}
} }
} }
else else
{ {
sprintData.ValueRW.sprintRemaining = math.clamp(sprintData.ValueRW.sprintRemaining + deltaTime, 0, if (!sprintData.ValueRO.isSprintCooldown)
sprintData.ValueRO.sprintDuration);
}
if (sprintData.ValueRO.isSprintCooldown)
{
sprintData.ValueRW.sprintCooldown -= deltaTime;
if (sprintData.ValueRW.sprintCooldown <= 0)
{ {
sprintData.ValueRW.isSprintCooldown = false; sprintData.ValueRW.sprintRemaining = math.clamp(sprintData.ValueRW.sprintRemaining + deltaTime, 0,
sprintData.ValueRW.sprintCooldown = sprintData.ValueRO.sprintCooldownReset; sprintData.ValueRO.sprintDuration);
} }
} }
// Apply smooth movement
physicsVelocity.ValueRW.Linear = physicsVelocity.ValueRW.Linear =
math.lerp(physicsVelocity.ValueRO.Linear, moveVector * moveSpeed, deltaTime * 10); math.lerp(physicsVelocity.ValueRO.Linear, moveVector * moveSpeed, deltaTime * 10);
// Optionally, update the rotation to face the movement direction
if (!math.all(moveVector == float3.zero)) if (!math.all(moveVector == float3.zero))
{ {
quaternion targetRotation = quaternion.LookRotationSafe(moveVector, math.up()); quaternion targetRotation = quaternion.LookRotationSafe(moveVector, math.up());
......
...@@ -150,9 +150,5 @@ public class ClientConnectionManager : MonoBehaviour ...@@ -150,9 +150,5 @@ public class ClientConnectionManager : MonoBehaviour
} }
World.DefaultGameObjectInjectionWorld = clientWorld; World.DefaultGameObjectInjectionWorld = clientWorld;
var ConnectionRequestEntity = clientWorld.EntityManager.CreateEntity();
clientWorld.EntityManager.AddComponentData(ConnectionRequestEntity, new ClientConnectionRpc());
} }
} }
\ No newline at end of file
...@@ -147,11 +147,11 @@ MonoBehaviour: ...@@ -147,11 +147,11 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: a82f6d8766908894faabdee547539756, type: 3} m_Script: {fileID: 11500000, guid: a82f6d8766908894faabdee547539756, type: 3}
m_Name: m_Name:
m_EditorClassIdentifier: m_EditorClassIdentifier:
sprintRemaining: 5 sprintRemaining: 8
sprintDuration: 5 sprintDuration: 8
sprintSpeed: 12 sprintSpeed: 25
walkSpeed: 9 walkSpeed: 1
sprintCooldownReset: 2 sprintCooldownReset: 1
--- !u!114 &3955402020692204287 --- !u!114 &3955402020692204287
MonoBehaviour: MonoBehaviour:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
...@@ -320,7 +320,7 @@ MonoBehaviour: ...@@ -320,7 +320,7 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 8e73c985659b81d408f4e99cb152349d, type: 3} m_Script: {fileID: 11500000, guid: 8e73c985659b81d408f4e99cb152349d, type: 3}
m_Name: m_Name:
m_EditorClassIdentifier: m_EditorClassIdentifier:
MaxHitPoints: 20000 MaxHitPoints: 500
--- !u!1001 &6975352639711469968 --- !u!1001 &6975352639711469968
PrefabInstance: PrefabInstance:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
......
...@@ -490,7 +490,7 @@ MonoBehaviour: ...@@ -490,7 +490,7 @@ MonoBehaviour:
SlimeAmountContainer: {fileID: 7438304585132253661} SlimeAmountContainer: {fileID: 7438304585132253661}
_connectButton: {fileID: 661734915} _connectButton: {fileID: 661734915}
_gameStartCountDownTime: 2 _gameStartCountDownTime: 2
_slimeSpawnCooldownTime: 0.3 _slimeSpawnCooldownTime: 0.1
_rogueSpawnCooldownTime: 1 _rogueSpawnCooldownTime: 1
--- !u!114 &1734898360 stripped --- !u!114 &1734898360 stripped
MonoBehaviour: MonoBehaviour:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment