68 lines
2.4 KiB
C#
68 lines
2.4 KiB
C#
using Unity.Entities;
|
|
using UnityEngine;
|
|
using EE2Clone.Components;
|
|
using EE2Clone.Data;
|
|
|
|
namespace EE2Clone.Authoring
|
|
{
|
|
public class BuildingAuthoring : MonoBehaviour
|
|
{
|
|
public BuildingDataSO BuildingData;
|
|
public bool StartConstructed = false;
|
|
|
|
public class Baker : Baker<BuildingAuthoring>
|
|
{
|
|
public override void Bake(BuildingAuthoring authoring)
|
|
{
|
|
var data = authoring.BuildingData;
|
|
if (data == null) return;
|
|
|
|
var entity = GetEntity(TransformUsageFlags.Dynamic);
|
|
|
|
AddComponent(entity, new BuildingTag());
|
|
AddComponent(entity, new Health
|
|
{
|
|
Current = authoring.StartConstructed ? data.MaxHealth : 1,
|
|
Max = data.MaxHealth
|
|
});
|
|
AddComponent(entity, new OwnerPlayer { PlayerId = 0 });
|
|
AddComponent(entity, new BuildingTypeComponent { Value = data.BuildingType });
|
|
AddComponent(entity, new LineOfSight { Range = data.LineOfSightRange });
|
|
AddComponent(entity, new EpochLevel { Value = data.RequiredEpoch });
|
|
|
|
if (!authoring.StartConstructed)
|
|
{
|
|
AddComponent(entity, new UnderConstructionTag());
|
|
AddComponent(entity, new ConstructionProgress
|
|
{
|
|
Progress = 0f,
|
|
BuildTime = data.BuildTime
|
|
});
|
|
}
|
|
|
|
if (data.TerritoryRadius > 0)
|
|
{
|
|
AddComponent(entity, new TerritorySource { Radius = data.TerritoryRadius });
|
|
}
|
|
|
|
if (data.ProvidesPopulation > 0)
|
|
{
|
|
AddComponent(entity, new ProvidesPopulation { Amount = data.ProvidesPopulation });
|
|
}
|
|
|
|
AddComponent(entity, new RallyPoint { Position = default });
|
|
|
|
// Production queue
|
|
AddBuffer<ProductionQueueElement>(entity);
|
|
AddBuffer<ResearchQueueElement>(entity);
|
|
|
|
// Dropoff
|
|
if (data.IsDropoff && data.AcceptedResourceTypes != null && data.AcceptedResourceTypes.Length > 0)
|
|
{
|
|
AddComponent(entity, new DropoffBuilding { AcceptedType = data.AcceptedResourceTypes[0] });
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|