Files
Project-M/Assets/_Project/Scripts/Authoring/Player/PlayerAuthoring.cs
T
2026-05-31 14:27:52 -07:00

38 lines
1.3 KiB
C#

using ProjectM.Simulation;
using Unity.Entities;
using Unity.Mathematics;
using UnityEngine;
namespace ProjectM.Authoring
{
/// <summary>
/// Authoring for the player ghost prefab. Bakes the gameplay components onto the entity and
/// exposes movement tunables for designers. Ghost replication, <c>GhostOwner</c> and
/// AutoCommandTarget are supplied by the GhostAuthoringComponent added on the same prefab
/// GameObject. <c>GetEntity(TransformUsageFlags.Dynamic)</c> ensures a runtime-mutable
/// LocalTransform exists.
/// </summary>
public class PlayerAuthoring : MonoBehaviour
{
[Min(0f)] public float MoveSpeed = 6f;
[Min(0f)] public float TurnRateDegreesPerSec = 720f;
private class PlayerBaker : Baker<PlayerAuthoring>
{
public override void Bake(PlayerAuthoring authoring)
{
var entity = GetEntity(authoring, TransformUsageFlags.Dynamic);
AddComponent<PlayerTag>(entity);
AddComponent(entity, new PlayerMoveStats
{
MoveSpeed = authoring.MoveSpeed,
TurnRateRadiansPerSec = math.radians(authoring.TurnRateDegreesPerSec)
});
AddComponent<PlayerFacing>(entity);
AddComponent<PlayerInput>(entity);
}
}
}
}