49 lines
1.9 KiB
C#
49 lines
1.9 KiB
C#
using ProjectM.Simulation;
|
|
using Unity.Entities;
|
|
using UnityEngine;
|
|
|
|
namespace ProjectM.Authoring
|
|
{
|
|
/// <summary>
|
|
/// Authoring for the baked <see cref="TrainingDummySpawner"/> singleton. Place this on a single
|
|
/// GameObject in the gameplay subscene; at runtime the server-only
|
|
/// <c>TrainingDummySpawnSystem</c> reads the singleton, instantiates <see cref="Count"/> dummies
|
|
/// laid out along +X from <see cref="Origin"/> at <see cref="Spacing"/> intervals, then destroys
|
|
/// the singleton so it fires exactly once. The entity itself carries no transform
|
|
/// (<c>TransformUsageFlags.None</c>); only the referenced <see cref="DummyPrefab"/> needs a
|
|
/// runtime-mutable LocalTransform (<c>TransformUsageFlags.Dynamic</c>).
|
|
/// </summary>
|
|
public class TrainingDummySpawnerAuthoring : MonoBehaviour
|
|
{
|
|
[Tooltip("Training dummy prefab to instantiate. Must carry TrainingDummyAuthoring.")]
|
|
public GameObject DummyPrefab;
|
|
|
|
[Min(0)]
|
|
[Tooltip("How many dummies to spawn.")]
|
|
public int Count = 3;
|
|
|
|
[Min(0f)]
|
|
[Tooltip("World-unit spacing between consecutive dummies along +X.")]
|
|
public float Spacing = 3f;
|
|
|
|
[Tooltip("World-space position of the first dummy.")]
|
|
public Vector3 Origin = new Vector3(0, 0, 8);
|
|
|
|
private class TrainingDummySpawnerBaker : Baker<TrainingDummySpawnerAuthoring>
|
|
{
|
|
public override void Bake(TrainingDummySpawnerAuthoring authoring)
|
|
{
|
|
var entity = GetEntity(authoring, TransformUsageFlags.None);
|
|
|
|
AddComponent(entity, new TrainingDummySpawner
|
|
{
|
|
Prefab = GetEntity(authoring.DummyPrefab, TransformUsageFlags.Dynamic),
|
|
Count = authoring.Count,
|
|
Spacing = authoring.Spacing,
|
|
Origin = authoring.Origin
|
|
});
|
|
}
|
|
}
|
|
}
|
|
}
|