Initial import
This commit is contained in:
45
Assets/Scripts/Components/Aspects.cs
Normal file
45
Assets/Scripts/Components/Aspects.cs
Normal file
@@ -0,0 +1,45 @@
|
||||
using Unity.Entities;
|
||||
using Unity.Transforms;
|
||||
|
||||
namespace EE2Clone.Components
|
||||
{
|
||||
public readonly partial struct UnitAspect : IAspect
|
||||
{
|
||||
public readonly Entity Entity;
|
||||
|
||||
public readonly RefRW<LocalTransform> Transform;
|
||||
public readonly RefRO<Health> Health;
|
||||
public readonly RefRO<OwnerPlayer> Owner;
|
||||
public readonly RefRO<MovementSpeed> Speed;
|
||||
public readonly RefRW<MoveTarget> MoveTarget;
|
||||
public readonly RefRO<AttackData> Attack;
|
||||
public readonly RefRO<ArmorData> Armor;
|
||||
public readonly RefRO<UnitClassComponent> UnitClass;
|
||||
public readonly RefRW<UnitStateComponent> State;
|
||||
public readonly RefRO<LineOfSight> LineOfSight;
|
||||
}
|
||||
|
||||
public readonly partial struct BuildingAspect : IAspect
|
||||
{
|
||||
public readonly Entity Entity;
|
||||
|
||||
public readonly RefRO<LocalTransform> Transform;
|
||||
public readonly RefRW<Health> Health;
|
||||
public readonly RefRO<OwnerPlayer> Owner;
|
||||
public readonly RefRO<BuildingTypeComponent> BuildingType;
|
||||
public readonly RefRO<LineOfSight> LineOfSight;
|
||||
}
|
||||
|
||||
public readonly partial struct GathererAspect : IAspect
|
||||
{
|
||||
public readonly Entity Entity;
|
||||
|
||||
public readonly RefRW<LocalTransform> Transform;
|
||||
public readonly RefRO<OwnerPlayer> Owner;
|
||||
public readonly RefRO<MovementSpeed> Speed;
|
||||
public readonly RefRW<MoveTarget> MoveTarget;
|
||||
public readonly RefRW<CitizenStateComponent> CitizenState;
|
||||
public readonly RefRW<CarriedResource> CarriedResource;
|
||||
public readonly RefRW<GatherTarget> GatherTarget;
|
||||
}
|
||||
}
|
||||
2
Assets/Scripts/Components/Aspects.cs.meta
Normal file
2
Assets/Scripts/Components/Aspects.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1d3da0d6cb90d294287efd6c1fa55c9f
|
||||
39
Assets/Scripts/Components/BufferComponents.cs
Normal file
39
Assets/Scripts/Components/BufferComponents.cs
Normal file
@@ -0,0 +1,39 @@
|
||||
using Unity.Entities;
|
||||
using Unity.NetCode;
|
||||
using EE2Clone.Core;
|
||||
|
||||
namespace EE2Clone.Components
|
||||
{
|
||||
[GhostComponent]
|
||||
[InternalBufferCapacity(4)]
|
||||
public struct CounterBonusElement : IBufferElementData
|
||||
{
|
||||
[GhostField] public UnitClass TargetClass;
|
||||
[GhostField] public float Multiplier;
|
||||
}
|
||||
|
||||
[GhostComponent]
|
||||
[InternalBufferCapacity(5)]
|
||||
public struct ProductionQueueElement : IBufferElementData
|
||||
{
|
||||
[GhostField] public int UnitDataId;
|
||||
[GhostField] public float TimeRemaining;
|
||||
[GhostField] public float TotalTime;
|
||||
}
|
||||
|
||||
[GhostComponent]
|
||||
[InternalBufferCapacity(2)]
|
||||
public struct ResearchQueueElement : IBufferElementData
|
||||
{
|
||||
[GhostField] public int TechId;
|
||||
[GhostField] public float TimeRemaining;
|
||||
[GhostField] public float TotalTime;
|
||||
}
|
||||
|
||||
[GhostComponent]
|
||||
[InternalBufferCapacity(32)]
|
||||
public struct PlayerTechBufferElement : IBufferElementData
|
||||
{
|
||||
[GhostField] public int TechId;
|
||||
}
|
||||
}
|
||||
2
Assets/Scripts/Components/BufferComponents.cs.meta
Normal file
2
Assets/Scripts/Components/BufferComponents.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d3fc0cacffc268b4f966956f308fbc31
|
||||
168
Assets/Scripts/Components/GameplayComponents.cs
Normal file
168
Assets/Scripts/Components/GameplayComponents.cs
Normal file
@@ -0,0 +1,168 @@
|
||||
using Unity.Entities;
|
||||
using Unity.Mathematics;
|
||||
using Unity.NetCode;
|
||||
using EE2Clone.Core;
|
||||
|
||||
namespace EE2Clone.Components
|
||||
{
|
||||
[GhostComponent]
|
||||
public struct Health : IComponentData
|
||||
{
|
||||
[GhostField] public float Current;
|
||||
[GhostField] public float Max;
|
||||
}
|
||||
|
||||
[GhostComponent]
|
||||
public struct OwnerPlayer : IComponentData
|
||||
{
|
||||
[GhostField] public int PlayerId;
|
||||
}
|
||||
|
||||
[GhostComponent]
|
||||
public struct MovementSpeed : IComponentData
|
||||
{
|
||||
[GhostField] public float Value;
|
||||
}
|
||||
|
||||
[GhostComponent]
|
||||
public struct MoveTarget : IComponentData
|
||||
{
|
||||
[GhostField] public float3 Position;
|
||||
[GhostField] public bool IsActive;
|
||||
}
|
||||
|
||||
[GhostComponent]
|
||||
public struct AttackData : IComponentData
|
||||
{
|
||||
[GhostField] public float Damage;
|
||||
[GhostField] public float Range;
|
||||
[GhostField] public float AttackCooldown;
|
||||
public float CooldownRemaining;
|
||||
}
|
||||
|
||||
[GhostComponent]
|
||||
public struct ArmorData : IComponentData
|
||||
{
|
||||
[GhostField] public float Value;
|
||||
}
|
||||
|
||||
[GhostComponent]
|
||||
public struct UnitClassComponent : IComponentData
|
||||
{
|
||||
[GhostField] public UnitClass Value;
|
||||
}
|
||||
|
||||
[GhostComponent]
|
||||
public struct UnitStateComponent : IComponentData
|
||||
{
|
||||
[GhostField] public UnitState Value;
|
||||
}
|
||||
|
||||
[GhostComponent]
|
||||
public struct ResourceNode : IComponentData
|
||||
{
|
||||
[GhostField] public ResourceType Type;
|
||||
[GhostField] public int RemainingAmount;
|
||||
}
|
||||
|
||||
[GhostComponent]
|
||||
public struct CarriedResource : IComponentData
|
||||
{
|
||||
[GhostField] public ResourceType Type;
|
||||
[GhostField] public int Amount;
|
||||
[GhostField] public int MaxCarryCapacity;
|
||||
}
|
||||
|
||||
[GhostComponent]
|
||||
public struct GatherTarget : IComponentData
|
||||
{
|
||||
[GhostField] public Entity Target;
|
||||
}
|
||||
|
||||
[GhostComponent]
|
||||
public struct BuildTarget : IComponentData
|
||||
{
|
||||
[GhostField] public Entity Target;
|
||||
}
|
||||
|
||||
[GhostComponent]
|
||||
public struct ConstructionProgress : IComponentData
|
||||
{
|
||||
[GhostField] public float Progress; // 0.0 to 1.0
|
||||
[GhostField] public float BuildTime; // Total time required
|
||||
}
|
||||
|
||||
[GhostComponent]
|
||||
public struct ProductionTimer : IComponentData
|
||||
{
|
||||
[GhostField] public float TimeRemaining;
|
||||
[GhostField] public float TotalTime;
|
||||
}
|
||||
|
||||
[GhostComponent]
|
||||
public struct RallyPoint : IComponentData
|
||||
{
|
||||
[GhostField] public float3 Position;
|
||||
}
|
||||
|
||||
[GhostComponent]
|
||||
public struct TerritorySource : IComponentData
|
||||
{
|
||||
[GhostField] public float Radius;
|
||||
}
|
||||
|
||||
[GhostComponent]
|
||||
public struct LineOfSight : IComponentData
|
||||
{
|
||||
[GhostField] public float Range;
|
||||
}
|
||||
|
||||
[GhostComponent]
|
||||
public struct EpochLevel : IComponentData
|
||||
{
|
||||
[GhostField] public Epoch Value;
|
||||
}
|
||||
|
||||
[GhostComponent]
|
||||
public struct CitizenStateComponent : IComponentData
|
||||
{
|
||||
[GhostField] public CitizenState Value;
|
||||
}
|
||||
|
||||
[GhostComponent]
|
||||
public struct DropoffBuilding : IComponentData
|
||||
{
|
||||
[GhostField] public ResourceType AcceptedType;
|
||||
}
|
||||
|
||||
[GhostComponent]
|
||||
public struct CombatTarget : IComponentData
|
||||
{
|
||||
[GhostField] public Entity Target;
|
||||
}
|
||||
|
||||
[GhostComponent]
|
||||
public struct BuildingTypeComponent : IComponentData
|
||||
{
|
||||
[GhostField] public BuildingType Value;
|
||||
}
|
||||
|
||||
[GhostComponent]
|
||||
public struct ProvidesPopulation : IComponentData
|
||||
{
|
||||
[GhostField] public int Amount;
|
||||
}
|
||||
|
||||
public struct ProjectileData : IComponentData
|
||||
{
|
||||
[GhostField] public Entity Target;
|
||||
[GhostField] public float Damage;
|
||||
[GhostField] public float Speed;
|
||||
[GhostField] public int OwnerPlayerId;
|
||||
}
|
||||
|
||||
public struct DeathTimer : IComponentData
|
||||
{
|
||||
public float TimeRemaining;
|
||||
}
|
||||
}
|
||||
2
Assets/Scripts/Components/GameplayComponents.cs.meta
Normal file
2
Assets/Scripts/Components/GameplayComponents.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 43034d84c3a5fa249b16c70c205c781d
|
||||
61
Assets/Scripts/Components/PlayerComponents.cs
Normal file
61
Assets/Scripts/Components/PlayerComponents.cs
Normal file
@@ -0,0 +1,61 @@
|
||||
using Unity.Entities;
|
||||
using Unity.NetCode;
|
||||
using EE2Clone.Core;
|
||||
|
||||
namespace EE2Clone.Components
|
||||
{
|
||||
[GhostComponent(PrefabType = GhostPrefabType.All)]
|
||||
public struct PlayerStateComponent : IComponentData
|
||||
{
|
||||
[GhostField] public int PlayerId;
|
||||
[GhostField] public Epoch CurrentEpoch;
|
||||
[GhostField] public int PopulationCurrent;
|
||||
[GhostField] public int PopulationMax;
|
||||
[GhostField] public int CivilizationId;
|
||||
[GhostField] public bool IsAlive;
|
||||
}
|
||||
|
||||
[GhostComponent(PrefabType = GhostPrefabType.All)]
|
||||
public struct PlayerResourcesComponent : IComponentData
|
||||
{
|
||||
[GhostField] public int Food;
|
||||
[GhostField] public int Wood;
|
||||
[GhostField] public int Stone;
|
||||
[GhostField] public int Gold;
|
||||
[GhostField] public int Tin;
|
||||
|
||||
public int GetResource(ResourceType type)
|
||||
{
|
||||
return type switch
|
||||
{
|
||||
ResourceType.Food => Food,
|
||||
ResourceType.Wood => Wood,
|
||||
ResourceType.Stone => Stone,
|
||||
ResourceType.Gold => Gold,
|
||||
ResourceType.Tin => Tin,
|
||||
_ => 0
|
||||
};
|
||||
}
|
||||
|
||||
public void AddResource(ResourceType type, int amount)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case ResourceType.Food: Food += amount; break;
|
||||
case ResourceType.Wood: Wood += amount; break;
|
||||
case ResourceType.Stone: Stone += amount; break;
|
||||
case ResourceType.Gold: Gold += amount; break;
|
||||
case ResourceType.Tin: Tin += amount; break;
|
||||
}
|
||||
}
|
||||
|
||||
public bool TrySpend(ResourceType type, int amount)
|
||||
{
|
||||
if (GetResource(type) < amount)
|
||||
return false;
|
||||
|
||||
AddResource(type, -amount);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
2
Assets/Scripts/Components/PlayerComponents.cs.meta
Normal file
2
Assets/Scripts/Components/PlayerComponents.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f66e6e599792edc4594f96c856bd7ccd
|
||||
22
Assets/Scripts/Components/Tags.cs
Normal file
22
Assets/Scripts/Components/Tags.cs
Normal file
@@ -0,0 +1,22 @@
|
||||
using Unity.Entities;
|
||||
|
||||
namespace EE2Clone.Components
|
||||
{
|
||||
public struct UnitTag : IComponentData { }
|
||||
public struct BuildingTag : IComponentData { }
|
||||
public struct CitizenTag : IComponentData { }
|
||||
public struct ProjectileTag : IComponentData { }
|
||||
public struct ResourceNodeTag : IComponentData { }
|
||||
public struct SelectedTag : IComponentData { }
|
||||
public struct DestroyEntityTag : IComponentData { }
|
||||
|
||||
/// <summary>
|
||||
/// Marks an entity as under construction (not yet functional).
|
||||
/// </summary>
|
||||
public struct UnderConstructionTag : IComponentData { }
|
||||
|
||||
/// <summary>
|
||||
/// Tag for entities that have just spawned and need initialization.
|
||||
/// </summary>
|
||||
public struct NewlySpawnedTag : IComponentData { }
|
||||
}
|
||||
2
Assets/Scripts/Components/Tags.cs.meta
Normal file
2
Assets/Scripts/Components/Tags.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 38e1791fd078c6a4c923d7fdb0d81da1
|
||||
Reference in New Issue
Block a user