using System.Collections.Generic;
using UnityEngine;
namespace GrassCutter
{
///
/// Keeps the meadow from growing through fixed ground furniture (the loading ramp, the unloading yard): registers an
/// axis-aligned rectangle with . is local (x, z); a quarter-turned
/// placement swaps the axes.
///
public class GrassBlocker : MonoBehaviour
{
public Vector3 center;
public Vector2 halfSize = Vector2.one;
static readonly List s_all = new List();
void Start()
{
s_all.Add(this);
Block();
}
void OnDestroy() => s_all.Remove(this);
void Block()
{
var c = transform.TransformPoint(center);
bool turned = Mathf.Abs(Vector3.Dot(transform.right, Vector3.forward)) > 0.7f;
MowMap.Block(c, turned ? new Vector2(halfSize.y, halfSize.x) : halfSize);
}
/// The ball has changed size and the blocks were wiped with it: the ramp and the yard keep their spot
/// (without this a smaller planet grew grass over them).
public static void ReblockAll()
{
foreach (var b in s_all) if (b) b.Block();
}
}
}