Files
Project-M/Assets/_Project/Scripts/Authoring/Combat/UpgradePickupAuthoring.cs
T
2026-05-31 21:35:12 -07:00

44 lines
1.7 KiB
C#

using ProjectM.Simulation;
using Unity.Entities;
using UnityEngine;
namespace ProjectM.Authoring
{
/// <summary>
/// Authoring for an upgrade pickup ghost prefab: a world object that grants one stat modifier to the
/// first player that overlaps it (server-authoritative, applied by <c>UpgradePickupSystem</c>) and
/// then despawns. Bake the prefab as an interpolated ghost (add a GhostAuthoringComponent) so clients
/// see it appear and despawn. <c>GetEntity(TransformUsageFlags.Dynamic)</c> gives it a world transform.
/// </summary>
public class UpgradePickupAuthoring : MonoBehaviour
{
[Tooltip("Which stat the granted modifier targets.")]
public StatTarget Target = StatTarget.Damage;
[Tooltip("How the granted modifier combines.")]
public ModOp Op = ModOp.Flat;
[Tooltip("Modifier magnitude: flat amount, or fractional percent (0.1 = +10%).")]
public float Value = 10f;
[Tooltip("Overlap radius (world units) for the player pickup test.")]
[Min(0f)] public float HitRadius = 1f;
private class UpgradePickupBaker : Baker<UpgradePickupAuthoring>
{
public override void Bake(UpgradePickupAuthoring authoring)
{
var entity = GetEntity(authoring, TransformUsageFlags.Dynamic);
AddComponent(entity, new UpgradePickup
{
Target = (byte)authoring.Target,
Op = (byte)authoring.Op,
Value = authoring.Value,
SourceId = 0u,
});
AddComponent(entity, new HitRadius { Value = authoring.HitRadius });
}
}
}
}