Initial import
This commit is contained in:
72
Assets/Scripts/Authoring/UnitAuthoring.cs
Normal file
72
Assets/Scripts/Authoring/UnitAuthoring.cs
Normal file
@@ -0,0 +1,72 @@
|
||||
using Unity.Entities;
|
||||
using UnityEngine;
|
||||
using EE2Clone.Components;
|
||||
using EE2Clone.Core;
|
||||
using EE2Clone.Data;
|
||||
|
||||
namespace EE2Clone.Authoring
|
||||
{
|
||||
public class UnitAuthoring : MonoBehaviour
|
||||
{
|
||||
public UnitDataSO UnitData;
|
||||
|
||||
public class Baker : Baker<UnitAuthoring>
|
||||
{
|
||||
public override void Bake(UnitAuthoring authoring)
|
||||
{
|
||||
var data = authoring.UnitData;
|
||||
if (data == null) return;
|
||||
|
||||
var entity = GetEntity(TransformUsageFlags.Dynamic);
|
||||
|
||||
AddComponent(entity, new UnitTag());
|
||||
AddComponent(entity, new Health { Current = data.MaxHealth, Max = data.MaxHealth });
|
||||
AddComponent(entity, new OwnerPlayer { PlayerId = 0 });
|
||||
AddComponent(entity, new MovementSpeed { Value = data.MoveSpeed });
|
||||
AddComponent(entity, new MoveTarget { Position = default, IsActive = false });
|
||||
AddComponent(entity, new AttackData
|
||||
{
|
||||
Damage = data.AttackDamage,
|
||||
Range = data.AttackRange,
|
||||
AttackCooldown = data.AttackCooldown,
|
||||
CooldownRemaining = 0
|
||||
});
|
||||
AddComponent(entity, new ArmorData { Value = data.Armor });
|
||||
AddComponent(entity, new UnitClassComponent { Value = data.UnitClass });
|
||||
AddComponent(entity, new UnitStateComponent { Value = UnitState.Idle });
|
||||
AddComponent(entity, new LineOfSight { Range = data.LineOfSightRange });
|
||||
AddComponent(entity, new EpochLevel { Value = data.RequiredEpoch });
|
||||
AddComponent(entity, new CombatTarget { Target = Entity.Null });
|
||||
|
||||
// Counter bonuses
|
||||
var counterBuffer = AddBuffer<CounterBonusElement>(entity);
|
||||
if (data.CounterBonuses != null)
|
||||
{
|
||||
foreach (var bonus in data.CounterBonuses)
|
||||
{
|
||||
counterBuffer.Add(new CounterBonusElement
|
||||
{
|
||||
TargetClass = bonus.TargetClass,
|
||||
Multiplier = bonus.Multiplier
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// Citizen-specific components
|
||||
if (data.UnitClass == UnitClass.Citizen)
|
||||
{
|
||||
AddComponent(entity, new CitizenTag());
|
||||
AddComponent(entity, new CitizenStateComponent { Value = CitizenState.Idle });
|
||||
AddComponent(entity, new CarriedResource
|
||||
{
|
||||
Type = ResourceType.Food,
|
||||
Amount = 0,
|
||||
MaxCarryCapacity = data.MaxCarryCapacity
|
||||
});
|
||||
AddComponent(entity, new GatherTarget { Target = Entity.Null });
|
||||
AddComponent(entity, new BuildTarget { Target = Entity.Null });
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user