A Civilization-style strategy game about governing Israel from 15 May 1948. Real ministers, real map, every fact sourced. Unity + deterministic C# sim.
Units: tokens slide when they move, figures walk (supersedes #1900) (#2176)
Eyal Golanb6bdb4400335
diff --git a/changelog.d/1866-unit-motion.md b/changelog.d/1866-unit-motion.mdnew file mode 100644index 000000000..534fa7a5f--- /dev/null+++ b/changelog.d/1866-unit-motion.md@@ -0,0 +1,9 @@+### Added++- Units move on the map instead of jumping: a moved unit's token slides from its old place to its new one in about two+ thirds of a second, and its figures walk while it moves and stand idle again when it stops. The C04 and C06 to C12F+ figures walk up close, where their detailed models are drawn; the Syrian, Iraqi, Egyptian, Lebanese and ALA infantry+ walk at every zoom. A click and the map's names find the token where it is drawn during the slide. Designed by Tal+ Heuberger (#1900, #1866), using Tal Heuberger's own walk takes; the models and animations are unchanged. The figures+ with a fire take (C06, C07, C08, C09 and C12F) also gain an attack state, which the combat presentation of #1867+ plays (a separate change).diff --git a/unity/Assets/Art/Collection/figure-ala-infantry-1948-v1/figure-ala-infantry-1948-v1.controller b/unity/Assets/Art/Collection/figure-ala-infantry-1948-v1/figure-ala-infantry-1948-v1.controllerindex 041209ae1..1b9b50e4f 100644--- a/unity/Assets/Art/Collection/figure-ala-infantry-1948-v1/figure-ala-infantry-1948-v1.controller+++ b/unity/Assets/Art/Collection/figure-ala-infantry-1948-v1/figure-ala-infantry-1948-v1.controller@@ -12,6 +12,9 @@ AnimatorStateMachine:- serializedVersion: 1m_State: {fileID: 69232615161724142}m_Position: {x: 200, y: 0, z: 0}+ - serializedVersion: 1+ m_State: {fileID: 1119529243155612524}+ m_Position: {x: 235, y: 65, z: 0}m_ChildStateMachines: []m_AnyStateTransitions: []m_EntryTransitions: []@@ -65,8 +68,34 @@ AnimatorState:m_CycleOffsetParameterActive: 0m_TimeParameterActive: 0m_Motion: {fileID: 3752702422747699540, guid: 31f21311220ed4a3a99bfb84f1da4d22, type: 3}- m_Tag:- m_SpeedParameter:- m_MirrorParameter:- m_CycleOffsetParameter:- m_TimeParameter:+ m_Tag:+ m_SpeedParameter:+ m_MirrorParameter:+ m_CycleOffsetParameter:+ m_TimeParameter:+--- !u!1102 &1119529243155612524+AnimatorState:+ serializedVersion: 6+ m_ObjectHideFlags: 1+ m_CorrespondingSourceObject: {fileID: 0}+ m_PrefabInstance: {fileID: 0}+ m_PrefabAsset: {fileID: 0}+ m_Name: walk+ m_Speed: 1+ m_CycleOffset: 0+ m_Transitions: []+ m_StateMachineBehaviours: []+ m_Position: {x: 50, y: 50, z: 0}+ m_IKOnFeet: 0+ m_WriteDefaultValues: 1+ m_Mirror: 0+ m_SpeedParameterActive: 0+ m_MirrorParameterActive: 0+ m_CycleOffsetParameterActive: 0+ m_TimeParameterActive: 0+ m_Motion: {fileID: 6531620196345656355, guid: 31f21311220ed4a3a99bfb84f1da4d22, type: 3}+ m_Tag:+ m_SpeedParameter:+ m_MirrorParameter:+ m_CycleOffsetParameter:+ m_TimeParameter:diff --git a/unity/Assets/Art/Collection/figure-c04-sabra-pioneer-v3/figure-c04-sabra-pioneer-v3-near.controller b/unity/Assets/Art/Collection/figure-c04-sabra-pioneer-v3/figure-c04-sabra-pioneer-v3-near.controllerindex 72a26b594..98025babf 100644--- a/unity/Assets/Art/Collection/figure-c04-sabra-pioneer-v3/figure-c04-sabra-pioneer-v3-near.controller+++ b/unity/Assets/Art/Collection/figure-c04-sabra-pioneer-v3/figure-c04-sabra-pioneer-v3-near.controller@@ -34,6 +34,9 @@ AnimatorStateMachine:- serializedVersion: 1m_State: {fileID: 7674372291624684852}m_Position: {x: 200, y: 0, z: 0}+ - serializedVersion: 1+ m_State: {fileID: 6028982528785062703}+ m_Position: {x: 235, y: 65, z: 0}m_ChildStateMachines: []m_AnyStateTransitions: []m_EntryTransitions: []@@ -44,6 +47,32 @@ AnimatorStateMachine:m_ExitPosition: {x: 800, y: 120, z: 0}m_ParentStateMachinePosition: {x: 800, y: 20, z: 0}m_DefaultState: {fileID: 7674372291624684852}+--- !u!1102 &6028982528785062703+AnimatorState:+ serializedVersion: 6+ m_ObjectHideFlags: 1+ m_CorrespondingSourceObject: {fileID: 0}+ m_PrefabInstance: {fileID: 0}+ m_PrefabAsset: {fileID: 0}+ m_Name: walk+ m_Speed: 1+ m_CycleOffset: 0+ m_Transitions: []+ m_StateMachineBehaviours: []+ m_Position: {x: 50, y: 50, z: 0}+ m_IKOnFeet: 0+ m_WriteDefaultValues: 1+ m_Mirror: 0+ m_SpeedParameterActive: 0+ m_MirrorParameterActive: 0+ m_CycleOffsetParameterActive: 0+ m_TimeParameterActive: 0+ m_Motion: {fileID: -4799524434163024911, guid: 44477a4c167224adbb6fba23f8066e87, type: 3}+ m_Tag:+ m_SpeedParameter:+ m_MirrorParameter:+ m_CycleOffsetParameter:+ m_TimeParameter:--- !u!1102 &7674372291624684852AnimatorState:serializedVersion: 6diff --git a/unity/Assets/Art/Collection/figure-c05-pioneer-veteran-v2/figure-c05-pioneer-veteran-v2-near.controller b/unity/Assets/Art/Collection/figure-c05-pioneer-veteran-v2/figure-c05-pioneer-veteran-v2-near.controllerindex 4cb556320..ecb877c78 100644--- a/unity/Assets/Art/Collection/figure-c05-pioneer-veteran-v2/figure-c05-pioneer-veteran-v2-near.controller+++ b/unity/Assets/Art/Collection/figure-c05-pioneer-veteran-v2/figure-c05-pioneer-veteran-v2-near.controller@@ -12,6 +12,9 @@ AnimatorStateMachine:- serializedVersion: 1m_State: {fileID: -4074649165901278264}m_Position: {x: 200, y: 0, z: 0}+ - serializedVersion: 1+ m_State: {fileID: -730996437457982151}+ m_Position: {x: 235, y: 65, z: 0}m_ChildStateMachines: []m_AnyStateTransitions: []m_EntryTransitions: []@@ -48,6 +51,32 @@ AnimatorState:m_MirrorParameter:m_CycleOffsetParameter:m_TimeParameter:+--- !u!1102 &-730996437457982151+AnimatorState:+ serializedVersion: 6+ m_ObjectHideFlags: 1+ m_CorrespondingSourceObject: {fileID: 0}+ m_PrefabInstance: {fileID: 0}+ m_PrefabAsset: {fileID: 0}+ m_Name: walk+ m_Speed: 1+ m_CycleOffset: 0+ m_Transitions: []+ m_StateMachineBehaviours: []+ m_Position: {x: 50, y: 50, z: 0}+ m_IKOnFeet: 0+ m_WriteDefaultValues: 1+ m_Mirror: 0+ m_SpeedParameterActive: 0+ m_MirrorParameterActive: 0+ m_CycleOffsetParameterActive: 0+ m_TimeParameterActive: 0+ m_Motion: {fileID: -4914750403990082345, guid: 58dce8c7118da4962afac5ac5827dfc5, type: 3}+ m_Tag:+ m_SpeedParameter:+ m_MirrorParameter:+ m_CycleOffsetParameter:+ m_TimeParameter:--- !u!91 &9100000AnimatorController:m_ObjectHideFlags: 0diff --git a/unity/Assets/Art/Collection/figure-c06-young-recruit-v2/figure-c06-young-recruit-v2-near.controller b/unity/Assets/Art/Collection/figure-c06-young-recruit-v2/figure-c06-young-recruit-v2-near.controllerindex f1c7a5e78..12ab129cb 100644--- a/unity/Assets/Art/Collection/figure-c06-young-recruit-v2/figure-c06-young-recruit-v2-near.controller+++ b/unity/Assets/Art/Collection/figure-c06-young-recruit-v2/figure-c06-young-recruit-v2-near.controller@@ -48,6 +48,32 @@ AnimatorController:m_IKPass: 0m_SyncedLayerAffectsTiming: 0m_Controller: {fileID: 9100000}+--- !u!1102 &201953648056946350+AnimatorState:+ serializedVersion: 6+ m_ObjectHideFlags: 1+ m_CorrespondingSourceObject: {fileID: 0}+ m_PrefabInstance: {fileID: 0}+ m_PrefabAsset: {fileID: 0}+ m_Name: walk+ m_Speed: 1+ m_CycleOffset: 0+ m_Transitions: []+ m_StateMachineBehaviours: []+ m_Position: {x: 50, y: 50, z: 0}+ m_IKOnFeet: 0+ m_WriteDefaultValues: 1+ m_Mirror: 0+ m_SpeedParameterActive: 0+ m_MirrorParameterActive: 0+ m_CycleOffsetParameterActive: 0+ m_TimeParameterActive: 0+ m_Motion: {fileID: -4799524434163024911, guid: f359caab0d8394150a6b603e554cd427, type: 3}+ m_Tag:+ m_SpeedParameter:+ m_MirrorParameter:+ m_CycleOffsetParameter:+ m_TimeParameter:--- !u!1107 &238079324535047471AnimatorStateMachine:serializedVersion: 6@@ -60,6 +86,12 @@ AnimatorStateMachine:- serializedVersion: 1m_State: {fileID: -5410907811944464208}m_Position: {x: 200, y: 0, z: 0}+ - serializedVersion: 1+ m_State: {fileID: 201953648056946350}+ m_Position: {x: 235, y: 65, z: 0}+ - serializedVersion: 1+ m_State: {fileID: 1112931706859443745}+ m_Position: {x: 270, y: 130, z: 0}m_ChildStateMachines: []m_AnyStateTransitions: []m_EntryTransitions: []@@ -70,3 +102,29 @@ AnimatorStateMachine:m_ExitPosition: {x: 800, y: 120, z: 0}m_ParentStateMachinePosition: {x: 800, y: 20, z: 0}m_DefaultState: {fileID: -5410907811944464208}+--- !u!1102 &1112931706859443745+AnimatorState:+ serializedVersion: 6+ m_ObjectHideFlags: 1+ m_CorrespondingSourceObject: {fileID: 0}+ m_PrefabInstance: {fileID: 0}+ m_PrefabAsset: {fileID: 0}+ m_Name: attack+ m_Speed: 1+ m_CycleOffset: 0+ m_Transitions: []+ m_StateMachineBehaviours: []+ m_Position: {x: 50, y: 50, z: 0}+ m_IKOnFeet: 0+ m_WriteDefaultValues: 1+ m_Mirror: 0+ m_SpeedParameterActive: 0+ m_MirrorParameterActive: 0+ m_CycleOffsetParameterActive: 0+ m_TimeParameterActive: 0+ m_Motion: {fileID: -3576926933002285359, guid: f359caab0d8394150a6b603e554cd427, type: 3}+ m_Tag:+ m_SpeedParameter:+ m_MirrorParameter:+ m_CycleOffsetParameter:+ m_TimeParameter:diff --git a/unity/Assets/Art/Collection/figure-c07-veteran-fighter-v2/figure-c07-veteran-fighter-v2-near.controller b/unity/Assets/Art/Collection/figure-c07-veteran-fighter-v2/figure-c07-veteran-fighter-v2-near.controllerindex f4926c500..bcd53b63b 100644--- a/unity/Assets/Art/Collection/figure-c07-veteran-fighter-v2/figure-c07-veteran-fighter-v2-near.controller+++ b/unity/Assets/Art/Collection/figure-c07-veteran-fighter-v2/figure-c07-veteran-fighter-v2-near.controller@@ -12,6 +12,12 @@ AnimatorStateMachine:- serializedVersion: 1m_State: {fileID: 5111504875057381313}m_Position: {x: 200, y: 0, z: 0}+ - serializedVersion: 1+ m_State: {fileID: 8105642660979229761}+ m_Position: {x: 235, y: 65, z: 0}+ - serializedVersion: 1+ m_State: {fileID: -3134273200985475237}+ m_Position: {x: 270, y: 130, z: 0}m_ChildStateMachines: []m_AnyStateTransitions: []m_EntryTransitions: []@@ -22,6 +28,32 @@ AnimatorStateMachine:m_ExitPosition: {x: 800, y: 120, z: 0}m_ParentStateMachinePosition: {x: 800, y: 20, z: 0}m_DefaultState: {fileID: 5111504875057381313}+--- !u!1102 &-3134273200985475237+AnimatorState:+ serializedVersion: 6+ m_ObjectHideFlags: 1+ m_CorrespondingSourceObject: {fileID: 0}+ m_PrefabInstance: {fileID: 0}+ m_PrefabAsset: {fileID: 0}+ m_Name: attack+ m_Speed: 1+ m_CycleOffset: 0+ m_Transitions: []+ m_StateMachineBehaviours: []+ m_Position: {x: 50, y: 50, z: 0}+ m_IKOnFeet: 0+ m_WriteDefaultValues: 1+ m_Mirror: 0+ m_SpeedParameterActive: 0+ m_MirrorParameterActive: 0+ m_CycleOffsetParameterActive: 0+ m_TimeParameterActive: 0+ m_Motion: {fileID: -3576926933002285359, guid: 7305475eee65c44ea9b49b5642e3f081, type: 3}+ m_Tag:+ m_SpeedParameter:+ m_MirrorParameter:+ m_CycleOffsetParameter:+ m_TimeParameter:--- !u!91 &9100000AnimatorController:m_ObjectHideFlags: 0@@ -70,3 +102,29 @@ AnimatorState:m_MirrorParameter:m_CycleOffsetParameter:m_TimeParameter:+--- !u!1102 &8105642660979229761+AnimatorState:+ serializedVersion: 6+ m_ObjectHideFlags: 1+ m_CorrespondingSourceObject: {fileID: 0}+ m_PrefabInstance: {fileID: 0}+ m_PrefabAsset: {fileID: 0}+ m_Name: walk+ m_Speed: 1+ m_CycleOffset: 0+ m_Transitions: []+ m_StateMachineBehaviours: []+ m_Position: {x: 50, y: 50, z: 0}+ m_IKOnFeet: 0+ m_WriteDefaultValues: 1+ m_Mirror: 0+ m_SpeedParameterActive: 0+ m_MirrorParameterActive: 0+ m_CycleOffsetParameterActive: 0+ m_TimeParameterActive: 0+ m_Motion: {fileID: -4799524434163024911, guid: 7305475eee65c44ea9b49b5642e3f081, type: 3}+ m_Tag:+ m_SpeedParameter:+ m_MirrorParameter:+ m_CycleOffsetParameter:+ m_TimeParameter:diff --git a/unity/Assets/Art/Collection/figure-c08-arab-legion-v2/figure-c08-arab-legion-v2-near.controller b/unity/Assets/Art/Collection/figure-c08-arab-legion-v2/figure-c08-arab-legion-v2-near.controllerindex 18dda7fff..c2a45241d 100644--- a/unity/Assets/Art/Collection/figure-c08-arab-legion-v2/figure-c08-arab-legion-v2-near.controller+++ b/unity/Assets/Art/Collection/figure-c08-arab-legion-v2/figure-c08-arab-legion-v2-near.controller@@ -60,6 +60,12 @@ AnimatorStateMachine:- serializedVersion: 1m_State: {fileID: 1749075809006148466}m_Position: {x: 200, y: 0, z: 0}+ - serializedVersion: 1+ m_State: {fileID: 3890417377103863829}+ m_Position: {x: 235, y: 65, z: 0}+ - serializedVersion: 1+ m_State: {fileID: 4516383773810673136}+ m_Position: {x: 270, y: 130, z: 0}m_ChildStateMachines: []m_AnyStateTransitions: []m_EntryTransitions: []@@ -70,3 +76,55 @@ AnimatorStateMachine:m_ExitPosition: {x: 800, y: 120, z: 0}m_ParentStateMachinePosition: {x: 800, y: 20, z: 0}m_DefaultState: {fileID: 1749075809006148466}+--- !u!1102 &3890417377103863829+AnimatorState:+ serializedVersion: 6+ m_ObjectHideFlags: 1+ m_CorrespondingSourceObject: {fileID: 0}+ m_PrefabInstance: {fileID: 0}+ m_PrefabAsset: {fileID: 0}+ m_Name: walk+ m_Speed: 1+ m_CycleOffset: 0+ m_Transitions: []+ m_StateMachineBehaviours: []+ m_Position: {x: 50, y: 50, z: 0}+ m_IKOnFeet: 0+ m_WriteDefaultValues: 1+ m_Mirror: 0+ m_SpeedParameterActive: 0+ m_MirrorParameterActive: 0+ m_CycleOffsetParameterActive: 0+ m_TimeParameterActive: 0+ m_Motion: {fileID: -4799524434163024911, guid: e0dc952aa9f9d47ea8f99c03a6f32a54, type: 3}+ m_Tag:+ m_SpeedParameter:+ m_MirrorParameter:+ m_CycleOffsetParameter:+ m_TimeParameter:+--- !u!1102 &4516383773810673136+AnimatorState:+ serializedVersion: 6+ m_ObjectHideFlags: 1+ m_CorrespondingSourceObject: {fileID: 0}+ m_PrefabInstance: {fileID: 0}+ m_PrefabAsset: {fileID: 0}+ m_Name: attack+ m_Speed: 1+ m_CycleOffset: 0+ m_Transitions: []+ m_StateMachineBehaviours: []+ m_Position: {x: 50, y: 50, z: 0}+ m_IKOnFeet: 0+ m_WriteDefaultValues: 1+ m_Mirror: 0+ m_SpeedParameterActive: 0+ m_MirrorParameterActive: 0+ m_CycleOffsetParameterActive: 0+ m_TimeParameterActive: 0+ m_Motion: {fileID: -3576926933002285359, guid: e0dc952aa9f9d47ea8f99c03a6f32a54, type: 3}+ m_Tag:+ m_SpeedParameter:+ m_MirrorParameter:+ m_CycleOffsetParameter:+ m_TimeParameter:diff --git a/unity/Assets/Art/Collection/figure-c09-irregular-v2/figure-c09-irregular-v2-near.controller b/unity/Assets/Art/Collection/figure-c09-irregular-v2/figure-c09-irregular-v2-near.controllerindex e2178bfd3..b9c4505fd 100644--- a/unity/Assets/Art/Collection/figure-c09-irregular-v2/figure-c09-irregular-v2-near.controller+++ b/unity/Assets/Art/Collection/figure-c09-irregular-v2/figure-c09-irregular-v2-near.controller@@ -60,6 +60,12 @@ AnimatorStateMachine:- serializedVersion: 1m_State: {fileID: 2210044081207883849}m_Position: {x: 200, y: 0, z: 0}+ - serializedVersion: 1+ m_State: {fileID: 8362894444766633722}+ m_Position: {x: 235, y: 65, z: 0}+ - serializedVersion: 1+ m_State: {fileID: 8206693622271876285}+ m_Position: {x: 270, y: 130, z: 0}m_ChildStateMachines: []m_AnyStateTransitions: []m_EntryTransitions: []@@ -70,3 +76,55 @@ AnimatorStateMachine:m_ExitPosition: {x: 800, y: 120, z: 0}m_ParentStateMachinePosition: {x: 800, y: 20, z: 0}m_DefaultState: {fileID: 2210044081207883849}+--- !u!1102 &8206693622271876285+AnimatorState:+ serializedVersion: 6+ m_ObjectHideFlags: 1+ m_CorrespondingSourceObject: {fileID: 0}+ m_PrefabInstance: {fileID: 0}+ m_PrefabAsset: {fileID: 0}+ m_Name: attack+ m_Speed: 1+ m_CycleOffset: 0+ m_Transitions: []+ m_StateMachineBehaviours: []+ m_Position: {x: 50, y: 50, z: 0}+ m_IKOnFeet: 0+ m_WriteDefaultValues: 1+ m_Mirror: 0+ m_SpeedParameterActive: 0+ m_MirrorParameterActive: 0+ m_CycleOffsetParameterActive: 0+ m_TimeParameterActive: 0+ m_Motion: {fileID: -3576926933002285359, guid: 2f29e0bbc423941198c8ee84fba87327, type: 3}+ m_Tag:+ m_SpeedParameter:+ m_MirrorParameter:+ m_CycleOffsetParameter:+ m_TimeParameter:+--- !u!1102 &8362894444766633722+AnimatorState:+ serializedVersion: 6+ m_ObjectHideFlags: 1+ m_CorrespondingSourceObject: {fileID: 0}+ m_PrefabInstance: {fileID: 0}+ m_PrefabAsset: {fileID: 0}+ m_Name: walk+ m_Speed: 1+ m_CycleOffset: 0+ m_Transitions: []+ m_StateMachineBehaviours: []+ m_Position: {x: 50, y: 50, z: 0}+ m_IKOnFeet: 0+ m_WriteDefaultValues: 1+ m_Mirror: 0+ m_SpeedParameterActive: 0+ m_MirrorParameterActive: 0+ m_CycleOffsetParameterActive: 0+ m_TimeParameterActive: 0+ m_Motion: {fileID: -4799524434163024911, guid: 2f29e0bbc423941198c8ee84fba87327, type: 3}+ m_Tag:+ m_SpeedParameter:+ m_MirrorParameter:+ m_CycleOffsetParameter:+ m_TimeParameter:diff --git a/unity/Assets/Art/Collection/figure-c12f-palmach-scout-v2/figure-c12f-palmach-scout-v2-near.controller b/unity/Assets/Art/Collection/figure-c12f-palmach-scout-v2/figure-c12f-palmach-scout-v2-near.controllerindex 24bf34acd..50765bb08 100644--- a/unity/Assets/Art/Collection/figure-c12f-palmach-scout-v2/figure-c12f-palmach-scout-v2-near.controller+++ b/unity/Assets/Art/Collection/figure-c12f-palmach-scout-v2/figure-c12f-palmach-scout-v2-near.controller@@ -38,6 +38,12 @@ AnimatorStateMachine:- serializedVersion: 1m_State: {fileID: -8888434568490173117}m_Position: {x: 200, y: 0, z: 0}+ - serializedVersion: 1+ m_State: {fileID: 248583114969000619}+ m_Position: {x: 235, y: 65, z: 0}+ - serializedVersion: 1+ m_State: {fileID: 3347279397362056509}+ m_Position: {x: 270, y: 130, z: 0}m_ChildStateMachines: []m_AnyStateTransitions: []m_EntryTransitions: []@@ -70,3 +76,55 @@ AnimatorController:m_IKPass: 0m_SyncedLayerAffectsTiming: 0m_Controller: {fileID: 9100000}+--- !u!1102 &248583114969000619+AnimatorState:+ serializedVersion: 6+ m_ObjectHideFlags: 1+ m_CorrespondingSourceObject: {fileID: 0}+ m_PrefabInstance: {fileID: 0}+ m_PrefabAsset: {fileID: 0}+ m_Name: walk+ m_Speed: 1+ m_CycleOffset: 0+ m_Transitions: []+ m_StateMachineBehaviours: []+ m_Position: {x: 50, y: 50, z: 0}+ m_IKOnFeet: 0+ m_WriteDefaultValues: 1+ m_Mirror: 0+ m_SpeedParameterActive: 0+ m_MirrorParameterActive: 0+ m_CycleOffsetParameterActive: 0+ m_TimeParameterActive: 0+ m_Motion: {fileID: -4799524434163024911, guid: 623d93e9af58543f28fad0dc97d73ca9, type: 3}+ m_Tag:+ m_SpeedParameter:+ m_MirrorParameter:+ m_CycleOffsetParameter:+ m_TimeParameter:+--- !u!1102 &3347279397362056509+AnimatorState:+ serializedVersion: 6+ m_ObjectHideFlags: 1+ m_CorrespondingSourceObject: {fileID: 0}+ m_PrefabInstance: {fileID: 0}+ m_PrefabAsset: {fileID: 0}+ m_Name: attack+ m_Speed: 1+ m_CycleOffset: 0+ m_Transitions: []+ m_StateMachineBehaviours: []+ m_Position: {x: 50, y: 50, z: 0}+ m_IKOnFeet: 0+ m_WriteDefaultValues: 1+ m_Mirror: 0+ m_SpeedParameterActive: 0+ m_MirrorParameterActive: 0+ m_CycleOffsetParameterActive: 0+ m_TimeParameterActive: 0+ m_Motion: {fileID: -3576926933002285359, guid: 623d93e9af58543f28fad0dc97d73ca9, type: 3}+ m_Tag:+ m_SpeedParameter:+ m_MirrorParameter:+ m_CycleOffsetParameter:+ m_TimeParameter:diff --git a/unity/Assets/Art/Collection/figure-egyptian-infantry-1948-v1/figure-egyptian-infantry-1948-v1.controller b/unity/Assets/Art/Collection/figure-egyptian-infantry-1948-v1/figure-egyptian-infantry-1948-v1.controllerindex c5dd148e3..6257bd0ed 100644--- a/unity/Assets/Art/Collection/figure-egyptian-infantry-1948-v1/figure-egyptian-infantry-1948-v1.controller+++ b/unity/Assets/Art/Collection/figure-egyptian-infantry-1948-v1/figure-egyptian-infantry-1948-v1.controller@@ -12,6 +12,9 @@ AnimatorStateMachine:- serializedVersion: 1m_State: {fileID: -3050471348568675152}m_Position: {x: 200, y: 0, z: 0}+ - serializedVersion: 1+ m_State: {fileID: -1267802467971863354}+ m_Position: {x: 235, y: 65, z: 0}m_ChildStateMachines: []m_AnyStateTransitions: []m_EntryTransitions: []@@ -43,11 +46,37 @@ AnimatorState:m_CycleOffsetParameterActive: 0m_TimeParameterActive: 0m_Motion: {fileID: 1701753570676288061, guid: be350127b83d0419fa12e93943595e47, type: 3}- m_Tag:- m_SpeedParameter:- m_MirrorParameter:- m_CycleOffsetParameter:- m_TimeParameter:+ m_Tag:+ m_SpeedParameter:+ m_MirrorParameter:+ m_CycleOffsetParameter:+ m_TimeParameter:+--- !u!1102 &-1267802467971863354+AnimatorState:+ serializedVersion: 6+ m_ObjectHideFlags: 1+ m_CorrespondingSourceObject: {fileID: 0}+ m_PrefabInstance: {fileID: 0}+ m_PrefabAsset: {fileID: 0}+ m_Name: walk+ m_Speed: 1+ m_CycleOffset: 0+ m_Transitions: []+ m_StateMachineBehaviours: []+ m_Position: {x: 50, y: 50, z: 0}+ m_IKOnFeet: 0+ m_WriteDefaultValues: 1+ m_Mirror: 0+ m_SpeedParameterActive: 0+ m_MirrorParameterActive: 0+ m_CycleOffsetParameterActive: 0+ m_TimeParameterActive: 0+ m_Motion: {fileID: 3950386597520904993, guid: be350127b83d0419fa12e93943595e47, type: 3}+ m_Tag:+ m_SpeedParameter:+ m_MirrorParameter:+ m_CycleOffsetParameter:+ m_TimeParameter:--- !u!91 &9100000AnimatorController:m_ObjectHideFlags: 0diff --git a/unity/Assets/Art/Collection/figure-iraqi-infantry-1948-v1/figure-iraqi-infantry-1948-v1.controller b/unity/Assets/Art/Collection/figure-iraqi-infantry-1948-v1/figure-iraqi-infantry-1948-v1.controllerindex c4c5946b7..78a8ea632 100644--- a/unity/Assets/Art/Collection/figure-iraqi-infantry-1948-v1/figure-iraqi-infantry-1948-v1.controller+++ b/unity/Assets/Art/Collection/figure-iraqi-infantry-1948-v1/figure-iraqi-infantry-1948-v1.controller@@ -21,11 +21,37 @@ AnimatorState:m_CycleOffsetParameterActive: 0m_TimeParameterActive: 0m_Motion: {fileID: -2712534827805580397, guid: 0e876e2b7720d4a3ab301e85d36455ba, type: 3}- m_Tag:- m_SpeedParameter:- m_MirrorParameter:- m_CycleOffsetParameter:- m_TimeParameter:+ m_Tag:+ m_SpeedParameter:+ m_MirrorParameter:+ m_CycleOffsetParameter:+ m_TimeParameter:+--- !u!1102 &-5010195292539569296+AnimatorState:+ serializedVersion: 6+ m_ObjectHideFlags: 1+ m_CorrespondingSourceObject: {fileID: 0}+ m_PrefabInstance: {fileID: 0}+ m_PrefabAsset: {fileID: 0}+ m_Name: walk+ m_Speed: 1+ m_CycleOffset: 0+ m_Transitions: []+ m_StateMachineBehaviours: []+ m_Position: {x: 50, y: 50, z: 0}+ m_IKOnFeet: 0+ m_WriteDefaultValues: 1+ m_Mirror: 0+ m_SpeedParameterActive: 0+ m_MirrorParameterActive: 0+ m_CycleOffsetParameterActive: 0+ m_TimeParameterActive: 0+ m_Motion: {fileID: 7606915860368782285, guid: 0e876e2b7720d4a3ab301e85d36455ba, type: 3}+ m_Tag:+ m_SpeedParameter:+ m_MirrorParameter:+ m_CycleOffsetParameter:+ m_TimeParameter:--- !u!91 &9100000AnimatorController:m_ObjectHideFlags: 0@@ -60,6 +86,9 @@ AnimatorStateMachine:- serializedVersion: 1m_State: {fileID: -7133584600400362682}m_Position: {x: 200, y: 0, z: 0}+ - serializedVersion: 1+ m_State: {fileID: -5010195292539569296}+ m_Position: {x: 235, y: 65, z: 0}m_ChildStateMachines: []m_AnyStateTransitions: []m_EntryTransitions: []diff --git a/unity/Assets/Art/Collection/figure-lebanese-regular-1948-v1/figure-lebanese-regular-1948-v1.controller b/unity/Assets/Art/Collection/figure-lebanese-regular-1948-v1/figure-lebanese-regular-1948-v1.controllerindex 291e82bf0..990852802 100644--- a/unity/Assets/Art/Collection/figure-lebanese-regular-1948-v1/figure-lebanese-regular-1948-v1.controller+++ b/unity/Assets/Art/Collection/figure-lebanese-regular-1948-v1/figure-lebanese-regular-1948-v1.controller@@ -12,6 +12,9 @@ AnimatorStateMachine:- serializedVersion: 1m_State: {fileID: -2512876718787654953}m_Position: {x: 200, y: 0, z: 0}+ - serializedVersion: 1+ m_State: {fileID: 5165067635446302913}+ m_Position: {x: 235, y: 65, z: 0}m_ChildStateMachines: []m_AnyStateTransitions: []m_EntryTransitions: []@@ -43,11 +46,11 @@ AnimatorState:m_CycleOffsetParameterActive: 0m_TimeParameterActive: 0m_Motion: {fileID: -2711213294437986769, guid: 3fd125e677ca247f8bd5934b0655de55, type: 3}- m_Tag:- m_SpeedParameter:- m_MirrorParameter:- m_CycleOffsetParameter:- m_TimeParameter:+ m_Tag:+ m_SpeedParameter:+ m_MirrorParameter:+ m_CycleOffsetParameter:+ m_TimeParameter:--- !u!91 &9100000AnimatorController:m_ObjectHideFlags: 0@@ -70,3 +73,29 @@ AnimatorController:m_IKPass: 0m_SyncedLayerAffectsTiming: 0m_Controller: {fileID: 9100000}+--- !u!1102 &5165067635446302913+AnimatorState:+ serializedVersion: 6+ m_ObjectHideFlags: 1+ m_CorrespondingSourceObject: {fileID: 0}+ m_PrefabInstance: {fileID: 0}+ m_PrefabAsset: {fileID: 0}+ m_Name: walk+ m_Speed: 1+ m_CycleOffset: 0+ m_Transitions: []+ m_StateMachineBehaviours: []+ m_Position: {x: 50, y: 50, z: 0}+ m_IKOnFeet: 0+ m_WriteDefaultValues: 1+ m_Mirror: 0+ m_SpeedParameterActive: 0+ m_MirrorParameterActive: 0+ m_CycleOffsetParameterActive: 0+ m_TimeParameterActive: 0+ m_Motion: {fileID: -7863667462855643789, guid: 3fd125e677ca247f8bd5934b0655de55, type: 3}+ m_Tag:+ m_SpeedParameter:+ m_MirrorParameter:+ m_CycleOffsetParameter:+ m_TimeParameter:diff --git a/unity/Assets/Art/Collection/figure-syrian-infantry-1948-v1/figure-syrian-infantry-1948-v1.controller b/unity/Assets/Art/Collection/figure-syrian-infantry-1948-v1/figure-syrian-infantry-1948-v1.controllerindex 2af4d7d0e..2a12a6448 100644--- a/unity/Assets/Art/Collection/figure-syrian-infantry-1948-v1/figure-syrian-infantry-1948-v1.controller+++ b/unity/Assets/Art/Collection/figure-syrian-infantry-1948-v1/figure-syrian-infantry-1948-v1.controller@@ -12,6 +12,9 @@ AnimatorStateMachine:- serializedVersion: 1m_State: {fileID: 7051146291796491306}m_Position: {x: 200, y: 0, z: 0}+ - serializedVersion: 1+ m_State: {fileID: 2966093353589676723}+ m_Position: {x: 235, y: 65, z: 0}m_ChildStateMachines: []m_AnyStateTransitions: []m_EntryTransitions: []@@ -44,6 +47,32 @@ AnimatorController:m_IKPass: 0m_SyncedLayerAffectsTiming: 0m_Controller: {fileID: 9100000}+--- !u!1102 &2966093353589676723+AnimatorState:+ serializedVersion: 6+ m_ObjectHideFlags: 1+ m_CorrespondingSourceObject: {fileID: 0}+ m_PrefabInstance: {fileID: 0}+ m_PrefabAsset: {fileID: 0}+ m_Name: walk+ m_Speed: 1+ m_CycleOffset: 0+ m_Transitions: []+ m_StateMachineBehaviours: []+ m_Position: {x: 50, y: 50, z: 0}+ m_IKOnFeet: 0+ m_WriteDefaultValues: 1+ m_Mirror: 0+ m_SpeedParameterActive: 0+ m_MirrorParameterActive: 0+ m_CycleOffsetParameterActive: 0+ m_TimeParameterActive: 0+ m_Motion: {fileID: 7747523122156599542, guid: 0f1fdfe45c64048559ae663c10a7d76f, type: 3}+ m_Tag:+ m_SpeedParameter:+ m_MirrorParameter:+ m_CycleOffsetParameter:+ m_TimeParameter:--- !u!1102 &7051146291796491306AnimatorState:serializedVersion: 6@@ -65,8 +94,8 @@ AnimatorState:m_CycleOffsetParameterActive: 0m_TimeParameterActive: 0m_Motion: {fileID: 4705583348635683718, guid: 0f1fdfe45c64048559ae663c10a7d76f, type: 3}- m_Tag:- m_SpeedParameter:- m_MirrorParameter:- m_CycleOffsetParameter:- m_TimeParameter:+ m_Tag:+ m_SpeedParameter:+ m_MirrorParameter:+ m_CycleOffsetParameter:+ m_TimeParameter:diff --git a/unity/Assets/Editor/CollectionImport.cs b/unity/Assets/Editor/CollectionImport.csindex a77b28fbd..ce9620276 100644--- a/unity/Assets/Editor/CollectionImport.cs+++ b/unity/Assets/Editor/CollectionImport.cs@@ -1,8 +1,10 @@#nullable enableusing System;+using System.Collections.Generic;using System.IO;using System.Linq;using Statecraft.Game.Map.Collection;+using Statecraft.Game.Map.Units;using UnityEditor;using UnityEditor.Animations;using UnityEngine;@@ -139,12 +141,64 @@ namespace Statecraft.Game.EditorTools.Where(c => !c.name.StartsWith("__preview__", StringComparison.Ordinal)).OrderBy(c => c.name.IndexOf(id == "figure-c05-pioneer-veteran-v2" ? "walk" : "idle", StringComparison.OrdinalIgnoreCase) < 0 ? 1 : 0).ThenBy(c => c.name, StringComparer.Ordinal).First();var path = Controller(id);var ctrl = AssetDatabase.LoadAssetAtPath<AnimatorController>(path);- if (ctrl == null) return AnimatorController.CreateAnimatorControllerAtPathWithClip(path, clip);+ if (ctrl == null) ctrl = AnimatorController.CreateAnimatorControllerAtPathWithClip(path, clip);var state = ctrl.layers[0].stateMachine.defaultState;if (state.motion != clip) { state.motion = clip; EditorUtility.SetDirty(ctrl); }+ if (TokenFigures.Contains(id)) AddMotionStates(ctrl, Model(id, CollectionDetail.Near));return ctrl;}+ /// <summary>The models that stand on unit tokens (UnitFigures) and have a rig: their controllers also get the+ /// walk and attack states a token's move and attack play (#1866, #1867; design by Tal Heuberger, #1900).</summary>+ public static readonly IReadOnlyCollection<string> TokenFigures = new HashSet<string>(StringComparer.Ordinal)+ {+ UnitFigures.SabraPioneer, UnitFigures.PioneerVeteran, UnitFigures.YoungRecruit, UnitFigures.VeteranFighter,+ UnitFigures.PalmachScout, UnitFigures.ArabLegion, UnitFigures.Irregular,+ UnitFigures.SyrianInfantry, UnitFigures.IraqiInfantry, UnitFigures.EgyptianInfantry, UnitFigures.AlaInfantry,+ UnitFigures.LebaneseRegular,+ };++ /// <summary>Adds the token figures' walk and attack states to their existing controllers, from the takes already in+ /// each figure's own FBX. Reimports nothing: no model, texture, clip or prefab changes. Idempotent.+ /// Headless: Unity -batchmode -CI false -GITHUB_ACTIONS false -TF_BUILD false -quit -projectPath unity -executeMethod Statecraft.Game.EditorTools.CollectionImport.PrepareTokenFigureControllers</summary>+ [MenuItem("Statecraft/Collection/Add token figure walk and attack states")]+ public static void PrepareTokenFigureControllers()+ {+ foreach (var id in TokenFigures)+ {+ if (CollectionCatalog.IsFullQualityGeneratedInfantry(id)) { Generated1948Characters.Controller(id); continue; }+ var ctrl = AssetDatabase.LoadAssetAtPath<AnimatorController>(Controller(id))+ ?? throw new InvalidOperationException(id + ": no controller (run CollectionImport.Run first)");+ AddMotionStates(ctrl, Model(id, CollectionDetail.Near));+ }+ AssetDatabase.SaveAssets();+ }++ /// <summary>Sets <paramref name="controller"/>'s walk state to the model's walk take and its attack state to its+ /// fire take, adding each state the first time; a take the model lacks adds no state (C04 has no fire).</summary>+ internal static void AddMotionStates(AnimatorController controller, string model)+ {+ var clips = AssetDatabase.LoadAllAssetsAtPath(model).OfType<AnimationClip>()+ .Where(c => !c.name.StartsWith("__preview__", StringComparison.Ordinal)).ToList();+ SetState(controller, UnitFigureMotion.WalkState, WalkTake(clips));+ SetState(controller, UnitFigureMotion.AttackState, clips.FirstOrDefault(c => UnitTokenMotion.CollectionFireTake(c.name)));+ }++ /// <summary>The walk take: a take named walk first, else C05's idle_walk (his only walk), whatever the takes' order.</summary>+ internal static AnimationClip? WalkTake(IReadOnlyList<AnimationClip> clips) =>+ clips.FirstOrDefault(c => c.name == "walk" || c.name.EndsWith("|walk", StringComparison.OrdinalIgnoreCase))+ ?? clips.FirstOrDefault(c => c.name.EndsWith("|idle_walk", StringComparison.OrdinalIgnoreCase));++ static void SetState(AnimatorController controller, string name, AnimationClip? clip)+ {+ if (clip == null) return;+ var machine = controller.layers[0].stateMachine;+ var state = machine.states.Select(s => s.state).FirstOrDefault(s => s != null && s.name == name) ?? machine.AddState(name);+ if (state.motion == clip) return;+ state.motion = clip;+ EditorUtility.SetDirty(controller);+ }+static void MakePrefab(string id, CollectionDetail detail, Material mat, AnimatorController? idle){var model = AssetDatabase.LoadAssetAtPath<GameObject>(Model(id, detail));diff --git a/unity/Assets/Editor/Generated1948Characters.cs b/unity/Assets/Editor/Generated1948Characters.csindex cd8c9261a..d722405ae 100644--- a/unity/Assets/Editor/Generated1948Characters.cs+++ b/unity/Assets/Editor/Generated1948Characters.cs@@ -2,6 +2,7 @@ using System;using System.Collections.Generic;using System.IO;using System.Linq;+using Statecraft.Game.Map.Units;using UnityEditor;using UnityEditor.Animations;using UnityEditor.SceneManagement;@@ -139,19 +140,36 @@ namespace Statecraft.Game.EditorToolsreturn mat;}- static AnimatorController Controller(string id)+ internal static AnimatorController Controller(string id){string path = $"{Dir(id)}/{id}.controller";var clip = Clip(id, "near");- var controller = AssetDatabase.LoadAssetAtPath<AnimatorController>(path);- if (controller == null) return AnimatorController.CreateAnimatorControllerAtPathWithClip(path, clip);- if (controller.layers.Length != 1 || controller.layers[0].stateMachine.states.Length != 1)- throw new InvalidOperationException(id + ": expected an owned one-state idle controller");- controller.layers[0].stateMachine.defaultState.motion = clip;- EditorUtility.SetDirty(controller);+ var controller = AssetDatabase.LoadAssetAtPath<AnimatorController>(path)+ ?? AnimatorController.CreateAnimatorControllerAtPathWithClip(path, clip);+ try { ConfigureController(controller, clip, Model(id, "original"), CollectionImport.TokenFigures.Contains(id)); }+ catch (InvalidOperationException e) { throw new InvalidOperationException(id + ": " + e.Message, e); }return controller;}+ /// <summary>Sets the controller's default idle to <paramref name="idle"/> and, for a token figure, adds its walk and+ /// attack states (CollectionImport.AddMotionStates). The whole graph is checked before anything changes: one layer,+ /// no sub-machines, each state idle, walk or attack and named once, and the default one of them, the idle.</summary>+ internal static void ConfigureController(AnimatorController controller, AnimationClip idle, string model, bool tokenFigure)+ {+ if (controller.layers.Length != 1) throw new InvalidOperationException("expected one layer");+ var machine = controller.layers[0].stateMachine;+ var states = machine.states.Select(s => s.state).ToArray();+ var names = states.Select(s => s != null ? s.name : null).ToArray();+ if (states.Length == 0 || machine.stateMachines.Length != 0+ || names.Any(n => n != UnitFigureMotion.IdleState && n != UnitFigureMotion.WalkState && n != UnitFigureMotion.AttackState)+ || names.Distinct().Count() != names.Length+ || machine.defaultState == null || Array.IndexOf(states, machine.defaultState) < 0+ || machine.defaultState.name != UnitFigureMotion.IdleState)+ throw new InvalidOperationException("expected idle, walk or attack states, each once, with the idle the default");+ if (machine.defaultState.motion != idle) { machine.defaultState.motion = idle; EditorUtility.SetDirty(controller); }+ if (tokenFigure) CollectionImport.AddMotionStates(controller, model);+ }+static void MakePrefab(string id, string level, Material mat, AnimatorController controller){var model = AssetDatabase.LoadAssetAtPath<GameObject>(Model(id, level)) ?? throw new InvalidOperationException("Model missing: " + id);diff --git a/unity/Assets/Scripts/Map/Units/UnitFigureDetail.cs b/unity/Assets/Scripts/Map/Units/UnitFigureDetail.csindex 532e19484..0509d5c94 100644--- a/unity/Assets/Scripts/Map/Units/UnitFigureDetail.cs+++ b/unity/Assets/Scripts/Map/Units/UnitFigureDetail.cs@@ -171,6 +171,9 @@ namespace Statecraft.Game.Map.Unitsforeach (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;+ // A figure that turns near mid-move or mid-attack takes up its token's walk or fire at once (#1866).+ var motion = near && f.Holder != null ? f.Holder.GetComponentInParent<UnitTokenMotion>() : null;+ if (motion != null && (motion.Moving || motion.Attacking)) motion.RefreshPose();}}}diff --git a/unity/Assets/Scripts/Map/Units/UnitFigureMotion.cs b/unity/Assets/Scripts/Map/Units/UnitFigureMotion.csnew file mode 100644index 000000000..7a4b98aaf--- /dev/null+++ b/unity/Assets/Scripts/Map/Units/UnitFigureMotion.cs@@ -0,0 +1,34 @@+#nullable enable+using UnityEngine;++namespace Statecraft.Game.Map.Units+{+ /// <summary>The figure states a token's Animators can play while the token moves or attacks (#1866, #1867; design by+ /// Tal Heuberger, #1900): the controllers' <c>idle</c>, <c>walk</c> and <c>attack</c> states, which CollectionImport adds+ /// only where the figure's own FBX has the take. A missing controller or state leaves the figure as it is.</summary>+ public static class UnitFigureMotion+ {+ public const string IdleState = "idle", WalkState = "walk", AttackState = "attack";+ public static readonly int Idle = Animator.StringToHash("Base Layer." + IdleState);+ public static readonly int Walk = Animator.StringToHash("Base Layer." + WalkState);+ public static readonly int Attack = Animator.StringToHash("Base Layer." + AttackState);++ /// <summary>Whether <paramref name="animator"/> can play <paramref name="state"/> now: active and enabled, with a+ /// controller that has the state.</summary>+ public static bool CanPlay(Animator? animator, int state) =>+ animator != null && animator.isActiveAndEnabled && animator.runtimeAnimatorController != null && animator.HasState(0, state);++ /// <summary>Plays <paramref name="state"/> (one of the hashes above) on <paramref name="animator"/> from its start,+ /// unless it is already playing it and <paramref name="restart"/> is false (the Animator reports a Play only after its+ /// next update, so a caller that changed the state this frame passes true). False when the Animator cannot play it:+ /// none, not active and enabled (a far figure's near Animator, or a token being torn down), no controller, or no+ /// such state. No allocation.</summary>+ public static bool Play(Animator? animator, int state, bool restart = false)+ {+ if (!CanPlay(animator, state)) return false;+ animator!.applyRootMotion = false; // the token's offset moves the figure; a take's root motion must not add to it+ if (restart || animator.GetCurrentAnimatorStateInfo(0).fullPathHash != state) animator.Play(state, 0, 0f);+ return true;+ }+ }+}diff --git a/unity/Assets/Scripts/Map/Units/UnitFigureMotion.cs.meta b/unity/Assets/Scripts/Map/Units/UnitFigureMotion.cs.metanew file mode 100644index 000000000..043d423e2--- /dev/null+++ b/unity/Assets/Scripts/Map/Units/UnitFigureMotion.cs.meta@@ -0,0 +1,2 @@+fileFormatVersion: 2+guid: 45c1e52f668ba4594ad7d160346cf4e3\ No newline at end of filediff --git a/unity/Assets/Scripts/Map/Units/UnitFigures.cs b/unity/Assets/Scripts/Map/Units/UnitFigures.csindex 52883ef95..d3411e714 100644--- a/unity/Assets/Scripts/Map/Units/UnitFigures.cs+++ b/unity/Assets/Scripts/Map/Units/UnitFigures.cs@@ -393,6 +393,9 @@ namespace Statecraft.Game.Map.Units}if (code != null) code.enabled = false;if (CollectionCatalog.Animated.Contains(id) && !CollectionCatalog.IsFullQualityGeneratedInfantry(id)) UnitFigureDetail.Of(piece).Add(holder, id); // C05 has no idle: he stays far+ // A model that arrives mid-move walks with its token at once (#1866).+ var motion = piece.GetComponentInParent<UnitTokenMotion>();+ if (motion != null && (motion.Moving || motion.Attacking)) motion.RefreshPose();GeometryChanged();}diff --git a/unity/Assets/Scripts/Map/Units/UnitLayer.cs b/unity/Assets/Scripts/Map/Units/UnitLayer.csindex a3abae661..63d75ca03 100644--- a/unity/Assets/Scripts/Map/Units/UnitLayer.cs+++ b/unity/Assets/Scripts/Map/Units/UnitLayer.cs@@ -135,11 +135,20 @@ namespace Statecraft.Game.Map.Unitspublic const float BadgeBackShare = 0.6f, BadgeAsideM = 400f, BadgeOverFlagM = 150f;readonly List<(Vector2 centre, float radius)> treeHoles = new List<(Vector2, float)>();List<Bounds[]> keepClear = new List<Bounds[]>();+ /// <summary>A slide moves the boxes in place, but the labels re-place only for a new list: FaceCamera then hands+ /// out this second list with the same boxes, the two taking turns (no allocation per frame). A new pair per rebuild.</summary>+ List<Bounds[]> keepClearSpare = new List<Bounds[]>();+ bool slid; // a token's slide moved since FaceCamera last turned the boxesGameObject? ring;bool still;/// <summary>The camera pose and projection (vertical scale, orthographic) <see cref="FaceCamera"/> last turned the badges and flags to; a call from the same pose and projection/// changes nothing and returns at once (GameRoot calls it every frame). Cleared when the tokens are rebuilt.</summary>(Vector3 eye, Quaternion rotation, float m11, bool orthographic)? facedFor;+ /// <summary>Each token's move and attack (#1866, #1867), in the order of <see cref="badges"/>; null where the layer+ /// does not animate (an edit-mode build, such as the promo captures, whose tokens stand still at their places).</summary>+ readonly List<UnitTokenMotion?> motions = new List<UnitTokenMotion?>();+ /// <summary>A rebuild slides a moved unit's token from where it was drawn (true in play; tests set it).</summary>+ internal bool AnimateMoves;/// <summary>The GDD loop's anchors for units that moved off their starting hex (UnitRoster.FromState), one per row and/// sim hex, and their spots: placed once, the first time a unit stands there, so a rebuild after a move places only@@ -198,6 +207,7 @@ namespace Statecraft.Game.Map.Unitsroot.transform.position = Vector3.zero; // children are placed in world spacevar layer = root.AddComponent<UnitLayer>();layer.map = map; layer.units = units; layer.still = still;+ layer.AnimateMoves = Application.isPlaying;// The same ground and the same placement as MapScene's (which keeps the kits off a token in a town).layer.ground = Ground(map, hexes);// The map's own spots when it placed these units on these hexes (issue #321: the same ground, so the same spots;@@ -291,6 +301,9 @@ namespace Statecraft.Game.Map.Unitsfor (int i = 0; i < badges.Count; i++){var b = badges[i]; if (b == null) continue;+ // A moving token's root stands off the origin by its slide (UnitTokenMotion); its pieces are placed in the+ // world here, so they take the same offset, and the boxes follow the token as drawn, not its destination.+ var slide = b.parent.position;var (home, back, pole, flag, standing) = badgeHomes[i];var (centre, radius, lift, figures, meshes) = trios[i];if (turn && figures.Length > 0)@@ -301,7 +314,7 @@ namespace Statecraft.Game.Map.Unitsvar p = centre + turning * offset;p.y = UnitPlinth.FigureY(map, radius, p.x, p.z);highest = Mathf.Max(highest, p.y);- figure.SetPositionAndRotation(p, Quaternion.Euler(0f, yaw + heading, 0f));+ figure.SetPositionAndRotation(p + slide, Quaternion.Euler(0f, yaw + heading, 0f));}home.y = highest + lift; // the badge clears the highest figure, wherever the turn set itbadgeHomes[i] = (home, back, pole, flag, standing);@@ -309,12 +322,12 @@ namespace Statecraft.Game.Map.Units{var foot = centre + turning * pole;foot.y = UnitPlinth.FigureY(map, radius, foot.x, foot.z);- flag.transform.position = foot;+ flag.transform.position = foot + slide;}}if (figures.Length > 0) pole = turning * pole; // where the pole stands now, for the badge's sidevar aside = pole == Vector3.zero ? Vector3.zero : (Vector3.Dot(pole, right) > 0f ? -right : right) * BadgeAsideM;- var at = home + away * back + aside;+ var at = home + away * back + aside + slide;// Owner, 31 October 2026 ("Shrink up close"): a near camera draws the plate no taller than a 30 km view does.// It shrinks about its lower edge (the plate faces the camera, so its edges run along the camera's up), which// stays where the full plate's is, clear of the flag and the figures; that move keeps the plate's depth.@@ -324,8 +337,9 @@ namespace Statecraft.Game.Map.Unitsb.localScale = Vector3.one * size;var boxes = keepClear[i];boxes[0] = new Bounds(at, Vector3.one * size); // the click and the names follow the plate as drawn- if ((flag != null || meshes.Length > 0) && standing is Bounds s)+ if (standing is Bounds s){+ s.center += slide; // the still pieces' box was taken at the unit's place; the flag and figures are where drawnif (flag != null){UnitFlagFacing.Face(flag.transform, eye); // as it will turn for this camera@@ -335,11 +349,19 @@ namespace Statecraft.Game.Map.Unitsboxes[1] = s;}}+ if (!slid) return;+ // Review of #2176: with a still camera the names kept clear of where the token started, not where it stands.+ slid = false;+ (keepClear, keepClearSpare) = (keepClearSpare, keepClear);+ keepClear.Clear();+ for (int i = 0; i < keepClearSpare.Count; i++) keepClear.Add(keepClearSpare[i]);}/// <summary>Draws the units for <paramref name="state"/> (read only). Rebuilds the tokens only when the roster- /// changed; returns true when it did. A selected unit that is no longer drawn is deselected.</summary>- public bool Show(Content content, GameState state)+ /// changed; returns true when it did. A selected unit that is no longer drawn is deselected. A moved unit's token+ /// slides from where it was drawn (<see cref="AnimateMoves"/>) unless <paramref name="slide"/> is false: another game+ /// (New Game) reuses the sim ids, so its tokens are drawn where they stand.</summary>+ public bool Show(Content content, GameState state, bool slide = true){shownContent = content; shownState = state;PrepareMapOnlySpots(content);@@ -360,7 +382,7 @@ namespace Statecraft.Game.Map.Unitsroster = now;PlaceMoved(now);placed = UnitPlacer.Place(now, drawSpots ?? DisplaySpots);- Rebuild();+ Rebuild(slide);ScheduleSatisfiedPrefetchRetirement();if (Selected != null && !placed.Any(p => p.Token.Unit.Id == Selected)) Select(null); else Select(Selected);seenAvailability = UnitFigures.AvailabilityVersion;@@ -631,8 +653,19 @@ namespace Statecraft.Game.Map.Units_ => throw new ArgumentException($"unknown headgear '{headgear}'", nameof(headgear)),};- void Rebuild()+ void Rebuild(bool slide){+ // Where each unit's token is drawn now (its place plus any slide under way), before the old tokens go: a unit+ // drawn somewhere else after the rebuild slides from there (#1866). Keyed by the sim unit, else by the row.+ var drawnAt = new Dictionary<(int sim, string row), Vector3>();+ var firing = new Dictionary<(int sim, string row), float>(); // and how far into its fire take each attack is+ for (int i = 0; slide && i < motions.Count && i < trios.Count; i++)+ {+ var m = motions[i];+ if (m == null) continue;+ drawnAt[Key(m.SimId, m.name)] = trios[i].centre + m.transform.position;+ if (m.AttackPlayed > 0f) firing[Key(m.SimId, m.name)] = m.AttackPlayed;+ }var outgoing = new List<GameObject>();for (int i = tokensRoot.childCount - 1; i >= 0; i--){@@ -646,17 +679,22 @@ namespace Statecraft.Game.Map.Units// The outgoing holders are destroyed only after the new tokens have acquired their models, as the player's// deferred Destroy already does: an edit-mode rebuild must not drop a model's last owner in between and ask the// source again for a request still in flight (or release an arrived model) only to re-acquire it.- try { BuildTokens(); }+ try { BuildTokens(drawnAt, firing); }finally { foreach (var old in outgoing) if (Application.isPlaying) Destroy(old); else DestroyImmediate(old); }}- void BuildTokens()+ static (int sim, string row) Key(int simId, string row) => simId >= 0 ? (simId, "") : (-1, row);++ void BuildTokens(IReadOnlyDictionary<(int sim, string row), Vector3> drawnAt,+ IReadOnlyDictionary<(int sim, string row), float> firing){FreeTokenMeshes();+ motions.Clear();badges.Clear(); badgeHomes.Clear(); facedFor = null;trios.Clear(); turnedFor = null; // the new figures stand as at yaw 0treeHoles.Clear();keepClear = new List<Bounds[]>(); // a new list, so the labels see the change+ keepClearSpare = new List<Bounds[]>(); slid = false; // and a spare no label pass has seenfloat hex = map.Hexes.hex_size_km * 1000f;foreach (var p in placed){@@ -764,6 +802,29 @@ namespace Statecraft.Game.Map.Units}FaceCamera(Camera.main); // the badges as the main camera sees them until a render turns themHideTrees();+ for (int i = 0; i < placed.Count; i++)+ {+ if (!AnimateMoves) { motions.Add(null); continue; }+ var token = tokensRoot.GetChild(i);+ var motion = token.gameObject.AddComponent<UnitTokenMotion>();+ motion.enabled = false; // runs only while it moves or attacks+ motion.SimId = placed[i].Token.StateUnit?.Id ?? -1;+ motion.Changed = () => { facedFor = null; slid = true; }; // FaceCamera sets the badge and the boxes where the token is drawn+ motions.Add(motion);+ // With the units hidden the token cannot be seen, and it would slide only once they are shown again.+ if (tokensRoot.gameObject.activeInHierarchy && drawnAt.TryGetValue(Key(motion.SimId, token.name), out var was))+ motion.Begin(was - trios[i].centre);+ if (firing.TryGetValue(Key(motion.SimId, token.name), out var played)) motion.ContinueAttack(played);+ }+ }++ /// <summary>Plays the attack take of sim unit <paramref name="simId"/>'s figures (#1867). False when no token draws+ /// that unit or none of its figures can play one now (a far zoom, the units hidden, or no fire take).</summary>+ public bool PlayAttack(int simId)+ {+ foreach (var motion in motions)+ if (motion != null && motion.SimId == simId) return motion.PlayAttack();+ return false;}/// <summary>The world box of a mesh's bounds through its transform. From the mesh and the transform, notdiff --git a/unity/Assets/Scripts/Map/Units/UnitTokenMotion.cs b/unity/Assets/Scripts/Map/Units/UnitTokenMotion.csnew file mode 100644index 000000000..2158bf7ff--- /dev/null+++ b/unity/Assets/Scripts/Map/Units/UnitTokenMotion.cs@@ -0,0 +1,173 @@+#nullable enable+using System;+using System.Collections.Generic;+using UnityEngine;++namespace Statecraft.Game.Map.Units+{+ /// <summary>A token's move and attack as the player sees them (#1866, #1867; design by Tal Heuberger, #1900).+ /// Presentation only: the sim has already moved the unit. A token's root stands at the world origin and its pieces+ /// stand at their map places under it, so the root's position is an offset from where the unit now is. A move slides+ /// that offset from the old place to zero over <see cref="Duration"/>; the figures walk meanwhile and stand idle after.+ /// An attack plays the figures' fire take once, then they walk or stand again. The component runs its LateUpdate only+ /// while a move or an attack is under way. Disabling it (the token hidden or rebuilt) puts the token where the unit is.+ /// A figure that turns near mid-move or mid-attack (UnitFigureDetail) or arrives then (UnitFigures) joins in at once.</summary>+ public sealed class UnitTokenMotion : MonoBehaviour+ {+ public const float Duration = 0.65f;+ /// <summary>A shorter move than this (metres) is drawn at once.</summary>+ public const float MinMoveM = 1f;+ /// <summary>How long an attack waits for a figure that can play it. An engagement usually changes strengths, so the+ /// tokens are rebuilt just before it plays, and the new ones turn their near figures on at the next render.</summary>+ public const float AttackWaitS = 0.25f;++ /// <summary>The sim unit this token draws, or -1 for a row with no sim unit (the legacy loop).</summary>+ public int SimId { get; internal set; } = -1;+ /// <summary>Raised when the token's place changes, so UnitLayer redraws its badge and hit boxes there.</summary>+ internal Action? Changed;++ Vector3 from;+ float elapsed = Duration, attackLeft;+ bool firing; // a figure plays the attack (else it waits for one, up to AttackWaitS)+ bool fired; // an attack just ended: its figures go back to walking or standing+ float attackLength, resumeAt; // the playing take's length; where a continued attack picks up+ int posed; // the walk or idle the figures were last asked for+ readonly List<Animator> animators = new List<Animator>();++ public bool Moving => elapsed < Duration;+ /// <summary>An attack plays, or waits for a figure to play it.</summary>+ public bool Attacking => attackLeft > 0f;++ /// <summary>Starts a slide from <paramref name="offset"/> (the old place less the new) to the unit's place.</summary>+ public void Begin(Vector3 offset)+ {+ if (offset.sqrMagnitude < MinMoveM * MinMoveM) { if (Moving || Attacking) Snap(); return; }+ from = offset; elapsed = 0f;+ transform.position = from;+ enabled = true;+ Pose();+ Changed?.Invoke();+ }++ /// <summary>Plays the figures' attack take once from its start (again, if one is playing). True when a figure+ /// plays it now; else it waits <see cref="AttackWaitS"/> for one to turn near, and then is dropped. A hidden token+ /// does nothing. Nothing is kept to play later.</summary>+ public bool PlayAttack()+ {+ if (!gameObject.activeInHierarchy) return false;+ attackLeft = AttackWaitS; firing = false; resumeAt = 0f;+ enabled = true;+ return Fire();+ }++ /// <summary>How far into its fire take the token's attack is (seconds), or 0 when none plays: a rebuild hands it to+ /// the unit's new token (<see cref="ContinueAttack"/>).</summary>+ internal float AttackPlayed => firing ? Mathf.Max(0f, attackLength - attackLeft) : 0f;++ /// <summary>Goes on with an attack the unit's previous token had played <paramref name="played"/> seconds of, from+ /// there (a rebuild for another unit's order must not cut a take short).</summary>+ internal void ContinueAttack(float played)+ {+ if (played <= 0f || !gameObject.activeInHierarchy) return;+ resumeAt = played; attackLeft = AttackWaitS; firing = false;+ enabled = true;+ Fire();+ }++ /// <summary>Starts the fire take on every live figure that has one (even mid-attack), from its start or, for a+ /// continued attack, from where it was; the attack then lasts as long as the longest take has left. A take that had+ /// finished plays nothing, so the figures keep their walk or idle (review of #2176, item 8).</summary>+ bool Fire()+ {+ float longest = 0f;+ animators.Clear(); GetComponentsInChildren(false, animators);+ foreach (var animator in animators)+ if (UnitFigureMotion.CanPlay(animator, UnitFigureMotion.Attack)) longest = Mathf.Max(longest, FireLength(animator));+ if (longest <= 0f) return false; // no live figure has a fire take yet: keep waiting+ if (longest <= resumeAt) { attackLeft = 0f; resumeAt = 0f; return false; } // the take had finished+ foreach (var animator in animators)+ {+ if (!UnitFigureMotion.CanPlay(animator, UnitFigureMotion.Attack)) continue;+ float length = FireLength(animator);+ animator.applyRootMotion = false; // as UnitFigureMotion.Play+ animator.Play(UnitFigureMotion.Attack, 0, resumeAt > 0f && length > 0f ? Mathf.Clamp01(resumeAt / length) : 0f);+ }+ attackLength = longest; attackLeft = longest - resumeAt; resumeAt = 0f; firing = true;+ return true;+ }++ /// <summary>The longest fire take on <paramref name="animator"/>'s controller (reading its clips allocates).</summary>+ static float FireLength(Animator animator)+ {+ float length = 0f;+ foreach (var clip in animator.runtimeAnimatorController.animationClips)+ if (CollectionFireTake(clip.name)) length = Mathf.Max(length, clip.length);+ return length;+ }++ /// <summary>The fire take's name as CollectionImport binds it to the attack state.</summary>+ public static bool CollectionFireTake(string name) =>+ name == "fire" || name.EndsWith("|fire", StringComparison.OrdinalIgnoreCase);++ /// <summary>Puts every live figure of the token in the state its move and attack call for now: a figure that+ /// arrives or turns near mid-move walks at once, and one that can play a waiting attack plays it. UnitFigures and+ /// UnitFigureDetail call it. It allocates only when it starts a waiting attack (reading the controller's clips).</summary>+ public void RefreshPose() => Pose();++ void Pose()+ {+ bool started = Attacking && !firing && Fire(); // a figure that can play the waiting attack turned near+ int state = Moving ? UnitFigureMotion.Walk : UnitFigureMotion.Idle;+ bool changed = state != posed, ended = fired;+ posed = state; fired = false;+ animators.Clear(); GetComponentsInChildren(false, animators);+ foreach (var animator in animators)+ {+ // Fire has just set a starting figure's take and time; Play would read the Animator's old state and restart+ // the take (review of #2176, item 3).+ if (firing && (started ? UnitFigureMotion.CanPlay(animator, UnitFigureMotion.Attack)+ : UnitFigureMotion.Play(animator, UnitFigureMotion.Attack))) continue;+ // A figure leaves its walk, idle or fire this frame: play the new state even before its Animator reports the old.+ UnitFigureMotion.Play(animator, state,+ changed || ended && animator.isActiveAndEnabled && animator.HasState(0, UnitFigureMotion.Attack));+ }+ }++ /// <summary>Advances the move and the attack by <paramref name="seconds"/>; LateUpdate passes the frame's time.</summary>+ internal void Tick(float seconds)+ {+ seconds = Mathf.Max(0f, seconds);+ bool wasMoving = Moving, wasFiring = firing;+ if (Moving)+ {+ elapsed = Mathf.Min(Duration, elapsed + seconds);+ transform.position = Vector3.Lerp(from, Vector3.zero, elapsed / Duration);+ Changed?.Invoke();+ }+ if (Attacking)+ {+ attackLeft = Mathf.Max(0f, attackLeft - seconds);+ if (!Attacking) { fired = firing; firing = false; resumeAt = 0f; }+ }+ if (wasMoving != Moving || wasFiring != firing) Pose();+ if (!Moving && !Attacking) enabled = false; // an idle token costs nothing per frame+ }++ void LateUpdate() => Tick(Time.deltaTime);++ void OnDisable()+ {+ if (Moving || Attacking) Snap();+ }++ void Snap()+ {+ bool moved = transform.position != Vector3.zero;+ fired = firing;+ elapsed = Duration; attackLeft = 0f; firing = false; resumeAt = 0f; from = Vector3.zero;+ transform.position = Vector3.zero;+ Pose();+ if (moved) Changed?.Invoke();+ }+ }+}diff --git a/unity/Assets/Scripts/Map/Units/UnitTokenMotion.cs.meta b/unity/Assets/Scripts/Map/Units/UnitTokenMotion.cs.metanew file mode 100644index 000000000..237c46c8f--- /dev/null+++ b/unity/Assets/Scripts/Map/Units/UnitTokenMotion.cs.meta@@ -0,0 +1,2 @@+fileFormatVersion: 2+guid: 88e5fac7a59d54e4db1548ae72dc27ba\ No newline at end of filediff --git a/unity/Assets/Scripts/UI/GameRoot.cs b/unity/Assets/Scripts/UI/GameRoot.csindex 94135ac46..c520b7388 100644--- a/unity/Assets/Scripts/UI/GameRoot.cs+++ b/unity/Assets/Scripts/UI/GameRoot.cs@@ -410,9 +410,12 @@ namespace Statecraft.Game.UIif (Statecraft.Game.Map.Units.UnitLayer.HiddenInCaptures(Application.absoluteURL, Environment.GetCommandLineArgs(),Application.platform == RuntimePlatform.WebGLPlayer))VisualToggles.Set(Statecraft.Game.Map.Units.UnitLayer.ToggleName, false);+ GameSession? shownSession = null;Action showUnits = () =>{- unitLayer.Show(bridge.Content, bridge.State);+ // New Game replaces the session, and its sim ids are the old game's: its tokens are drawn where they stand.+ unitLayer.Show(bridge.Content, bridge.State, slide: ReferenceEquals(shownSession, bridge.Session));+ shownSession = bridge.Session;unitLayer.Dim(unitLayer.Tokens.Where(t => t.Token.Unit.Side == Statecraft.Game.Map.Units.UnitData.Israel).Where(t => UnitCard.SimUnit(bridge.Content, bridge.State, t.Token) is int id&& Movement.ActionsLeft(bridge.Content, bridge.State, id, bridge.Spent) == 0)diff --git a/unity/Assets/Tests/EditMode/Generated1948CharacterTests.cs b/unity/Assets/Tests/EditMode/Generated1948CharacterTests.csindex 037126534..7d11625c0 100644--- a/unity/Assets/Tests/EditMode/Generated1948CharacterTests.cs+++ b/unity/Assets/Tests/EditMode/Generated1948CharacterTests.cs@@ -272,7 +272,10 @@ public class Generated1948CharacterTestsAssert.AreEqual($"{dir}/{id}.controller", AssetDatabase.GetAssetPath(controller));Assert.AreEqual(1, controller!.layers.Length);var machine = controller.layers[0].stateMachine;- Assert.AreEqual(1, machine.states.Length);+ // A figure that stands on unit tokens also walks with its own walk take (#1866); the Bedouin civilian stays idle only.+ bool token = id != "figure-bedouin-civilian-1948-v1";+ CollectionAssert.AreEquivalent(token ? new[] { "idle", "walk" } : new[] { "idle" }, machine.states.Select(s => s.state.name));+ if (token) Assert.AreSame(clips.Single(c => c.name == "walk"), machine.states.Single(s => s.state.name == "walk").state.motion);Assert.IsNotNull(machine.defaultState);Assert.AreSame(clips.Single(c => c.name == "idle"), machine.defaultState.motion, "the default idle comes from this character's FBX");Assert.AreEqual(source, AssetDatabase.GetAssetPath(machine.defaultState.motion));diff --git a/unity/Assets/Tests/EditMode/Generated1948RigTests.cs b/unity/Assets/Tests/EditMode/Generated1948RigTests.csindex 3870c9c54..802aa4ead 100644--- a/unity/Assets/Tests/EditMode/Generated1948RigTests.cs+++ b/unity/Assets/Tests/EditMode/Generated1948RigTests.cs@@ -58,7 +58,9 @@ public class Generated1948RigTestsvar idle = Clip(id, "near");Assert.AreEqual("idle", idle.name);Assert.IsTrue(idle.isLooping);- Assert.AreSame(idle, animator.runtimeAnimatorController.animationClips.Single());+ // The infantry on unit tokens also walk with their own walk take (#1866); the civilians stay idle only.+ bool token = id != "figure-bedouin-civilian-1948-v1" && id != "figure-local-arab-irregular-1948-v1";+ CollectionAssert.AreEquivalent(token ? new[] { idle, Clip(id, "walk") } : new[] { idle }, animator.runtimeAnimatorController.animationClips);Assert.AreEqual(ModelImporterMeshCompression.Off, imp.meshCompression);Assert.AreEqual(ModelImporterAnimationCompression.Off, imp.animationCompression);CollectionAssert.AreEquivalent(new[] { "idle", "walk" }, imp.clipAnimations.Select(c => c.name));diff --git a/unity/Assets/Tests/EditMode/MapLabelTests.cs b/unity/Assets/Tests/EditMode/MapLabelTests.csindex 2461ff213..f63520f4c 100644--- a/unity/Assets/Tests/EditMode/MapLabelTests.cs+++ b/unity/Assets/Tests/EditMode/MapLabelTests.cs@@ -906,14 +906,87 @@ public class MapLabelTestsfinally { inset.Dispose(); labels.Dispose(); hd.Dispose(); }}+ /// <summary>Review of #2176, item 1: a moved unit's token slides to its new spot (#1866), and with no camera move the+ /// names keep clear of the token where it is drawn, during the slide and after it. At gameplay03 the Tel Aviv pill+ /// stands clear of the Kiryati Brigade (PillsKeepClearOfTheUnitTokens). The brigade's token then starts a slide from+ /// 150 km east, and the labels' pass at the rebuild sees it there, so the pill comes down. Near the slide's end, and+ /// once it has arrived, a plain refresh (GameRoot's every LateUpdate, the boxes faced to the camera first) puts the pill+ /// clear of the brigade again. Before the fix the slide moved the boxes inside the same list, the labels re-place only+ /// for a new list, and the pill stayed where the token had been drawn at the start.</summary>+ [UnityTest]+ public IEnumerator PillsKeepClearOfASlidingTokenWithoutACameraMove()+ {+ var layer = StartUnits(animateMoves: true);+ HdPanel hd = new HdPanel(cam);+ var labels = new MapLabelsPresenter(hd.Root, map, cam, keepClear: () => { layer.FaceCamera(cam); return layer.KeepClear; }); // as GameRoot+ var inset = new TopBarInset(hd.Root, rig);+ try+ {+ var pose = PromoPose.Gameplay03;+ rig.LookAt = map.Frame.ToWorld(pose.Lon, pose.Lat, 0); rig.Distance = pose.Distance; rig.Yaw = pose.Yaw; rig.Apply();+ yield return null;+ inset.Update();+ // An Arab force's token is drawn only once its figure has loaded or failed (UnitLayer.Show), and each such+ // arrival (UnitFigures.AvailabilityVersion) makes the next FaceCamera redraw every token (Rebuild), which can+ // move the names and replaces the brigade's token. Only figures near the camera load, so wait until no+ // arrival has come for 3 s (at most 60 s) before the names are measured.+ var clock = System.Diagnostics.Stopwatch.StartNew();+ int version = Statecraft.Game.Map.Units.UnitFigures.AvailabilityVersion; double quietSince = 0;+ while (clock.Elapsed.TotalSeconds - quietSince < 3 && clock.Elapsed.TotalSeconds < 60)+ {+ yield return null;+ layer.FaceCamera(cam); // as a render would: an arrival redraws the tokens now+ if (Statecraft.Game.Map.Units.UnitFigures.AvailabilityVersion != version)+ { version = Statecraft.Game.Map.Units.UnitFigures.AvailabilityVersion; quietSince = clock.Elapsed.TotalSeconds; }+ }+ TestContext.WriteLine($"figures quiet after {quietSince:F1} s (availability version {version})");+ layer.FaceCamera(cam); // the redraw for them, before the names are placed+ yield return Settle(labels);+ var tlv = labels.Slots.Single(s => s.name == "slot-tel_aviv");+ Assert.IsTrue(Shown(tlv), "Tel Aviv is named at gameplay03");+ var clear = tlv.Q<Label>().worldBound; // clear of the brigade standing in Tel Aviv+ // Found again after every frame: a redraw replaces the token, and its new motion goes on with the slide.+ Statecraft.Game.Map.Units.UnitTokenMotion Motion() =>+ GameObject.Find(Statecraft.Game.Map.Units.UnitLayer.RootName).transform.Find("Tokens").Find("kiryati")+ .GetComponent<Statecraft.Game.Map.Units.UnitTokenMotion>();+ Assert.IsNotNull(Motion(), "a play build moves the brigade's token");++ Motion().Begin(new Vector3(150000f, 0f, 0f));+ labels.Refresh(force: true); yield return null; // the labels' pass at the rebuild sees the slide's start+ // and the frames after it, while the token has barely moved: a placement that shows or hides a pill changes the+ // pills' sizes, which re-places them once more (MapLabelsPresenter.Refresh), so let that settle at the start.+ for (int i = 0; i < 3; i++) { labels.Refresh(); yield return null; }+ var away = tlv.Q<Label>().worldBound;+ TestContext.WriteLine($"slide start: Tel Aviv pill {away}, clear of the brigade {clear}");+ Assert.Greater(away.yMax, clear.yMax + 1f, $"with the brigade drawn 150 km east the pill {away} comes down from {clear}");++ var motion = Motion();+ motion.Tick(Statecraft.Game.Map.Units.UnitTokenMotion.Duration * 0.9999f); // 15 m short of Tel Aviv+ Assert.IsTrue(motion.Moving, "still sliding");+ labels.Refresh(); yield return null;+ var during = tlv.Q<Label>().worldBound;+ TestContext.WriteLine($"near the end: Tel Aviv pill {during}");+ Assert.AreEqual(clear.yMax, during.yMax, 1f, $"mid-slide the pill {during} keeps clear of the token as drawn, not of its start {away}");++ motion = Motion();+ motion.Tick(Statecraft.Game.Map.Units.UnitTokenMotion.Duration);+ Assert.IsFalse(motion.Moving, "arrived");+ labels.Refresh(); yield return null;+ Assert.AreEqual(clear.yMax, tlv.Q<Label>().worldBound.yMax, 0.5f, "arrived, the pill keeps clear of the brigade in Tel Aviv");+ }+ finally { inset.Dispose(); labels.Dispose(); hd.Dispose(); }+ }+static readonly string[] Occluders = { "top-bar", "info-panel", "minimap" };- /// <summary>The units in play as a new game starts (golden seed, historical mode), as the game draws them.</summary>- Statecraft.Game.Map.Units.UnitLayer StartUnits()+ /// <summary>The units in play as a new game starts (golden seed, historical mode), as the game draws them; with+ /// <paramref name="animateMoves"/> as in play, where a moved unit's token slides (#1866).</summary>+ Statecraft.Game.Map.Units.UnitLayer StartUnits(bool animateMoves = false){var content = Statecraft.Sim.ContentLoader.Load(Statecraft.Game.Paths.Content);var units = Statecraft.Game.Map.Units.UnitData.Parse(File.ReadAllText(Path.Combine(Statecraft.Game.Paths.Content, "map", Statecraft.Game.Map.Units.UnitData.DefaultFileName)));var layer = Statecraft.Game.Map.Units.UnitLayer.Create(map, units, content.Hexes, still: true);+ layer.AnimateMoves = animateMoves;layer.Show(content, Statecraft.Sim.Simulation.NewGame(content, Statecraft.Sim.GoldenRun.Seed, Statecraft.Sim.Mode.Historical));return layer;}diff --git a/unity/Assets/Tests/EditMode/UnitFigureControllerTests.cs b/unity/Assets/Tests/EditMode/UnitFigureControllerTests.csnew file mode 100644index 000000000..f0ceeb3b4--- /dev/null+++ b/unity/Assets/Tests/EditMode/UnitFigureControllerTests.cs@@ -0,0 +1,219 @@+using System;+using System.Collections.Generic;+using System.Linq;+using System.Reflection;+using NUnit.Framework;+using Statecraft.Game.Map.Collection;+using Statecraft.Game.Map.Units;+using UnityEditor;+using UnityEditor.Animations;+using UnityEngine;+using Object = UnityEngine.Object;++/// <summary>#1866 and #1867 (design by Tal Heuberger, #1900): the token figures' controllers get walk and attack states+/// from takes already in each figure's own FBX (CollectionImport.AddMotionStates); no model, clip or prefab changes.</summary>+public class UnitFigureControllerTests+{+ static Type Import => Type.GetType("Statecraft.Game.EditorTools.CollectionImport, Assembly-CSharp-Editor")!;+ static Type Generated => Type.GetType("Statecraft.Game.EditorTools.Generated1948Characters, Assembly-CSharp-Editor")!;+ const BindingFlags Any = BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic;+ static IReadOnlyCollection<string> TokenFigures => (IReadOnlyCollection<string>)Import.GetField("TokenFigures", Any)!.GetValue(null);+ static void AddMotionStates(AnimatorController c, string model) => Import.GetMethod("AddMotionStates", Any)!.Invoke(null, new object[] { c, model });+ static AnimationClip WalkTake(IReadOnlyList<AnimationClip> clips) => (AnimationClip)Import.GetMethod("WalkTake", Any)!.Invoke(null, new object[] { clips });+ static void Configure(AnimatorController c, AnimationClip idle, string model, bool token)+ {+ try { Generated.GetMethod("ConfigureController", Any)!.Invoke(null, new object[] { c, idle, model, token }); }+ catch (TargetInvocationException e) { throw e.InnerException!; }+ }++ const string C06 = "Assets/Art/Collection/figure-c06-young-recruit-v2/figure-c06-young-recruit-v2.fbx";++ static string ControllerPath(string id) => CollectionCatalog.IsFullQualityGeneratedInfantry(id)+ ? $"Assets/Art/Collection/{id}/{id}.controller" : $"Assets/Art/Collection/{id}/{id}-near.controller";+ static string ModelPath(string id) => $"Assets/Art/Collection/{id}/{id}.fbx";+ static AnimationClip[] Takes(string model) => AssetDatabase.LoadAllAssetsAtPath(model).OfType<AnimationClip>()+ .Where(c => !c.name.StartsWith("__preview__", StringComparison.Ordinal)).ToArray();+ static AnimatorState State(AnimatorController c, string name) =>+ c.layers[0].stateMachine.states.Select(s => s.state).SingleOrDefault(s => s.name == name);++ /// <summary>Every rigged model a unit token can stand (UnitFigures) is a token figure, so none is left without a walk.</summary>+ [Test]+ public void EveryRiggedFigureOnATokenIsATokenFigure()+ {+ var onTokens = UnitFigures.ByHeadgear.Values.Concat(UnitFigures.ThirdFigure.Values).Concat(UnitFigures.BySide.Values)+ .Concat(UnitFigures.ThirdBySide.Values).Append(UnitFigures.PioneerVeteran).Distinct();+ foreach (var id in onTokens.Where(id => CollectionCatalog.Animated.Contains(id) || id == UnitFigures.PioneerVeteran))+ Assert.That(TokenFigures, Has.Member(id), id);+ }++ /// <summary>UnitFigureMotion plays "Base Layer.idle", "Base Layer.walk" and "Base Layer.attack" by full path (review of+ /// #2176, H1): every token figure whose near Animator is ever on has its default state named idle in a machine named+ /// Base Layer, so a figure stands idle again after a move. C05 is the exception: his only idle is a walk and he stays far+ /// (UnitFigures.Swap), so his near Animator never plays.</summary>+ [Test]+ public void EachTokenFigureAnimatorCanPlayIdleWalkAndItsAttack()+ {+ foreach (var id in TokenFigures.Where(id => id != UnitFigures.PioneerVeteran))+ {+ var c = AssetDatabase.LoadAssetAtPath<AnimatorController>(ControllerPath(id));+ Assert.AreEqual("Base Layer", c.layers[0].stateMachine.name, id);+ Assert.AreEqual("idle", c.layers[0].stateMachine.defaultState.name, id);+ var go = new GameObject(id);+ try+ {+ var animator = go.AddComponent<Animator>(); animator.runtimeAnimatorController = c;+ Assert.IsTrue(animator.HasState(0, UnitFigureMotion.Idle), id + ": idle");+ Assert.IsTrue(animator.HasState(0, UnitFigureMotion.Walk), id + ": walk");+ Assert.AreEqual(State(c, "attack") != null, animator.HasState(0, UnitFigureMotion.Attack), id + ": attack");+ }+ finally { Object.DestroyImmediate(go); }+ }+ }++ /// <summary>The committed controllers are what PrepareTokenFigureControllers makes: the idle default untouched, a walk+ /// state on the figure's own walk take, and an attack state on its own fire take exactly where the FBX has one.</summary>+ [Test]+ public void EachTokenFigureControllerWalksAndFiresWithItsOwnTakes()+ {+ foreach (var id in TokenFigures)+ {+ var c = AssetDatabase.LoadAssetAtPath<AnimatorController>(ControllerPath(id));+ Assert.IsNotNull(c, id);+ var takes = Takes(ModelPath(id));+ var machine = c.layers[0].stateMachine;+ Assert.AreEqual(id == UnitFigures.PioneerVeteran ? "Armature|idle_walk" : id.EndsWith("-v1", StringComparison.Ordinal) ? "idle" : "Armature|idle",+ machine.defaultState.motion.name, id + ": the default is still the idle the figure stood in");+ var walk = State(c, "walk");+ Assert.IsNotNull(walk, id + ": walk");+ Assert.AreSame(WalkTake(takes), walk.motion, id + ": its own walk take");+ var fire = takes.FirstOrDefault(t => UnitTokenMotion.CollectionFireTake(t.name));+ if (fire == null) Assert.IsNull(State(c, "attack"), id + ": no fire take, no attack state");+ else Assert.AreSame(fire, State(c, "attack")?.motion, id + ": its own fire take");+ Assert.AreEqual(fire == null ? 2 : 3, machine.states.Length, id);+ foreach (var clip in c.animationClips)+ Assert.AreEqual(ModelPath(id), AssetDatabase.GetAssetPath(clip), id + ": every take from the figure's own FBX");+ }+ }++ [Test]+ public void AddingTheStatesTwiceChangesNothing()+ {+ var c = new AnimatorController(); c.AddLayer("Base Layer");+ try+ {+ AddMotionStates(c, C06);+ var first = c.layers[0].stateMachine.states.Select(s => s.state).ToArray();+ CollectionAssert.AreEquivalent(new[] { "walk", "attack" }, first.Select(s => s.name));+ Assert.AreEqual("Armature|walk", State(c, "walk").motion.name);+ Assert.AreEqual("Armature|fire", State(c, "attack").motion.name);+ AddMotionStates(c, C06);+ CollectionAssert.AreEqual(first, c.layers[0].stateMachine.states.Select(s => s.state));+ }+ finally { Object.DestroyImmediate(c); }+ }++ /// <summary>A take named walk wins over C05's idle_walk whichever comes first; idle_walk is used only alone.</summary>+ [Test]+ public void TheWalkTakeIsChosenByNameNotByOrder()+ {+ var walk = new AnimationClip { name = "Armature|walk" };+ var idleWalk = new AnimationClip { name = "Armature|idle_walk" };+ var run = new AnimationClip { name = "Armature|run" };+ try+ {+ Assert.AreSame(walk, WalkTake(new[] { idleWalk, run, walk }));+ Assert.AreSame(walk, WalkTake(new[] { walk, idleWalk }));+ Assert.AreSame(idleWalk, WalkTake(new[] { run, idleWalk }));+ Assert.IsNull(WalkTake(new[] { run }));+ }+ finally { Object.DestroyImmediate(walk); Object.DestroyImmediate(idleWalk); Object.DestroyImmediate(run); }+ }++ /// <summary>A generated figure's controller is checked whole before anything in it changes.</summary>+ [TestCase("empty")]+ [TestCase("two-layers")]+ [TestCase("duplicate-idle")]+ [TestCase("duplicate-walk")]+ [TestCase("unknown-state")]+ [TestCase("walk-default")]+ [TestCase("missing-idle")]+ public void ABadGeneratedControllerIsRefusedUntouched(string layout)+ {+ var c = new AnimatorController(); c.AddLayer("Base Layer");+ var before = new AnimationClip { name = "before" };+ var idle = new AnimationClip { name = "idle" };+ try+ {+ var machine = c.layers[0].stateMachine;+ AnimatorState Add(string name) { var s = machine.AddState(name); s.motion = before; return s; }+ switch (layout)+ {+ case "empty": break;+ case "two-layers": machine.defaultState = Add("idle"); c.AddLayer("Second"); break;+ case "duplicate-idle": machine.defaultState = Add("idle"); machine.AddState("x").name = "idle"; break;+ case "duplicate-walk": machine.defaultState = Add("idle"); Add("walk"); machine.AddState("x").name = "walk"; break;+ case "unknown-state": machine.defaultState = Add("idle"); Add("run"); break;+ case "walk-default": Add("idle"); machine.defaultState = Add("walk"); break;+ case "missing-idle": machine.defaultState = Add("walk"); break;+ }+ foreach (var s in machine.states) s.state.motion = before;+ var states = machine.states.Select(s => s.state).ToArray();+ var defaultState = machine.defaultState;+ int layers = c.layers.Length;+ Assert.Throws<InvalidOperationException>(() => Configure(c, idle, C06, token: true), layout);+ CollectionAssert.AreEqual(states, c.layers[0].stateMachine.states.Select(s => s.state), "no state added");+ Assert.AreSame(defaultState, c.layers[0].stateMachine.defaultState, "the default unchanged");+ Assert.AreEqual(layers, c.layers.Length);+ foreach (var s in states) Assert.AreSame(before, s.motion, "no take changed");+ if (defaultState != null) Assert.AreSame(before, defaultState.motion);+ }+ finally { Object.DestroyImmediate(c); Object.DestroyImmediate(before); Object.DestroyImmediate(idle); }+ }++ /// <summary>A default that is none or another machine's state (review of #1900). Unity does not keep such a default:+ /// it reports the machine's own state instead (pinned here; review of #2176, C4), so the importer's check for it guards+ /// only a hand-edited asset, and the importer configures the owned idle as for any controller.</summary>+ [TestCase("missing-default")]+ [TestCase("foreign-default")]+ public void UnityKeepsADefaultInsideTheMachineAndTheImporterConfiguresIt(string layout)+ {+ var c = new AnimatorController(); c.AddLayer("Base Layer");+ var before = new AnimationClip { name = "before" };+ var idle = new AnimationClip { name = "idle" };+ var foreign = new AnimatorStateMachine();+ try+ {+ var machine = c.layers[0].stateMachine;+ var own = machine.AddState("idle"); own.motion = before;+ if (layout == "missing-default") machine.defaultState = null;+ else { var other = foreign.AddState("idle"); other.motion = before; machine.defaultState = other; }+ Assert.AreSame(own, machine.defaultState, "Unity reports the machine's own state as the default");+ Configure(c, idle, C06, token: false);+ Assert.AreSame(own, machine.defaultState);+ Assert.AreSame(idle, own.motion, "configured as any owned idle");+ }+ finally { Object.DestroyImmediate(c); Object.DestroyImmediate(before); Object.DestroyImmediate(idle); Object.DestroyImmediate(foreign); }+ }++ [TestCase(true)]+ [TestCase(false)]+ public void AnIdleOnlyGeneratedControllerGainsTheStatesOnlyForATokenFigure(bool token)+ {+ var c = new AnimatorController(); c.AddLayer("Base Layer");+ var idle = new AnimationClip { name = "idle" };+ try+ {+ var machine = c.layers[0].stateMachine;+ var original = machine.AddState("idle"); machine.defaultState = original;+ Configure(c, idle, C06, token);+ CollectionAssert.AreEquivalent(token ? new[] { "idle", "walk", "attack" } : new[] { "idle" },+ machine.states.Select(s => s.state.name));+ Assert.AreSame(original, machine.defaultState);+ Assert.AreSame(idle, original.motion);+ var states = machine.states.Select(s => s.state).ToArray();+ Configure(c, idle, C06, token);+ CollectionAssert.AreEqual(states, machine.states.Select(s => s.state), "a second run adds nothing");+ }+ finally { Object.DestroyImmediate(c); Object.DestroyImmediate(idle); }+ }+}diff --git a/unity/Assets/Tests/EditMode/UnitFigureControllerTests.cs.meta b/unity/Assets/Tests/EditMode/UnitFigureControllerTests.cs.metanew file mode 100644index 000000000..9d91262de--- /dev/null+++ b/unity/Assets/Tests/EditMode/UnitFigureControllerTests.cs.meta@@ -0,0 +1,2 @@+fileFormatVersion: 2+guid: 1f03dfe14f4ef4c1d88353304f164aa9\ No newline at end of filediff --git a/unity/Assets/Tests/EditMode/UnitTokenMotionTests.cs b/unity/Assets/Tests/EditMode/UnitTokenMotionTests.csnew file mode 100644index 000000000..f790e2894--- /dev/null+++ b/unity/Assets/Tests/EditMode/UnitTokenMotionTests.cs@@ -0,0 +1,301 @@+using System.Reflection;+using NUnit.Framework;+using Statecraft.Game.Map.Units;+using UnityEditor.Animations;+using UnityEngine;+using UnityEngine.TestTools.Constraints;+using Is = UnityEngine.TestTools.Constraints.Is;+using Object = UnityEngine.Object;++/// <summary>#1866 and #1867 (design by Tal Heuberger, #1900): a token's slide, its figures' walk and idle, and the+/// one-shot attack, on real Animators with throwaway controllers.</summary>+public class UnitTokenMotionTests+{+ GameObject token = null!;+ AnimatorController controller = null!;+ AnimationClip idle = null!, walk = null!, fire = null!;++ [SetUp]+ public void Make()+ {+ token = new GameObject("token");+ controller = new AnimatorController(); controller.AddLayer("Base Layer");+ idle = new AnimationClip { name = "idle" }; walk = new AnimationClip { name = "walk" };+ fire = new AnimationClip { name = "Armature|fire" };+ fire.SetCurve("", typeof(Transform), "localScale.x", AnimationCurve.Linear(0f, 1f, 0.2f, 1f)); // a 0.2 s take+ }++ [TearDown]+ public void Free()+ {+ Object.DestroyImmediate(token); Object.DestroyImmediate(controller);+ Object.DestroyImmediate(idle); Object.DestroyImmediate(walk); Object.DestroyImmediate(fire);+ }++ /// <summary>A figure under the token with the idle default and, as asked, a walk and an attack state.</summary>+ Animator Figure(bool walkState = true, bool attackState = true)+ {+ var machine = controller.layers[0].stateMachine;+ machine.defaultState = machine.AddState("idle"); machine.defaultState.motion = idle;+ if (walkState) machine.AddState("walk").motion = walk;+ if (attackState) machine.AddState("attack").motion = fire;+ var figure = new GameObject("figure"); figure.transform.SetParent(token.transform, false);+ var animator = figure.AddComponent<Animator>();+ animator.runtimeAnimatorController = controller;+ animator.applyRootMotion = true;+ animator.Rebind(); animator.Update(0f);+ return animator;+ }++ static bool In(Animator a, int state) { a.Update(0f); return a.GetCurrentAnimatorStateInfo(0).fullPathHash == state; }++ [Test]+ public void PlaySwitchesStatesAndFailsOpenWithoutOne()+ {+ var a = Figure(attackState: false);+ Assert.IsTrue(UnitFigureMotion.Play(a, UnitFigureMotion.Walk));+ Assert.IsTrue(In(a, UnitFigureMotion.Walk));+ Assert.IsFalse(a.applyRootMotion, "the token's offset moves the figure, not the take's root");+ Assert.IsTrue(UnitFigureMotion.Play(a, UnitFigureMotion.Idle));+ Assert.IsTrue(In(a, UnitFigureMotion.Idle));+ Assert.IsFalse(UnitFigureMotion.Play(a, UnitFigureMotion.Attack), "no attack state: nothing plays");+ Assert.IsTrue(In(a, UnitFigureMotion.Idle));+ Assert.IsFalse(UnitFigureMotion.Play(null, UnitFigureMotion.Walk));+ }++ [Test]+ public void AnAnimatorThatCannotPlayIsLeftAlone()+ {+ var a = Figure();+ a.enabled = false;+ Assert.IsFalse(UnitFigureMotion.Play(a, UnitFigureMotion.Walk), "a disabled Animator (a far figure's near one)");+ a.enabled = true; a.gameObject.SetActive(false);+ Assert.IsFalse(UnitFigureMotion.Play(a, UnitFigureMotion.Walk), "an Animator on an inactive object (a token torn down)");+ a.gameObject.SetActive(true); a.runtimeAnimatorController = null;+ Assert.IsFalse(UnitFigureMotion.Play(a, UnitFigureMotion.Walk), "no controller");+ }++ [Test]+ public void ASlideWalksToTheUnitsPlaceThenStandsIdleAndStops()+ {+ var a = Figure();+ var motion = token.AddComponent<UnitTokenMotion>();+ int changes = 0; motion.Changed = () => changes++;+ motion.Begin(new Vector3(1000f, 0f, -500f));+ Assert.IsTrue(motion.Moving); Assert.IsTrue(motion.enabled);+ Assert.AreEqual(new Vector3(1000f, 0f, -500f), token.transform.position, "it starts where it was drawn");+ Assert.IsTrue(In(a, UnitFigureMotion.Walk));+ motion.Tick(UnitTokenMotion.Duration / 2f);+ Assert.That(Vector3.Distance(new Vector3(500f, 0f, -250f), token.transform.position), Is.LessThan(1e-3f));+ Assert.IsTrue(motion.enabled, "still sliding");+ motion.Tick(UnitTokenMotion.Duration);+ Assert.AreEqual(Vector3.zero, token.transform.position, "it ends exactly at the unit's place");+ Assert.IsFalse(motion.Moving);+ Assert.IsFalse(motion.enabled, "an idle token runs no LateUpdate");+ Assert.IsTrue(In(a, UnitFigureMotion.Idle));+ Assert.AreEqual(3, changes, "Begin and each step tell the layer to redraw the badge and boxes");+ }++ [Test]+ public void AMoveTooShortToSeeIsDrawnAtOnce()+ {+ var motion = token.AddComponent<UnitTokenMotion>();+ motion.enabled = false;+ motion.Begin(Vector3.right * (UnitTokenMotion.MinMoveM / 2f));+ Assert.IsFalse(motion.Moving);+ Assert.IsFalse(motion.enabled);+ Assert.AreEqual(Vector3.zero, token.transform.position);+ }++ /// <summary>Every rebuild calls Begin on every token, most with no move (review of #2176, H5): a token that does not+ /// move and was not moving leaves its figures as they are.</summary>+ [Test]+ public void ANoMoveBeginLeavesAnIdleTokensFiguresAlone()+ {+ var a = Figure();+ UnitFigureMotion.Play(a, UnitFigureMotion.Walk);+ Assert.IsTrue(In(a, UnitFigureMotion.Walk), "fixture: the figure plays something else than idle");+ var motion = token.AddComponent<UnitTokenMotion>();+ motion.enabled = false;+ int changes = 0; motion.Changed = () => changes++;+ motion.Begin(Vector3.zero);+ Assert.IsTrue(In(a, UnitFigureMotion.Walk), "no pose was forced on it");+ Assert.AreEqual(0, changes);+ Assert.IsFalse(motion.enabled);+ }++ [Test]+ public void DisablingMidSlidePutsTheTokenAtItsPlace()+ {+ var a = Figure();+ var motion = token.AddComponent<UnitTokenMotion>();+ int changes = 0;+ motion.Begin(Vector3.right * 1000f);+ motion.Changed = () => changes++;+ // EditMode sends no OnDisable to a script without ExecuteAlways: call it as the player would.+ typeof(UnitTokenMotion).GetMethod("OnDisable", BindingFlags.Instance | BindingFlags.NonPublic)!.Invoke(motion, null);+ Assert.IsFalse(motion.Moving);+ Assert.AreEqual(Vector3.zero, token.transform.position);+ Assert.AreEqual(1, changes, "the layer moves the badge and boxes back with it");+ Assert.IsTrue(In(a, UnitFigureMotion.Idle));+ }++ [Test]+ public void AnAttackPlaysOnceThenTheFiguresWalkOnAndStandIdle()+ {+ var a = Figure();+ var motion = token.AddComponent<UnitTokenMotion>();+ motion.enabled = false;+ motion.Begin(Vector3.right * 1000f);+ Assert.IsTrue(motion.PlayAttack());+ Assert.IsTrue(motion.Attacking); Assert.IsTrue(motion.enabled);+ Assert.IsTrue(In(a, UnitFigureMotion.Attack));+ motion.Tick(0.1f);+ Assert.IsTrue(In(a, UnitFigureMotion.Attack), "the 0.2 s take is still playing");+ motion.Tick(0.15f);+ Assert.IsFalse(motion.Attacking);+ Assert.IsTrue(In(a, UnitFigureMotion.Walk), "the slide is still under way, so the figure walks on");+ motion.Tick(1f);+ Assert.IsTrue(In(a, UnitFigureMotion.Idle));+ Assert.IsFalse(motion.enabled);+ Assert.IsTrue(motion.PlayAttack(), "a standing token attacks too");+ motion.Tick(0.05f);+ Assert.IsTrue(motion.PlayAttack(), "a second attack restarts the take");+ motion.Tick(0.15f);+ Assert.IsTrue(motion.Attacking, "the restarted take runs its full length");+ motion.Tick(0.1f);+ Assert.IsFalse(motion.Attacking); Assert.IsFalse(motion.enabled);+ Assert.IsTrue(In(a, UnitFigureMotion.Idle));+ }++ /// <summary>A rebuild for another unit's order hands a playing attack to the unit's new token (review of #2177, 3): it+ /// goes on from where it was, for what is left of the take, not from the start and not cut short.</summary>+ [Test]+ public void AContinuedAttackPlaysOnFromWhereItWas()+ {+ var a = Figure();+ var motion = token.AddComponent<UnitTokenMotion>();+ motion.enabled = false;+ Assert.IsTrue(motion.PlayAttack());+ motion.Tick(0.05f);+ Assert.AreEqual(0.05f, motion.AttackPlayed, 1e-4f);+ var next = new GameObject("rebuilt token");+ try+ {+ var figure = new GameObject("figure"); figure.transform.SetParent(next.transform, false);+ var b = figure.AddComponent<Animator>(); b.runtimeAnimatorController = controller; b.Rebind(); b.Update(0f);+ var successor = next.AddComponent<UnitTokenMotion>();+ successor.enabled = false;+ successor.ContinueAttack(motion.AttackPlayed);+ Assert.IsTrue(successor.Attacking); Assert.IsTrue(successor.enabled);+ b.Update(0f);+ Assert.AreEqual(UnitFigureMotion.Attack, b.GetCurrentAnimatorStateInfo(0).fullPathHash);+ Assert.AreEqual(0.25f, b.GetCurrentAnimatorStateInfo(0).normalizedTime, 0.02f, "from 0.05 s into the 0.2 s take");+ successor.Tick(0.14f);+ Assert.IsTrue(successor.Attacking, "0.15 s of the take is left");+ successor.Tick(0.02f);+ Assert.IsFalse(successor.Attacking);+ }+ finally { Object.DestroyImmediate(next); }+ }++ /// <summary>Review of #2176, item 3: the usual hand-over, where the rebuilt token's near figure turns on a frame+ /// later (UnitFigureDetail calls RefreshPose). The figure picks the take up where it was, not from its first frame,+ /// and the attack lasts only for what is left.</summary>+ [Test]+ public void AContinuedAttackWhoseFigureTurnsNearLaterPlaysOnFromWhereItWas()+ {+ var a = Figure();+ a.enabled = false; // far: the near Animator is off+ var motion = token.AddComponent<UnitTokenMotion>();+ motion.enabled = false;+ motion.ContinueAttack(0.05f);+ Assert.IsTrue(motion.Attacking, "it waits for a figure that can fire");+ a.enabled = true; motion.RefreshPose(); // the figure turns near+ a.Update(0f);+ Assert.AreEqual(UnitFigureMotion.Attack, a.GetCurrentAnimatorStateInfo(0).fullPathHash);+ Assert.AreEqual(0.25f, a.GetCurrentAnimatorStateInfo(0).normalizedTime, 0.02f, "from 0.05 s into the 0.2 s take, not from its start");+ motion.Tick(0.14f);+ Assert.IsTrue(motion.Attacking);+ motion.Tick(0.02f);+ Assert.IsFalse(motion.Attacking, "0.15 s was left, not the whole take");+ }++ /// <summary>Review of #2176, item 8: an attack the new token's figures had already played to the end stands them+ /// idle, not on the fire take's last frame.</summary>+ [Test]+ public void AContinuedAttackPastItsTakeLeavesTheFiguresIdle()+ {+ var a = Figure();+ var motion = token.AddComponent<UnitTokenMotion>();+ motion.enabled = false;+ motion.ContinueAttack(0.3f); // the take is 0.2 s+ Assert.IsFalse(motion.Attacking, "the take had finished");+ Assert.IsTrue(In(a, UnitFigureMotion.Idle), "the figure stands idle");+ }++ /// <summary>Review of #2176, item 5 (#1900's test, in our words): switching a figure between walk and idle, as every+ /// slide's start and end does, allocates nothing.</summary>+ [Test]+ public void PlayingAStateDoesNotAllocate()+ {+ var a = Figure();+ for (int i = 0; i < 5; i++) { UnitFigureMotion.Play(a, UnitFigureMotion.Walk); a.Update(0f); }+ Assert.That(() => { UnitFigureMotion.Play(a, UnitFigureMotion.Walk); UnitFigureMotion.Play(a, UnitFigureMotion.Idle); },+ Is.Not.AllocatingGCMemory());+ }++ [Test]+ public void AFigureWithoutAFireTakeDoesNotAttack()+ {+ var a = Figure(attackState: false);+ var motion = token.AddComponent<UnitTokenMotion>();+ motion.enabled = false;+ Assert.IsFalse(motion.PlayAttack());+ motion.Tick(UnitTokenMotion.AttackWaitS);+ Assert.IsFalse(motion.Attacking); Assert.IsFalse(motion.enabled, "after the short wait nothing runs");+ Assert.IsTrue(In(a, UnitFigureMotion.Idle));+ }++ /// <summary>An engagement rebuilds the tokens just before it plays, and the new ones turn their near figures on at the+ /// next render: the attack waits that long for them, and no longer.</summary>+ [Test]+ public void AnAttackWaitsBrieflyForAFigureThatTurnsNear()+ {+ var a = Figure();+ a.enabled = false; // far: the near Animator is off+ var motion = token.AddComponent<UnitTokenMotion>();+ motion.enabled = false;+ Assert.IsFalse(motion.PlayAttack(), "no figure can play it yet");+ Assert.IsTrue(motion.Attacking); Assert.IsTrue(motion.enabled);+ motion.Tick(0.05f);+ a.enabled = true; motion.RefreshPose(); // as UnitFigureDetail does when the figure turns near+ Assert.IsTrue(In(a, UnitFigureMotion.Attack));+ motion.Tick(0.15f);+ Assert.IsTrue(motion.Attacking, "the take's own 0.2 s, from when it started");+ motion.Tick(0.1f);+ Assert.IsFalse(motion.Attacking);+ Assert.IsTrue(In(a, UnitFigureMotion.Idle));++ a.enabled = false;+ Assert.IsFalse(motion.PlayAttack());+ motion.Tick(UnitTokenMotion.AttackWaitS);+ Assert.IsFalse(motion.Attacking); Assert.IsFalse(motion.enabled);+ a.enabled = true; motion.RefreshPose();+ Assert.IsTrue(In(a, UnitFigureMotion.Idle), "a figure that turns near later does not play an old attack");+ }++ [Test]+ public void AHiddenTokensAttackIsDroppedNotKept()+ {+ var a = Figure();+ var motion = token.AddComponent<UnitTokenMotion>();+ motion.enabled = false;+ token.SetActive(false);+ Assert.IsFalse(motion.PlayAttack());+ Assert.IsFalse(motion.Attacking);+ token.SetActive(true);+ motion.RefreshPose();+ Assert.IsTrue(In(a, UnitFigureMotion.Idle), "shown again, it does not play the attack it missed");+ }+}diff --git a/unity/Assets/Tests/EditMode/UnitTokenMotionTests.cs.meta b/unity/Assets/Tests/EditMode/UnitTokenMotionTests.cs.metanew file mode 100644index 000000000..257258480--- /dev/null+++ b/unity/Assets/Tests/EditMode/UnitTokenMotionTests.cs.meta@@ -0,0 +1,2 @@+fileFormatVersion: 2+guid: 4e935660770ff4613b770b83ac81714c\ No newline at end of filediff --git a/unity/Assets/Tests/EditMode/UnitsFromStateTests.cs b/unity/Assets/Tests/EditMode/UnitsFromStateTests.csindex 8e3f86931..9f2fe5683 100644--- a/unity/Assets/Tests/EditMode/UnitsFromStateTests.cs+++ b/unity/Assets/Tests/EditMode/UnitsFromStateTests.cs@@ -11,7 +11,9 @@ using Statecraft.Sim;using UnityEditor;using UnityEditor.SceneManagement;using UnityEngine;+using UnityEngine.TestTools.Constraints;using UnityEngine.UIElements;+using Is = UnityEngine.TestTools.Constraints.Is;/// <summary>GDD Phase 5 PR 14 (#753; impact plan §2.6): in the GDD loop the map's army tokens come from the sim's units/// (GameState.Units), one per unit on its sim hex, and a token's figures follow Q-UI-3, not the call-up. The squadron and@@ -386,5 +388,282 @@ public class UnitsFromStateTestsfinally { UnityEngine.Object.DestroyImmediate(map.gameObject); UnitFigures.Source = savedSource; }}+ static MapScene BuildMap()+ {+ EditorSceneManager.NewScene(NewSceneSetup.DefaultGameObjects, NewSceneMode.Single);+ var map = new GameObject("MapScene").AddComponent<MapScene>();+ map.Configure(Load("Terrain"), Load("SettlementMarker"), Load("HexSelection"), Load("Sea"), Load("MapFrame"));+ Statecraft.Game.Map.Kits.KitPopulation.Use(Statecraft.Game.Map.Kits.KitPopulation.Parse(+ File.ReadAllText(Path.Combine(Paths.Content, "map", Statecraft.Game.Map.Kits.KitPopulation.FileName))));+ map.Build();+ return map;+ }++ static Transform TokenOf(MapScene map, string row) => map.Terrain.transform.Find(UnitLayer.RootName).Find("Tokens").Find(row);+ static Vector2 SpotOf(UnitLayer layer, string row)+ {+ var spot = layer.Tokens.Single(p => p.Token.Unit.Id == row).Spot;+ return new Vector2((float)spot.X, (float)spot.Z);+ }+ static Vector2 XZ(Vector3 v) => new Vector2(v.x, v.z);++ /// <summary>#1866 (design by Tal Heuberger, #1900): a moved unit's token slides from where it was drawn to its new spot+ /// and stops there; a second move mid-slide starts from where the token is drawn then; every other token stands still,+ /// with nothing running per frame. Presentation only: the state is not touched.</summary>+ [Test]+ public void AMovedTokenSlidesFromWhereItWasDrawnAndStops()+ {+ var map = BuildMap();+ try+ {+ var s = NewGame();+ var layer = UnitLayer.Create(map, Units, C.Hexes, still: true);+ layer.AnimateMoves = true;+ layer.Show(C, s);+ var unit = s.Units.Values.First(u => u.Side == "israel");+ string row = C.StartingForces[unit.Id].Row;+ var first = SpotOf(layer, row);+ var to = FreeNeighbour(s, unit.Q, unit.R);+ MoveTo(s, unit.Id, to.q, to.r);+ Assert.IsTrue(layer.Show(C, s));+ var second = SpotOf(layer, row);+ Assert.Greater((first - second).magnitude, 1000f, "a real move, not a nudge");+ var token = TokenOf(map, row);+ var motion = token.GetComponent<UnitTokenMotion>();+ Assert.AreEqual(unit.Id, motion.SimId);+ Assert.IsTrue(motion.Moving && motion.enabled);+ Assert.Less((XZ(token.position) - (first - second)).magnitude, 1f, "it starts where it was drawn");+ foreach (var other in map.Terrain.transform.Find(UnitLayer.RootName).GetComponentsInChildren<UnitTokenMotion>(true).Where(m => m != motion))+ {+ Assert.IsFalse(other.Moving, other.name);+ Assert.IsFalse(other.enabled, other.name + ": an idle token runs nothing per frame");+ Assert.AreEqual(Vector3.zero, other.transform.position, other.name);+ }++ motion.Tick(UnitTokenMotion.Duration / 2f);+ var drawn = second + XZ(token.position); // halfway along+ Assert.Less((drawn - (first + second) / 2f).magnitude, 1f);+ var next = FreeNeighbour(s, to.q, to.r);+ MoveTo(s, unit.Id, next.q, next.r);+ Assert.IsTrue(layer.Show(C, s));+ var third = SpotOf(layer, row);+ token = TokenOf(map, row);+ motion = token.GetComponent<UnitTokenMotion>();+ Assert.Less((XZ(token.position) - (drawn - third)).magnitude, 1f, "a second move starts from where the token is drawn");++ motion.Tick(UnitTokenMotion.Duration);+ Assert.AreEqual(Vector3.zero, token.position, "it ends on its spot");+ Assert.IsFalse(motion.Moving); Assert.IsFalse(motion.enabled);+ }+ finally { UnityEngine.Object.DestroyImmediate(map.gameObject); }+ }++ /// <summary>Another unit's order rebuilds every token (review of #2177, 3): a unit whose figures were firing goes on+ /// firing on its new token, from where it was.</summary>+ [Test]+ public void ARebuildForAnotherUnitsOrderKeepsAnAttackPlaying()+ {+ var map = BuildMap();+ var controller = new UnityEditor.Animations.AnimatorController(); controller.AddLayer("Base Layer");+ var fire = new AnimationClip { name = "fire" };+ fire.SetCurve("", typeof(Transform), "localScale.x", AnimationCurve.Linear(0f, 1f, 1f, 1f));+ try+ {+ var machine = controller.layers[0].stateMachine;+ machine.defaultState = machine.AddState("idle"); machine.AddState("attack").motion = fire;+ var s = NewGame();+ var layer = UnitLayer.Create(map, Units, C.Hexes, still: true);+ layer.AnimateMoves = true;+ layer.Show(C, s);+ var israel = s.Units.Values.Where(u => u.Side == "israel").Take(2).ToArray();+ string firing = C.StartingForces[israel[0].Id].Row;+ var figure = new GameObject("test figure").transform; figure.SetParent(TokenOf(map, firing), false);+ var animator = figure.gameObject.AddComponent<Animator>(); animator.runtimeAnimatorController = controller;+ animator.Rebind(); animator.Update(0f);+ Assert.IsTrue(layer.PlayAttack(israel[0].Id), "fixture: the token plays the attack");+ TokenOf(map, firing).GetComponent<UnitTokenMotion>().Tick(0.3f);+ var to = FreeNeighbour(s, israel[1].Q, israel[1].R);+ MoveTo(s, israel[1].Id, to.q, to.r);+ Assert.IsTrue(layer.Show(C, s), "another unit's move rebuilds the tokens");+ var successor = TokenOf(map, firing).GetComponent<UnitTokenMotion>();+ Assert.IsTrue(successor.Attacking, "the attack goes on on the new token");+ // Its near figure turns on a frame later (UnitFigureDetail) and plays on from 0.3 s, not from the start+ // (review of #2176, items 3 and 4).+ var near = new GameObject("test figure").transform; near.SetParent(TokenOf(map, firing), false);+ var b = near.gameObject.AddComponent<Animator>(); b.runtimeAnimatorController = controller; b.Rebind(); b.Update(0f);+ successor.RefreshPose(); b.Update(0f);+ Assert.AreEqual(UnitFigureMotion.Attack, b.GetCurrentAnimatorStateInfo(0).fullPathHash, "the new figure fires");+ Assert.AreEqual(0.3f, b.GetCurrentAnimatorStateInfo(0).normalizedTime, 0.02f, "from 0.3 s into the 1 s take");+ }+ finally { UnityEngine.Object.DestroyImmediate(map.gameObject); UnityEngine.Object.DestroyImmediate(controller); UnityEngine.Object.DestroyImmediate(fire); }+ }++ /// <summary>Review of #2176, item 5 (#1900's test, in our words): a slide is the one time FaceCamera's whole loop runs+ /// every frame with a still camera, and each slide frame hands the map's names the other KeepClear list. Neither+ /// allocates (per-frame garbage stutters on WebGL).</summary>+ [Test]+ public void FacingASlidingTokenDoesNotAllocate()+ {+ var map = BuildMap();+ var eye = new GameObject("SlideCamera");+ try+ {+ var layer = UnitLayer.Create(map, Units, C.Hexes, still: true);+ layer.AnimateMoves = true;+ layer.Show(C, NewGame());+ var motion = map.Terrain.transform.Find(UnitLayer.RootName).GetComponentInChildren<UnitTokenMotion>(true);+ Assert.IsNotNull(motion, "fixture: a play build gives the tokens their motion");+ var cam = eye.AddComponent<Camera>(); cam.farClipPlane = 1e6f;+ motion.Begin(new Vector3(30000f, 0f, 0f));+ for (int k = 0; k < 5; k++) { motion.Tick(0.001f); layer.FaceCamera(cam); } // warm up: both lists grown+ var before = layer.KeepClear;+ Assert.That(() => { for (int k = 0; k < 50; k++) { motion.Tick(0.001f); layer.FaceCamera(cam); } }, Is.Not.AllocatingGCMemory());+ Assert.IsTrue(motion.Moving, "the token slid throughout");+ motion.Tick(0.001f); layer.FaceCamera(cam);+ Assert.AreNotSame(before, layer.KeepClear, "the measured frames were slide frames that hand the names a list");+ }+ finally { UnityEngine.Object.DestroyImmediate(eye); UnityEngine.Object.DestroyImmediate(map.gameObject); }+ }++ /// <summary>New Game (SimBridge.Replace) shows another game whose sim ids are the old game's (review of #2176, H4): its+ /// tokens are drawn where they stand, with no slide from where the old game's units were.</summary>+ [Test]+ public void AnotherGamesTokensDoNotSlideFromTheOldGames()+ {+ var map = BuildMap();+ try+ {+ var s = NewGame();+ var layer = UnitLayer.Create(map, Units, C.Hexes, still: true);+ layer.AnimateMoves = true;+ var unit = s.Units.Values.First(u => u.Side == "israel");+ var to = FreeNeighbour(s, unit.Q, unit.R);+ MoveTo(s, unit.Id, to.q, to.r);+ layer.Show(C, s);+ Assert.IsTrue(layer.Show(C, NewGame(), slide: false), "the new game's roster differs, so the tokens are rebuilt");+ var motions = map.Terrain.transform.Find(UnitLayer.RootName).GetComponentsInChildren<UnitTokenMotion>(true);+ Assert.IsNotEmpty(motions);+ foreach (var m in motions) { Assert.IsFalse(m.Moving, m.name); Assert.AreEqual(Vector3.zero, m.transform.position, m.name); }+ }+ finally { UnityEngine.Object.DestroyImmediate(map.gameObject); }+ }++ /// <summary>With the "units" toggle off, a move does not slide: the token would play its slide only when shown again,+ /// from where it stood when hidden (review of #1900).</summary>+ [Test]+ public void AMoveWhileTheUnitsAreHiddenDoesNotSlideLater()+ {+ var map = BuildMap();+ try+ {+ var s = NewGame();+ var layer = UnitLayer.Create(map, Units, C.Hexes, still: true);+ layer.AnimateMoves = true;+ layer.Show(C, s);+ var unit = s.Units.Values.First(u => u.Side == "israel");+ string row = C.StartingForces[unit.Id].Row;+ VisualToggles.Set(UnitLayer.ToggleName, false);+ var to = FreeNeighbour(s, unit.Q, unit.R);+ MoveTo(s, unit.Id, to.q, to.r);+ Assert.IsTrue(layer.Show(C, s));+ VisualToggles.Set(UnitLayer.ToggleName, true);+ var motion = TokenOf(map, row).GetComponent<UnitTokenMotion>();+ Assert.IsFalse(motion.Moving);+ Assert.AreEqual(Vector3.zero, motion.transform.position);+ }+ finally { VisualToggles.Set(UnitLayer.ToggleName, true); UnityEngine.Object.DestroyImmediate(map.gameObject); }+ }++ /// <summary>Mid-slide, a click and the map's names find the token where it is drawn, not on its empty spot or on the path+ /// (#1900): the badge's box is the plate as drawn, at the size #2077 caps it to up close, and the box of the still pieces+ /// moves with the token, for an army token (flag and figures) and a ship (neither).</summary>+ [TestCase(UnitData.Army, false)]+ [TestCase(UnitData.Army, true)]+ [TestCase(UnitData.Navy, false)]+ public void MidSlideTheHitBoxesAreWhereTheTokenIsDrawn(string service, bool perspective)+ {+ var map = BuildMap();+ var eye = new GameObject("SlideCamera");+ var target = new RenderTexture(512, 512, 16);+ try+ {+ var s = NewGame();+ var layer = UnitLayer.Create(map, Units, C.Hexes, still: true);+ layer.AnimateMoves = true;+ layer.Show(C, s);+ int i = layer.Tokens.ToList().FindIndex(p => p.Token.Unit.Service == service);+ Assert.GreaterOrEqual(i, 0, "the new game draws such a token");+ var token = TokenOf(map, layer.Tokens[i].Token.Unit.Id);+ var spot = SpotOf(layer, layer.Tokens[i].Token.Unit.Id);+ var slide = new Vector3(30000f, 0f, 0f); // halfway through a slide from 60 km east of the spot+ var cam = eye.AddComponent<Camera>();+ cam.targetTexture = target; cam.farClipPlane = 1e6f;+ if (perspective)+ {+ // Close over the drawn token: #2077 caps the plate below its full size.+ cam.fieldOfView = 30f;+ cam.transform.SetPositionAndRotation(new Vector3(spot.x, 0f, spot.y) + slide + new Vector3(0f, 6000f, -6000f),+ Quaternion.Euler(45f, 0f, 0f));+ }+ else+ {+ // Top-down over the spot and the drawn token alike, for the clicks.+ cam.orthographic = true; cam.orthographicSize = 40000f;+ cam.transform.SetPositionAndRotation(new Vector3(spot.x, 100000f, spot.y) + slide / 2f, Quaternion.Euler(90f, 0f, 0f));+ }+ layer.FaceCamera(cam);+ var rest = layer.KeepClear[i].ToArray();+ var motion = token.GetComponent<UnitTokenMotion>();+ motion.Begin(slide * 2f);+ motion.Tick(UnitTokenMotion.Duration / 2f);+ Assert.Less((token.position - slide).magnitude, 1f);+ layer.FaceCamera(cam);+ var boxes = layer.KeepClear[i];+ var badge = token.Find("Badge");+ Assert.Less((boxes[0].center - badge.position).magnitude, 1e-2f, "the badge's box is the plate as drawn");+ Assert.AreEqual(badge.localScale.x, boxes[0].size.x, 1e-3f, "at the plate's drawn size");+ if (perspective) Assert.Less(badge.localScale.x, UnitBadge.SizeM, "the close camera caps the plate (#2077)");+ Assert.Less((XZ(boxes[0].center) - XZ(rest[0].center + slide)).magnitude, UnitBadge.SizeM, "the badge moved with its token");+ Assert.Less((boxes[1].center - (rest[1].center + slide)).magnitude, rest[1].extents.magnitude / 2f, "the pieces' box moved with it");+ Assert.Less(boxes[1].size.magnitude, rest[1].size.magnitude * 1.5f, "and does not stretch along the path");+ if (perspective) return; // the clicks below need the spot and the drawn token in one view+ var hit = layer.TokenAtScreen(cam, cam.WorldToScreenPoint(rest[1].center + slide));+ Assert.AreEqual(layer.Tokens[i].Token.Unit.Id, hit?.Token.Unit.Id, "a click on the drawn token selects it");+ var empty = layer.TokenAtScreen(cam, cam.WorldToScreenPoint(rest[1].center));+ Assert.AreNotEqual(layer.Tokens[i].Token.Unit.Id, empty?.Token.Unit.Id, "its empty spot does not");+ motion.Tick(UnitTokenMotion.Duration);+ Assert.AreEqual(layer.Tokens[i].Token.Unit.Id, layer.TokenAtScreen(cam, cam.WorldToScreenPoint(rest[1].center))?.Token.Unit.Id,+ "arrived, the spot selects it again");+ Assert.Less((layer.KeepClear[i][1].center - rest[1].center).magnitude, 1f);+ }+ finally { UnityEngine.Object.DestroyImmediate(eye); UnityEngine.Object.DestroyImmediate(target); UnityEngine.Object.DestroyImmediate(map.gameObject); }+ }++ /// <summary>An edit-mode build (promo captures) draws every token still; no token there can attack (#1867).</summary>+ [Test]+ public void AnEditModeBuildDrawsTokensStillAndAttacksNothing()+ {+ var map = BuildMap();+ try+ {+ var s = NewGame();+ var layer = UnitLayer.Create(map, Units, C.Hexes, still: true);+ Assert.IsFalse(layer.AnimateMoves, "only a playing game animates");+ layer.Show(C, s);+ var unit = s.Units.Values.First(u => u.Side == "israel");+ var to = FreeNeighbour(s, unit.Q, unit.R);+ MoveTo(s, unit.Id, to.q, to.r);+ Assert.IsTrue(layer.Show(C, s));+ Assert.IsEmpty(map.Terrain.transform.Find(UnitLayer.RootName).GetComponentsInChildren<UnitTokenMotion>(true));+ Assert.IsFalse(layer.PlayAttack(unit.Id));+ layer.AnimateMoves = true;+ MoveTo(s, unit.Id, unit.Q, unit.R);+ Assert.IsTrue(layer.Show(C, s));+ Assert.IsFalse(layer.PlayAttack(unit.Id), "no near Animator is on in an edit-mode map (nothing has rendered)");+ Assert.IsFalse(layer.PlayAttack(-5), "no such unit");+ }+ finally { UnityEngine.Object.DestroyImmediate(map.gameObject); }+ }+static Material Load(string name) => AssetDatabase.LoadAssetAtPath<Material>($"Assets/Materials/{name}.mat");}