Skip to content
This repository has been archived by the owner on Jul 3, 2024. It is now read-only.

Commit

Permalink
Fixed health bar system
Browse files Browse the repository at this point in the history
Implemented turret shooting
  • Loading branch information
Amatsugu committed Jun 27, 2020
1 parent 76f3448 commit a3aabe2
Show file tree
Hide file tree
Showing 15 changed files with 79 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ MonoBehaviour:
healthBar: {fileID: 11400000, guid: 64264ba37fb009140b7237d68e6e4e60, type: 2}
healthBarOffset:
x: 0
y: 0
y: 1
z: 0
validator: {fileID: 11400000, guid: 611c8b3b246b0c54397fbe5fece4c1b9, type: 2}
cost: []
Expand Down
19 changes: 9 additions & 10 deletions Assets/Materials/UI/Health Bars/HealthBar BG.mat
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,12 @@ Material:
m_PrefabAsset: {fileID: 0}
m_Name: HealthBar BG
m_Shader: {fileID: 4800000, guid: c4edd00ff2db5b24391a4fcb1762e459, type: 3}
m_ShaderKeywords: _BLENDMODE_ALPHA _ENABLE_FOG_ON_TRANSPARENT _NORMALMAP_TANGENT_SPACE
_SURFACE_TYPE_TRANSPARENT
m_ShaderKeywords: _NORMALMAP_TANGENT_SPACE
m_LightmapFlags: 4
m_EnableInstancingVariants: 1
m_DoubleSidedGI: 0
m_CustomRenderQueue: 3000
stringTagMap:
RenderType: Transparent
m_CustomRenderQueue: 2000
stringTagMap: {}
disabledShaderPasses:
- DistortionVectors
- MOTIONVECTORS
Expand Down Expand Up @@ -122,7 +120,7 @@ Material:
- _AlphaCutoffPostpass: 0.5
- _AlphaCutoffPrepass: 0.5
- _AlphaCutoffShadow: 0.5
- _AlphaDstBlend: 10
- _AlphaDstBlend: 0
- _AlphaSrcBlend: 1
- _Anisotropy: 0
- _BlendMode: 0
Expand Down Expand Up @@ -156,7 +154,7 @@ Material:
- _DistortionVectorScale: 2
- _DoubleSidedEnable: 0
- _DoubleSidedNormalMode: 1
- _DstBlend: 10
- _DstBlend: 0
- _EmissiveColorMode: 1
- _EmissiveExposureWeight: 1
- _EmissiveIntensity: 87682.42
Expand Down Expand Up @@ -211,7 +209,7 @@ Material:
- _StencilWriteMaskMV: 40
- _SubsurfaceMask: 1
- _SupportDecals: 1
- _SurfaceType: 1
- _SurfaceType: 0
- _TexWorldScale: 1
- _TexWorldScaleEmissive: 1
- _Thickness: 1
Expand All @@ -228,11 +226,11 @@ Material:
- _UVEmissive: 0
- _UseEmissiveIntensity: 0
- _UseShadowThreshold: 0
- _ZTestDepthEqualForOpaque: 4
- _ZTestDepthEqualForOpaque: 3
- _ZTestGBuffer: 4
- _ZTestModeDistortion: 4
- _ZTestTransparent: 4
- _ZWrite: 0
- _ZWrite: 1
m_Colors:
- _BaseColor: {r: 1, g: 1, b: 1, a: 1}
- _BaseColorMap_MipInfo: {r: 0, g: 0, b: 0, a: 0}
Expand All @@ -251,6 +249,7 @@ Material:
- _UVMappingMask: {r: 1, g: 0, b: 0, a: 0}
- _UVMappingMaskEmissive: {r: 1, g: 0, b: 0, a: 0}
- _UnlitColor: {r: 0.14999995, g: 0.14999995, b: 0.14999995, a: 0.83137256}
- _UnlitColorMap_MipInfo: {r: 0, g: 0, b: 0, a: 0}
m_BuildTextureStacks: []
--- !u!114 &5547995080011716073
MonoBehaviour:
Expand Down
1 change: 1 addition & 0 deletions Assets/Materials/UI/Health Bars/HealthBar Fill.mat
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ Material:
- _UVMappingMask: {r: 1, g: 0, b: 0, a: 0}
- _UVMappingMaskEmissive: {r: 1, g: 0, b: 0, a: 0}
- _UnlitColor: {r: 1, g: 0, b: 0.39215687, a: 1}
- _UnlitColorMap_MipInfo: {r: 0, g: 0, b: 0, a: 0}
m_BuildTextureStacks: []
--- !u!114 &5547995080011716073
MonoBehaviour:
Expand Down
1 change: 1 addition & 0 deletions Assets/Materials/UI/Health Bars/Phos HealthBar Fill.mat
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ Material:
- _UVMappingMask: {r: 1, g: 0, b: 0, a: 0}
- _UVMappingMaskEmissive: {r: 1, g: 0, b: 0, a: 0}
- _UnlitColor: {r: 0, g: 1, b: 0.8048501, a: 1}
- _UnlitColorMap_MipInfo: {r: 0, g: 0, b: 0, a: 0}
m_BuildTextureStacks: []
--- !u!114 &5547995080011716073
MonoBehaviour:
Expand Down
Binary file modified Assets/Models/Health Bar.blend
Binary file not shown.
Binary file added Assets/Models/Health Bar.blend1
Binary file not shown.
7 changes: 7 additions & 0 deletions Assets/Models/Health Bar.blend1.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions Assets/Scenes/Main.unity
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ RenderSettings:
m_ReflectionIntensity: 1
m_CustomReflection: {fileID: 0}
m_Sun: {fileID: 0}
m_IndirectSpecularColor: {r: 101.7119, g: 217.4172, b: 729.53644, a: 1}
m_IndirectSpecularColor: {r: 0, g: 0, b: 0, a: 1}
m_UseRadianceAmbientProbe: 0
--- !u!157 &3
LightmapSettings:
Expand Down Expand Up @@ -6229,7 +6229,7 @@ MonoBehaviour:
m_HandleRect: {fileID: 2102994817}
m_Direction: 2
m_Value: 0
m_Size: 0.99999684
m_Size: 0.9999935
m_NumberOfSteps: 0
m_OnValueChanged:
m_PersistentCalls:
Expand Down Expand Up @@ -12866,7 +12866,7 @@ RectTransform:
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 1}
m_AnchorMax: {x: 1, y: 1}
m_AnchoredPosition: {x: 0, y: -442.99924}
m_AnchoredPosition: {x: 0, y: -442.99933}
m_SizeDelta: {x: 0, y: 0}
m_Pivot: {x: 0, y: 0}
--- !u!114 &1427279150
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ private void DealDamage(Entity src, Entity tgt)
var dmg = damage[src];
if (!dmg.friendlyFire && faction.HasComponent(src) && faction.HasComponent(tgt))
{
if(faction[src] == faction[tgt])
if(faction[src].Value == faction[tgt].Value)
return;
}
var h = health[tgt];
Expand Down
28 changes: 27 additions & 1 deletion Assets/Scripts/Game Logic/Systems/Combat/TurretSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,35 @@
using Unity.Mathematics;
using Unity.Transforms;

using UnityEngine.AddressableAssets;

namespace Amatsugu.Phos.ECS
{
public class TurretSystem : ComponentSystem
{

private bool _isReady = false;
private ProjectileMeshEntity _bullet;

protected override void OnCreate()
{
base.OnCreate();
var op = Addressables.LoadAssetAsync<ProjectileMeshEntity>("PlayerProjectile");
op.Completed += e =>
{
if (e.Status == UnityEngine.ResourceManagement.AsyncOperations.AsyncOperationStatus.Succeeded)
{
_bullet = e.Result;
_isReady = true;
}
};
}

protected override void OnUpdate()
{
if (!_isReady)
return;

Entities.ForEach((Entity e, ref Turret t, ref Translation pos, ref AttackSpeed speed, ref AttackRange range) =>
{
var r = EntityManager.GetComponentData<Rotation>(t.Head).Value;
Expand All @@ -25,9 +48,12 @@ protected override void OnUpdate()
Value = r
});

var fwd = math.rotate(r, new float3(0, 0, 1));
var fwd = -math.rotate(r, new float3(0, 0, 1));


var b = _bullet.BufferedInstantiate(PostUpdateCommands, pos.Value + fwd * 2f, 0.1f, fwd * 10);

PostUpdateCommands.AddComponent(b, new DeathTime { Value = Time.ElapsedTime + 5 });

});
}
Expand Down
11 changes: 1 addition & 10 deletions Assets/Scripts/Game Logic/Systems/HealthBarSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,20 +112,11 @@ protected override void OnStartRunning()
}
};
_barQuery = GetEntityQuery(barDesc);
GameEvents.OnGameReady += Init;
}

private void Init()
{
_cam = GameRegistry.Camera.transform;
GameEvents.OnGameReady -= Init;
_cam = Camera.main.transform;
}

protected override JobHandle OnUpdate(JobHandle inputDeps)
{
if (_cam == null)
return inputDeps;

var hBarType = GetArchetypeChunkComponentType<HealthBar>(true);
var rotJob = new UpdateBarRotation
{
Expand Down
6 changes: 6 additions & 0 deletions Assets/Scripts/Map/Tiles/MappedTiles/Buildings/TurretTile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,11 @@ public override void OnShow()
base.OnShow();
Map.EM.RemoveComponent<FrozenRenderSceneTag>(_turretHead);
}

public override void Destroy()
{
base.Destroy();
Map.EM.DestroyEntity(_turretHead);
}
}
}
8 changes: 4 additions & 4 deletions Packages/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@
"com.unity.addressables": "1.8.4",
"com.unity.audio.dspgraph": "0.1.0-preview.11",
"com.unity.build-report-inspector": "0.1.2-preview",
"com.unity.burst": "1.3.0-preview.13",
"com.unity.burst": "1.3.3",
"com.unity.collections": "0.8.0-preview.5",
"com.unity.entities": "0.10.0-preview.6",
"com.unity.ide.visualstudio": "2.0.1",
"com.unity.ide.visualstudio": "2.0.2",
"com.unity.jobs": "0.2.9-preview.15",
"com.unity.mathematics": "1.1.0",
"com.unity.physics": "0.3.2-preview",
"com.unity.platforms": "0.4.0-preview.3",
"com.unity.probuilder": "4.2.3",
"com.unity.progrids": "3.0.3-preview.4",
"com.unity.quicksearch": "1.5.3",
"com.unity.quicksearch": "1.5.4",
"com.unity.render-pipelines.high-definition": "8.1.0",
"com.unity.rendering.hybrid": "0.5.1-preview.18",
"com.unity.rendering.hybrid": "0.5.2-preview.4",
"com.unity.scriptablebuildpipeline": "1.7.3",
"com.unity.test-framework": "1.1.14",
"com.unity.test-framework.performance": "2.0.9-preview",
Expand Down
22 changes: 11 additions & 11 deletions Packages/packages-lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"url": "https://packages.unity.com"
},
"com.unity.burst": {
"version": "1.3.0-preview.13",
"version": "1.3.3",
"depth": 0,
"source": "registry",
"dependencies": {
Expand All @@ -46,7 +46,7 @@
"url": "https://packages.unity.com"
},
"com.unity.collections": {
"version": "0.9.0-preview.5",
"version": "0.9.0-preview.6",
"depth": 2,
"source": "registry",
"dependencies": {
Expand All @@ -56,18 +56,18 @@
"url": "https://packages.unity.com"
},
"com.unity.entities": {
"version": "0.11.0-preview.7",
"version": "0.11.1-preview.4",
"depth": 1,
"source": "registry",
"dependencies": {
"com.unity.burst": "1.3.0-preview.12",
"com.unity.collections": "0.9.0-preview.5",
"com.unity.collections": "0.9.0-preview.6",
"com.unity.properties": "1.2.0-preview",
"com.unity.mathematics": "1.1.0",
"com.unity.test-framework.performance": "2.0.8-preview",
"com.unity.serialization": "1.2.0-preview",
"nuget.mono-cecil": "0.1.5-preview",
"com.unity.jobs": "0.2.10-preview.11",
"com.unity.jobs": "0.2.10-preview.12",
"com.unity.scriptablebuildpipeline": "1.6.4-preview",
"com.unity.platforms": "0.3.0-preview.4"
},
Expand All @@ -81,18 +81,18 @@
"url": "https://packages.unity.com"
},
"com.unity.ide.visualstudio": {
"version": "2.0.1",
"version": "2.0.2",
"depth": 0,
"source": "registry",
"dependencies": {},
"url": "https://packages.unity.com"
},
"com.unity.jobs": {
"version": "0.2.10-preview.11",
"version": "0.2.10-preview.12",
"depth": 2,
"source": "registry",
"dependencies": {
"com.unity.collections": "0.9.0-preview.5",
"com.unity.collections": "0.9.0-preview.6",
"com.unity.mathematics": "1.1.0"
},
"url": "https://packages.unity.com"
Expand Down Expand Up @@ -187,7 +187,7 @@
"url": "https://packages.unity.com"
},
"com.unity.quicksearch": {
"version": "1.5.3",
"version": "1.5.4",
"depth": 0,
"source": "registry",
"dependencies": {},
Expand Down Expand Up @@ -224,11 +224,11 @@
"url": "https://packages.unity.com"
},
"com.unity.rendering.hybrid": {
"version": "0.5.1-preview.18",
"version": "0.5.2-preview.4",
"depth": 0,
"source": "registry",
"dependencies": {
"com.unity.entities": "0.11.0-preview.7"
"com.unity.entities": "0.11.1-preview.4"
},
"url": "https://packages.unity.com"
},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"m_Name": "Settings",
"m_Path": "ProjectSettings/Packages/com.unity.settings-manager/Settings.json",
"m_Dictionary": {
"m_DictionaryValues": []
}
}

0 comments on commit a3aabe2

Please sign in to comment.