Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Multiplayer-arena-game
/
Multiplayer-arena-game-Entities
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
b4e7688f
authored
Apr 11, 2025
by
alsunj
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add slime target and moving system
parent
752a165c
Hide whitespace changes
Inline
Side-by-side
Showing
34 changed files
with
185 additions
and
211 deletions
Assets/_Game/Code/Authoring/Enemy/DamageOnTriggerAuthoring.cs → Assets/_Game/Code/Authoring/Enemy/DamageOnCollisionAuthoring.cs
Assets/_Game/Code/Authoring/Enemy/DamageOnTriggerAuthoring.cs.meta → Assets/_Game/Code/Authoring/Enemy/DamageOnCollisionAuthoring.cs.meta
Assets/_Game/Code/Authoring/Enemy/SlimeTargetAuthoring.cs
Assets/_Game/Code/Authoring/Player/EntitiesReferencesAuthoring.cs
Assets/_Game/Code/Components/Combat/CombatComponents.cs
Assets/_Game/Code/Components/Connection/GameBootstrap.cs
Assets/_Game/Code/Components/Player/PlayerComponents.cs
Assets/_Game/Code/Components/RPCs/RpcComponents.cs
Assets/_Game/Code/Input/NetcodePlayerInputAuthoring.cs
Assets/_Game/Code/Systems/Combat/ApplyDamageSystem.cs
Assets/_Game/Code/Systems/Combat/CalculateFrameDamageSystem.cs
Assets/_Game/Code/Systems/Combat/DamageOnTriggerSystem.cs
Assets/_Game/Code/Systems/Combat/MoveAbilitySystem.cs
Assets/_Game/Code/Systems/Combat/MoveSlimeSystem.cs
Assets/_Game/Code/Systems/Combat/NpcTargetingSystem.cs
Assets/_Game/Code/Systems/Combat/NpcAttackSystem.cs → Assets/_Game/Code/Systems/Combat/RogueAttackSystem.cs
Assets/_Game/Code/Systems/Combat/NpcAttackSystem.cs.meta → Assets/_Game/Code/Systems/Combat/RogueAttackSystem.cs.meta
Assets/_Game/Code/Systems/Combat/SetTargetSlimeSystem.cs
Assets/_Game/Code/Components/Connection/GameBootstrap.cs.meta → Assets/_Game/Code/Systems/Combat/SetTargetSlimeSystem.cs.meta
Assets/_Game/Code/Systems/Connection/ClientRequestGameEntrySystem.cs
Assets/_Game/Code/Systems/Connection/GoInGameClientSystem.cs
Assets/_Game/Code/Systems/Connection/GoInGameClientSystem.cs.meta
Assets/_Game/Code/Systems/Connection/ServerStartGameSystem.cs
Assets/_Game/Code/Systems/Connection/ServerStartGameSystem.cs.meta
Assets/_Game/Code/Systems/Destroy/DestroyEntitySystem.cs
Assets/_Game/Code/Systems/Destroy/DestroyOnTimerSystem.cs
Assets/_Game/Code/Systems/Destroy/InitializeDestroyOnTimerSystem.cs
Assets/_Game/Code/Systems/Destroy/RespawnPlayerSystem.cs
Assets/_Game/Code/Systems/Enemy/EnemySpawnerSystem.cs
Assets/_Game/Code/Systems/Input/NetcodePlayerInputSystem.cs
Assets/_Game/Code/Systems/Input/NetcodePlayerMovementSystem.cs
Assets/_Game/Mono/ClientConnectionManager.cs
Assets/_Game/Prefabs/Player/Player.prefab
Assets/_Game/Scenes/ConnectionScene.unity
Assets/_Game/Code/Authoring/Enemy/DamageOn
Trigger
Authoring.cs
→
Assets/_Game/Code/Authoring/Enemy/DamageOn
Collision
Authoring.cs
View file @
b4e7688f
using
Unity.Entities
;
using
UnityEngine
;
public
class
DamageOn
Trigger
Authoring
:
MonoBehaviour
public
class
DamageOn
Collision
Authoring
:
MonoBehaviour
{
public
int
DamageOnTrigger
;
public
class
DamageOn
TriggerBaker
:
Baker
<
DamageOnTrigger
Authoring
>
public
class
DamageOn
CollisionBaker
:
Baker
<
DamageOnCollision
Authoring
>
{
public
override
void
Bake
(
DamageOn
Trigger
Authoring
authoring
)
public
override
void
Bake
(
DamageOn
Collision
Authoring
authoring
)
{
var
entity
=
GetEntity
(
TransformUsageFlags
.
Dynamic
);
AddComponent
(
entity
,
new
DamageOn
Trigger
{
Value
=
authoring
.
DamageOnTrigger
});
AddComponent
(
entity
,
new
DamageOn
Collision
{
Value
=
authoring
.
DamageOnTrigger
});
AddBuffer
<
AlreadyDamagedEntity
>(
entity
);
}
}
...
...
Assets/_Game/Code/Authoring/Enemy/DamageOn
Trigger
Authoring.cs.meta
→
Assets/_Game/Code/Authoring/Enemy/DamageOn
Collision
Authoring.cs.meta
View file @
b4e7688f
File moved
Assets/_Game/Code/Authoring/Enemy/SlimeTargetAuthoring.cs
View file @
b4e7688f
...
...
@@ -25,6 +25,7 @@ public class SlimeTargetAuthoring : MonoBehaviour
});
AddComponent
<
NpcTargetEntity
>(
entity
);
AddComponent
<
SlimeTag
>(
entity
);
AddComponent
<
SlimeTargetDirection
>(
entity
);
AddBuffer
<
NpcAttackCooldown
>(
entity
);
}
}
...
...
Assets/_Game/Code/Authoring/Player/EntitiesReferencesAuthoring.cs
View file @
b4e7688f
...
...
@@ -23,10 +23,6 @@ public class EntitiesReferencesAuthoring : MonoBehaviour
SlimeEnemyEntity
=
GetEntity
(
authoring
.
SlimeEnemyGameObject
,
TransformUsageFlags
.
Dynamic
),
RespawnEntity
=
GetEntity
(
authoring
.
RespawnEntity
,
TransformUsageFlags
.
None
)
});
AddComponentObject
(
entity
,
new
UIPrefabs
{
HealthBar
=
authoring
.
HealthBarPrefab
,
});
}
}
}
...
...
@@ -37,11 +33,5 @@ public struct EntititesReferences : IComponentData
public
Entity
PlayerPrefabEntity
;
public
Entity
RougeEnemyEntity
;
public
Entity
SlimeEnemyEntity
;
public
Entity
RespawnEntity
;
}
public
class
UIPrefabs
:
IComponentData
{
public
GameObject
HealthBar
;
}
\ No newline at end of file
Assets/_Game/Code/Components/Combat/CombatComponents.cs
View file @
b4e7688f
...
...
@@ -46,7 +46,7 @@ public struct AbilityMoveSpeed : IComponentData
public
float
Value
;
}
public
struct
DamageOn
Trigger
:
IComponentData
public
struct
DamageOn
Collision
:
IComponentData
{
public
int
Value
;
}
...
...
@@ -81,4 +81,9 @@ public struct CurrentHitPoints : IComponentData
public
struct
SlimeTag
:
IComponentData
{
}
public
struct
SlimeTargetDirection
:
IComponentData
{
public
float3
Value
;
}
\ No newline at end of file
Assets/_Game/Code/Components/Connection/GameBootstrap.cs
deleted
100644 → 0
View file @
752a165c
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
Assets/_Game/Code/Components/Player/PlayerComponents.cs
View file @
b4e7688f
...
...
@@ -20,32 +20,10 @@ public struct PlayerSprintData : IComponentData
public
float
sprintCooldownReset
;
}
public
struct
PlayerAttackData
:
IComponentData
{
public
float
attackCooldownTimer
;
}
public
struct
PlayerDefenceData
:
IComponentData
{
public
float
defenceCooldownTimer
;
}
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
{
[
GhostField
]
public
TeamType
Value
;
...
...
Assets/_Game/Code/Components/RPCs/RpcComponents.cs
View file @
b4e7688f
...
...
@@ -4,10 +4,6 @@ public struct GoInGameRequestRpc : IRpcCommand
{
}
public
struct
ClientConnectionRpc
:
IRpcCommand
{
}
public
struct
PlayersRemainingToStart
:
IRpcCommand
{
public
int
Value
;
...
...
Assets/_Game/Code/Input/NetcodePlayerInputAuthoring.cs
View file @
b4e7688f
...
...
@@ -5,11 +5,11 @@ using UnityEngine;
public
class
NetcodePlayerInputAuthoring
:
MonoBehaviour
{
public
float
sprintRemaining
=
5f
;
public
float
sprintDuration
=
5f
;
public
float
sprintSpeed
=
12f
;
public
float
walkSpeed
=
9f
;
public
float
sprintCooldownReset
=
2f
;
public
float
sprintRemaining
;
public
float
sprintDuration
;
public
float
sprintSpeed
;
public
float
walkSpeed
;
public
float
sprintCooldownReset
;
public
class
Baker
:
Baker
<
NetcodePlayerInputAuthoring
>
{
...
...
@@ -20,19 +20,13 @@ public class NetcodePlayerInputAuthoring : MonoBehaviour
AddComponent
(
entity
,
new
PlayerSprintData
{
isSprinting
=
false
,
isSprintCooldown
=
false
,
sprintRemaining
=
authoring
.
sprintRemaining
,
sprintDuration
=
authoring
.
sprintDuration
,
sprintSpeed
=
authoring
.
sprintSpeed
,
walkSpeed
=
authoring
.
walkSpeed
,
sprintCooldown
=
0f
,
sprintCooldownReset
=
authoring
.
sprintCooldownReset
,
});
AddComponent
(
entity
,
new
PlayerAttackData
());
AddComponent
(
entity
,
new
PlayerDefenceData
());
AddComponent
<
PlayerTag
>(
entity
);
}
}
}
}
\ No newline at end of file
Assets/_Game/Code/Systems/Combat/ApplyDamageSystem.cs
View file @
b4e7688f
...
...
@@ -11,6 +11,7 @@ public partial struct ApplyDamageSystem : ISystem
public
void
OnCreate
(
ref
SystemState
state
)
{
state
.
RequireForUpdate
<
NetworkTime
>();
state
.
RequireForUpdate
<
GamePlayingTag
>();
}
[
BurstCompile
]
...
...
Assets/_Game/Code/Systems/Combat/CalculateFrameDamageSystem.cs
View file @
b4e7688f
...
...
@@ -8,6 +8,8 @@ public partial struct CalculateFrameDamageSystem : ISystem
public
void
OnCreate
(
ref
SystemState
state
)
{
state
.
RequireForUpdate
<
NetworkTime
>();
state
.
RequireForUpdate
<
GamePlayingTag
>();
state
.
RequireForUpdate
<
DamageBufferElement
>();
}
[
BurstCompile
]
...
...
Assets/_Game/Code/Systems/Combat/DamageOnTriggerSystem.cs
View file @
b4e7688f
...
...
@@ -12,6 +12,7 @@ public partial struct DamageOnCollisionSystem : ISystem
{
state
.
RequireForUpdate
<
SimulationSingleton
>();
state
.
RequireForUpdate
<
EndSimulationEntityCommandBufferSystem
.
Singleton
>();
state
.
RequireForUpdate
<
GamePlayingTag
>();
}
[
BurstCompile
]
...
...
@@ -20,7 +21,7 @@ public partial struct DamageOnCollisionSystem : ISystem
var
ecbSingleton
=
SystemAPI
.
GetSingleton
<
EndSimulationEntityCommandBufferSystem
.
Singleton
>();
var
damageOnCollisionJob
=
new
DamageOnCollisionJob
{
DamageOn
TriggerLookup
=
SystemAPI
.
GetComponentLookup
<
DamageOnTrigger
>(
true
),
DamageOn
CollisionLookup
=
SystemAPI
.
GetComponentLookup
<
DamageOnCollision
>(
true
),
TeamLookup
=
SystemAPI
.
GetComponentLookup
<
TeamTypes
>(
true
),
AlreadyDamagedLookup
=
SystemAPI
.
GetBufferLookup
<
AlreadyDamagedEntity
>(
true
),
DamageBufferLookup
=
SystemAPI
.
GetBufferLookup
<
DamageBufferElement
>(
true
),
...
...
@@ -34,7 +35,7 @@ public partial struct DamageOnCollisionSystem : ISystem
public
struct
DamageOnCollisionJob
:
ICollisionEventsJob
{
[
ReadOnly
]
public
ComponentLookup
<
DamageOn
Trigger
>
DamageOnTrigger
Lookup
;
[
ReadOnly
]
public
ComponentLookup
<
DamageOn
Collision
>
DamageOnCollision
Lookup
;
[
ReadOnly
]
public
ComponentLookup
<
TeamTypes
>
TeamLookup
;
public
BufferLookup
<
AlreadyDamagedEntity
>
AlreadyDamagedLookup
;
public
BufferLookup
<
DamageBufferElement
>
DamageBufferLookup
;
...
...
@@ -49,12 +50,12 @@ public struct DamageOnCollisionJob : ICollisionEventsJob
Entity
damageReceivingEntity
=
Entity
.
Null
;
if
(
DamageBufferLookup
.
HasBuffer
(
entityA
)
&&
DamageOn
Trigger
Lookup
.
HasComponent
(
entityB
))
DamageOn
Collision
Lookup
.
HasComponent
(
entityB
))
{
damageReceivingEntity
=
entityA
;
damageDealingEntity
=
entityB
;
}
else
if
(
DamageOn
Trigger
Lookup
.
HasComponent
(
entityA
)
&&
else
if
(
DamageOn
Collision
Lookup
.
HasComponent
(
entityA
)
&&
DamageBufferLookup
.
HasBuffer
(
entityB
))
{
damageDealingEntity
=
entityA
;
...
...
@@ -84,7 +85,7 @@ public struct DamageOnCollisionJob : ICollisionEventsJob
if
(
damageDealingTeam
.
Value
==
damageReceivingTeam
.
Value
)
return
;
}
if
(
DamageOn
Trigger
Lookup
.
TryGetComponent
(
damageDealingEntity
,
out
var
damageOnTrigger
))
if
(
DamageOn
Collision
Lookup
.
TryGetComponent
(
damageDealingEntity
,
out
var
damageOnTrigger
))
{
ECB
.
AddComponent
<
DestroyEntityTag
>(
damageDealingEntity
);
ECB
.
AppendToBuffer
(
damageReceivingEntity
,
new
DamageBufferElement
{
Value
=
damageOnTrigger
.
Value
});
...
...
Assets/_Game/Code/Systems/Combat/MoveAbilitySystem.cs
View file @
b4e7688f
...
...
@@ -6,6 +6,11 @@ using Unity.Transforms;
[UpdateInGroup(typeof(PredictedSimulationSystemGroup))]
public
partial
struct
MoveAbilitySystem
:
ISystem
{
public
void
OnCreate
(
ref
SystemState
state
)
{
state
.
RequireForUpdate
<
AbilityMoveSpeed
>();
}
public
void
OnUpdate
(
ref
SystemState
state
)
{
var
deltaTime
=
SystemAPI
.
Time
.
DeltaTime
;
...
...
Assets/_Game/Code/Systems/Combat/MoveSlimeSystem.cs
View file @
b4e7688f
using
Unity.Burst
;
using
Unity.Entities
;
using
Unity.Mathematics
;
using
Unity.NetCode
;
using
Unity.Transforms
;
...
...
@@ -8,29 +8,34 @@ public partial struct MoveSlimeSystem : ISystem
{
public
void
OnCreate
(
ref
SystemState
state
)
{
state
.
RequireForUpdate
<
AbilityMoveSpeed
>();
state
.
RequireForUpdate
<
TeamTypes
>();
state
.
RequireForUpdate
<
NpcTargetEntity
>();
state
.
RequireForUpdate
<
NetworkTime
>();
state
.
RequireForUpdate
<
EndSimulationEntityCommandBufferSystem
.
Singleton
>();
state
.
RequireForUpdate
<
SlimeTargetDirection
>();
state
.
RequireForUpdate
<
SlimeTag
>();
}
[
BurstCompile
]
public
void
OnUpdate
(
ref
SystemState
state
)
{
var
deltaTime
=
SystemAPI
.
Time
.
DeltaTime
;
var
localTransformLookup
=
SystemAPI
.
GetComponentLookup
<
LocalTransform
>(
true
);
foreach
(
var
(
transform
,
moveSpeed
,
teamType
,
targetEntity
)
in
SystemAPI
.
Query
<
RefRW
<
LocalTransform
>,
RefRO
<
AbilityMoveSpeed
>,
RefRO
<
TeamTypes
>,
RefRO
<
NpcTargetEntity
>>()
.
WithAny
<
SlimeTag
>())
state
.
Dependency
=
new
MoveSlimeJob
{
if
(
teamType
.
ValueRO
.
Value
==
TeamType
.
Enemy
&&
targetEntity
.
ValueRO
.
Value
!=
Entity
.
Null
)
{
if
(
localTransformLookup
.
HasComponent
(
targetEntity
.
ValueRO
.
Value
))
{
var
targetPosition
=
localTransformLookup
[
targetEntity
.
ValueRO
.
Value
].
Position
;
var
direction
=
math
.
normalize
(
targetPosition
-
transform
.
ValueRW
.
Position
);
transform
.
ValueRW
.
Position
+=
direction
*
moveSpeed
.
ValueRO
.
Value
*
deltaTime
;
}
}
}
DeltaTime
=
deltaTime
}.
ScheduleParallel
(
state
.
Dependency
);
}
}
[BurstCompile]
[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
Assets/_Game/Code/Systems/Combat/NpcTargetingSystem.cs
View file @
b4e7688f
...
...
@@ -16,6 +16,7 @@ public partial struct NpcTargetingSystem : ISystem
public
void
OnCreate
(
ref
SystemState
state
)
{
state
.
RequireForUpdate
<
PhysicsWorldSingleton
>();
state
.
RequireForUpdate
<
GamePlayingTag
>();
_npcAttackFilter
=
new
CollisionFilter
{
BelongsTo
=
1
<<
6
,
//Target Cast
...
...
Assets/_Game/Code/Systems/Combat/
Npc
AttackSystem.cs
→
Assets/_Game/Code/Systems/Combat/
Rogue
AttackSystem.cs
View file @
b4e7688f
...
...
@@ -6,12 +6,13 @@ using Unity.NetCode;
using
Unity.Transforms
;
[UpdateInGroup(typeof(PredictedSimulationSystemGroup))]
public
partial
struct
Npc
AttackSystem
:
ISystem
public
partial
struct
Rogue
AttackSystem
:
ISystem
{
public
void
OnCreate
(
ref
SystemState
state
)
{
state
.
RequireForUpdate
<
NetworkTime
>();
state
.
RequireForUpdate
<
BeginSimulationEntityCommandBufferSystem
.
Singleton
>();
state
.
RequireForUpdate
<
GamePlayingTag
>();
}
public
void
OnUpdate
(
ref
SystemState
state
)
...
...
Assets/_Game/Code/Systems/Combat/
Npc
AttackSystem.cs.meta
→
Assets/_Game/Code/Systems/Combat/
Rogue
AttackSystem.cs.meta
View file @
b4e7688f
File moved
Assets/_Game/Code/Systems/Combat/SetTargetSlimeSystem.cs
0 → 100644
View file @
b4e7688f
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
Assets/_Game/Code/
Components/Connection/GameBootstrap
.cs.meta
→
Assets/_Game/Code/
Systems/Combat/SetTargetSlimeSystem
.cs.meta
View file @
b4e7688f
fileFormatVersion: 2
guid: 6236f73d74af5b04da99a398ca41c536
\ No newline at end of file
guid: 86f8c4a7fca9c2244981a82be26b0c7d
\ No newline at end of file
Assets/_Game/Code/Systems/Connection/ClientRequestGameEntrySystem.cs
View file @
b4e7688f
...
...
@@ -32,7 +32,7 @@ public partial struct ClientRequestGameEntrySystem : ISystem
GameObject
playerCameraGO
=
new
GameObject
(
$"Camera
{
networkId
.
ValueRO
.
Value
}
"
);
playerCameraGO
.
AddComponent
<
Camera
>();
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
<
SendRpcCommandRequest
>(
requestGameConnection
);
...
...
Assets/_Game/Code/Systems/Connection/GoInGameClientSystem.cs
deleted
100644 → 0
View file @
752a165c
// 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)
// {
// }
// }
Assets/_Game/Code/Systems/Connection/GoInGameClientSystem.cs.meta
deleted
100644 → 0
View file @
752a165c
fileFormatVersion: 2
guid: fba7b32c8a6f16243985cbaa18fe1c44
\ No newline at end of file
Assets/_Game/Code/Systems/Connection/ServerStartGameSystem.cs
deleted
100644 → 0
View file @
752a165c
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
Assets/_Game/Code/Systems/Connection/ServerStartGameSystem.cs.meta
deleted
100644 → 0
View file @
752a165c
fileFormatVersion: 2
guid: 4b9f0553ae9c13c4a8e2e6161fdca969
\ No newline at end of file
Assets/_Game/Code/Systems/Destroy/DestroyEntitySystem.cs
View file @
b4e7688f
...
...
@@ -14,6 +14,8 @@ public partial struct DestroyEntitySystem : ISystem
state
.
RequireForUpdate
<
RespawnEntityTag
>();
state
.
RequireForUpdate
<
BeginSimulationEntityCommandBufferSystem
.
Singleton
>();
state
.
RequireForUpdate
<
NetworkTime
>();
state
.
RequireForUpdate
<
GamePlayingTag
>();
state
.
RequireForUpdate
<
DestroyEntityTag
>();
}
public
void
OnUpdate
(
ref
SystemState
state
)
...
...
@@ -67,10 +69,6 @@ public partial struct DestroyEntitySystem : ISystem
ecb
.
DestroyEntity
(
entity
);
// Destroy non-player entities
}
}
else
{
transform
.
ValueRW
.
Position
=
new
float3
(
1000f
,
1000f
,
1000f
);
}
}
}
}
\ No newline at end of file
Assets/_Game/Code/Systems/Destroy/DestroyOnTimerSystem.cs
View file @
b4e7688f
...
...
@@ -9,6 +9,8 @@ public partial struct DestroyOnTimerSystem : ISystem
{
state
.
RequireForUpdate
<
NetworkTime
>();
state
.
RequireForUpdate
<
EndSimulationEntityCommandBufferSystem
.
Singleton
>();
state
.
RequireForUpdate
<
DestroyAtTick
>();
state
.
RequireForUpdate
<
GamePlayingTag
>();
}
[
BurstCompile
]
...
...
@@ -19,10 +21,10 @@ public partial struct DestroyOnTimerSystem : ISystem
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
())
{
if
(
currentTick
.
Equals
(
destroyAtTick
.
Value
)
||
currentTick
.
IsNewerThan
(
destroyAtTick
.
Value
))
if
(
currentTick
.
Equals
(
destroyAtTick
.
Value
RW
.
Value
)
||
currentTick
.
IsNewerThan
(
destroyAtTick
.
ValueRW
.
Value
))
{
ecb
.
AddComponent
<
DestroyEntityTag
>(
entity
);
}
...
...
Assets/_Game/Code/Systems/Destroy/InitializeDestroyOnTimerSystem.cs
View file @
b4e7688f
...
...
@@ -7,6 +7,8 @@ public partial struct InitializeDestroyOnTimerSystem : ISystem
public
void
OnCreate
(
ref
SystemState
state
)
{
state
.
RequireForUpdate
<
NetworkTime
>();
state
.
RequireForUpdate
<
DestroyOnTimer
>();
state
.
RequireForUpdate
<
GamePlayingTag
>();
}
public
void
OnUpdate
(
ref
SystemState
state
)
...
...
@@ -15,10 +17,10 @@ public partial struct InitializeDestroyOnTimerSystem : ISystem
var
simulationTickRate
=
NetCodeConfig
.
Global
.
ClientServerTickRate
.
SimulationTickRate
;
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
())
{
var
lifetimeInTicks
=
(
uint
)(
destroyOnTimer
.
Value
*
simulationTickRate
);
var
lifetimeInTicks
=
(
uint
)(
destroyOnTimer
.
Value
RW
.
Value
*
simulationTickRate
);
var
targetTick
=
currentTick
;
targetTick
.
Add
(
lifetimeInTicks
);
ecb
.
AddComponent
(
entity
,
new
DestroyAtTick
{
Value
=
targetTick
});
...
...
Assets/_Game/Code/Systems/Destroy/RespawnPlayerSystem.cs
View file @
b4e7688f
...
...
@@ -17,6 +17,7 @@ public partial class RespawnPlayerSystem : SystemBase
{
RequireForUpdate
<
NetworkTime
>();
RequireForUpdate
<
TeamTypes
>();
RequireForUpdate
<
GamePlayingTag
>();
}
protected
override
void
OnStartRunning
()
...
...
Assets/_Game/Code/Systems/Enemy/EnemySpawnerSystem.cs
View file @
b4e7688f
...
...
@@ -36,7 +36,7 @@ partial struct EnemySpawnerSystem : ISystem
float
randomValue
=
aspect
.
RandomSpawnOffset
;
float3
spawnPosition
=
spawnPoints
[
slimeSpawnIndex
].
SpawnPoint
+
new
float3
(
randomValue
,
0
,
-
randomValue
);
SpawnEnemy
(
ecb
,
enemySlimeEntity
,
spawnPosition
);
SpawnEnemy
(
ecb
,
enemySlimeEntity
,
spawnPosition
);
aspect
.
IncreaseSlimeCounter
();
aspect
.
ResetSlimeTimer
();
}
...
...
Assets/_Game/Code/Systems/Input/NetcodePlayerInputSystem.cs
View file @
b4e7688f
using
System
;
using
Unity.Burst
;
using
Unity.Entities
;
using
Unity.Mathematics
;
...
...
@@ -15,15 +16,19 @@ public partial class NetcodePlayerInputSystem : SystemBase
_inputActions
=
new
InputSystem_Actions
();
_inputActions
.
Enable
();
RequireForUpdate
<
NetworkStreamInGame
>();
RequireForUpdate
<
GamePlayingTag
>();
RequireForUpdate
<
NetcodePlayerInput
>();
RequireForUpdate
<
PlayerSprintData
>();
}
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
>())
{
netcodePlayerInput
.
ValueRW
.
inputVector
=
_inputActions
.
Player
.
Move
.
ReadValue
<
Vector2
>();
playerSprintData
.
ValueRW
.
isSprinting
=
true
;
}
}
...
...
Assets/_Game/Code/Systems/Input/NetcodePlayerMovementSystem.cs
View file @
b4e7688f
...
...
@@ -4,11 +4,22 @@ using Unity.Mathematics;
using
Unity.NetCode
;
using
Unity.Physics
;
using
Unity.Transforms
;
using
UnityEngine
;
[UpdateInGroup(typeof(PredictedSimulationSystemGroup))]
partial
struct
NetcodePlayerMovementSystem
:
ISystem
{
[
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
)
{
float
deltaTime
=
SystemAPI
.
Time
.
DeltaTime
;
...
...
@@ -22,41 +33,37 @@ partial struct NetcodePlayerMovementSystem : ISystem
{
float3
moveVector
=
new
float3
(
netcodePlayerInput
.
ValueRO
.
inputVector
.
x
,
0
,
netcodePlayerInput
.
ValueRO
.
inputVector
.
y
);
float
moveSpeed
=
sprintData
.
ValueRO
.
isSprinting
?
sprintData
.
ValueRO
.
sprintSpeed
:
sprintData
.
ValueRO
.
walkSpeed
;
float
moveSpeed
;
if
(
sprintData
.
ValueRO
.
isSprinting
)
moveSpeed
=
sprintData
.
ValueRO
.
walkSpeed
;
else
moveSpeed
=
sprintData
.
ValueRO
.
sprintSpeed
;
// Update sprinting logic
if
(
sprintData
.
ValueRO
.
isSprinting
&&
!
sprintData
.
ValueRO
.
isSprintCooldown
)
if
(
sprintData
.
ValueRO
.
isSprinting
)
{
sprintData
.
ValueRW
.
sprintRemaining
-=
deltaTime
;
if
(
sprintData
.
ValueRW
.
sprintRemaining
<=
0
)
if
(!
sprintData
.
ValueRO
.
isSprintCooldown
)
{
sprintData
.
ValueRW
.
isSprinting
=
false
;
sprintData
.
ValueRW
.
isSprintCooldown
=
true
;
sprintData
.
ValueRW
.
sprintRemaining
-=
deltaTime
;
if
(
sprintData
.
ValueRW
.
sprintRemaining
<=
0
)
{
sprintData
.
ValueRW
.
isSprintCooldown
=
true
;
sprintData
.
ValueRW
.
sprintCooldown
=
sprintData
.
ValueRO
.
sprintCooldownReset
;
}
}
}
else
{
sprintData
.
ValueRW
.
sprintRemaining
=
math
.
clamp
(
sprintData
.
ValueRW
.
sprintRemaining
+
deltaTime
,
0
,
sprintData
.
ValueRO
.
sprintDuration
);
}
if
(
sprintData
.
ValueRO
.
isSprintCooldown
)
{
sprintData
.
ValueRW
.
sprintCooldown
-=
deltaTime
;
if
(
sprintData
.
ValueRW
.
sprintCooldown
<=
0
)
if
(!
sprintData
.
ValueRO
.
isSprintCooldown
)
{
sprintData
.
ValueRW
.
isSprintCooldown
=
false
;
sprintData
.
ValueRW
.
sprintCooldown
=
sprintData
.
ValueRO
.
sprintCooldownReset
;
sprintData
.
ValueRW
.
sprintRemaining
=
math
.
clamp
(
sprintData
.
ValueRW
.
sprintRemaining
+
deltaTime
,
0
,
sprintData
.
ValueRO
.
sprintDuration
)
;
}
}
// Apply smooth movement
physicsVelocity
.
ValueRW
.
Linear
=
math
.
lerp
(
physicsVelocity
.
ValueRO
.
Linear
,
moveVector
*
moveSpeed
,
deltaTime
*
10
);
// Optionally, update the rotation to face the movement direction
if
(!
math
.
all
(
moveVector
==
float3
.
zero
))
{
quaternion
targetRotation
=
quaternion
.
LookRotationSafe
(
moveVector
,
math
.
up
());
...
...
Assets/_Game/Mono/ClientConnectionManager.cs
View file @
b4e7688f
...
...
@@ -150,9 +150,5 @@ public class ClientConnectionManager : MonoBehaviour
}
World
.
DefaultGameObjectInjectionWorld
=
clientWorld
;
var
ConnectionRequestEntity
=
clientWorld
.
EntityManager
.
CreateEntity
();
clientWorld
.
EntityManager
.
AddComponentData
(
ConnectionRequestEntity
,
new
ClientConnectionRpc
());
}
}
\ No newline at end of file
Assets/_Game/Prefabs/Player/Player.prefab
View file @
b4e7688f
...
...
@@ -147,11 +147,11 @@ MonoBehaviour:
m_Script
:
{
fileID
:
11500000
,
guid
:
a82f6d8766908894faabdee547539756
,
type
:
3
}
m_Name
:
m_EditorClassIdentifier
:
sprintRemaining
:
5
sprintDuration
:
5
sprintSpeed
:
12
walkSpeed
:
9
sprintCooldownReset
:
2
sprintRemaining
:
8
sprintDuration
:
8
sprintSpeed
:
25
walkSpeed
:
1
sprintCooldownReset
:
1
---
!u!114
&3955402020692204287
MonoBehaviour
:
m_ObjectHideFlags
:
0
...
...
@@ -320,7 +320,7 @@ MonoBehaviour:
m_Script
:
{
fileID
:
11500000
,
guid
:
8e73c985659b81d408f4e99cb152349d
,
type
:
3
}
m_Name
:
m_EditorClassIdentifier
:
MaxHitPoints
:
200
00
MaxHitPoints
:
5
00
---
!u!1001
&6975352639711469968
PrefabInstance
:
m_ObjectHideFlags
:
0
...
...
Assets/_Game/Scenes/ConnectionScene.unity
View file @
b4e7688f
...
...
@@ -490,7 +490,7 @@ MonoBehaviour:
SlimeAmountContainer
:
{
fileID
:
7438304585132253661
}
_connectButton
:
{
fileID
:
661734915
}
_gameStartCountDownTime
:
2
_slimeSpawnCooldownTime
:
0.
3
_slimeSpawnCooldownTime
:
0.
1
_rogueSpawnCooldownTime
:
1
---
!u!114
&1734898360
stripped
MonoBehaviour
:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment