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
264da874
authored
Apr 27, 2025
by
alsunj
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
destroy the player instead of repositioning
parent
f111cbb4
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
107 additions
and
20 deletions
Assets/_Game/Code/Authoring/Common/HitPointsAuthoring.cs
Assets/_Game/Code/Authoring/Player/EntitiesReferencesAuthoring.cs
Assets/_Game/Code/Authoring/Camera.meta → Assets/_Game/Code/Components/Entities.meta
Assets/_Game/Code/Components/Entities/EntitiesComponents.cs
Assets/_Game/Code/Components/Entities/EntitiesComponents.cs.meta
Assets/_Game/Code/Components/Player/PlayerComponents.cs
Assets/_Game/Code/Systems/Combat/HealthBarSystem.cs
Assets/_Game/Code/Systems/Combat/HealthBarSystem.cs.meta
Assets/_Game/Prefabs/Enemies/Cube.prefab
Assets/_Game/Prefabs/HealthBarCanvas.prefab → Assets/_Game/Prefabs/Player/HealthBarCanvas.prefab
Assets/_Game/Prefabs/HealthBarCanvas.prefab.meta → Assets/_Game/Prefabs/Player/HealthBarCanvas.prefab.meta
Assets/_Game/Prefabs/Player/Player.prefab
Assets/_Game/Code/Authoring/Common/HitPointsAuthoring.cs
View file @
264da874
...
...
@@ -4,7 +4,7 @@ using UnityEngine;
public
class
HitPointsAuthoring
:
MonoBehaviour
{
public
int
MaxHitPoints
;
//
public Vector3 HealthBarOffset;
public
Vector3
HealthBarOffset
;
public
class
HitPointsBaker
:
Baker
<
HitPointsAuthoring
>
{
...
...
@@ -15,7 +15,7 @@ public class HitPointsAuthoring : MonoBehaviour
AddComponent
(
entity
,
new
MaxHitPoints
{
Value
=
authoring
.
MaxHitPoints
});
AddBuffer
<
DamageBufferElement
>(
entity
);
AddBuffer
<
DamageThisTick
>(
entity
);
//AddComponent(entity, new HealthBarOffset { Value = authoring.HealthBarOffset });0
AddComponent
(
entity
,
new
HealthBarOffset
{
Value
=
authoring
.
HealthBarOffset
});
}
}
}
\ No newline at end of file
Assets/_Game/Code/Authoring/Player/EntitiesReferencesAuthoring.cs
View file @
264da874
...
...
@@ -15,7 +15,7 @@ public class EntitiesReferencesAuthoring : MonoBehaviour
{
public
override
void
Bake
(
EntitiesReferencesAuthoring
authoring
)
{
Entity
entity
=
GetEntity
(
TransformUsageFlags
.
Dynamic
);
Entity
entity
=
GetEntity
(
TransformUsageFlags
.
None
);
AddComponent
(
entity
,
new
EntititesReferences
{
PlayerPrefabEntity
=
GetEntity
(
authoring
.
playerPrefabGameObject
,
TransformUsageFlags
.
Dynamic
),
...
...
@@ -23,15 +23,10 @@ public class EntitiesReferencesAuthoring : MonoBehaviour
SlimeEnemyEntity
=
GetEntity
(
authoring
.
SlimeEnemyGameObject
,
TransformUsageFlags
.
Dynamic
),
RespawnEntity
=
GetEntity
(
authoring
.
RespawnEntity
,
TransformUsageFlags
.
None
)
});
AddComponentObject
(
entity
,
new
UIPrefabs
{
PlayerHealthUIEntity
=
authoring
.
HealthBarPrefab
});
}
}
}
public
struct
EntititesReferences
:
IComponentData
{
public
Entity
PlayerPrefabEntity
;
public
Entity
RougeEnemyEntity
;
public
Entity
SlimeEnemyEntity
;
public
Entity
RespawnEntity
;
}
\ No newline at end of file
Assets/_Game/Code/
Authoring/Camera
.meta
→
Assets/_Game/Code/
Components/Entities
.meta
View file @
264da874
fileFormatVersion: 2
guid:
54055e963725d3946b0f8ecd5aff2954
guid:
2bc8e0b896da57345a538ac0f5f3b6a2
folderAsset: yes
DefaultImporter:
externalObjects: {}
...
...
Assets/_Game/Code/Components/Entities/EntitiesComponents.cs
0 → 100644
View file @
264da874
using
Unity.Entities
;
using
UnityEngine
;
public
struct
EntititesReferences
:
IComponentData
{
public
Entity
PlayerPrefabEntity
;
public
Entity
RougeEnemyEntity
;
public
Entity
SlimeEnemyEntity
;
public
Entity
RespawnEntity
;
}
public
class
UIPrefabs
:
IComponentData
{
public
GameObject
PlayerHealthUIEntity
;
}
\ No newline at end of file
Assets/_Game/Code/Components/Entities/EntitiesComponents.cs.meta
0 → 100644
View file @
264da874
fileFormatVersion: 2
guid: c212b1d1bc3a33f46b6d0a1916775ff0
\ No newline at end of file
Assets/_Game/Code/Components/Player/PlayerComponents.cs
View file @
264da874
...
...
@@ -27,4 +27,14 @@ public struct PlayerTag : IComponentData
public
struct
TeamTypes
:
IComponentData
{
[
GhostField
]
public
TeamType
Value
;
}
public
class
HealthBarUIReference
:
ICleanupComponentData
{
public
GameObject
Value
;
}
public
struct
HealthBarOffset
:
IComponentData
{
public
float3
Value
;
}
\ No newline at end of file
Assets/_Game/Code/Systems/Combat/HealthBarSystem.cs
0 → 100644
View file @
264da874
using
Unity.Entities
;
using
Unity.Transforms
;
using
UnityEngine
;
using
UnityEngine.UI
;
[UpdateAfter(typeof(TransformSystemGroup))]
[WorldSystemFilter(WorldSystemFilterFlags.ClientSimulation)]
public
partial
struct
HealthBarSystem
:
ISystem
{
public
void
OnCreate
(
ref
SystemState
state
)
{
state
.
RequireForUpdate
<
EndSimulationEntityCommandBufferSystem
.
Singleton
>();
state
.
RequireForUpdate
<
UIPrefabs
>();
}
public
void
OnUpdate
(
ref
SystemState
state
)
{
var
ecbSingleton
=
SystemAPI
.
GetSingleton
<
EndSimulationEntityCommandBufferSystem
.
Singleton
>();
var
ecb
=
ecbSingleton
.
CreateCommandBuffer
(
state
.
WorldUnmanaged
);
foreach
(
var
(
transform
,
healthBarOffset
,
maxHitPoints
,
entity
)
in
SystemAPI
.
Query
<
LocalTransform
,
HealthBarOffset
,
MaxHitPoints
>().
WithNone
<
HealthBarUIReference
>()
.
WithEntityAccess
())
{
var
healthBarPrefab
=
SystemAPI
.
ManagedAPI
.
GetSingleton
<
UIPrefabs
>().
PlayerHealthUIEntity
;
var
spawnPosition
=
transform
.
Position
+
healthBarOffset
.
Value
;
var
newHealthBar
=
Object
.
Instantiate
(
healthBarPrefab
,
spawnPosition
,
Quaternion
.
identity
);
SetHealthBar
(
newHealthBar
,
maxHitPoints
.
Value
,
maxHitPoints
.
Value
);
ecb
.
AddComponent
(
entity
,
new
HealthBarUIReference
{
Value
=
newHealthBar
});
}
// Update position and values of health bar
foreach
(
var
(
transform
,
healthBarOffset
,
currentHitPoints
,
maxHitPoints
,
healthBarUI
)
in
SystemAPI
.
Query
<
LocalTransform
,
HealthBarOffset
,
CurrentHitPoints
,
MaxHitPoints
,
HealthBarUIReference
>())
{
var
healthBarPosition
=
transform
.
Position
+
healthBarOffset
.
Value
;
healthBarUI
.
Value
.
transform
.
position
=
healthBarPosition
;
SetHealthBar
(
healthBarUI
.
Value
,
currentHitPoints
.
Value
,
maxHitPoints
.
Value
);
}
// Cleanup health bar once associated entity is destroyed
foreach
(
var
(
healthBarUI
,
entity
)
in
SystemAPI
.
Query
<
HealthBarUIReference
>().
WithNone
<
LocalTransform
>()
.
WithEntityAccess
())
{
Object
.
Destroy
(
healthBarUI
.
Value
);
ecb
.
RemoveComponent
<
HealthBarUIReference
>(
entity
);
}
}
private
void
SetHealthBar
(
GameObject
healthBarCanvasObject
,
int
curHitPoints
,
int
maxHitPoints
)
{
var
healthBarSlider
=
healthBarCanvasObject
.
GetComponentInChildren
<
Slider
>();
healthBarSlider
.
minValue
=
0
;
healthBarSlider
.
maxValue
=
maxHitPoints
;
healthBarSlider
.
value
=
curHitPoints
;
}
}
\ No newline at end of file
Assets/_Game/Code/Systems/Combat/HealthBarSystem.cs.meta
0 → 100644
View file @
264da874
fileFormatVersion: 2
guid: 23d3a8759edba9248b7506c0f3009f02
\ No newline at end of file
Assets/_Game/Prefabs/Enemies/Cube.prefab
View file @
264da874
...
...
@@ -102,7 +102,7 @@ MonoBehaviour:
m_Script
:
{
fileID
:
11500000
,
guid
:
2de495c310a322143be08aa7819a1a33
,
type
:
3
}
m_Name
:
m_EditorClassIdentifier
:
DamageOnTrigger
:
10
0
DamageOnTrigger
:
5
0
---
!u!114
&-8527907258641966621
MonoBehaviour
:
m_ObjectHideFlags
:
0
...
...
Assets/_Game/Prefabs/HealthBarCanvas.prefab
→
Assets/_Game/Prefabs/
Player/
HealthBarCanvas.prefab
View file @
264da874
...
...
@@ -24,7 +24,7 @@ RectTransform:
m_PrefabInstance
:
{
fileID
:
0
}
m_PrefabAsset
:
{
fileID
:
0
}
m_GameObject
:
{
fileID
:
1001200712104652852
}
m_LocalRotation
:
{
x
:
0.
5
,
y
:
0
,
z
:
0
,
w
:
0.8660254
}
m_LocalRotation
:
{
x
:
0.
17364816
,
y
:
0
,
z
:
0
,
w
:
0.9848078
}
m_LocalPosition
:
{
x
:
0
,
y
:
0
,
z
:
0
}
m_LocalScale
:
{
x
:
1
,
y
:
1
,
z
:
1
}
m_ConstrainProportionsScale
:
0
...
...
@@ -34,11 +34,11 @@ RectTransform:
-
{
fileID
:
1049164032731023949
}
-
{
fileID
:
6194065087393849582
}
m_Father
:
{
fileID
:
8603131648779679062
}
m_LocalEulerAnglesHint
:
{
x
:
6
0
,
y
:
0
,
z
:
0
}
m_LocalEulerAnglesHint
:
{
x
:
2
0
,
y
:
0
,
z
:
0
}
m_AnchorMin
:
{
x
:
0.5
,
y
:
0.5
}
m_AnchorMax
:
{
x
:
0.5
,
y
:
0.5
}
m_AnchoredPosition
:
{
x
:
0
,
y
:
0
}
m_SizeDelta
:
{
x
:
200
,
y
:
75
}
m_SizeDelta
:
{
x
:
120
,
y
:
40
}
m_Pivot
:
{
x
:
0.5
,
y
:
0.5
}
---
!u!114
&8986874467296708868
MonoBehaviour
:
...
...
@@ -239,7 +239,7 @@ RectTransform:
m_AnchorMin
:
{
x
:
0
,
y
:
0
}
m_AnchorMax
:
{
x
:
0
,
y
:
0
}
m_AnchoredPosition
:
{
x
:
0
,
y
:
3
}
m_SizeDelta
:
{
x
:
1000
,
y
:
1000
}
m_SizeDelta
:
{
x
:
4
,
y
:
1000
}
m_Pivot
:
{
x
:
0.5
,
y
:
0.5
}
---
!u!223
&7587403821176963594
Canvas
:
...
...
Assets/_Game/Prefabs/HealthBarCanvas.prefab.meta
→
Assets/_Game/Prefabs/
Player/
HealthBarCanvas.prefab.meta
View file @
264da874
File moved
Assets/_Game/Prefabs/Player/Player.prefab
View file @
264da874
...
...
@@ -320,7 +320,8 @@ MonoBehaviour:
m_Script
:
{
fileID
:
11500000
,
guid
:
8e73c985659b81d408f4e99cb152349d
,
type
:
3
}
m_Name
:
m_EditorClassIdentifier
:
MaxHitPoints
:
500
MaxHitPoints
:
1000
HealthBarOffset
:
{
x
:
0
,
y
:
2.5
,
z
:
0
}
---
!u!1001
&6975352639711469968
PrefabInstance
:
m_ObjectHideFlags
:
0
...
...
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