Protfolio-Emanuel-Polsky / Assets / _Project / Code / PathFinding / Mono / PathFinderMono.cs
PathFinderMono.cs
Raw
using Unity.Burst;
using Unity.Entities;
using UnityEngine;

namespace GarmentButton.PathFinding
{
    [BurstCompile]
    public class PathFinderMono : MonoBehaviour
    {
        [Min(0f)] public float MoveSpeed = 4f;
        [Min(0f)] public float StopDistance = 0.15f;
    }

    public class PathFinderMonoBaker : Baker<PathFinderMono>
    {
        public override void Bake(PathFinderMono authoring)
        {
            var entity = GetEntity(TransformUsageFlags.Dynamic);
            AddBuffer<PathElement>(entity);
            AddComponent<EndPointPath>(entity);
            AddComponent<EndPointIndexPath>(entity);
            AddComponent<LastPointPath>(entity);
            AddComponent<CheckStuck>(entity);
            AddComponent(entity, new PathRigidbodyMovement
            {
                MoveSpeed = authoring.MoveSpeed,
                StopDistance = authoring.StopDistance,
            });
            SetComponentEnabled<EndPointPath>(entity, false);
        }
    }
}