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

Commit

Permalink
Started Implementation of turrets
Browse files Browse the repository at this point in the history
  • Loading branch information
Amatsugu committed Jun 26, 2020
1 parent 3589fdf commit 76f3448
Show file tree
Hide file tree
Showing 9 changed files with 187 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 8aac08c7606c20c41967144a17c65c2f, type: 3}
m_Name: '[PH] Turret BuildingMeshEntity'
m_EditorClassIdentifier:
mesh: {fileID: 0}
material: {fileID: 0}
mesh: {fileID: 2534964839176971238, guid: 71d31be2f1742ad4e94e50f8ccef23f5, type: 3}
material: {fileID: 15303, guid: 0000000000000000f000000000000000, type: 0}
castShadows: 1
receiveShadows: 1
isStatic: 1
nonUniformScale: 1
nonUniformScale: 0
centerOfMassOffset:
x: 0
y: 0
y: 1
z: 0
radius: 0
height: 0
radius: 1
height: 1
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ MonoBehaviour:
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 9b936cc80a414424e9bb00833d28a8a0, type: 3}
m_Script: {fileID: 11500000, guid: 93f6de7c742a08b4cadb99176a63d07e, type: 3}
m_Name: '[PH] Turret'
m_EditorClassIdentifier:
mesh: {fileID: 0}
Expand Down Expand Up @@ -40,9 +40,9 @@ MonoBehaviour:
offshoreOnly: 0
offshorePlatformMesh: {fileID: 0}
icon: {fileID: 0}
faction: 0
faction: 1
maxHealth: 100
healthBar: {fileID: 0}
healthBar: {fileID: 11400000, guid: 64264ba37fb009140b7237d68e6e4e60, type: 2}
healthBarOffset:
x: 0
y: 0
Expand All @@ -52,3 +52,8 @@ MonoBehaviour:
production: []
consumption: []
adjacencyEffects: []
fireRate: 1
damage: 10
attackRange: 20
projectileMesh: {fileID: 11400000, guid: 55862559bdae3734096a682461b34c0c, type: 2}
turretHead: {fileID: 11400000, guid: 68cb1fd3b1861fd4880a15223d7f5b63, type: 2}
4 changes: 2 additions & 2 deletions Assets/Scenes/Main.unity
Original file line number Diff line number Diff line change
Expand Up @@ -6229,7 +6229,7 @@ MonoBehaviour:
m_HandleRect: {fileID: 2102994817}
m_Direction: 2
m_Value: 0
m_Size: 1
m_Size: 0.99999684
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: -443}
m_AnchoredPosition: {x: 0, y: -442.99924}
m_SizeDelta: {x: 0, y: 0}
m_Pivot: {x: 0, y: 0}
--- !u!114 &1427279150
Expand Down
40 changes: 40 additions & 0 deletions Assets/Scripts/Game Logic/Systems/Combat/TurretSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using Amatsugu.Phos.Tiles;

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using Unity.Entities;
using Unity.Mathematics;
using Unity.Transforms;

namespace Amatsugu.Phos.ECS
{
public class TurretSystem : ComponentSystem
{
protected override void OnUpdate()
{
Entities.ForEach((Entity e, ref Turret t, ref Translation pos, ref AttackSpeed speed, ref AttackRange range) =>
{
var r = EntityManager.GetComponentData<Rotation>(t.Head).Value;
r = math.mul(math.normalizesafe(r), quaternion.AxisAngle(math.up(), 10 * Time.DeltaTime));
EntityManager.SetComponentData(t.Head, new Rotation
{
Value = r
});

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



});
}
}

public struct Turret : IComponentData
{
internal Entity Head;
}
}
11 changes: 11 additions & 0 deletions Assets/Scripts/Game Logic/Systems/Combat/TurretSystem.cs.meta

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

68 changes: 68 additions & 0 deletions Assets/Scripts/Map/Tiles/MappedTiles/Buildings/TurretTile.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
using Amatsugu.Phos.ECS;
using Amatsugu.Phos.TileEntities;
using Amatsugu.Phos.UnitComponents;

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using Unity.Entities;
using Unity.Rendering;

using UnityEngine;

namespace Amatsugu.Phos.Tiles
{
public class TurretTile : BuildingTile
{
public TurretTileEntity turretTile;

private Entity _turretHead;

public TurretTile(HexCoords coords, float height, Map map, TurretTileEntity tInfo) : base(coords, height, map, tInfo)
{
turretTile = tInfo;
}

public override void RenderBuilding()
{
base.RenderBuilding();
var e = GetBuildingEntity();
_turretHead = turretTile.turretHead.Instantiate(SurfacePoint);
Map.EM.AddComponentData(e, new Turret
{
Head = _turretHead
});
}


protected override void PrepareEntity()
{
base.PrepareEntity();
var e = GetBuildingEntity();
Map.EM.AddComponentData(e, new AttackRange
{
Value = turretTile.attackRange,
ValueSq = turretTile.attackRange * turretTile.attackRange
});
Map.EM.AddComponentData(e, new AttackSpeed
{
Value = turretTile.fireRate
});
}

public override void OnHide()
{
base.OnHide();
Map.EM.AddComponent<FrozenRenderSceneTag>(_turretHead);
}

public override void OnShow()
{
base.OnShow();
Map.EM.RemoveComponent<FrozenRenderSceneTag>(_turretHead);
}
}
}
11 changes: 11 additions & 0 deletions Assets/Scripts/Map/Tiles/MappedTiles/Buildings/TurretTile.cs.meta

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

30 changes: 30 additions & 0 deletions Assets/Scripts/Map/Tiles/TileInfo/Buildings/TurretTileEntity.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using Amatsugu.Phos.Tiles;

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using Unity.Entities;

using UnityEngine;

namespace Amatsugu.Phos.TileEntities
{
[CreateAssetMenu(menuName = "Map Asset/Tile/Building/Turret")]
public class TurretTileEntity : BuildingTileEntity
{
[Header("Turret")]
public float fireRate;
public float damage;
public float attackRange;
public ProjectileMeshEntity projectileMesh;
public MeshEntityRotatable turretHead;

public override Tile CreateTile(Map map, HexCoords pos, float height)
{
return new TurretTile(pos, height, map, this);
}
}
}

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

0 comments on commit 76f3448

Please sign in to comment.