Files
grass-cutters/Assets/Scripts/World/GrassBlocker.cs
NiemandKG d1c3761e58 Grass Cutters Together: the project as of moon-sweepers f3666f0
A clean start for the shared repository: the Unity project (Assets, Packages, ProjectSettings), ArtSource, Docs and
Tools as they stood at f3666f0 in the old local repository, with its generated prefabs and scene brought up to date.
Images, audio, models and binaries go through Git LFS (.gitattributes).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-06 18:44:40 +06:00

41 lines
1.3 KiB
C#

using System.Collections.Generic;
using UnityEngine;
namespace GrassCutter
{
/// <summary>
/// Keeps the meadow from growing through fixed ground furniture (the loading ramp, the unloading yard): registers an
/// axis-aligned rectangle with <see cref="MowMap.Block"/>. <see cref="halfSize"/> is local (x, z); a quarter-turned
/// placement swaps the axes.
/// </summary>
public class GrassBlocker : MonoBehaviour
{
public Vector3 center;
public Vector2 halfSize = Vector2.one;
static readonly List<GrassBlocker> s_all = new List<GrassBlocker>();
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);
}
/// <summary>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).</summary>
public static void ReblockAll()
{
foreach (var b in s_all) if (b) b.Block();
}
}
}