Skip to content

A Civilization-style strategy game about governing Israel from 15 May 1948. Real ministers, real map, every fact sourced. Unity + deterministic C# sim.

Map: up close, the unit tokens' figures play their idle clip (refs #665) (#1087)

Eyal Golan4affe386c764
diff --git a/CHANGELOG.md b/CHANGELOG.md
index a730a7336..1db95e41e 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -121,6 +121,10 @@ adds a line under **Unreleased**; CI's `Changelog` job checks this (see `CONTRIB
in its text, not the acronym הצה״ר; it stays flagged `agent-checked` for a native speaker (refs #875, #564).
- The Burma Road convoy truck and lorry stop on 7 December 1948, the approximate boundary when the Road of Valour
replaced the Burma Road for regular Jerusalem traffic; the Burma Road itself stays drawn (refs #1040, #1051).
+- Up close, the unit tokens' figures are MATKOT's skinned 1948 Collection figures playing their idle clip: below the town
+ models' 40 km switch, back to the still far mesh beyond 45 km. The near figures are asked for only once the camera first
+ comes close, streamed like the far ones, and the far mesh stays when one is missing. C05, the pioneer veteran, has no
+ idle clip and keeps his still model (owner, 18 October 2026: "Keep its still model") (refs #665).
- MATKOT's whole-town models now stand on their towns far off, and the towns draw no procedural houses at any zoom
(refs #663, #917, #659; owner, 18 October 2026: "Whole model far, buildings near"). Each mapped town's model stands
on the town's core (where most of its building models stand, inside its kit footprint, clear of the next town and of
diff --git a/docs/units.md b/docs/units.md
index 8e21852e8..16add7307 100644
--- a/docs/units.md
+++ b/docs/units.md
@@ -186,10 +186,16 @@ own root rotation kept (the FBX axis turn, -90 degrees about X), so the camera's
the figures as the aircraft and the ship are, not to scale, so it fits on the base.
- **C05's pose:** he had no idle clip and shipped in his rest pose, a T-pose. His static meshes are now posed at the first
frame of his own walk (`tools/slim_collection.py`, `POSE_CLIP`).
+- **Close zoom:** below the town models' switch (`TownModelLayer.CloseEnterM`, 40 km; far again beyond `CloseExitM`,
+ 45 km), each figure whose model has an idle clip (`CollectionCatalog.Animated`) shows its skinned near model playing the
+ clip, as tall as its far model and under the same holder (`UnitFigureDetail`). The near models are asked for only once a
+ camera first comes close; until one arrives, and for good if it is missing, the far mesh stays. C05 has no idle clip
+ (walk and run only) and keeps his still far model (owner, 18 October 2026, #665: "Keep its still model"). The vehicles
+ stay far.
- **Fail open:** an Israeli figure keeps its code-built mesh until its model arrives, and for good if the bundle is
missing or damaged; a vehicle and an Arab force's token are not drawn until their model arrives.
- Tests: `UnitFiguresTests` (every one of the nine is placed on some day of the war; the table; the swap; arms down;
- fail open).
+ fail open; the close-zoom swap and its idle clip, the missing near model and C05).
### What the player sees
diff --git a/unity/Assets/Scripts/Map/Units/UnitFigureDetail.cs b/unity/Assets/Scripts/Map/Units/UnitFigureDetail.cs
new file mode 100644
index 000000000..5528e125f
--- /dev/null
+++ b/unity/Assets/Scripts/Map/Units/UnitFigureDetail.cs
@@ -0,0 +1,125 @@
+#nullable enable
+using System;
+using System.Collections.Generic;
+using Statecraft.Game.Map.Collection;
+using Statecraft.Game.Map.Kits;
+using UnityEngine;
+using UnityEngine.Rendering;
+
+namespace Statecraft.Game.Map.Units
+{
+ /// <summary>The close-zoom detail of the tokens' Collection figures (issue #665, #663's rule: "full detail and the idle
+ /// clip only at close zoom"). Each camera picks with the town models' switch and its hysteresis (TownModelLayer.CloseAt:
+ /// close below CloseEnterM, far again beyond CloseExitM). Up close, each figure whose model has an idle clip
+ /// (CollectionCatalog.Animated) shows its skinned near model, playing the clip, under the same holder as its far model, so
+ /// the camera's yaw (#644) and the far model's height and feet carry over; far off, the far mesh draws and the clip stops.
+ /// The near prefabs are asked for only once a camera first comes close, through the same stream, after the first frame.
+ /// It fails open: until a near prefab arrives, and for good when it is missing or damaged, the far model stays. C05, the
+ /// pioneer veteran, has no idle clip (walk and run only), so he keeps his still far model close up (owner, 18 October
+ /// 2026, #665: "Keep its still model"). One per unit layer or showcase; nothing is allocated while the zoom band holds.</summary>
+ [ExecuteAlways]
+ public sealed class UnitFigureDetail : MonoBehaviour
+ {
+ /// <summary>The name of the near model's object, beside the far model under the figure's holder.</summary>
+ public const string NearName = "Near";
+
+ sealed class Figure
+ {
+ public Transform Holder = null!, Far = null!;
+ public string Id = "";
+ public Renderer[] FarRenderers = Array.Empty<Renderer>(), NearRenderers = Array.Empty<Renderer>();
+ public Animator[] Animators = Array.Empty<Animator>();
+ }
+
+ readonly List<Figure> figures = new List<Figure>();
+ readonly HashSet<string> nearAsked = new HashSet<string>(StringComparer.Ordinal);
+ /// <summary>Each camera's last choice (by instance id), for the hysteresis.</summary>
+ readonly Dictionary<int, bool> closeFor = new Dictionary<int, bool>();
+ static readonly Predicate<Figure> Gone = f => f.Holder == null;
+ static bool logged;
+
+ /// <summary>True when the last camera to render was close (the near models show where they have arrived).</summary>
+ public bool LastClose { get; private set; }
+
+ /// <summary>The switch of the unit layer or showcase that <paramref name="piece"/> stands in (the root that owns its
+ /// runtime assets, so it goes with the layer), made on first use.</summary>
+ internal static UnitFigureDetail Of(Transform piece)
+ {
+ var assets = piece.GetComponentInParent<MapRuntimeAssets>(true);
+ var root = assets != null ? assets.gameObject : piece.root.gameObject;
+ return root.TryGetComponent<UnitFigureDetail>(out var detail) ? detail : root.AddComponent<UnitFigureDetail>();
+ }
+
+ /// <summary>A figure whose far model <paramref name="holder"/> now holds (its first child), with an idle clip.</summary>
+ internal void Add(Transform holder, string id)
+ {
+ var far = holder.GetChild(0);
+ var f = new Figure { Holder = holder, Far = far, Id = id, FarRenderers = far.GetComponentsInChildren<Renderer>(true) };
+ figures.Add(f);
+ if (LastClose) { Ask(id); Attach(f); }
+ Show(f);
+ }
+
+ void OnEnable() => RenderPipelineManager.beginCameraRendering += Choose;
+ void OnDisable() => RenderPipelineManager.beginCameraRendering -= Choose;
+
+ internal void Choose(ScriptableRenderContext context, Camera camera)
+ {
+ if (camera.cameraType == CameraType.Preview || camera.cameraType == CameraType.Reflection) return;
+ int id = camera.GetInstanceID();
+ bool close = TownModelLayer.CloseAt(TownModelLayer.ViewDistance(camera), closeFor.TryGetValue(id, out var was) ? was : (bool?)null);
+ closeFor[id] = close;
+ if (close == LastClose) return;
+ LastClose = close;
+ figures.RemoveAll(Gone);
+ foreach (var f in figures) { if (close) { Ask(f.Id); Attach(f); } Show(f); }
+ }
+
+ void Ask(string id)
+ {
+ if (nearAsked.Add(id)) UnitFigures.RequestNear(id, () => Arrived(id));
+ }
+
+ void Arrived(string id)
+ {
+ if (this == null) return; // the layer was rebuilt meanwhile
+ figures.RemoveAll(Gone);
+ foreach (var f in figures)
+ if (f.Id == id) { Attach(f); Show(f); }
+ }
+
+ /// <summary>Puts the near model beside the far one, once it has arrived: as tall as the far model, centred over its
+ /// feet, casting shadows as it does, with the probes off as on the far model.</summary>
+ void Attach(Figure f)
+ {
+ if (f.NearRenderers.Length > 0 || f.Holder == null) return;
+ var prefab = UnitFigures.Near(f.Id);
+ if (prefab == null) return;
+ var near = Instantiate(prefab, f.Holder, false).transform; // the prefab's own root rotation (the FBX axis turn) kept
+ near.name = NearName;
+ if (UnitFigures.BoxIn(f.Holder, f.Far) is Bounds far && UnitFigures.BoxIn(f.Holder, near) is Bounds box && box.size.y > 1e-6f)
+ {
+ near.localScale *= far.size.y / box.size.y;
+ if (UnitFigures.BoxIn(f.Holder, near) is Bounds fit)
+ near.localPosition += new Vector3(far.center.x - fit.center.x, far.min.y - fit.min.y, far.center.z - fit.center.z);
+ }
+ var like = f.FarRenderers.Length > 0 ? f.FarRenderers[0] : null;
+ f.NearRenderers = near.GetComponentsInChildren<Renderer>(true);
+ foreach (var r in f.NearRenderers)
+ {
+ if (like != null) { r.shadowCastingMode = like.shadowCastingMode; r.receiveShadows = like.receiveShadows; }
+ r.lightProbeUsage = LightProbeUsage.Off; r.reflectionProbeUsage = ReflectionProbeUsage.Off;
+ }
+ f.Animators = near.GetComponentsInChildren<Animator>(true);
+ if (!logged && Application.isPlaying) { logged = true; Debug.Log("UNITS figures: the skinned near figures streamed in (close zoom)"); }
+ }
+
+ void Show(Figure f)
+ {
+ bool near = LastClose && f.NearRenderers.Length > 0;
+ foreach (var r in f.FarRenderers) if (r != null) r.forceRenderingOff = near;
+ foreach (var r in f.NearRenderers) if (r != null) r.forceRenderingOff = !near;
+ foreach (var a in f.Animators) if (a != null) a.enabled = near;
+ }
+ }
+}
diff --git a/unity/Assets/Scripts/Map/Units/UnitFigureDetail.cs.meta b/unity/Assets/Scripts/Map/Units/UnitFigureDetail.cs.meta
new file mode 100644
index 000000000..874d740e9
--- /dev/null
+++ b/unity/Assets/Scripts/Map/Units/UnitFigureDetail.cs.meta
@@ -0,0 +1,2 @@
+fileFormatVersion: 2
+guid: 73f12792a27154e0fb693f8e45059e4e
\ No newline at end of file
diff --git a/unity/Assets/Scripts/Map/Units/UnitFigures.cs b/unity/Assets/Scripts/Map/Units/UnitFigures.cs
index 68515e374..8901d6d3b 100644
--- a/unity/Assets/Scripts/Map/Units/UnitFigures.cs
+++ b/unity/Assets/Scripts/Map/Units/UnitFigures.cs
@@ -1,6 +1,7 @@
#nullable enable
using System;
using System.Collections.Generic;
+using System.Linq;
using Statecraft.Game.Map.Collection;
using UnityEngine;
using UnityEngine.Rendering;
@@ -18,7 +19,8 @@ namespace Statecraft.Game.Map.Units
/// #740: "Nothing is drawn with IDF figures, and there is no placeholder art"): the roster draws it only once its model
/// has arrived (<see cref="Arrived"/>). A vehicle has no code-built model either: it appears when it arrives. A model
/// that has arrived once is put on new tokens at once (a roster change rebuilds them), so a rebuild never shows the
- /// code-built figures for a frame.</summary>
+ /// code-built figures for a frame. Up close (<see cref="UnitFigureDetail"/>), each figure whose model has an idle clip
+ /// shows its skinned near model playing it instead.</summary>
public static class UnitFigures
{
/// <summary>The name of the model's object under its figure or vehicle.</summary>
@@ -101,12 +103,16 @@ namespace Statecraft.Game.Map.Units
static readonly HashSet<string> asked = new HashSet<string>(StringComparer.Ordinal);
/// <summary>The figures and vehicles waiting for each asked-for model.</summary>
static readonly Dictionary<string, List<Transform>> waiting = new Dictionary<string, List<Transform>>(StringComparer.Ordinal);
+ /// <summary>The near prefabs answered (null: missing or damaged, so the far model stays), and the callers waiting for
+ /// each near prefab asked for.</summary>
+ static readonly Dictionary<string, GameObject?> near = new Dictionary<string, GameObject?>(StringComparer.Ordinal);
+ static readonly Dictionary<string, List<Action>> nearWaiting = new Dictionary<string, List<Action>>(StringComparer.Ordinal);
/// <summary>Raised once for each model when it first arrives (the unit layer then draws the tokens that waited for it).</summary>
public static event Action<string>? ModelArrived;
/// <summary>Forgets every model and request (tests, and a change of <see cref="Source"/>).</summary>
- public static void Forget() { arrived.Clear(); asked.Clear(); waiting.Clear(); }
+ public static void Forget() { arrived.Clear(); asked.Clear(); waiting.Clear(); near.Clear(); nearWaiting.Clear(); }
/// <summary>True when model <paramref name="id"/> has arrived (and its prefab still exists).</summary>
public static bool Arrived(string id) => arrived.TryGetValue(id, out var p) && p != null;
@@ -126,6 +132,28 @@ namespace Statecraft.Game.Map.Units
Ask(id);
}
+ /// <summary>Asks once for model <paramref name="id"/>'s near (close-zoom) prefab and calls <paramref name="ready"/> when
+ /// it is answered (at once if it already was), found or not: <see cref="Near"/> then gives it, or null.</summary>
+ internal static void RequestNear(string id, Action ready)
+ {
+ if (near.ContainsKey(id)) { ready(); return; }
+ var ask = Requester;
+ if (ask == null) return;
+ if (!nearWaiting.TryGetValue(id, out var list)) nearWaiting[id] = list = new List<Action>();
+ list.Add(ready);
+ if (list.Count > 1) return; // asked already
+ ask(id, CollectionDetail.Near, prefab =>
+ {
+ near[id] = prefab; // null: fail open, the far model stays (the stream has warned once)
+ if (!nearWaiting.TryGetValue(id, out var done)) return;
+ nearWaiting.Remove(id);
+ foreach (var callback in done) callback();
+ });
+ }
+
+ /// <summary>Model <paramref name="id"/>'s near prefab once it has arrived, else null.</summary>
+ internal static GameObject? Near(string id) => near.TryGetValue(id, out var prefab) ? prefab : null;
+
static void Ask(string id)
{
if (Arrived(id) || asked.Contains(id)) return;
@@ -166,20 +194,7 @@ namespace Statecraft.Game.Map.Units
var renderers = model.GetComponentsInChildren<Renderer>(true);
if (renderers.Length > 0)
{
- // The box in the holder's frame, from each mesh's own bounds (Renderer.bounds is empty while the layer is off).
- var inv = holder.worldToLocalMatrix;
- Bounds? box = null;
- foreach (var f in model.GetComponentsInChildren<MeshFilter>(true))
- {
- if (f.sharedMesh == null) continue;
- var b = f.sharedMesh.bounds; var m = inv * f.transform.localToWorldMatrix;
- for (int c = 0; c < 8; c++)
- {
- var p = m.MultiplyPoint3x4(new Vector3((c & 1) == 0 ? b.min.x : b.max.x, (c & 2) == 0 ? b.min.y : b.max.y, (c & 4) == 0 ? b.min.z : b.max.z));
- if (box is Bounds bb) { bb.Encapsulate(p); box = bb; } else box = new Bounds(p, Vector3.zero);
- }
- }
- if (box is Bounds have && have.size.y > 1e-6f)
+ if (BoxIn(holder, model.transform) is Bounds have && have.size.y > 1e-6f)
{
float k;
bool vehicle = ByVehicleId(id);
@@ -200,6 +215,29 @@ namespace Statecraft.Game.Map.Units
r.lightProbeUsage = LightProbeUsage.Off; r.reflectionProbeUsage = ReflectionProbeUsage.Off;
}
if (code != null) code.enabled = false;
+ if (CollectionCatalog.Animated.Contains(id)) UnitFigureDetail.Of(piece).Add(holder, id); // C05 has no idle: he stays far
+ }
+
+ /// <summary>The box of <paramref name="model"/>'s meshes in <paramref name="frame"/>'s space, from each mesh's own
+ /// bounds (Renderer.bounds is empty while the layer is off). A skinned mesh is drawn through its bones, so its box is
+ /// the renderer's local bounds in its root bone's space (as Unity bounds it), not its mesh's. Null with no mesh.</summary>
+ internal static Bounds? BoxIn(Transform frame, Transform model)
+ {
+ var inv = frame.worldToLocalMatrix;
+ Bounds? box = null;
+ void Add(Bounds b, Transform at)
+ {
+ var m = inv * at.localToWorldMatrix;
+ for (int c = 0; c < 8; c++)
+ {
+ var p = m.MultiplyPoint3x4(new Vector3((c & 1) == 0 ? b.min.x : b.max.x, (c & 2) == 0 ? b.min.y : b.max.y, (c & 4) == 0 ? b.min.z : b.max.z));
+ if (box is Bounds bb) { bb.Encapsulate(p); box = bb; } else box = new Bounds(p, Vector3.zero);
+ }
+ }
+ foreach (var f in model.GetComponentsInChildren<MeshFilter>(true)) if (f.sharedMesh != null) Add(f.sharedMesh.bounds, f.transform);
+ foreach (var s in model.GetComponentsInChildren<SkinnedMeshRenderer>(true))
+ if (s.sharedMesh != null) Add(s.localBounds, s.rootBone != null ? s.rootBone : s.transform);
+ return box;
}
static bool ByVehicleId(string id) => id == Napoleonchik || id == WillysJeep;
diff --git a/unity/Assets/Tests/EditMode/UnitFiguresTests.cs b/unity/Assets/Tests/EditMode/UnitFiguresTests.cs
index 4d72f3100..890a517b9 100644
--- a/unity/Assets/Tests/EditMode/UnitFiguresTests.cs
+++ b/unity/Assets/Tests/EditMode/UnitFiguresTests.cs
@@ -8,6 +8,7 @@ using NUnit.Framework;
using Statecraft.Game;
using Statecraft.Game.Map;
using Statecraft.Game.Map.Collection;
+using Statecraft.Game.Map.Kits;
using Statecraft.Game.Map.Units;
using Statecraft.Sim;
using UnityEditor;
@@ -64,6 +65,7 @@ public class UnitFiguresTests
.SelectMany(t => t.Cast<Transform>().Where(x => prefixes.Any(x.name.StartsWith))).ToList();
static GameObject Prefab(string id) => AssetDatabase.LoadAssetAtPath<GameObject>(CollectionCatalog.PrefabPath(id, CollectionDetail.Far));
+ static GameObject NearPrefab(string id) => AssetDatabase.LoadAssetAtPath<GameObject>(CollectionCatalog.PrefabPath(id, CollectionDetail.Near));
/// <summary>The model ids a token draws: its figures', then its vehicles'.</summary>
static IEnumerable<string> ModelsOf(UnitToken t) =>
@@ -222,6 +224,8 @@ public class UnitFiguresTests
var centre = v.parent.Find(UnitPlinth.PlinthName).position;
Assert.Less(new Vector2(v.position.x - centre.x, v.position.z - centre.z).magnitude, 0.75f * plinth, $"{v.parent.name}/{v.name}: on its base");
}
+ Assert.IsTrue(map.Terrain.transform.Find(UnitLayer.RootName).TryGetComponent<UnitFigureDetail>(out _),
+ "the close-zoom switch stands on the unit layer's root, and goes with it");
// A roster change rebuilds the tokens: the new pieces are dressed at once, with no new request.
int n = asked.Count;
Assert.IsTrue(layer.Show(C, StateAt(July12, 0.3)), "the call-up changes the roster");
@@ -232,6 +236,136 @@ public class UnitFiguresTests
finally { UnityEngine.Object.DestroyImmediate(map.gameObject); }
}
+ /// <summary>A figure standing on its own (a showcase figure, by the code-built rifleman), dressed with model
+ /// <paramref name="id"/> once its far model is answered.</summary>
+ static Transform DressedFigure(Transform root, string name, string id, Vector3 at, List<(string id, CollectionDetail detail, Action<GameObject> done)> asked)
+ {
+ var piece = UnitShowcase.Piece(root, name, UnitModels.Rifleman(UnitModels.Headgear.SlouchHat, UnitModels.RiflePose.Ready, false, name),
+ Load("Terrain"), at, Quaternion.Euler(0f, 30f, 0f), UnitShowcase.FigureScale).transform;
+ UnitFigures.Dress(piece, id);
+ asked.Single(a => a.id == id && a.detail == CollectionDetail.Far).done(Prefab(id));
+ Assert.IsTrue(UnitFigures.Dressed(piece), $"{name}: the far model is on");
+ return piece;
+ }
+
+ static Renderer[] FarOf(Transform piece) => piece.Find(UnitFigures.ModelName).GetChild(0).GetComponentsInChildren<Renderer>(true);
+ static Transform NearOf(Transform piece) => piece.Find(UnitFigures.ModelName).Find(UnitFigureDetail.NearName);
+
+ /// <summary>Issue #665, close zoom (#663: "full detail and the idle clip only at close zoom"): a camera that comes in
+ /// below TownModelLayer.CloseEnterM asks for the near model (and not before); once it arrives the figure shows it, skinned
+ /// and playing its idle clip, as tall as the far model and on its feet, under the same holder (so the camera's yaw, #644,
+ /// turns it too); the far mesh is off. The band's hysteresis holds it to CloseExitM; beyond, the far mesh is back and the
+ /// clip stops. Coming close again asks for nothing new.</summary>
+ [Test]
+ public void AFigureShowsItsSkinnedIdleModelOnlyCloseUp()
+ {
+ var root = new GameObject("Units");
+ var asked = new List<(string id, CollectionDetail detail, Action<GameObject> done)>();
+ UnitFigures.Source = (id, detail, done) => asked.Add((id, detail, done));
+ var camera = TopDownCamera(root.transform);
+ try
+ {
+ var piece = DressedFigure(root.transform, "Rifleman0", UnitFigures.SabraPioneer, Vector3.zero, asked);
+ Assert.IsTrue(root.TryGetComponent<UnitFigureDetail>(out var detail), "the switch stands on the figures' root");
+ int Nears() => asked.Count(a => a.detail == CollectionDetail.Near);
+
+ View(detail, camera, TownModelLayer.CloseEnterM + 1f);
+ Assert.AreEqual(0, Nears(), "just beyond the switch the near model is not asked for");
+ Assert.IsNull(NearOf(piece));
+ Assert.IsTrue(FarOf(piece).All(r => !r.forceRenderingOff), "far off: the far mesh draws");
+
+ View(detail, camera, TownModelLayer.CloseEnterM - 1f);
+ Assert.AreEqual(1, Nears(), "close: the near model is asked for, once");
+ Assert.IsTrue(FarOf(piece).All(r => !r.forceRenderingOff), "the far mesh draws while the near one streams");
+ asked.Single(a => a.detail == CollectionDetail.Near).done(NearPrefab(UnitFigures.SabraPioneer));
+
+ var holder = piece.Find(UnitFigures.ModelName);
+ var near = NearOf(piece);
+ Assert.IsNotNull(near, "the near model stands beside the far one");
+ Assert.AreEqual(holder, near.parent, "under the same holder, so the figure's yaw turns it (#644)");
+ Assert.AreEqual(NearPrefab(UnitFigures.SabraPioneer).transform.localRotation, near.localRotation, "the prefab keeps its own rotation (the FBX axis turn)");
+ Assert.IsTrue(near.GetComponentsInChildren<SkinnedMeshRenderer>(true).Length > 0, "the near model is the skinned one");
+ Assert.IsTrue(FarOf(piece).All(r => r.forceRenderingOff), "close: the far mesh is off");
+ Assert.IsTrue(near.GetComponentsInChildren<Renderer>(true).All(r => !r.forceRenderingOff), "close: the near model draws");
+ var animators = near.GetComponentsInChildren<Animator>(true);
+ Assert.Greater(animators.Length, 0, "the near model has its animator");
+ Assert.IsTrue(animators.All(a => a.enabled && a.runtimeAnimatorController != null), "close: the idle clip plays");
+ // Sized by what Unity draws: the renderers' own world bounds (a skinned mesh's through its bones), not by BoxIn.
+ var far = WorldBounds(holder.GetChild(0)); var box = WorldBounds(near);
+ Assert.AreEqual(far.size.y, box.size.y, 0.05f * far.size.y, "as tall as the far model");
+ Assert.AreEqual(far.min.y, box.min.y, 0.05f * far.size.y, "feet where the far model's are");
+ Assert.AreEqual(0f, new Vector2(box.center.x - far.center.x, box.center.z - far.center.z).magnitude, 0.1f * far.size.y, "centred over them");
+
+ View(detail, camera, TownModelLayer.CloseExitM - 1f);
+ Assert.IsTrue(FarOf(piece).All(r => r.forceRenderingOff), "the band's hysteresis: still close inside CloseExitM");
+ View(detail, camera, TownModelLayer.CloseExitM + 1f);
+ Assert.IsTrue(FarOf(piece).All(r => !r.forceRenderingOff), "beyond the band: the far mesh again");
+ Assert.IsTrue(near.GetComponentsInChildren<Renderer>(true).All(r => r.forceRenderingOff), "and the near model off");
+ Assert.IsTrue(animators.All(a => !a.enabled), "the idle clip stops far off");
+
+ View(detail, camera, TownModelLayer.CloseEnterM - 1f);
+ Assert.AreEqual(1, Nears(), "close again: nothing asked for anew");
+ Assert.AreEqual(1, piece.Find(UnitFigures.ModelName).Cast<Transform>().Count(c => c.name == UnitFigureDetail.NearName), "one near model");
+ Assert.IsTrue(animators.All(a => a.enabled), "the idle clip plays again");
+ }
+ finally { UnityEngine.Object.DestroyImmediate(camera.gameObject); UnityEngine.Object.DestroyImmediate(root); }
+ }
+
+ /// <summary>Close up, a near model that never comes (null: a missing or damaged bundle) leaves the far mesh drawing (fail
+ /// open); and C05, the pioneer veteran, has no idle clip (walk and run only), so his near model is never asked for and he
+ /// keeps his still far model (owner, 18 October 2026, #665: "Keep its still model"), while the figures beside him swap.</summary>
+ [Test]
+ public void AMissingNearModelKeepsTheFarMeshAndC05KeepsHisStillModel()
+ {
+ var root = new GameObject("Units");
+ var asked = new List<(string id, CollectionDetail detail, Action<GameObject> done)>();
+ UnitFigures.Source = (id, detail, done) => asked.Add((id, detail, done));
+ var camera = TopDownCamera(root.transform);
+ try
+ {
+ var c04 = DressedFigure(root.transform, "C04", UnitFigures.SabraPioneer, Vector3.zero, asked);
+ var c05 = DressedFigure(root.transform, "C05", UnitFigures.PioneerVeteran, Vector3.right, asked);
+ var c06 = DressedFigure(root.transform, "C06", UnitFigures.YoungRecruit, Vector3.left, asked);
+ Assert.IsNotNull(NearPrefab(UnitFigures.PioneerVeteran), "C05 has a near prefab, so leaving it out is a choice (not a vacuous pass)");
+ View(root.GetComponent<UnitFigureDetail>(), camera, TownModelLayer.CloseEnterM - 1f);
+ var nears = asked.Where(a => a.detail == CollectionDetail.Near).ToList();
+ CollectionAssert.AreEquivalent(new[] { UnitFigures.SabraPioneer, UnitFigures.YoungRecruit }, nears.Select(a => a.id),
+ "C05 has no idle clip: his near model is never asked for");
+ nears.Single(a => a.id == UnitFigures.SabraPioneer).done(null);
+ nears.Single(a => a.id == UnitFigures.YoungRecruit).done(NearPrefab(UnitFigures.YoungRecruit));
+ Assert.IsNull(NearOf(c04), "C04's near model did not come");
+ Assert.IsTrue(FarOf(c04).All(r => !r.forceRenderingOff), "so C04's far mesh draws (fail open)");
+ Assert.IsNull(NearOf(c05), "C05 has no near model");
+ Assert.IsTrue(FarOf(c05).All(r => !r.forceRenderingOff), "C05 keeps his still far model close up");
+ Assert.IsNotNull(NearOf(c06), "C06 swaps beside him");
+ Assert.IsTrue(FarOf(c06).All(r => r.forceRenderingOff));
+ }
+ finally { UnityEngine.Object.DestroyImmediate(camera.gameObject); UnityEngine.Object.DestroyImmediate(root); }
+ }
+
+ static Bounds WorldBounds(Transform model)
+ {
+ var rs = model.GetComponentsInChildren<Renderer>(true);
+ var b = rs[0].bounds;
+ foreach (var r in rs) b.Encapsulate(r.bounds);
+ return b;
+ }
+
+ static Camera TopDownCamera(Transform parent)
+ {
+ var camera = new GameObject("Camera").AddComponent<Camera>();
+ camera.transform.SetParent(parent, false);
+ camera.transform.rotation = Quaternion.Euler(90f, 0f, 0f); // looking straight down: the view distance is its height
+ return camera;
+ }
+
+ static void View(UnitFigureDetail detail, Camera camera, float distanceM)
+ {
+ camera.transform.position = new Vector3(0f, distanceM, 0f);
+ Assert.AreEqual(distanceM, TownModelLayer.ViewDistance(camera), 1f);
+ detail.Choose(default, camera);
+ }
+
/// <summary>The Arab Legion and the Arab Liberation Army are drawn only once their own figure has arrived, three of it on
/// a base under the neutral pennant, never an IDF figure, and on ground no Israeli force held on the window's first day
/// (#226, ruling 9). A figure that never comes (null: a missing or damaged bundle) draws nothing, and warns nothing more.</summary>