using UnityEngine; namespace GrassCutter { /// /// Steps every bundle and every grabbable thing from one FixedUpdate. A big farm has two thousand bundles, and a Unity /// message per object per physics step (two scripts each) cost more than what they do, which is mostly nothing. /// public class CargoTick : MonoBehaviour { static CargoTick s_on; public static void Ensure() { if (s_on) return; var go = new GameObject("CargoTick"); DontDestroyOnLoad(go); s_on = go.AddComponent(); } void FixedUpdate() { // backwards: a step can hand a bundle to a depot, which takes it off the list var g = Grabbable.All; for (int i = g.Count - 1; i >= 0; i--) if (i < g.Count && g[i]) g[i].Step(); var c = Cargo.All; for (int i = c.Count - 1; i >= 0; i--) if (i < c.Count && c[i]) c[i].Step(); } } }