using UnityEngine; using System.Collections.Generic; /// /// Tank decor (rocks, corals) that fish steer around. Registers its renderer bounds, slightly padded, /// for PaperFishController's look-ahead and wander-point checks. /// public class FishObstacle : MonoBehaviour { public static readonly List All = new List(); [Tooltip("Shrink (below 1) or grow the registered box; rocks are lumpy, so their boxes are a bit generous as-is.")] public float boundsScale = 0.85f; Bounds registered; bool added; void OnEnable() { var rs = GetComponentsInChildren(); if (rs.Length == 0) return; var b = rs[0].bounds; foreach (var r in rs) b.Encapsulate(r.bounds); b.extents *= boundsScale; registered = b; All.Add(b); added = true; } void OnDisable() { if (added) { All.Remove(registered); added = false; } } public static bool Contains(Vector3 p, float radius) { foreach (var b in All) { var e = b; e.Expand(radius * 2f); if (e.Contains(p)) return true; } return false; } }