{"id":335097,"date":"2022-06-28T21:00:13","date_gmt":"2022-06-28T21:00:13","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=335097"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=335097","title":{"rendered":"<span>\u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 dungeon crawler&#8217;\u0430 \u0441 LeoECS Lite. \u0427\u0430\u0441\u0442\u044c 2<\/span>"},"content":{"rendered":"<div><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p><em>\u0414\u0440\u0443\u0437\u044c\u044f, \u0432 \u044d\u0442\u043e\u0439 \u0447\u0430\u0441\u0442\u0438 \u043c\u044b \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0432\u0440\u0430\u0433\u043e\u0432, \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u043c \u043f\u043e\u043e\u0447\u0435\u0440\u0435\u0434\u043d\u0443\u044e \u0441\u0438\u0441\u0442\u0435\u043c\u0443 \u0445\u043e\u0434\u043e\u0432, \u043c\u0435\u0445\u0430\u043d\u0438\u043a\u0443 \u0441\u043f\u043e\u0441\u043e\u0431\u043d\u043e\u0441\u0442\u0435\u0439 \u0438 \u043d\u0430\u043f\u0438\u0448\u0435\u043c \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u0418\u0418 \u0432\u0440\u0430\u0436\u0435\u0441\u043a\u0438\u043c \u044e\u043d\u0438\u0442\u0430\u043c.<\/em><\/p>\n<p><em>\u041f\u0435\u0440\u0435\u0434 \u043f\u0440\u043e\u0447\u0442\u0435\u043d\u0438\u0435\u043c \u044d\u0442\u043e\u0439 \u0447\u0430\u0441\u0442\u0438 \u043e\u0437\u043d\u0430\u043a\u043e\u043c\u044c\u0442\u0435\u0441\u044c \u0441 <\/em><a href=\"https:\/\/habr.com\/ru\/post\/661085\/\" rel=\"noopener noreferrer nofollow\"><em>\u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0439<\/em><\/a><em>.<\/em><\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/63f\/3ef\/c47\/63f3efc473664fdaaf1a249f258e2486.png\" width=\"1554\" height=\"889\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/63f\/3ef\/c47\/63f3efc473664fdaaf1a249f258e2486.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u041d\u043e \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u043d\u0430\u0447\u043d\u0435\u043c \u0441 \u0440\u0430\u0437\u0434\u0435\u043b\u0435\u043d\u0438\u044f MonoBehaviour \u043a\u043b\u0430\u0441\u0441\u0430 <em>CellView<\/em> \u043d\u0430 \u0434\u0432\u0430: <strong>SnapTransform<\/strong> \u0438 <strong>CellView<\/strong>. \u042d\u0442\u043e \u043d\u0443\u0436\u043d\u043e, \u0447\u0442\u043e\u0431\u044b \u043e\u0442\u0434\u0435\u043b\u0438\u0442\u044c \u043f\u0440\u0438\u043c\u0430\u0433\u043d\u0438\u0447\u0438\u0432\u0430\u043d\u0438\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u043a \u043a\u043b\u0435\u0442\u043a\u0435 \u043d\u0430 \u0441\u0435\u0442\u043a\u0435 \u0438 \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u0435\u0435 \u0432 \u0440\u0435\u0434\u0430\u043a\u0442\u043e\u0440\u0435, \u0442\u043e \u0435\u0441\u0442\u044c \u043f\u043e \u0441\u0443\u0442\u0438 \u0440\u0430\u0437\u0433\u0440\u0430\u043d\u0438\u0447\u0438\u0442\u044c \u0434\u0432\u0430 \u0440\u0430\u0437\u043d\u044b\u0445 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u044f.<\/p>\n<pre><code class=\"cs\">namespace Client { #if UNITY_EDITOR     [ExecuteAlways]     [SelectionBase] #endif     sealed class SnapTransform : MonoBehaviour {         public Transform Transform;         public float XzStep = 3f;         public float YStep = 1f;          #if UNITY_EDITOR         void Awake () {             Transform = transform;         }          void Update () {             if (!Application.isPlaying &amp;&amp; Transform.hasChanged) {                 var newPos = Vector3.zero;                 var curPos = Transform.localPosition;                 newPos.x = Mathf.RoundToInt (curPos.x \/ XzStep) * XzStep;                 newPos.z = Mathf.RoundToInt (curPos.z \/ XzStep) * XzStep;                 newPos.y = Mathf.RoundToInt (curPos.y \/ YStep) * YStep;                 Transform.localPosition = newPos;             }         } #endif     } }<\/code><\/pre>\n<pre><code class=\"cs\">namespace Client { #if UNITY_EDITOR     [ExecuteAlways]     [SelectionBase] #endif     sealed class CellView : MonoBehaviour {         public Transform Transform;         public float Size = 3f;  #if UNITY_EDITOR         void Awake () {             Transform = transform;         }                  void OnDrawGizmos () {             var selected = Selection.Contains (gameObject);             Gizmos.color = selected ? Color.green : Color.cyan;             var yAdd = selected ? 0.02f : 0f;             var curPos = Transform.localPosition;             var leftDown = curPos - Vector3.right * Size \/ 2 - Vector3.forward * Size \/ 2 + Vector3.up * yAdd;             var leftUp = curPos - Vector3.right * Size \/ 2 + Vector3.forward * Size \/ 2 + Vector3.up * yAdd;             var rightDown = curPos + Vector3.right * Size \/ 2 - Vector3.forward * Size \/ 2 + Vector3.up * yAdd;             var rightUp = curPos + Vector3.right * Size \/ 2 + Vector3.forward * Size \/ 2 + Vector3.up * yAdd;             Gizmos.DrawLine (leftDown, leftUp);             Gizmos.DrawLine (leftUp, rightUp);             Gizmos.DrawLine (rightUp, rightDown);             Gizmos.DrawLine (rightDown, leftDown);             Gizmos.DrawSphere (curPos, 0.1f);         } #endif     } }<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043c\u044b \u0441\u043c\u043e\u0436\u0435\u043c \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u0441\u043f\u0430\u0443\u043d-\u043c\u0430\u0440\u043a\u0435\u0440\u044b \u0434\u043b\u044f \u0432\u0440\u0430\u0433\u043e\u0432, \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0442\u044c \u043a \u043d\u0438\u043c \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 <strong>SnapTransform<\/strong> \u0438 \u0443\u0434\u043e\u0431\u043d\u043e \u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0438\u0445 \u043d\u0430 \u0441\u0435\u0442\u043a\u0435 \u0431\u0435\u0437 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u0432\u044b\u0434\u0435\u043b\u044f\u0442\u044c \u0438\u0445 \u043a\u0430\u043a \u043a\u043b\u0435\u0442\u043a\u0443. (\u0441\u0430\u043c\u0438 \u043a\u043b\u0435\u0442\u043a\u0438 \u0431\u0443\u0434\u0443\u0442 \u0438\u043c\u0435\u0442\u044c \u043e\u0431\u0430 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430)<\/p>\n<pre><code class=\"cs\">namespace Client {     sealed class SpawnMarker : MonoBehaviour {         public Transform Transform;         public string PrefabName; \/\/ \u0438\u043c\u044f \u043f\u0440\u0435\u0444\u0430\u0431\u0430         public Side Side;          public void Awake () {             Transform = transform;         }     } }<\/code><\/pre>\n<p>\u041a\u0430\u043a \u0432\u0438\u0434\u0438\u0442\u0435, \u0437\u0434\u0435\u0441\u044c \u0435\u0441\u0442\u044c \u043f\u043e\u043b\u0435 \u0442\u0438\u043f\u0430 <strong>Side<\/strong>. \u042d\u0442\u043e \u043f\u0440\u043e\u0441\u0442\u043e\u0439 enum, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043e\u0431\u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442 \u0441\u0442\u043e\u0440\u043e\u043d\u0443 \u044e\u043d\u0438\u0442\u0430 (\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\/\u0418\u0418).<\/p>\n<pre><code class=\"cs\">namespace Client {     public enum Side {         User = 0,         Enemy = 1,     } }<\/code><\/pre>\n<p>\u041a\u0430\u043a \u0432\u044b \u043f\u043e\u043c\u043d\u0438\u0442\u0435, \u0432 \u043f\u0440\u043e\u0448\u043b\u043e\u0439 \u0447\u0430\u0441\u0442\u0438 \u043c\u044b \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043b\u0438 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u043d\u043e\u0435 \u043c\u0435\u043d\u044e \u0432 \u043a\u043b\u0430\u0441\u0441\u0435 SceneData \u0434\u043b\u044f \u043f\u043e\u0438\u0441\u043a\u0430 \u043a\u043b\u0435\u0442\u043e\u043a \u043d\u0430 \u043a\u0430\u0440\u0442\u0435. \u0421\u0434\u0435\u043b\u0430\u0435\u043c \u0442\u043e \u0436\u0435 \u0441\u0430\u043c\u043e\u0435 \u0434\u043b\u044f \u0441\u043f\u0430\u0443\u043d \u043c\u0430\u0440\u043a\u0435\u0440\u043e\u0432.<\/p>\n<pre><code class=\"cs\">namespace Client {     sealed class SceneData : MonoBehaviour {         public CellView[] Cells;         public SpawnMarker[] Markers;          #if UNITY_EDITOR         [ContextMenu (\"Find Cells\")]         void FindCells () {             Cells = FindObjectsOfType&lt;CellView> ();             Debug.Log ($\"Successfully found {Cells.Length} cells!\");         }          [ContextMenu (\"Find Markers\")]         void FindMarkers () {             Markers = FindObjectsOfType&lt;SpawnMarker> ();             Debug.Log ($\"Successfully found {Markers.Length} markers!\");         } #endif     } }<\/code><\/pre>\n<p>\u0422\u0430\u043a\u0436\u0435 \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u0440\u0430\u0437\u043c\u0435\u0440 \u043a\u043b\u0435\u0442\u043a\u0438 \u0438 \u043c\u0435\u0442\u043e\u0434 InBounds \u0432 <strong>GridService<\/strong>, \u044d\u0442\u043e \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u0438\u0442\u0441\u044f \u043d\u0430\u043c \u043f\u0440\u0438 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0438 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0435 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u044f \u0432\u0440\u0430\u0433\u043e\u0432.<\/p>\n<pre><code class=\"cs\">namespace Client {     sealed class GridService {         public int CellSize = 3;          readonly int[] _cells;         readonly int _width;         readonly int _height;          public GridService (int width, int height) {             _cells = new int[width * height];             _width = width;              _height = height;         }          public (int, bool) GetCell (Int2 coords) {             if (!InBounds (coords)) {                 return (-1, false);             }                          var entity = _cells[_width * coords.Y + coords.X] - 1;             return (entity, entity >= 0);         }          bool InBounds (Int2 coords) {             return coords.X >= 0 &amp;&amp; coords.Y >= 0;         }          public void AddCell (Int2 coords, int entity) {             _cells[_width * coords.Y + coords.X] = entity + 1;         }     } } <\/code><\/pre>\n<p>\u0422\u0430\u043a\u0436\u0435 \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u043f\u043e\u043b\u0435 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438 \u0432 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 \u043a\u043b\u0435\u0442\u043a\u0438 &#8212; \u044d\u0442\u043e \u043d\u0443\u0436\u043d\u043e \u0431\u0443\u0434\u0435\u0442, \u0447\u0442\u043e\u0431\u044b \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c, \u043a\u0430\u043a\u0438\u0435 \u043a\u043b\u0435\u0442\u043a\u0438 \u043a\u0435\u043c \u0437\u0430\u043d\u044f\u0442\u044b \u0438\u043b\u0438 \u043d\u0435 \u0437\u0430\u043d\u044f\u0442\u044b \u0432\u043e\u0432\u0441\u0435.<\/p>\n<pre><code class=\"cs\">namespace Client {     struct Cell {         public CellView View;         public int Entity;     } }<\/code><\/pre>\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043e\u0431\u043d\u043e\u0432\u0438\u043c \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 <strong>Unit<\/strong>. \u041d\u0443\u0436\u043d\u043e \u0431\u0443\u0434\u0435\u0442 \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0442\u0430\u043a\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0435, \u043a\u0430\u043a \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043e\u0447\u043a\u043e\u0432 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f (\u0434\u0430\u043b\u0435\u0435 \u041e\u0414), &#171;\u0438\u043d\u0438\u0446\u0438\u0430\u0442\u0438\u0432\u0443&#187; (\u044d\u0442\u043e \u043d\u0443\u0436\u043d\u043e \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u0438 \u0432\u044b\u0431\u043e\u0440\u0435 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0433\u043e \u044e\u043d\u0438\u0442\u0430 \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u0441\u043c\u0435\u043d\u044b \u0445\u043e\u0434\u0430), \u0437\u0434\u043e\u0440\u043e\u0432\u044c\u0435, \u0440\u0430\u0434\u0438\u0443\u0441 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f (\u043d\u0443\u0436\u043d\u043e \u0431\u0443\u0434\u0435\u0442 \u0434\u043b\u044f \u0418\u0418) \u0438 \u0441\u0442\u043e\u0440\u043e\u043d\u0443.<\/p>\n<pre><code class=\"cs\">namespace Client {     struct Unit {         public Direction Direction;         public Int2 CellCoords;         public Transform Transform;         public Vector3 Position;         public Quaternion Rotation;         public float MoveSpeed;         public float RotateSpeed;         public int ActionPoints;         public int Initiative;         public int Health;         public int Radius;         public Side Side;     } }<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0440\u0430\u0437\u0431\u0435\u0440\u0435\u043c\u0441\u044f \u0441 \u043c\u0435\u0445\u0430\u043d\u0438\u043a\u043e\u0439 \u0441\u043f\u043e\u0441\u043e\u0431\u043d\u043e\u0441\u0442\u0435\u0439.<\/p>\n<p>\u041c\u044b \u0431\u0443\u0434\u0435\u043c \u0445\u0440\u0430\u043d\u0438\u0442\u044c \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u044e \u0441\u043f\u043e\u0441\u043e\u0431\u043d\u043e\u0441\u0442\u0438 \u0432 \u0444\u043e\u0440\u043c\u0430\u0442\u0435 <strong>Scriptable Object<\/strong> \u0432 Unity. \u041a\u0430\u0436\u0434\u0430\u044f \u0441\u043f\u043e\u0441\u043e\u0431\u043d\u043e\u0441\u0442\u044c \u0431\u0443\u0434\u0435\u0442 \u0438\u043c\u0435\u0442\u044c \u0441\u0432\u043e\u0451 \u0438\u043c\u044f, \u0441\u0442\u043e\u0438\u043c\u043e\u0441\u0442\u044c \u043e\u0447\u043a\u043e\u0432 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f, \u0434\u0438\u0441\u0442\u0430\u043d\u0446\u0438\u044e \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0438 \u0443\u0440\u043e\u043d.<\/p>\n<pre><code class=\"cs\">namespace Client {     [CreateAssetMenu]     public class AbilityConfig : ScriptableObject {         public string Name;         public int ActionPointsCost;         public int Damage;         public int Distance;     } }<\/code><\/pre>\n<p>\u0422\u0430\u043a\u0436\u0435 \u0443\u0434\u043e\u0431\u043d\u043e \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u044c \u043a\u043e\u043d\u0444\u0438\u0433 \u0430\u0431\u0438\u043b\u043a\u0438 \u0447\u0435\u0440\u0435\u0437 \u043a\u0430\u043a\u043e\u0439-\u043d\u0438\u0431\u0443\u0434\u044c \u0447\u0438\u0441\u043b\u043e\u0432\u043e\u0439 \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440. \u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043f\u043e\u043b\u0435 \u043c\u0430\u0441\u0441\u0438\u0432 Scriptable Object&#8217;\u043e\u0432 \u0432 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u043c \u043a\u043e\u043d\u0444\u0438\u0433\u0435 <strong>Configuration<\/strong>.<\/p>\n<pre><code class=\"cs\">namespace Client {     [CreateAssetMenu]     sealed class Configuration : ScriptableObject {         public int GridWidth;         public int GridHeight;         public LayerMask UnitLayerMask;         public AbilityConfig[] AbilitiesConfigs;     } }<\/code><\/pre>\n<p>\u041a\u0430\u0436\u0434\u044b\u0439 \u044e\u043d\u0438\u0442 \u0431\u0443\u0434\u0435\u0442 \u0438\u043c\u0435\u0442\u044c \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 <strong>HasAbilities<\/strong> \u0441\u043e \u0441\u043f\u0438\u0441\u043a\u043e\u043c \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0435\u0439 \u0434\u043b\u044f \u0430\u0431\u0438\u043b\u043e\u043a. \u041a\u0430\u043a \u0432\u044b \u0443\u0436\u0435 \u043f\u043e\u043d\u044f\u043b\u0438, \u043a\u0430\u0436\u0434\u0430\u044f \u0441\u043f\u043e\u0441\u043e\u0431\u043d\u043e\u0441\u0442\u044c \u0431\u0443\u0434\u0435\u0442 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e\u0439 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u044c\u044e \u0441 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u043e\u043c <strong>Ability<\/strong>, \u0432 \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u044b \u0441\u043e\u0445\u0440\u0430\u043d\u0438\u043c \u0441\u0442\u043e\u0438\u043c\u043e\u0441\u0442\u044c \u0432 \u041e\u0414, \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u044c \u0432\u043b\u0430\u0434\u0435\u043b\u044c\u0446\u0430, \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440, \u0434\u0438\u0441\u0442\u0430\u043d\u0446\u0438\u044e \u0438 \u0443\u0440\u043e\u043d.<\/p>\n<pre><code class=\"cs\">namespace Client {     struct HasAbilities : IEcsAutoReset&lt;HasAbilities> {         public List&lt;int> Entities;          public void AutoReset (ref HasAbilities c) {             c.Entities ??= new List&lt;int> (64);         }     } }<\/code><\/pre>\n<pre><code class=\"cs\">namespace Client {     struct Ability {         public int ActionPointsCost;         public int OwnerEntity;         public int Id;         public int Damage;         public int Distance;     } }<\/code><\/pre>\n<p>\u041a\u043e\u0433\u0434\u0430 \u043d\u0443\u0436\u043d\u043e \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u0442\u044c \u0441\u043f\u043e\u0441\u043e\u0431\u043d\u043e\u0441\u0442\u044c, \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0442\u044c \u043a \u0435\u0435 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 <strong>Applied<\/strong> \u0438 \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0442\u044c \u0432\u043d\u0443\u0442\u0440\u0438 \u044d\u043d\u0442\u0438\u0442\u0438 \u0446\u0435\u043b\u0438.<\/p>\n<pre><code class=\"cs\">namespace Client {     struct Applied {         public int Target;     } }<\/code><\/pre>\n<p>\u0422\u0430\u043a\u0436\u0435 \u0443 \u043a\u0430\u0436\u0434\u043e\u0439 \u0441\u043f\u043e\u0441\u043e\u0431\u043d\u043e\u0441\u0442\u0438 \u0431\u0443\u0434\u0435\u0442 \u0441\u0432\u043e\u0439 \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u044b\u0439 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439, \u043f\u043e \u0441\u0443\u0442\u0438, \u0435\u0435 \u043e\u0431\u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442. \u0414\u043e\u043f\u0443\u0441\u0442\u0438\u043c, \u0441\u043f\u043e\u0441\u043e\u0431\u043d\u043e\u0441\u0442\u044c &#171;\u0441\u043b\u0430\u0431\u043e\u0439 \u0430\u0442\u0430\u043a\u0438&#187; \u0431\u0443\u0434\u0435\u0442 \u0438\u043c\u0435\u0442\u044c \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 <strong>LightAttack<\/strong>, \u0441\u043f\u043e\u0441\u043e\u0431\u043d\u043e\u0441\u0442\u044c &#171;\u0441\u0438\u043b\u044c\u043d\u043e\u0439&#187; &#8212; <strong>HeavyAttack<\/strong>. \u042d\u0442\u043e \u043d\u0443\u0436\u043d\u043e \u0431\u0443\u0434\u0435\u0442, \u0447\u0442\u043e\u0431\u044b \u0443 \u043a\u0430\u0436\u0434\u043e\u0439 \u0441\u043f\u043e\u0441\u043e\u0431\u043d\u043e\u0441\u0442\u0438 \u0431\u044b\u043b\u0430 \u0441\u0432\u043e\u044f \u043b\u043e\u0433\u0438\u043a\u0430 \u0441\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u043d\u0438\u044f.<\/p>\n<p>\u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0439 \u0441\u0435\u0440\u0432\u0438\u0441 <strong>AbilityHelper<\/strong>, \u0433\u0434\u0435 \u0431\u0443\u0434\u0435\u043c \u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0441\u043b\u043e\u0432\u0430\u0440\u044c \u0441 \u0447\u0438\u0441\u043b\u043e\u043c \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043a\u043b\u044e\u0447\u0430 \u0438 \u043a\u043e\u043b\u043b\u0431\u0435\u043a\u043e\u043c \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f. \u041f\u043e \u0441\u0443\u0442\u0438 \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u044c \u0441\u0441\u044b\u043b\u043a\u0443 \u043d\u0430 \u043c\u0435\u0442\u043e\u0434 \u0434\u043b\u044f \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430 \u043f\u043e \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u0443 \u0441\u043f\u043e\u0441\u043e\u0431\u043d\u043e\u0441\u0442\u0438, \u0442\u043e \u0435\u0441\u0442\u044c \u0441\u043e\u043f\u043e\u0441\u0442\u0430\u0432\u0438\u043c \u0447\u0438\u0441\u043b\u043e \u0441 \u0442\u0438\u043f\u043e\u043c.<\/p>\n<pre><code class=\"cs\">namespace Client {     sealed class AbilityHelper {         readonly Dictionary&lt;int, Action&lt;EcsWorld, int>> _addComponentCallbacks;          public AbilityHelper () {             _addComponentCallbacks = new Dictionary&lt;int, Action&lt;EcsWorld, int>> {                 { 0, AddComponent&lt;LightAttack> },                 { 1, AddComponent&lt;HeavyAttack> },               { 2, AddComponent&lt;PowerShot> }             };         }          void AddComponent&lt;T> (EcsWorld world, int entity) where T : struct {             world.GetPool&lt;T> ().Add (entity);         }          public Action&lt;EcsWorld, int> GetAddComponentCallback (int abilityIdx) {             return _addComponentCallbacks.TryGetValue (abilityIdx, out Action&lt;EcsWorld, int> cb) ? cb : null;         }     } }<\/code><\/pre>\n<p>\u041d\u0435 \u0437\u0430\u0431\u0443\u0434\u044c\u0442\u0435 \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 \u044d\u0442\u043e\u0433\u043e \u0441\u0435\u0440\u0432\u0438\u0441\u0430 \u0432 \u0441\u0442\u0430\u0440\u0442\u0430\u043f\u0435 \u0438 \u043f\u0440\u043e\u0438\u043d\u0436\u0435\u043a\u0442\u0438\u0442\u044c \u0441\u0441\u044b\u043b\u043a\u0443 \u043d\u0430 \u043d\u0435\u0433\u043e \u0432 \u0441\u0438\u0441\u0442\u0435\u043c\u044b.<\/p>\n<p>\u042f \u0441\u043e\u0437\u0434\u0430\u043b \u0442\u0440\u0438 SO-\u0430\u0431\u0438\u043b\u043a\u0438: LightAttack, PowerShot \u0438 HeavyAttack \u0438 \u0434\u043e\u0431\u0430\u0432\u0438\u043b \u0438\u0445 \u0432 \u0441\u043f\u0438\u0441\u043e\u043a \u0441\u043f\u043e\u0441\u043e\u0431\u043d\u043e\u0441\u0442\u0435\u0439 \u0432 \u0433\u043b\u0430\u0432\u043d\u043e\u043c \u043a\u043e\u043d\u0444\u0438\u0433\u0435.<\/p>\n<p>\u041d\u0430 \u044d\u043a\u0440\u0430\u043d\u0435 \u0431\u0443\u0434\u0443\u0442 \u043a\u043d\u043e\u043f\u043a\u0438 \u0434\u043b\u044f \u0441\u043f\u043e\u0441\u043e\u0431\u043d\u043e\u0441\u0442\u0435\u0439, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u044b \u0438\u043d\u0441\u0442\u0430\u043d\u0446\u0438\u0440\u0443\u0435\u043c \u043d\u0430 \u0441\u0442\u0430\u0440\u0442\u0435 \u0438\u0433\u0440\u044b. \u041a\u043d\u043e\u043f\u043a\u0430 \u0434\u043e\u043b\u0436\u043d\u0430 \u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0438\u043d\u0434\u0435\u043a\u0441 \u0441\u043f\u043e\u0441\u043e\u0431\u043d\u043e\u0441\u0442\u0438 \u0432 \u043c\u0430\u0441\u0441\u0438\u0432\u0435, \u0445\u0440\u0430\u043d\u044f\u0449\u0435\u043c\u0441\u044f \u0432 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0435 HasAbilities \u0443 \u044e\u043d\u0438\u0442\u0430 \u0438\u0433\u0440\u043e\u043a\u0430. \u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0439 \u043c\u043e\u043d\u043e\u0431\u0435\u0445 <strong>AbilityView<\/strong>, \u0432 \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0442\u0430\u043a\u0436\u0435 \u0441\u043e\u0445\u0440\u0430\u043d\u0438\u043c \u0441\u0441\u044b\u043b\u043a\u0438 \u043d\u0430 TMP \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u044f \u0441\u043f\u043e\u0441\u043e\u0431\u043d\u043e\u0441\u0442\u0438 \u0438 \u0446\u0438\u0444\u0440\u044b, \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0435\u0439 \u043a\u043b\u0430\u0432\u0438\u0448\u0435 \u043d\u0430 \u043a\u043b\u0430\u0432\u0438\u0430\u0442\u0443\u0440\u0435 \u0434\u043b\u044f \u0430\u043a\u0442\u0438\u0432\u0430\u0446\u0438\u0438 \u0441\u043f\u043e\u0441\u043e\u0431\u043d\u043e\u0441\u0442\u0438.<\/p>\n<pre><code class=\"cs\">namespace Client {     sealed class AbilityView : MonoBehaviour {         \/\/ Ability index for owner.         public int AbilityIdx;         public TextMeshProUGUI Name;         public TextMeshProUGUI KeyIdx;     } }<\/code><\/pre>\n<p>\u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0442\u0430\u043a\u0436\u0435 \u0441\u0435\u0440\u0432\u0438\u0441, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0430\u043a\u0442\u0438\u0432\u043d\u0443\u044e \u0441\u0442\u043e\u0440\u043e\u043d\u0443 \u0438 \u0430\u043a\u0442\u0438\u0432\u043d\u043e\u0433\u043e \u044e\u043d\u0438\u0442\u0430.<\/p>\n<pre><code class=\"cs\">namespace Client {     sealed class RoundService {         public Side ActiveSide;         public readonly int StateMax = 2;          public int ActiveUnit;          public RoundService (Side activeSide) {             ActiveSide = activeSide;         }     } }<\/code><\/pre>\n<p>\u0414\u0432\u0438\u0436\u0435\u043c\u0441\u044f \u0434\u0430\u043b\u044c\u0448\u0435. \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043e\u0431\u043d\u043e\u0432\u0438\u043c \u0441\u0438\u0441\u0442\u0435\u043c\u0443 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0438\u0433\u0440\u043e\u043a\u0430 \u0438 \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0441\u043f\u043e\u0441\u043e\u0431\u043d\u043e\u0441\u0442\u0435\u0439.<\/p>\n<pre><code class=\"cs\">namespace Client {     sealed class PlayerInitSystem : IEcsInitSystem {         readonly EcsPoolInject&lt;Unit> _unitPool = default;         readonly EcsPoolInject&lt;ControlledByPlayer> _controlledByPlayerPool = default;         readonly EcsPoolInject&lt;HasAbilities> _hasAbilitiesPool = default;         readonly EcsPoolInject&lt;Ability> _abilityPool = default;          readonly EcsCustomInject&lt;RoundService> _rs = default;         readonly EcsCustomInject&lt;Configuration> _config = default;         readonly EcsCustomInject&lt;AbilityHelper> _ah = default;          [EcsUguiNamed (Idents.Ui.Abilities)]         readonly Transform _abilitiesLayoutGroup = default;         [EcsUguiNamed (Idents.Ui.GameOverPopup)]         readonly GameObject _popup = default;                  public void Init (EcsSystems systems) {             var world = _unitPool.Value.GetWorld ();             var playerEntity = world.NewEntity ();              ref var unit = ref _unitPool.Value.Add (playerEntity);             _controlledByPlayerPool.Value.Add (playerEntity);                          var playerPrefab = Resources.Load&lt;UnitView> (\"Player\");             var playerView =  Object.Instantiate (playerPrefab, Vector3.zero, Quaternion.identity);              _rs.Value.ActiveUnit = playerEntity;                          unit.Direction = 0;             unit.CellCoords = new Int2 (0, 0);             unit.Transform = playerView.transform;             unit.Position = Vector3.zero;             unit.Rotation = Quaternion.identity;             unit.MoveSpeed = 3f;             unit.RotateSpeed = 10f;             unit.ActionPoints = 2;             unit.Health = 10;             unit.Initiative = Random.Range (1, 10);             unit.Side = Side.User;             unit.View = playerView;              CreateAbilities (playerEntity, world);             _popup.SetActive (false);         }          void CreateAbilities (int playerEntity, EcsWorld world) {             var abilityAsset = Resources.Load&lt;AbilityView> (\"Ability\");             ref var hasAbilities = ref _hasAbilitiesPool.Value.Add (playerEntity);                          for (int i = 0; i &lt; 3; i++) {                 var abilityConfig = _config.Value.AbilitiesConfigs[i];                 var abilityEntity = world.NewEntity ();                                  ref var ability = ref _abilityPool.Value.Add (abilityEntity);                 ability.ActionPointsCost = abilityConfig.ActionPointsCost;                 ability.OwnerEntity = playerEntity;                 ability.Id = i;                 ability.Damage = abilityConfig.Damage;                 ability.Distance = abilityConfig.Distance;                  var abilityView = Object.Instantiate (abilityAsset, _abilitiesLayoutGroup);                 abilityView.Name.text = $\"{abilityConfig.Name}\\nCost: {abilityConfig.ActionPointsCost}\";                 abilityView.AbilityIdx = i;                 abilityView.KeyIdx.text = (i + 1).ToString();                 _ah.Value.GetAddComponentCallback (i)?.Invoke (world, abilityEntity);                                  hasAbilities.Entities.Add (abilityEntity);             }         }     } }<\/code><\/pre>\n<p>\u041a\u0430\u043a \u0432\u0438\u0434\u0438\u0442\u0435, \u044f \u0442\u0430\u043a\u0436\u0435 \u0441\u043e\u0437\u0434\u0430\u043b \u0432\u0438\u0434\u0436\u0435\u0442 \u0441 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u043e\u043c Horizontal Layout Group \u0434\u043b\u044f \u0432\u044b\u0440\u0430\u0432\u043d\u0438\u0432\u0430\u043d\u0438\u044f \u043a\u043d\u043e\u043f\u043e\u043a \u0438 \u043f\u043e\u043c\u0435\u0441\u0442\u0438\u043b \u0435\u0433\u043e \u043d\u0430 \u043a\u0430\u043d\u0432\u0430\u0441\u0435 \u0441\u043d\u0438\u0437\u0443. \u0427\u0442\u043e\u0431\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u043a \u043d\u0435\u043c\u0443 \u0434\u043e\u0441\u0442\u0443\u043f \u0432 \u0441\u0438\u0441\u0442\u0435\u043c\u0430\u0445, \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u0435\u043c \u0434\u043b\u044f uGui \u0438 \u043f\u0440\u0438\u043a\u0440\u0435\u043f\u0438\u0442\u044c NoAction \u043a \u0432\u0438\u0434\u0436\u0435\u0442\u0443, \u0443\u043a\u0430\u0437\u0430\u0432 \u0442\u0438\u043f \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u0438 \u0438\u043c\u0435\u043d\u0438 &#171;Awake&#187;.<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/68a\/812\/d72\/68a812d727b8ea42539e9a5642401b02.png\" width=\"1885\" height=\"622\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/68a\/812\/d72\/68a812d727b8ea42539e9a5642401b02.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0441\u0438\u0441\u0442\u0435\u043c\u0443 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0432\u0440\u0430\u0433\u043e\u0432.<\/p>\n<pre><code class=\"cs\">namespace Client {     sealed class AiInitSystem : IEcsInitSystem {         readonly EcsCustomInject&lt;SceneData> _sceneData = default;         readonly EcsCustomInject&lt;GridService> _gs = default;         readonly EcsCustomInject&lt;Configuration> _config = default;         readonly EcsCustomInject&lt;AbilityHelper> _ah = default;          readonly EcsPoolInject&lt;HasAbilities> _hasAbilitiesPool = default;         readonly EcsPoolInject&lt;Ability> _abilityPool = default;          readonly EcsPoolInject&lt;Cell> _cellPool = default;         readonly EcsPoolInject&lt;Unit> _unitPool = default;          public void Init (EcsSystems systems) {             for (var i = 0; i &lt; _sceneData.Value.Markers.Length; i++) {                 var marker = _sceneData.Value.Markers[i];                 var asset = Resources.Load&lt;UnitView> (Idents.Paths.Units + marker.PrefabName);                 var position = marker.Transform.position;                 var view = Object.Instantiate (asset, position, Quaternion.identity);                  var coords = new Int2 {                     X = (int) (position.x \/ _gs.Value.CellSize),                     Y = (int) (position.z \/ _gs.Value.CellSize)                 };                  var unitEntity = _unitPool.Value.GetWorld ().NewEntity ();                 ref var unit = ref _unitPool.Value.Add (unitEntity);                 unit.Direction = 0;                 unit.CellCoords = coords;                 var transform = view.transform;                 unit.Transform = transform;                 unit.Position = transform.position;                 unit.Rotation = Quaternion.identity;                 unit.MoveSpeed = 3f;                 unit.RotateSpeed = 10f;                 unit.ActionPoints = 2;                 unit.Initiative = Random.Range (1, 10);                 unit.Health = 3;                 unit.Radius = 2;                 unit.Side = marker.Side;                 unit.View = view;                                  var (cellEntity, ok) = _gs.Value.GetCell (coords);                  if (ok) {                     ref var cell = ref _cellPool.Value.Get (cellEntity);                      cell.Entity = unitEntity;                 }                  CreateAbilities (unitEntity, _unitPool.Value.GetWorld ());             }         }                  void CreateAbilities (int entity, EcsWorld world) {             ref var hasAbilities = ref _hasAbilitiesPool.Value.Add (entity);              for (int i = 0; i &lt; 3; i++) {                 var abilityConfig = _config.Value.AbilitiesConfigs[i];                 var abilityEntity = world.NewEntity ();                                  ref var ability = ref _abilityPool.Value.Add (abilityEntity);                 ability.ActionPointsCost = abilityConfig.ActionPointsCost;                 ability.OwnerEntity = entity;                 ability.Id = i;                 ability.Damage = abilityConfig.Damage;                 ability.Distance = abilityConfig.Distance;                  _ah.Value.GetAddComponentCallback (i)?.Invoke (world, abilityEntity);                                  hasAbilities.Entities.Add (abilityEntity);             }         }     } }<\/code><\/pre>\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0437\u0430\u0439\u043c\u0435\u043c\u0441\u044f \u0441\u043c\u0435\u043d\u043e\u0439 \u0445\u043e\u0434\u0430.<\/p>\n<p>\u041a\u0430\u043a \u0432\u044b \u043f\u043e\u043c\u043d\u0438\u0442\u0435, \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0432 \u0441\u0435\u0440\u0432\u0438\u0441\u0435 <strong>RoundService<\/strong> \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u044c \u0430\u043a\u0442\u0438\u0432\u043d\u043e\u0433\u043e \u044e\u043d\u0438\u0442\u0430 (\u0442.\u0435. \u0442\u043e\u0433\u043e, \u043a\u0442\u043e \u0441\u0435\u0439\u0447\u0430\u0441 \u0445\u043e\u0434\u0438\u0442) \u0438 \u0435\u0433\u043e \u0441\u0442\u043e\u0440\u043e\u043d\u0443 (Side). \u0425\u043e\u0434 \u0437\u0430\u043a\u0430\u043d\u0447\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u043b\u0438\u0431\u043e \u043a\u043e\u0433\u0434\u0430 \u0443 \u0430\u043a\u0442\u0438\u0432\u043d\u043e\u0433\u043e \u044e\u043d\u0438\u0442\u0430 \u043a\u043e\u043d\u0447\u0438\u043b\u0438\u0441\u044c \u041e\u0414, \u043b\u0438\u0431\u043e \u043e\u043d \u043f\u0440\u043e\u043f\u0443\u0441\u0442\u0438\u043b \u0445\u043e\u0434 (\u0434\u043e\u043f\u0443\u0441\u0442\u0438\u043c, \u0438\u0433\u0440\u043e\u043a \u0442\u0430\u043a \u0437\u0430\u0445\u043e\u0442\u0435\u043b \u0438\u043b\u0438 \u0418\u0418 \u043d\u0435 \u0441\u0442\u0430\u043b \u043d\u0438\u0447\u0435\u0433\u043e \u0434\u0435\u043b\u0430\u0442\u044c, \u0442\u0430\u043a \u043a\u0430\u043a \u0438\u0433\u0440\u043e\u043a \u0434\u0430\u043b\u0435\u043a\u043e). \u041a\u043e\u0433\u0434\u0430 \u044e\u043d\u0438\u0442 \u0437\u0430\u043a\u0430\u043d\u0447\u0438\u0432\u0430\u0435\u0442 \u0445\u043e\u0434, \u043d\u0430 \u0435\u0433\u043e \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438 \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u0432\u0435\u0448\u0435\u043d \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 <strong>TurnFinished<\/strong>, \u0430 \u043a\u043e\u0433\u0434\u0430 \u0432\u0441\u0435 \u044e\u043d\u0438\u0442\u044b \u043e\u0434\u043d\u043e\u0439 \u0441\u0442\u043e\u0440\u043e\u043d\u044b \u0437\u0430\u043a\u0430\u043d\u0447\u0438\u0432\u0430\u044e\u0442 \u0445\u043e\u0434, \u0441 \u043d\u0438\u0445 \u0441\u043d\u0438\u043c\u0430\u0435\u0442\u0441\u044f \u0440\u0430\u043d\u0435\u0435 \u0443\u043f\u043e\u043c\u044f\u043d\u0443\u0442\u044b\u0439 \u0444\u043b\u0430\u0433 \u0438 \u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f &#171;\u0430\u043a\u0442\u0438\u0432\u043d\u0430\u044f&#187; \u0441\u0442\u043e\u0440\u043e\u043d\u0430. \u042d\u0442\u043e \u0432\u0441\u0435 \u043d\u0443\u0436\u043d\u043e \u0431\u0443\u0434\u0435\u0442 \u0434\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e \u043d\u0430\u0439\u0442\u0438 \u043d\u043e\u0432\u043e\u0433\u043e \u0430\u043a\u0442\u0438\u0432\u043d\u043e\u0433\u043e \u044e\u043d\u0438\u0442\u0430.<\/p>\n<p>\u0412\u043d\u0435\u0441\u0435\u043c \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u0432 \u0441\u0438\u0441\u0442\u0435\u043c\u0443 \u0434\u0432\u0438\u0436\u0435\u043d\u0438\u044f \u044e\u043d\u0438\u0442\u0430:<\/p>\n<pre><code class=\"cs\"> namespace Client {     sealed class UnitMoveSystem : IEcsRunSystem {         readonly EcsFilterInject&lt;Inc&lt;Unit, Moving>> _movingUnits = default;          readonly EcsPoolInject&lt;Animating> _animatingPool = default;         readonly EcsPoolInject&lt;TurnFinished> _turnFinishedPool = default;         readonly EcsPoolInject&lt;NextUnitEvent> _nextUnitEventPool = Idents.Worlds.Events;          readonly EcsCustomInject&lt;TimeService> _ts = default;          const float DistanceToStop = 0.001f;          public void Run (EcsSystems systems) {             foreach (var entity in _movingUnits.Value) {                 ref var unit = ref _movingUnits.Pools.Inc1.Get (entity);                 ref var move = ref _movingUnits.Pools.Inc2.Get (entity);                                  unit.Position = Vector3.Lerp (unit.Position, move.Point, unit.MoveSpeed * _ts.Value.DeltaTime);                  if ((unit.Position - move.Point).sqrMagnitude &lt;= DistanceToStop) {                     unit.Position = move.Point;                     _animatingPool.Value.Del (entity);                     _movingUnits.Pools.Inc2.Del (entity);                     if (unit.ActionPoints == 0) {                         unit.ActionPoints = 2;                         _turnFinishedPool.Value.Add (entity);                         _nextUnitEventPool.Value.Add (_nextUnitEventPool.Value.GetWorld ().NewEntity ());                     }                 }                                  unit.Transform.localPosition = unit.Position;             }         }     } }<\/code><\/pre>\n<p>\u0418 \u0432 \u0441\u0438\u0441\u0442\u0435\u043c\u0443 \u043d\u0430\u0447\u0430\u043b\u0430 \u0434\u0432\u0438\u0436\u0435\u043d\u0438\u044f:<\/p>\n<pre><code class=\"cs\">namespace Client {     sealed class UnitStartMovingSystem : IEcsRunSystem {         readonly EcsFilterInject&lt;Inc&lt;Unit, MoveCommand>, Exc&lt;Animating>> _units = default;          readonly EcsPoolInject&lt;Animating> _animatingPool = default;         readonly EcsPoolInject&lt;Moving> _movingPool = default;         readonly EcsPoolInject&lt;Cell> _cellPool = default;          readonly EcsCustomInject&lt;GridService> _gs = default;         readonly EcsCustomInject&lt;RoundService> _rs = default;          public void Run (EcsSystems systems) {             foreach (var entity in _units.Value) {                 ref var unit = ref _units.Pools.Inc1.Get (entity);                  if (unit.Side != _rs.Value.ActiveSide) {                     continue;                 }                                  ref var cmd = ref _units.Pools.Inc2.Get (entity);                  var step = cmd.Backwards ? -1 : 1;                  var pos3d = Quaternion.Euler (0f, 90f * (int) unit.Direction, 0f) * Vector3.forward;                 var newCellCoords = unit.CellCoords + new Int2 (Mathf.RoundToInt (pos3d.x), Mathf.RoundToInt (pos3d.z)) * step;                                  var (newCell, ok) = _gs.Value.GetCell (newCellCoords);                 if (ok) {                     ref var cell = ref _cellPool.Value.Get (newCell);                                          if (cell.Entity != -1) {                         continue;                     }                      var (curCellEntity, _) = _gs.Value.GetCell (unit.CellCoords);                     ref var curCell = ref _cellPool.Value.Get (curCellEntity);                     curCell.Entity = -1;                                          cell.Entity = entity;                     _animatingPool.Value.Add (entity);                     ref var moving = ref _movingPool.Value.Add (entity);                     moving.Point = cell.View.Transform.localPosition;                     unit.CellCoords = newCellCoords;                      unit.ActionPoints--;                 }             }         }     } }<\/code><\/pre>\n<p>\u041a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 <strong>NextTurnEvent<\/strong> &#8212; \u043e\u0431\u044b\u0447\u043d\u043e\u0435 \u0441\u043e\u0431\u044b\u0442\u0438\u0435, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043d\u0443\u0436\u043d\u043e, \u0447\u0442\u043e\u0431\u044b \u0441\u043c\u0435\u043d\u0438\u0442\u044c \u0430\u043a\u0442\u0438\u0432\u043d\u043e\u0433\u043e \u044e\u043d\u0438\u0442\u0430 \u0438, \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e, \u0441\u0442\u043e\u0440\u043e\u043d\u0443 \u0442\u043e\u0436\u0435.<\/p>\n<p>\u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0441\u0438\u0441\u0442\u0435\u043c\u0443 \u0441\u043c\u0435\u043d\u044b \u0445\u043e\u0434\u0430:<\/p>\n<pre><code class=\"cs\">namespace Client {     sealed class NextUnitTurnSystem : IEcsRunSystem {         readonly EcsFilterInject&lt;Inc&lt;NextUnitEvent>> _nextUnitEvents = Idents.Worlds.Events;         readonly EcsFilterInject&lt;Inc&lt;Unit>, Exc&lt;TurnFinished>> _activeUnits = default;         readonly EcsFilterInject&lt;Inc&lt;TurnFinished>> _finishedUnits = default;          readonly EcsCustomInject&lt;RoundService> _rs = default;          public void Run (EcsSystems systems) {             foreach (var entity in _nextUnitEvents.Value) {                 var (newEntity, ok) = FindNewUnit ();                                  if (ok) {                     \/\/ successfully found.                     _rs.Value.ActiveUnit = newEntity;                 } else {                     \/\/ reset \"Finished\" flag because we change active side                     var found = false;                     ClearFinishedFlag ();                     while (!found) {                         var newSide = ((int) _rs.Value.ActiveSide + 1) % _rs.Value.StateMax;                         _rs.Value.ActiveSide = (Side) newSide;                         var (anotherNewEntity, foundNewUnit) = FindNewUnit ();                         found = foundNewUnit;                         _rs.Value.ActiveUnit = anotherNewEntity;                     }                 }             }         }          void ClearFinishedFlag () {             foreach (var entity in _finishedUnits.Value) {                 _finishedUnits.Pools.Inc1.Del (entity);             }         }          (int, bool) FindNewUnit () {             var found = -1;             var min = int.MaxValue;             foreach (var entity in _activeUnits.Value) {                 ref var unit = ref _activeUnits.Pools.Inc1.Get (entity);                  if (unit.Initiative &lt; min &amp;&amp; unit.Side == _rs.Value.ActiveSide) {                     found = entity;                 }             }              return (found, found >= 0);         }     } }<\/code><\/pre>\n<p>\u041a\u0430\u043a \u0432\u0438\u0434\u0438\u0442\u0435, \u0435\u0441\u043b\u0438 \u0432\u0441\u0435 \u044e\u043d\u0438\u0442\u044b \u043e\u0434\u043d\u043e\u0439 \u0441\u0442\u043e\u0440\u043e\u043d\u044b \u0437\u0430\u0432\u0435\u0440\u0448\u0438\u043b\u0438 \u0445\u043e\u0434\u044b \u0438 \u0438\u043c\u0435\u044e\u0442 \u0442\u0435\u0433\u0438 TurnFinished, \u0442\u043e \u043c\u044b \u0443\u0431\u0438\u0440\u0430\u0435\u043c \u044d\u0442\u043e\u0442 \u0442\u0435\u0433 \u0438 \u043c\u0435\u043d\u044f\u0435\u043c \u0441\u0442\u043e\u0440\u043e\u043d\u0443. \u0412 \u043f\u0440\u0435\u0434\u0435\u043b\u0430\u0445 \u0441\u0442\u043e\u0440\u043e\u043d\u044b \u043c\u044b \u0438\u0449\u0435\u043c \u044e\u043d\u0438\u0442\u0430, \u0443 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u0431\u0443\u0434\u0435\u0442 \u0441\u0430\u043c\u0430\u044f \u043c\u0430\u043b\u0435\u043d\u044c\u043a\u0430\u044f \u0438\u043d\u0438\u0446\u0438\u0430\u0442\u0438\u0432\u0430.<\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043f\u0440\u0438\u0448\u043b\u043e \u0432\u0440\u0435\u043c\u044f \u043a \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u044e \u0438\u0441\u043a\u0443\u0441\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0433\u043e \u0438\u043d\u0442\u0435\u043b\u043b\u0435\u043a\u0442\u0430. \u0420\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u043e\u043d \u0431\u0443\u0434\u0435\u0442 \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u043e: \u0432\u0440\u0430\u0436\u0435\u0441\u043a\u0438\u0439 \u044e\u043d\u0438\u0442 \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u043e\u0431\u043e\u0432\u0430\u0442\u044c \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u0442\u044c \u043a\u0430\u043a\u0443\u044e-\u0442\u043e \u0441\u043f\u043e\u0441\u043e\u0431\u043d\u043e\u0441\u0442\u044c, \u0430 \u0435\u0441\u043b\u0438 \u0435\u043c\u0443 \u043d\u0435 \u0443\u0434\u0430\u0435\u0442\u0441\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043d\u0438 \u043e\u0434\u043d\u0443, \u0442\u043e \u043e\u043d \u0441\u043e\u043a\u0440\u0430\u0449\u0430\u0435\u0442 \u0434\u0438\u0441\u0442\u0430\u043d\u0446\u0438\u044e \u0441 \u0438\u0433\u0440\u043e\u043a\u043e\u043c. \u041d\u043e \u043a\u0430\u043a \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c, \u043c\u043e\u0436\u0435\u0442 \u043b\u0438 \u043e\u043d \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0442\u0443 \u0438\u043b\u0438 \u0438\u043d\u0443\u044e \u0441\u043f\u043e\u0441\u043e\u0431\u043d\u043e\u0441\u0442\u044c? \u041d\u0435 \u0431\u0440\u0430\u0442\u044c \u0436\u0435 \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u0443\u044e?<\/p>\n<p>\u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043c\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u043f\u0440\u0438\u0434\u0443\u043c\u0430\u0442\u044c \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u044b \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438, \u043f\u043e\u0434\u0445\u043e\u0434\u0438\u0442 \u043b\u0438 \u0442\u0430 \u0438\u043b\u0438 \u0438\u043d\u0430\u044f \u0441\u043f\u043e\u0441\u043e\u0431\u043d\u043e\u0441\u0442\u044c \u0432 \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u0438, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0441\u0435\u0439\u0447\u0430\u0441 \u044e\u043d\u0438\u0442. \u041c\u044b \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u0432 \u0441\u0435\u0440\u0432\u0438\u0441 AbilityHelper \u043c\u0435\u0442\u043e\u0434\u044b \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0439 \u0441\u043f\u043e\u0441\u043e\u0431\u043d\u043e\u0441\u0442\u0438, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043f\u0440\u043e\u043f\u0438\u0448\u0435\u043c \u043b\u043e\u0433\u0438\u043a\u0443 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0438. \u041f\u043e \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0438 \u0441 \u043c\u0435\u0442\u043e\u0434\u0430\u043c\u0438, \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u044e\u0449\u0438\u043c\u0438 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442, \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u044c \u043c\u0435\u0442\u043e\u0434-\u0432\u0430\u043b\u0438\u0434\u0430\u0442\u043e\u0440 \u0447\u0435\u0440\u0435\u0437 ID \u0430\u0431\u0438\u043b\u043a\u0438. \u041a\u043e\u043d\u0435\u0447\u043d\u043e, \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u044f\u0442\u0441\u044f \u0434\u0430\u043d\u043d\u044b\u0435 \u043e \u0441\u0435\u0442\u043a\u0435 \u0438 \u044e\u043d\u0438\u0442\u0430\u0445, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435 \u0441\u0435\u0440\u0432\u0438\u0441\u0430 \u0431\u0443\u0434\u0435\u0442 \u0441\u0435\u0440\u044c\u0435\u0437\u043d\u044b\u043c. \u041f\u043e \u0441\u0443\u0442\u0438, \u043c\u044b \u0438\u043c\u043f\u043b\u0435\u043c\u0435\u043d\u0442\u0438\u0440\u0443\u0435\u043c <strong>Utility AI<\/strong>.<\/p>\n<p>\u0412\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u044e \u0441\u043f\u043e\u0441\u043e\u0431\u043d\u043e\u0441\u0442\u0438 \u043c\u044b \u0442\u0430\u043a\u0436\u0435 \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0438 \u0434\u043b\u044f \u0438\u0433\u0440\u043e\u043a\u0430. \u0412 \u043c\u043e\u043c\u0435\u043d\u0442, \u043a\u043e\u0433\u0434\u0430 \u043e\u043d \u043d\u0430\u0436\u0438\u043c\u0430\u0435\u0442 \u043a\u043d\u043e\u043f\u043a\u0443 \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0441\u043f\u043e\u0441\u043e\u0431\u043d\u043e\u0441\u0442\u0438, \u043d\u0443\u0436\u043d\u043e \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0432\u0430\u043b\u0438\u0434\u0430\u0442\u043e\u0440\u0430, \u043c\u043e\u0436\u0435\u0442 \u043b\u0438 \u043e\u043d \u044d\u0442\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c.<\/p>\n<pre><code class=\"cs\">namespace Client {     sealed class AbilityHelper {         internal delegate int ValidationCheck (in Unit unit, int damage);          readonly Dictionary&lt;int, Action&lt;EcsWorld, int>> _addComponentCallbacks;         readonly Dictionary&lt;int, ValidationCheck> _validationCallbacks;          readonly GridService _gs;          readonly EcsPool&lt;Cell> _cellPool;          public AbilityHelper (GridService gs, EcsPool&lt;Cell> cellPool) {             _addComponentCallbacks = new Dictionary&lt;int, Action&lt;EcsWorld, int>> {                 { 0, AddComponent&lt;LightAttack> },                 { 1, AddComponent&lt;HeavyAttack> },                 { 2, AddComponent&lt;PowerShot>}             };              _validationCallbacks = new Dictionary&lt;int, ValidationCheck> {                 { 0, LightAttackValidate },                 { 1, HeavyAttackValidate },                 { 2, PowerShotValidate }             };              _gs = gs;             _cellPool = cellPool;         }          void AddComponent&lt;T> (EcsWorld world, int entity) where T : struct {             world.GetPool&lt;T> ().Add (entity);         }          public Action&lt;EcsWorld, int> GetAddComponentCallback (int abilityIdx) {             return _addComponentCallbacks.TryGetValue (abilityIdx, out Action&lt;EcsWorld, int> cb) ? cb : null;         }          public ValidationCheck GetValidateCallback (int abilityIdx) {             return _validationCallbacks.TryGetValue (abilityIdx, out ValidationCheck cb) ? cb : null;         }          int LightAttackValidate (in Unit unit, int damage) {             var coords = unit.CellCoords;             var pos3d = Quaternion.Euler (0f, 90f * (int) unit.Direction, 0f) * Vector3.forward;             var add = new Int2 (Mathf.RoundToInt (pos3d.x), Mathf.RoundToInt (pos3d.z));             var frontCell = coords + add;             var (cellEntity, ok) = _gs.GetCell (frontCell);              if (ok) {                 ref var cell = ref _cellPool.Get (cellEntity);                 if (cell.Entity != -1) {                     return damage;                 }             }              return 0;         }          int HeavyAttackValidate (in Unit unit, int damage) {             var coords = unit.CellCoords;             var pos3d = Quaternion.Euler (0f, 90f * (int) unit.Direction, 0f) * Vector3.forward;             var add = new Int2 (Mathf.RoundToInt (pos3d.x), Mathf.RoundToInt (pos3d.z));              var frontCell = coords + add;             var (cellEntity, ok) = _gs.GetCell (frontCell);              if (ok) {                 ref var cell = ref _cellPool.Get (cellEntity);                 if (cell.Entity != -1) {                     return damage;                 }             }              return 0;         }          int PowerShotValidate (in Unit unit, int damage) {             var coords = unit.CellCoords;             var pos3d = Quaternion.Euler (0f, 90f * (int) unit.Direction, 0f) * Vector3.forward;             var add = new Int2 (Mathf.RoundToInt (pos3d.x), Mathf.RoundToInt (pos3d.z));                          var frontCell = coords + add;             var (cellEntity, ok) = _gs.GetCell (frontCell);             if (ok) {                 ref var cell = ref _cellPool.Get (cellEntity);                 if (cell.Entity != -1) {                     return 0;                 }             }                          frontCell = coords + add * 2;             var (anotherCellEntity, ok2) = _gs.GetCell (frontCell);             if (ok2) {                 ref var cell = ref _cellPool.Get (anotherCellEntity);                 if (cell.Entity != -1) {                     return damage;                 }             }              return 0;         }     } }<\/code><\/pre>\n<p>\u041f\u0435\u0440\u0435\u0434 \u0442\u0435\u043c, \u043a\u0430\u043a \u043f\u0440\u0438\u0441\u0442\u0443\u043f\u0438\u0442\u044c \u043a \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u044e \u043b\u043e\u0433\u0438\u043a\u0438 \u0418\u0418, \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0442\u0430\u043a\u0436\u0435 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442-\u0438\u0432\u0435\u043d\u0442 <strong>Apply<\/strong> \u0434\u043b\u044f \u0441\u043f\u043e\u0441\u043e\u0431\u043d\u043e\u0441\u0442\u0435\u0439.<\/p>\n<pre><code class=\"cs\">namespace Client {     struct Apply { } }<\/code><\/pre>\n<pre><code class=\"cs\">namespace Client {     sealed class ApplyAbilitySystem : IEcsRunSystem {         readonly EcsFilterInject&lt;Inc&lt;Ability, Apply>> _abilities = default;          readonly EcsPoolInject&lt;Unit> _unitPool = default;         readonly EcsPoolInject&lt;Cell> _cellPool = default;         readonly EcsPoolInject&lt;Applied> _appliedPool = default;         readonly EcsPoolInject&lt;TurnFinished> _turnFinishedPool = default;         readonly EcsPoolInject&lt;NextUnitEvent> _nextUnitEventPool = Idents.Worlds.Events;          readonly EcsCustomInject&lt;GridService> _gs = default;         readonly EcsCustomInject&lt;RoundService> _rs = default;          public void Run (EcsSystems systems) {             foreach (var entity in _abilities.Value) {                 ref var ability = ref _abilities.Pools.Inc1.Get (entity);                 ref var unit = ref _unitPool.Value.Get (ability.OwnerEntity);                  if (unit.Side != _rs.Value.ActiveSide) {                     continue;                 }                                  var pos3d = Quaternion.Euler (0f, 90f * (int) unit.Direction, 0f) * Vector3.forward;                 var add = new Int2 (Mathf.RoundToInt (pos3d.x), Mathf.RoundToInt (pos3d.z)) * ability.Distance;                  var cellCoords = unit.CellCoords + add;                 var (cellEntity, ok) = _gs.Value.GetCell (cellCoords);                  if (ok) {                     ref var cell = ref _cellPool.Value.Get (cellEntity);                     if (unit.ActionPoints &lt; ability.ActionPointsCost) {                     }                     if (cell.Entity != -1 &amp;&amp; unit.ActionPoints >= ability.ActionPointsCost) {                         ref var applied = ref _appliedPool.Value.Add (entity);                         applied.Target = cell.Entity;                         unit.ActionPoints -= ability.ActionPointsCost;                          if (unit.ActionPoints == 0) {                             unit.ActionPoints = 2;                             _turnFinishedPool.Value.Add (ability.OwnerEntity);                             _nextUnitEventPool.Value.Add (_nextUnitEventPool.Value.GetWorld ().NewEntity ());                         }                     }                 }             }         }     } }<\/code><\/pre>\n<p>\u0422\u0430\u043a\u0436\u0435 \u0434\u0430\u0434\u0438\u043c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0438\u0433\u0440\u043e\u043a\u0443 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u043f\u043e\u0441\u043e\u0431\u043d\u043e\u0441\u0442\u0438. \u0412\u044b \u043f\u043e\u043c\u043d\u0438\u0442\u0435, \u0447\u0442\u043e \u043c\u044b \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u043b\u0438 \u043a\u043d\u043e\u043f\u043a\u0438 \u0441 \u0438\u043d\u0434\u0435\u043a\u0441\u043e\u043c \u0441\u043f\u043e\u0441\u043e\u0431\u043d\u043e\u0441\u0442\u0438 \u0432 \u043a\u044d\u0448\u0435 \u0430\u0431\u0438\u043b\u043e\u043a \u0432\u043b\u0430\u0434\u0435\u043b\u044c\u0446\u0430 (\u0438\u0433\u0440\u043e\u043a\u0430). \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u043c \u043c\u0435\u0445\u0430\u043d\u0438\u043a\u0443 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0441\u043f\u043e\u0441\u043e\u0431\u043d\u043e\u0441\u0442\u0435\u0439 \u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u043e\u043c \u043d\u0430\u0436\u0430\u0442\u0438\u044f \u043a\u043d\u043e\u043f\u043e\u043a. \u041d\u0435\u043c\u043d\u043e\u0433\u043e \u0438\u0437\u043c\u0435\u043d\u0438\u043c \u043d\u0430\u0448\u0443 \u0441\u0438\u0441\u0442\u0435\u043c\u0443 <strong>UserButtonsInputSystem<\/strong>, \u0434\u043e\u0431\u0430\u0432\u0438\u0432 \u0442\u0443\u0434\u0430 \u043d\u043e\u0432\u044b\u0439 \u043c\u0435\u0442\u043e\u0434 \u0438 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043f\u0443\u043b\u043e\u0432:<\/p>\n<pre><code class=\"cs\">[Preserve] [EcsUguiClickEvent (Idents.Ui.Ability, Idents.Worlds.Events)] void OnClickAbility (in EcsUguiClickEvent e) {     var abilityView = e.Sender.GetComponent&lt;AbilityView> ();     foreach (var entity in _units.Value) {         ref var abilities = ref _hasAbilitiesPool.Value.Get (entity);         var abilityEntity = abilities.Entities[abilityView.AbilityIdx];         ref var ability = ref _abilityPool.Value.Get (abilityEntity);         ref var unit = ref _units.Pools.Inc1.Get (entity);         var dmg = _ah.Value.GetValidateCallback (ability.Id).Invoke (unit, ability.Damage);         if (dmg != 0 &amp;&amp; unit.ActionPoints >= ability.ActionPointsCost) {             _applyPool.Value.Add (abilityEntity);         }     } } <\/code><\/pre>\n<p>\u0422\u0430\u043a\u0436\u0435 \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u0441\u0438\u0441\u0442\u0435\u043c\u0443 \u0438\u043d\u043f\u0443\u0442\u0430 \u0441 \u043a\u043b\u0430\u0432\u0438\u0430\u0442\u0443\u0440\u044b <strong>UserKeyboardInputSystem:<\/strong><\/p>\n<pre><code class=\"cs\">namespace Client {     sealed class UserKeyboardInputSystem : IEcsRunSystem {         readonly EcsFilterInject&lt;Inc&lt;Unit, ControlledByPlayer>> _units = default;          readonly EcsPoolInject&lt;MoveCommand> _moveCommandPool = default;         readonly EcsPoolInject&lt;RotateCommand> _rotateCommandPool = default;         readonly EcsPoolInject&lt;HasAbilities> _hasAbilitiesPool = default;         readonly EcsPoolInject&lt;Apply> _applyPool = default;         readonly EcsPoolInject&lt;TurnFinished> _turnFinishedPool = default;         readonly EcsPoolInject&lt;NextUnitEvent> _nextUnitEventPool = Idents.Worlds.Events;         readonly EcsPoolInject&lt;Ability> _abilityPool = default;          readonly EcsCustomInject&lt;AbilityHelper> _ah = default;          public void Run (EcsSystems systems) {             foreach (var entity in _units.Value) {                 ref var unit = ref _units.Pools.Inc1.Get (entity);                 var vertInput = Input.GetAxisRaw (Idents.Input.VerticalAxis);                 var horizInput = Input.GetAxisRaw (Idents.Input.HorizontalAxis);                                  switch (vertInput) {                     case 1f:                         _moveCommandPool.Value.Add (entity);                         break;                     case -1f:                         ref var moveCmd = ref _moveCommandPool.Value.Add (entity);                         moveCmd.Backwards = true;                         break;                 }                  if (horizInput != 0f) {                     ref var rotCmd = ref _rotateCommandPool.Value.Add (entity);                     rotCmd.Side = (int) horizInput;                 }                  if (Input.GetKeyDown (KeyCode.Alpha1)) {                     TryApplyAbility (0, entity, unit);                 }                                  if (Input.GetKeyDown (KeyCode.Alpha2)) {                     TryApplyAbility (1, entity, unit);                 }                  if (Input.GetKeyDown (KeyCode.Alpha3)) {                     TryApplyAbility (2, entity, unit);                 }                  if (Input.GetKeyDown (KeyCode.Space) &amp;&amp; !_turnFinishedPool.Value.Has (entity)) {                     unit.ActionPoints = 2;                     _turnFinishedPool.Value.Add (entity);                     _nextUnitEventPool.Value.Add (_nextUnitEventPool.Value.GetWorld ().NewEntity ());                 }             }         }          void TryApplyAbility (int abilityIdx, int entity, in Unit unit) {             ref var abilities = ref _hasAbilitiesPool.Value.Get (entity);              var abilityEntity = abilities.Entities[abilityIdx];             ref var ability = ref _abilityPool.Value.Get (abilityEntity);                          var dmg = _ah.Value.GetValidateCallback (ability.Id).Invoke (unit, ability.Damage);             if (dmg != 0 &amp;&amp; unit.ActionPoints >= ability.ActionPointsCost) {                 _applyPool.Value.Add (abilityEntity);             }         }     } }<\/code><\/pre>\n<p>(\u0432\u044b \u0442\u0430\u043a\u0436\u0435 \u043c\u043e\u0436\u0435\u0442\u0435 \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u043c\u0435\u0442\u043e\u0434\u044b \u0438 \u0434\u043b\u044f \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0445 \u043a\u043b\u0430\u0432\u0438\u0448 \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u043e)<\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043f\u0435\u0440\u0435\u0439\u0434\u0435\u043c \u043a \u0433\u043b\u0430\u0432\u043d\u043e\u0439 \u0447\u0430\u0441\u0442\u0438 \u0418\u0418 \u0438 \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0441\u0438\u0441\u0442\u0435\u043c\u0443-\u0440\u043e\u0443\u0442\u0435\u0440, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0431\u0443\u0434\u0435\u0442 \u0441\u043b\u0430\u0442\u044c \u043a\u043e\u043c\u0430\u043d\u0434\u044b \u0430\u043a\u0442\u0438\u0432\u043d\u043e\u043c\u0443 \u044e\u043d\u0438\u0442\u0443, \u0435\u0441\u043b\u0438 \u043e\u043d \u043d\u0430 \u0441\u0442\u043e\u0440\u043e\u043d\u0435 \u0432\u0440\u0430\u0433\u043e\u0432.<\/p>\n<pre><code class=\"cs\">namespace Client {     sealed class AiCommandsSystem : IEcsRunSystem {         readonly EcsPoolInject&lt;Unit> _unitPool = default;         readonly EcsPoolInject&lt;Cell> _cellPool = default;          readonly EcsPoolInject&lt;TurnFinished> _turnFinishedPool = default;         readonly EcsPoolInject&lt;NextUnitEvent> _nextUnitEventPool = Idents.Worlds.Events;         readonly EcsPoolInject&lt;Animating> _animatingPool = default;         readonly EcsPoolInject&lt;RotateCommand> _rotateCommandPool = default;         readonly EcsPoolInject&lt;MoveCommand> _moveCommandPool = default;         readonly EcsPoolInject&lt;HasAbilities> _hasAbilitiesPool = default;         readonly EcsPoolInject&lt;Apply> _applyPool = default;         readonly EcsPoolInject&lt;Ability> _abilityPool = default;          readonly EcsCustomInject&lt;RoundService> _rs = default;         readonly EcsCustomInject&lt;GridService> _gs = default;         readonly EcsCustomInject&lt;AbilityHelper> _ah = default;          public void Run (EcsSystems systems) {             if (_animatingPool.Value.Has (_rs.Value.ActiveUnit)) {                 return;             }              if (_rs.Value.ActiveSide == Side.Enemy) {                 ref var unit = ref _unitPool.Value.Get (_rs.Value.ActiveUnit);                 var cellCoords = unit.CellCoords;                 var userCellCoords = new Int2 ();                 var userEntity = -1;                  \/\/ Checking cells that in radius range.                 for (int i = -unit.Radius; i &lt; unit.Radius + 1; i++) {                     for (int j = -unit.Radius; j &lt; unit.Radius + 1; j++) {                         var newCellCoords = new Int2 {                             X = cellCoords.X + i,                             Y = cellCoords.Y + j                         };                         var (cellToCheck, ok) = _gs.Value.GetCell (newCellCoords);                          if (ok) {                             ref var cell = ref _cellPool.Value.Get (cellToCheck);                             if (cell.Entity != -1) {                                 ref var unitOnCell = ref _unitPool.Value.Get (cell.Entity);                                  if (unitOnCell.Side != Side.Enemy) {                                     userEntity = cell.Entity;                                     userCellCoords = newCellCoords;                                     break;                                 }                             }                         }                     }                 }                  \/\/ if user is detected, attack or chase him. if user is not detected, finish turn.                 if (userEntity != -1) {                     var (ability, ok) = CheckAbilitiesValidation (_rs.Value.ActiveUnit);                     if (ok) {                         _applyPool.Value.Add (ability);                     } else {                         ChasePlayer (cellCoords, userCellCoords, unit);                     }                 } else {                     _turnFinishedPool.Value.Add (_rs.Value.ActiveUnit);                     _nextUnitEventPool.Value.Add (_nextUnitEventPool.Value.GetWorld ().NewEntity ());                 }             }         }          (int, bool) CheckAbilitiesValidation (int activeUnit) {             ref var hasAbilities = ref _hasAbilitiesPool.Value.Get (activeUnit);             ref var unit = ref _unitPool.Value.Get (activeUnit);             var maxDamage = 0;             var foundAbility = -1;              for (int i = 0; i &lt; hasAbilities.Entities.Count; i++) {                 ref var ability = ref _abilityPool.Value.Get (hasAbilities.Entities[i]);                 \/\/ skip if not enough AP.                 if (unit.ActionPoints &lt; ability.ActionPointsCost) {                     continue;                 }                 var dmg = _ah.Value.GetValidateCallback (ability.Id).Invoke (unit, ability.Damage);                 if (dmg > maxDamage) {                     foundAbility = hasAbilities.Entities[i];                     maxDamage = dmg;                 }             }              return (foundAbility, foundAbility != -1);         }          void ChasePlayer (Int2 activeUnitCoords, Int2 userCoords, in Unit activeUnit) {             if (userCoords.X != activeUnitCoords.X) {                 \/\/ X coord diff                 var diff = Mathf.Clamp (userCoords.X - activeUnitCoords.X, -1, 1);                 var newCoords = activeUnitCoords + new Int2 { X = diff, Y = 0 };                 var (cell, ok) = _gs.Value.GetCell (newCoords);                 var direction = (Direction) ((int) Direction.South - diff);                 if (ok) {                     \/\/ if can move along x axis                     \/\/ rotate to this cell and move there.                     if (activeUnit.Direction != direction) {                         ref var rotate = ref _rotateCommandPool.Value.Add (_rs.Value.ActiveUnit);                         rotate.Side = (int) direction - (int) activeUnit.Direction;                     } else {                         _moveCommandPool.Value.Add (_rs.Value.ActiveUnit);                     }                     return;                 }             }              if (userCoords.Y != activeUnitCoords.Y) {                 \/\/ Y coord diff                 var diff = Mathf.Clamp (userCoords.Y - activeUnitCoords.Y, -1, 1);                 var newCoords = activeUnitCoords + new Int2 { X = 0, Y = diff };                 var (cell, ok) = _gs.Value.GetCell (newCoords);                 var direction = (Direction) ((int) Direction.East - diff);                 if (ok) {                     \/\/ if can move along y axis                     \/\/ rotate to this cell and move there.                     if (activeUnit.Direction != direction) {                         ref var rotate = ref _rotateCommandPool.Value.Add (_rs.Value.ActiveUnit);                         rotate.Side = (int) direction - (int) activeUnit.Direction;                     } else {                         _moveCommandPool.Value.Add (_rs.Value.ActiveUnit);                     }                 }             }         }     } }<\/code><\/pre>\n<p>\u041e\u0431\u0449\u0430\u044f \u0441\u0445\u0435\u043c\u0430 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0442\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c: \u0435\u0441\u043b\u0438 \u0432 \u0440\u0430\u0434\u0438\u0443\u0441\u0435 \u044e\u043d\u0438\u0442\u0430 \u0435\u0441\u0442\u044c \u0432\u0440\u0430\u0433 (\u0438\u0433\u0440\u043e\u043a), \u0442\u043e \u043d\u0443\u0436\u043d\u043e \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0442\u044c \u0432\u0430\u043b\u0438\u0434\u0430\u0442\u043e\u0440\u044b \u0441\u043f\u043e\u0441\u043e\u0431\u043d\u043e\u0441\u0442\u0435\u0439. \u0415\u0441\u043b\u0438 \u043a\u0430\u043a\u0430\u044f-\u0442\u043e \u0441\u043f\u043e\u0441\u043e\u0431\u043d\u043e\u0441\u0442\u044c \u043d\u0430\u043d\u043e\u0441\u0438\u0442 \u0443\u0440\u043e\u043d, \u0431\u043e\u043b\u044c\u0448\u0438\u0439 \u043d\u0443\u043b\u044f, \u0442\u043e \u043d\u0443\u0436\u043d\u043e \u0435\u0435 \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u0442\u044c. \u0415\u0441\u043b\u0438 \u043d\u0435\u0442, \u0442\u043e \u043d\u0443\u0436\u043d\u043e \u0441\u043e\u043a\u0440\u0430\u0449\u0430\u0442\u044c \u0434\u0438\u0441\u0442\u0430\u043d\u0446\u0438\u044e \u0441 \u0438\u0433\u0440\u043e\u043a\u043e\u043c (\u043f\u043e \u043e\u0434\u043d\u043e\u0439 \u0438\u0437 \u043e\u0441\u0435\u0439), \u043f\u043e\u0432\u043e\u0440\u0430\u0447\u0438\u0432\u0430\u044f\u0441\u044c \u0432 \u0441\u0442\u043e\u0440\u043e\u043d\u0443 \u0434\u0432\u0438\u0436\u0435\u043d\u0438\u044f, \u0438 \u0442\u0430\u043a \u043f\u043e\u043a\u0430 \u043d\u0435 \u0441\u043c\u0435\u043d\u0438\u0442\u0441\u044f \u0430\u043a\u0442\u0438\u0432\u043d\u044b\u0439 \u044e\u043d\u0438\u0442.<\/p>\n<p>\u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442-\u0438\u0432\u0435\u043d\u0442 \u043e \u0441\u043c\u0435\u0440\u0442\u0438 \u044e\u043d\u0438\u0442\u0430:<\/p>\n<pre><code class=\"cs\">namespace Client {     struct DeathEvent { } }<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0441\u0438\u0441\u0442\u0435\u043c\u044b \u0434\u043b\u044f \u0441\u043f\u043e\u0441\u043e\u0431\u043d\u043e\u0441\u0442\u0435\u0439:<\/p>\n<pre><code class=\"cs\">namespace Client {     sealed class LightAttackAbilitySystem : IEcsRunSystem {         readonly EcsFilterInject&lt;Inc&lt;LightAttack, Applied>> _lightAttacksApplied = default;          readonly EcsPoolInject&lt;Unit> _unitPool = default;         readonly EcsPoolInject&lt;Ability> _abilityPool = default;         readonly EcsPoolInject&lt;DeathEvent> _deathEventPool = default;          public void Run (EcsSystems systems) {             foreach (var entity in _lightAttacksApplied.Value) {                 ref var ability = ref _abilityPool.Value.Get (entity);                 ref var applied = ref _lightAttacksApplied.Pools.Inc2.Get (entity);                 ref var unit = ref _unitPool.Value.Get (applied.Target);                  unit.Health -= ability.Damage;                  if (unit.Health &lt;= 0) {                     _deathEventPool.Value.Add (applied.Target);                 }             }         }     } }<\/code><\/pre>\n<pre><code class=\"cs\">namespace Client {     sealed class HeavyAttackAbilitySystem : IEcsRunSystem {         readonly EcsFilterInject&lt;Inc&lt;HeavyAttack, Applied>> _heavyAttacksApplied = default;          readonly EcsPoolInject&lt;Unit> _unitPool = default;         readonly EcsPoolInject&lt;Ability> _abilityPool = default;         readonly EcsPoolInject&lt;DeathEvent> _deathEventPool = default;          public void Run (EcsSystems systems) {             foreach (var entity in _heavyAttacksApplied.Value) {                 ref var ability = ref _abilityPool.Value.Get (entity);                 ref var applied = ref _heavyAttacksApplied.Pools.Inc2.Get (entity);                 ref var unit = ref _unitPool.Value.Get (applied.Target);                  unit.Health -= ability.Damage;                  if (unit.Health &lt;= 0) {                     _deathEventPool.Value.Add (applied.Target);                 }             }         }     } }<\/code><\/pre>\n<pre><code class=\"cs\"> namespace Client {     sealed class PowerShotAbilitySystem : IEcsRunSystem {         readonly EcsFilterInject&lt;Inc&lt;PowerShot, Applied>> _powerShotsApplied = default;          readonly EcsPoolInject&lt;Unit> _unitPool = default;         readonly EcsPoolInject&lt;Ability> _abilityPool = default;         readonly EcsPoolInject&lt;DeathEvent> _deathEventPool = default;          public void Run (EcsSystems systems) {             foreach (var entity in _powerShotsApplied.Value) {                 ref var ability = ref _abilityPool.Value.Get (entity);                 ref var applied = ref _powerShotsApplied.Pools.Inc2.Get (entity);                 ref var unit = ref _unitPool.Value.Get (applied.Target);                  unit.Health -= ability.Damage;                  if (unit.Health &lt;= 0) {                     _deathEventPool.Value.Add (applied.Target);                 }             }         }     } }<\/code><\/pre>\n<p>\u0414\u0430, \u0432\u044b\u0448\u043b\u043e \u043e\u0447\u0435\u043d\u044c \u043f\u043e\u0445\u043e\u0436\u0435, \u043d\u043e \u0443 \u0441\u043f\u043e\u0441\u043e\u0431\u043d\u043e\u0441\u0442\u0435\u0439 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0440\u0430\u0437\u043d\u0430\u044f \u043b\u043e\u0433\u0438\u043a\u0430. \u041a \u0442\u043e\u043c\u0443 \u0436\u0435, \u0433\u0435\u0439\u043c \u0434\u0438\u0437\u0430\u0439\u043d\u0435\u0440 \u043c\u043e\u0436\u0435\u0442 \u043f\u043e\u0442\u0440\u0435\u0431\u043e\u0432\u0430\u0442\u044c \u0440\u0430\u0437\u043d\u043e\u0433\u043e \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u044f \u0432 \u043b\u044e\u0431\u043e\u0439 \u043c\u043e\u043c\u0435\u043d\u0442, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043c\u044b \u043e\u0441\u0442\u0430\u0432\u0438\u043c \u044d\u0442\u043e \u043f\u043e\u0432\u0442\u043e\u0440\u0435\u043d\u0438\u0435.<\/p>\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0442\u0430\u043a\u0436\u0435 \u043e\u0442\u043e\u0431\u0440\u0430\u0437\u0438\u043c \u043d\u0430 \u044d\u043a\u0440\u0430\u043d\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u041e\u0414 \u0438\u0433\u0440\u043e\u043a\u0430. \u0412\u0441\u0435, \u0447\u0442\u043e \u043d\u0443\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c, \u044d\u0442\u043e \u0441\u043e\u0437\u0434\u0430\u0442\u044c TMP \u043d\u0430 \u043a\u0430\u043d\u0432\u0430\u0441\u0435, \u0440\u0430\u0441\u043f\u043e\u043b\u043e\u0436\u0438\u0442\u044c \u0435\u0433\u043e \u0442\u0430\u043c, \u0433\u0434\u0435 \u0432\u0430\u043c \u0443\u0434\u043e\u0431\u043d\u043e, \u043f\u0440\u043e\u0438\u043d\u0436\u0435\u043a\u0442\u0438\u0442\u044c \u0435\u0433\u043e \u0447\u0435\u0440\u0435\u0437 \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u0435 \u0434\u043b\u044f uGui \u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u043e\u043c \u043f\u0440\u0438\u043a\u0440\u0435\u043f\u043b\u0435\u043d\u0438\u044f \u043a \u0432\u0438\u0434\u0436\u0435\u0442\u0443 NoAction, \u0432\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u044e \u0438 \u043e\u0431\u043d\u043e\u0432\u043b\u044f\u0442\u044c \u0432 \u043a\u043e\u0434\u0435 \u043a\u0430\u0436\u0434\u044b\u0439 \u0440\u0430\u0437, \u043a\u043e\u0433\u0434\u0430 \u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f \u0443 \u043a\u043e\u0433\u043e-\u0442\u043e \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u041e\u0414 \u043f\u0430\u0440\u043e\u0439 \u0441\u0442\u0440\u043e\u0447\u0435\u043a:<\/p>\n<pre><code class=\"cs\">[EcsUguiNamed (Idents.Ui.PlayerAp)] readonly TextMeshProUGUI _playerAp = default; ... if (unit.Side == Side.User) {     _playerAp.text = unit.ActionPoints.ToString (); }<\/code><\/pre>\n<p>\u041e\u0441\u0442\u0430\u043b\u043e\u0441\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u043c\u0435\u0440\u0442\u044c \u044e\u043d\u0438\u0442\u043e\u0432. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043d\u0430\u043c \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u0438\u0442\u0441\u044f MonoBehaviour \u043a\u043b\u0430\u0441\u0441 UnitView, \u0443 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u0431\u0443\u0434\u0435\u0442 API \u0434\u043b\u044f \u043f\u0435\u0440\u0435\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u0430\u043d\u0438\u043c\u0430\u0446\u0438\u0439 &#8212; \u0442\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u043c\u044b \u0441\u043c\u043e\u0436\u0435\u043c \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c \u0441 \u0432\u0438\u0437\u0443\u0430\u043b\u043e\u043c, \u043d\u0435 \u0437\u043d\u0430\u044f \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e\u0441\u0442\u0435\u0439 \u0438\u0435\u0440\u0430\u0440\u0445\u0438\u0438 \u043f\u0440\u0435\u0444\u0430\u0431\u0430, \u0442.\u0435. \u044d\u0442\u043e \u0441\u0432\u043e\u0435\u0433\u043e \u0440\u043e\u0434\u0430 \u0443\u0440\u043e\u0432\u0435\u043d\u044c \u0430\u0431\u0441\u0442\u0440\u0430\u043a\u0446\u0438\u0438.<\/p>\n<pre><code class=\"cs\">namespace Client {     sealed class UnitDeathSystem : IEcsRunSystem {         readonly EcsFilterInject&lt;Inc&lt;Unit, DeathEvent>> _deadUnits = default;          readonly EcsPoolInject&lt;Cell> _cellPool = default;         readonly EcsPoolInject&lt;Unit> _unitPool = default;          readonly EcsCustomInject&lt;GridService> _gs = default;         readonly EcsCustomInject&lt;RoundService> _rs = default;          [EcsUguiNamed (Idents.Ui.GameOverPopup)]         readonly GameObject _popup = default;          public void Run (EcsSystems systems) {             foreach (var entity in _deadUnits.Value) {                 ref var unit = ref _deadUnits.Pools.Inc1.Get (entity);                  switch (unit.Side) {                     case Side.Enemy:                         var (cellEntity, ok) = _gs.Value.GetCell (unit.CellCoords);                          if (ok) {                             ref var cell = ref _cellPool.Value.Get (cellEntity);                             cell.Entity = -1;                         }                          unit.View.DieAnim ();                         break;                     case Side.User:                         var (cellEntity2, ok2) = _gs.Value.GetCell (unit.CellCoords);                          if (ok2) {                             ref var cell = ref _cellPool.Value.Get (cellEntity2);                             cell.Entity = -1;                         }                                                  _popup.SetActive (true);                         break;                 }                  _unitPool.Value.GetWorld ().DelEntity (entity);             }         }     } }<\/code><\/pre>\n<pre><code class=\"cs\">namespace Client {     sealed class UnitView : MonoBehaviour {         public Animator Animator;          public void DieAnim () {             Animator.SetTrigger (\"Dead\");         }     } }<\/code><\/pre>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/33e\/6fe\/8cc\/33e6fe8ccc5f6cca286d057bec0e3734.png\" width=\"831\" height=\"389\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/33e\/6fe\/8cc\/33e6fe8ccc5f6cca286d057bec0e3734.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u041d\u0435 \u0437\u0430\u0431\u0443\u0434\u044c\u0442\u0435 \u043f\u0440\u0438\u043a\u0440\u0435\u043f\u0438\u0442\u044c \u044d\u0442\u043e\u0442 \u043c\u043e\u043d\u043e\u0431\u0435\u0445 \u043a \u043f\u0440\u0435\u0444\u0430\u0431\u0443 \u044e\u043d\u0438\u0442\u0430 \u0438 \u0441\u043e\u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0441\u0441\u044b\u043b\u043a\u0443 \u043d\u0430 \u043d\u0435\u0433\u043e \u0432 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0435 Unit \u0432 \u0438\u043d\u0438\u0442-\u0441\u0438\u0441\u0442\u0435\u043c\u0430\u0445 \u0438\u0433\u0440\u043e\u043a\u0430 \u0438 \u0418\u0418.<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/391\/f3c\/884\/391f3c8849b60dd05814b838b96903b8.png\" alt=\"\u0412 \u0430\u0442\u0430\u043a\u0443!\" title=\"\u0412 \u0430\u0442\u0430\u043a\u0443!\" width=\"1161\" height=\"863\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/391\/f3c\/884\/391f3c8849b60dd05814b838b96903b8.png\"\/><figcaption>\u0412 \u0430\u0442\u0430\u043a\u0443!<\/figcaption><\/figure>\n<p>\u041f\u0440\u0435\u043a\u0440\u0430\u0441\u043d\u043e, \u043c\u044b \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043b\u0438 \u0441\u0438\u0441\u0442\u0435\u043c\u0443 \u0441\u043f\u043e\u0441\u043e\u0431\u043d\u043e\u0441\u0442\u0435\u0439, \u0445\u043e\u0434\u043e\u0432 \u0438 \u0441\u0434\u0435\u043b\u0430\u043b\u0438 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u044b\u0445 \u0432\u0440\u0430\u0433\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0441\u0440\u0430\u0436\u0430\u044e\u0442\u0441\u044f \u0441 \u0438\u0433\u0440\u043e\u043a\u043e\u043c, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0441\u0432\u043e\u0438 \u0430\u0431\u0438\u043b\u043a\u0438!<\/p>\n<ul>\n<li>\n<p><a href=\"https:\/\/github.com\/supremestranger\/dungeon-crawler\" rel=\"noopener noreferrer nofollow\">\u0421\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0439 \u0441 \u043f\u0440\u043e\u0435\u043a\u0442\u043e\u043c<\/a><\/p>\n<\/li>\n<\/ul>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"v-portal\" style=\"display:none;\"><\/div>\n<\/div>\n<p> <!----> <!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/post\/673926\/\"> https:\/\/habr.com\/ru\/post\/673926\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p><em>\u0414\u0440\u0443\u0437\u044c\u044f, \u0432 \u044d\u0442\u043e\u0439 \u0447\u0430\u0441\u0442\u0438 \u043c\u044b \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0432\u0440\u0430\u0433\u043e\u0432, \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u043c \u043f\u043e\u043e\u0447\u0435\u0440\u0435\u0434\u043d\u0443\u044e \u0441\u0438\u0441\u0442\u0435\u043c\u0443 \u0445\u043e\u0434\u043e\u0432, \u043c\u0435\u0445\u0430\u043d\u0438\u043a\u0443 \u0441\u043f\u043e\u0441\u043e\u0431\u043d\u043e\u0441\u0442\u0435\u0439 \u0438 \u043d\u0430\u043f\u0438\u0448\u0435\u043c \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u0418\u0418 \u0432\u0440\u0430\u0436\u0435\u0441\u043a\u0438\u043c \u044e\u043d\u0438\u0442\u0430\u043c.<\/em><\/p>\n<p><em>\u041f\u0435\u0440\u0435\u0434 \u043f\u0440\u043e\u0447\u0442\u0435\u043d\u0438\u0435\u043c \u044d\u0442\u043e\u0439 \u0447\u0430\u0441\u0442\u0438 \u043e\u0437\u043d\u0430\u043a\u043e\u043c\u044c\u0442\u0435\u0441\u044c \u0441 <\/em><a href=\"https:\/\/habr.com\/ru\/post\/661085\/\" rel=\"noopener noreferrer nofollow\"><em>\u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0439<\/em><\/a><em>.<\/em><\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u041d\u043e \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u043d\u0430\u0447\u043d\u0435\u043c \u0441 \u0440\u0430\u0437\u0434\u0435\u043b\u0435\u043d\u0438\u044f MonoBehaviour \u043a\u043b\u0430\u0441\u0441\u0430 <em>CellView<\/em> \u043d\u0430 \u0434\u0432\u0430: <strong>SnapTransform<\/strong> \u0438 <strong>CellView<\/strong>. \u042d\u0442\u043e \u043d\u0443\u0436\u043d\u043e, \u0447\u0442\u043e\u0431\u044b \u043e\u0442\u0434\u0435\u043b\u0438\u0442\u044c \u043f\u0440\u0438\u043c\u0430\u0433\u043d\u0438\u0447\u0438\u0432\u0430\u043d\u0438\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u043a \u043a\u043b\u0435\u0442\u043a\u0435 \u043d\u0430 \u0441\u0435\u0442\u043a\u0435 \u0438 \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u0435\u0435 \u0432 \u0440\u0435\u0434\u0430\u043a\u0442\u043e\u0440\u0435, \u0442\u043e \u0435\u0441\u0442\u044c \u043f\u043e \u0441\u0443\u0442\u0438 \u0440\u0430\u0437\u0433\u0440\u0430\u043d\u0438\u0447\u0438\u0442\u044c \u0434\u0432\u0430 \u0440\u0430\u0437\u043d\u044b\u0445 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u044f.<\/p>\n<pre><code class=\"cs\">namespace Client { #if UNITY_EDITOR     [ExecuteAlways]     [SelectionBase] #endif     sealed class SnapTransform : MonoBehaviour {         public Transform Transform;         public float XzStep = 3f;         public float YStep = 1f;          #if UNITY_EDITOR         void Awake () {             Transform = transform;         }          void Update () {             if (!Application.isPlaying &amp;&amp; Transform.hasChanged) {                 var newPos = Vector3.zero;                 var curPos = Transform.localPosition;                 newPos.x = Mathf.RoundToInt (curPos.x \/ XzStep) * XzStep;                 newPos.z = Mathf.RoundToInt (curPos.z \/ XzStep) * XzStep;                 newPos.y = Mathf.RoundToInt (curPos.y \/ YStep) * YStep;                 Transform.localPosition = newPos;             }         } #endif     } }<\/code><\/pre>\n<pre><code class=\"cs\">namespace Client { #if UNITY_EDITOR     [ExecuteAlways]     [SelectionBase] #endif     sealed class CellView : MonoBehaviour {         public Transform Transform;         public float Size = 3f;  #if UNITY_EDITOR         void Awake () {             Transform = transform;         }                  void OnDrawGizmos () {             var selected = Selection.Contains (gameObject);             Gizmos.color = selected ? Color.green : Color.cyan;             var yAdd = selected ? 0.02f : 0f;             var curPos = Transform.localPosition;             var leftDown = curPos - Vector3.right * Size \/ 2 - Vector3.forward * Size \/ 2 + Vector3.up * yAdd;             var leftUp = curPos - Vector3.right * Size \/ 2 + Vector3.forward * Size \/ 2 + Vector3.up * yAdd;             var rightDown = curPos + Vector3.right * Size \/ 2 - Vector3.forward * Size \/ 2 + Vector3.up * yAdd;             var rightUp = curPos + Vector3.right * Size \/ 2 + Vector3.forward * Size \/ 2 + Vector3.up * yAdd;             Gizmos.DrawLine (leftDown, leftUp);             Gizmos.DrawLine (leftUp, rightUp);             Gizmos.DrawLine (rightUp, rightDown);             Gizmos.DrawLine (rightDown, leftDown);             Gizmos.DrawSphere (curPos, 0.1f);         } #endif     } }<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043c\u044b \u0441\u043c\u043e\u0436\u0435\u043c \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u0441\u043f\u0430\u0443\u043d-\u043c\u0430\u0440\u043a\u0435\u0440\u044b \u0434\u043b\u044f \u0432\u0440\u0430\u0433\u043e\u0432, \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0442\u044c \u043a \u043d\u0438\u043c \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 <strong>SnapTransform<\/strong> \u0438 \u0443\u0434\u043e\u0431\u043d\u043e \u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0438\u0445 \u043d\u0430 \u0441\u0435\u0442\u043a\u0435 \u0431\u0435\u0437 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u0432\u044b\u0434\u0435\u043b\u044f\u0442\u044c \u0438\u0445 \u043a\u0430\u043a \u043a\u043b\u0435\u0442\u043a\u0443. (\u0441\u0430\u043c\u0438 \u043a\u043b\u0435\u0442\u043a\u0438 \u0431\u0443\u0434\u0443\u0442 \u0438\u043c\u0435\u0442\u044c \u043e\u0431\u0430 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430)<\/p>\n<pre><code class=\"cs\">namespace Client {     sealed class SpawnMarker : MonoBehaviour {         public Transform Transform;         public string PrefabName; \/\/ \u0438\u043c\u044f \u043f\u0440\u0435\u0444\u0430\u0431\u0430         public Side Side;          public void Awake () {             Transform = transform;         }     } }<\/code><\/pre>\n<p>\u041a\u0430\u043a \u0432\u0438\u0434\u0438\u0442\u0435, \u0437\u0434\u0435\u0441\u044c \u0435\u0441\u0442\u044c \u043f\u043e\u043b\u0435 \u0442\u0438\u043f\u0430 <strong>Side<\/strong>. \u042d\u0442\u043e \u043f\u0440\u043e\u0441\u0442\u043e\u0439 enum, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043e\u0431\u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442 \u0441\u0442\u043e\u0440\u043e\u043d\u0443 \u044e\u043d\u0438\u0442\u0430 (\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\/\u0418\u0418).<\/p>\n<pre><code class=\"cs\">namespace Client {     public enum Side {         User = 0,         Enemy = 1,     } }<\/code><\/pre>\n<p>\u041a\u0430\u043a \u0432\u044b \u043f\u043e\u043c\u043d\u0438\u0442\u0435, \u0432 \u043f\u0440\u043e\u0448\u043b\u043e\u0439 \u0447\u0430\u0441\u0442\u0438 \u043c\u044b \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043b\u0438 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u043d\u043e\u0435 \u043c\u0435\u043d\u044e \u0432 \u043a\u043b\u0430\u0441\u0441\u0435 SceneData \u0434\u043b\u044f \u043f\u043e\u0438\u0441\u043a\u0430 \u043a\u043b\u0435\u0442\u043e\u043a \u043d\u0430 \u043a\u0430\u0440\u0442\u0435. \u0421\u0434\u0435\u043b\u0430\u0435\u043c \u0442\u043e \u0436\u0435 \u0441\u0430\u043c\u043e\u0435 \u0434\u043b\u044f \u0441\u043f\u0430\u0443\u043d \u043c\u0430\u0440\u043a\u0435\u0440\u043e\u0432.<\/p>\n<pre><code class=\"cs\">namespace Client {     sealed class SceneData : MonoBehaviour {         public CellView[] Cells;         public SpawnMarker[] Markers;          #if UNITY_EDITOR         [ContextMenu (\"Find Cells\")]         void FindCells () {             Cells = FindObjectsOfType&lt;CellView> ();             Debug.Log ($\"Successfully found {Cells.Length} cells!\");         }          [ContextMenu (\"Find Markers\")]         void FindMarkers () {             Markers = FindObjectsOfType&lt;SpawnMarker> ();             Debug.Log ($\"Successfully found {Markers.Length} markers!\");         } #endif     } }<\/code><\/pre>\n<p>\u0422\u0430\u043a\u0436\u0435 \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u0440\u0430\u0437\u043c\u0435\u0440 \u043a\u043b\u0435\u0442\u043a\u0438 \u0438 \u043c\u0435\u0442\u043e\u0434 InBounds \u0432 <strong>GridService<\/strong>, \u044d\u0442\u043e \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u0438\u0442\u0441\u044f \u043d\u0430\u043c \u043f\u0440\u0438 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0438 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0435 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u044f \u0432\u0440\u0430\u0433\u043e\u0432.<\/p>\n<pre><code class=\"cs\">namespace Client {     sealed class GridService {         public int CellSize = 3;          readonly int[] _cells;         readonly int _width;         readonly int _height;          public GridService (int width, int height) {             _cells = new int[width * height];             _width = width;              _height = height;         }          public (int, bool) GetCell (Int2 coords) {             if (!InBounds (coords)) {                 return (-1, false);             }                          var entity = _cells[_width * coords.Y + coords.X] - 1;             return (entity, entity >= 0);         }          bool InBounds (Int2 coords) {             return coords.X >= 0 &amp;&amp; coords.Y >= 0;         }          public void AddCell (Int2 coords, int entity) {             _cells[_width * coords.Y + coords.X] = entity + 1;         }     } } <\/code><\/pre>\n<p>\u0422\u0430\u043a\u0436\u0435 \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u043f\u043e\u043b\u0435 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438 \u0432 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 \u043a\u043b\u0435\u0442\u043a\u0438 &#8212; \u044d\u0442\u043e \u043d\u0443\u0436\u043d\u043e \u0431\u0443\u0434\u0435\u0442, \u0447\u0442\u043e\u0431\u044b \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c, \u043a\u0430\u043a\u0438\u0435 \u043a\u043b\u0435\u0442\u043a\u0438 \u043a\u0435\u043c \u0437\u0430\u043d\u044f\u0442\u044b \u0438\u043b\u0438 \u043d\u0435 \u0437\u0430\u043d\u044f\u0442\u044b \u0432\u043e\u0432\u0441\u0435.<\/p>\n<pre><code class=\"cs\">namespace Client {     struct Cell {         public CellView View;         public int Entity;     } }<\/code><\/pre>\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043e\u0431\u043d\u043e\u0432\u0438\u043c \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 <strong>Unit<\/strong>. \u041d\u0443\u0436\u043d\u043e \u0431\u0443\u0434\u0435\u0442 \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0442\u0430\u043a\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0435, \u043a\u0430\u043a \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043e\u0447\u043a\u043e\u0432 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f (\u0434\u0430\u043b\u0435\u0435 \u041e\u0414), &#171;\u0438\u043d\u0438\u0446\u0438\u0430\u0442\u0438\u0432\u0443&#187; (\u044d\u0442\u043e \u043d\u0443\u0436\u043d\u043e \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u0438 \u0432\u044b\u0431\u043e\u0440\u0435 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0433\u043e \u044e\u043d\u0438\u0442\u0430 \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u0441\u043c\u0435\u043d\u044b \u0445\u043e\u0434\u0430), \u0437\u0434\u043e\u0440\u043e\u0432\u044c\u0435, \u0440\u0430\u0434\u0438\u0443\u0441 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f (\u043d\u0443\u0436\u043d\u043e \u0431\u0443\u0434\u0435\u0442 \u0434\u043b\u044f \u0418\u0418) \u0438 \u0441\u0442\u043e\u0440\u043e\u043d\u0443.<\/p>\n<pre><code class=\"cs\">namespace Client {     struct Unit {         public Direction Direction;         public Int2 CellCoords;         public Transform Transform;         public Vector3 Position;         public Quaternion Rotation;         public float MoveSpeed;         public float RotateSpeed;         public int ActionPoints;         public int Initiative;         public int Health;         public int Radius;         public Side Side;     } }<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0440\u0430\u0437\u0431\u0435\u0440\u0435\u043c\u0441\u044f \u0441 \u043c\u0435\u0445\u0430\u043d\u0438\u043a\u043e\u0439 \u0441\u043f\u043e\u0441\u043e\u0431\u043d\u043e\u0441\u0442\u0435\u0439.<\/p>\n<p>\u041c\u044b \u0431\u0443\u0434\u0435\u043c \u0445\u0440\u0430\u043d\u0438\u0442\u044c \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u044e \u0441\u043f\u043e\u0441\u043e\u0431\u043d\u043e\u0441\u0442\u0438 \u0432 \u0444\u043e\u0440\u043c\u0430\u0442\u0435 <strong>Scriptable Object<\/strong> \u0432 Unity. \u041a\u0430\u0436\u0434\u0430\u044f \u0441\u043f\u043e\u0441\u043e\u0431\u043d\u043e\u0441\u0442\u044c \u0431\u0443\u0434\u0435\u0442 \u0438\u043c\u0435\u0442\u044c \u0441\u0432\u043e\u0451 \u0438\u043c\u044f, \u0441\u0442\u043e\u0438\u043c\u043e\u0441\u0442\u044c \u043e\u0447\u043a\u043e\u0432 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f, \u0434\u0438\u0441\u0442\u0430\u043d\u0446\u0438\u044e \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0438 \u0443\u0440\u043e\u043d.<\/p>\n<pre><code class=\"cs\">namespace Client {     [CreateAssetMenu]     public class AbilityConfig : ScriptableObject {         public string Name;         public int ActionPointsCost;         public int Damage;         public int Distance;     } }<\/code><\/pre>\n<p>\u0422\u0430\u043a\u0436\u0435 \u0443\u0434\u043e\u0431\u043d\u043e \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u044c \u043a\u043e\u043d\u0444\u0438\u0433 \u0430\u0431\u0438\u043b\u043a\u0438 \u0447\u0435\u0440\u0435\u0437 \u043a\u0430\u043a\u043e\u0439-\u043d\u0438\u0431\u0443\u0434\u044c \u0447\u0438\u0441\u043b\u043e\u0432\u043e\u0439 \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440. \u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043f\u043e\u043b\u0435 \u043c\u0430\u0441\u0441\u0438\u0432 Scriptable Object&#8217;\u043e\u0432 \u0432 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u043c \u043a\u043e\u043d\u0444\u0438\u0433\u0435 <strong>Configuration<\/strong>.<\/p>\n<pre><code class=\"cs\">namespace Client {     [CreateAssetMenu]     sealed class Configuration : ScriptableObject {         public int GridWidth;         public int GridHeight;         public LayerMask UnitLayerMask;         public AbilityConfig[] AbilitiesConfigs;     } }<\/code><\/pre>\n<p>\u041a\u0430\u0436\u0434\u044b\u0439 \u044e\u043d\u0438\u0442 \u0431\u0443\u0434\u0435\u0442 \u0438\u043c\u0435\u0442\u044c \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 <strong>HasAbilities<\/strong> \u0441\u043e \u0441\u043f\u0438\u0441\u043a\u043e\u043c \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0435\u0439 \u0434\u043b\u044f \u0430\u0431\u0438\u043b\u043e\u043a. \u041a\u0430\u043a \u0432\u044b \u0443\u0436\u0435 \u043f\u043e\u043d\u044f\u043b\u0438, \u043a\u0430\u0436\u0434\u0430\u044f \u0441\u043f\u043e\u0441\u043e\u0431\u043d\u043e\u0441\u0442\u044c \u0431\u0443\u0434\u0435\u0442 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e\u0439 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u044c\u044e \u0441 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u043e\u043c <strong>Ability<\/strong>, \u0432 \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u044b \u0441\u043e\u0445\u0440\u0430\u043d\u0438\u043c \u0441\u0442\u043e\u0438\u043c\u043e\u0441\u0442\u044c \u0432 \u041e\u0414, \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u044c \u0432\u043b\u0430\u0434\u0435\u043b\u044c\u0446\u0430, \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440, \u0434\u0438\u0441\u0442\u0430\u043d\u0446\u0438\u044e \u0438 \u0443\u0440\u043e\u043d.<\/p>\n<pre><code class=\"cs\">namespace Client {     struct HasAbilities : IEcsAutoReset&lt;HasAbilities> {         public List&lt;int> Entities;          public void AutoReset (ref HasAbilities c) {             c.Entities ??= new List&lt;int> (64);         }     } }<\/code><\/pre>\n<pre><code class=\"cs\">namespace Client {     struct Ability {         public int ActionPointsCost;         public int OwnerEntity;         public int Id;         public int Damage;         public int Distance;     } }<\/code><\/pre>\n<p>\u041a\u043e\u0433\u0434\u0430 \u043d\u0443\u0436\u043d\u043e \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u0442\u044c \u0441\u043f\u043e\u0441\u043e\u0431\u043d\u043e\u0441\u0442\u044c, \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0442\u044c \u043a \u0435\u0435 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 <strong>Applied<\/strong> \u0438 \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0442\u044c \u0432\u043d\u0443\u0442\u0440\u0438 \u044d\u043d\u0442\u0438\u0442\u0438 \u0446\u0435\u043b\u0438.<\/p>\n<pre><code class=\"cs\">namespace Client {     struct Applied {         public int Target;     } }<\/code><\/pre>\n<p>\u0422\u0430\u043a\u0436\u0435 \u0443 \u043a\u0430\u0436\u0434\u043e\u0439 \u0441\u043f\u043e\u0441\u043e\u0431\u043d\u043e\u0441\u0442\u0438 \u0431\u0443\u0434\u0435\u0442 \u0441\u0432\u043e\u0439 \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u044b\u0439 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439, \u043f\u043e \u0441\u0443\u0442\u0438, \u0435\u0435 \u043e\u0431\u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442. \u0414\u043e\u043f\u0443\u0441\u0442\u0438\u043c, \u0441\u043f\u043e\u0441\u043e\u0431\u043d\u043e\u0441\u0442\u044c &#171;\u0441\u043b\u0430\u0431\u043e\u0439 \u0430\u0442\u0430\u043a\u0438&#187; \u0431\u0443\u0434\u0435\u0442 \u0438\u043c\u0435\u0442\u044c \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 <strong>LightAttack<\/strong>, \u0441\u043f\u043e\u0441\u043e\u0431\u043d\u043e\u0441\u0442\u044c &#171;\u0441\u0438\u043b\u044c\u043d\u043e\u0439&#187; &#8212; <strong>HeavyAttack<\/strong>. \u042d\u0442\u043e \u043d\u0443\u0436\u043d\u043e \u0431\u0443\u0434\u0435\u0442, \u0447\u0442\u043e\u0431\u044b \u0443 \u043a\u0430\u0436\u0434\u043e\u0439 \u0441\u043f\u043e\u0441\u043e\u0431\u043d\u043e\u0441\u0442\u0438 \u0431\u044b\u043b\u0430 \u0441\u0432\u043e\u044f \u043b\u043e\u0433\u0438\u043a\u0430 \u0441\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u043d\u0438\u044f.<\/p>\n<p>\u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0439 \u0441\u0435\u0440\u0432\u0438\u0441 <strong>AbilityHelper<\/strong>, \u0433\u0434\u0435 \u0431\u0443\u0434\u0435\u043c \u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0441\u043b\u043e\u0432\u0430\u0440\u044c \u0441 \u0447\u0438\u0441\u043b\u043e\u043c \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043a\u043b\u044e\u0447\u0430 \u0438 \u043a\u043e\u043b\u043b\u0431\u0435\u043a\u043e\u043c \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f. \u041f\u043e \u0441\u0443\u0442\u0438 \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u044c \u0441\u0441\u044b\u043b\u043a\u0443 \u043d\u0430 \u043c\u0435\u0442\u043e\u0434 \u0434\u043b\u044f \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430 \u043f\u043e \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u0443 \u0441\u043f\u043e\u0441\u043e\u0431\u043d\u043e\u0441\u0442\u0438, \u0442\u043e \u0435\u0441\u0442\u044c \u0441\u043e\u043f\u043e\u0441\u0442\u0430\u0432\u0438\u043c \u0447\u0438\u0441\u043b\u043e \u0441 \u0442\u0438\u043f\u043e\u043c.<\/p>\n<pre><code class=\"cs\">namespace Client {     sealed class AbilityHelper {         readonly Dictionary&lt;int, Action&lt;EcsWorld, int>> _addComponentCallbacks;          public AbilityHelper () {             _addComponentCallbacks = new Dictionary&lt;int, Action&lt;EcsWorld, int>> {                 { 0, AddComponent&lt;LightAttack> },                 { 1, AddComponent&lt;HeavyAttack> },               { 2, AddComponent&lt;PowerShot> }             };         }          void AddComponent&lt;T> (EcsWorld world, int entity) where T : struct {             world.GetPool&lt;T> ().Add (entity);         }          public Action&lt;EcsWorld, int> GetAddComponentCallback (int abilityIdx) {             return _addComponentCallbacks.TryGetValue (abilityIdx, out Action&lt;EcsWorld, int> cb) ? cb : null;         }     } }<\/code><\/pre>\n<p>\u041d\u0435 \u0437\u0430\u0431\u0443\u0434\u044c\u0442\u0435 \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 \u044d\u0442\u043e\u0433\u043e \u0441\u0435\u0440\u0432\u0438\u0441\u0430 \u0432 \u0441\u0442\u0430\u0440\u0442\u0430\u043f\u0435 \u0438 \u043f\u0440\u043e\u0438\u043d\u0436\u0435\u043a\u0442\u0438\u0442\u044c \u0441\u0441\u044b\u043b\u043a\u0443 \u043d\u0430 \u043d\u0435\u0433\u043e \u0432 \u0441\u0438\u0441\u0442\u0435\u043c\u044b.<\/p>\n<p>\u042f \u0441\u043e\u0437\u0434\u0430\u043b \u0442\u0440\u0438 SO-\u0430\u0431\u0438\u043b\u043a\u0438: LightAttack, PowerShot \u0438 HeavyAttack \u0438 \u0434\u043e\u0431\u0430\u0432\u0438\u043b \u0438\u0445 \u0432 \u0441\u043f\u0438\u0441\u043e\u043a \u0441\u043f\u043e\u0441\u043e\u0431\u043d\u043e\u0441\u0442\u0435\u0439 \u0432 \u0433\u043b\u0430\u0432\u043d\u043e\u043c \u043a\u043e\u043d\u0444\u0438\u0433\u0435.<\/p>\n<p>\u041d\u0430 \u044d\u043a\u0440\u0430\u043d\u0435 \u0431\u0443\u0434\u0443\u0442 \u043a\u043d\u043e\u043f\u043a\u0438 \u0434\u043b\u044f \u0441\u043f\u043e\u0441\u043e\u0431\u043d\u043e\u0441\u0442\u0435\u0439, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u044b \u0438\u043d\u0441\u0442\u0430\u043d\u0446\u0438\u0440\u0443\u0435\u043c \u043d\u0430 \u0441\u0442\u0430\u0440\u0442\u0435 \u0438\u0433\u0440\u044b. \u041a\u043d\u043e\u043f\u043a\u0430 \u0434\u043e\u043b\u0436\u043d\u0430 \u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0438\u043d\u0434\u0435\u043a\u0441 \u0441\u043f\u043e\u0441\u043e\u0431\u043d\u043e\u0441\u0442\u0438 \u0432 \u043c\u0430\u0441\u0441\u0438\u0432\u0435, \u0445\u0440\u0430\u043d\u044f\u0449\u0435\u043c\u0441\u044f \u0432 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0435 HasAbilities \u0443 \u044e\u043d\u0438\u0442\u0430 \u0438\u0433\u0440\u043e\u043a\u0430. \u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0439 \u043c\u043e\u043d\u043e\u0431\u0435\u0445 <strong>AbilityView<\/strong>, \u0432 \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0442\u0430\u043a\u0436\u0435 \u0441\u043e\u0445\u0440\u0430\u043d\u0438\u043c \u0441\u0441\u044b\u043b\u043a\u0438 \u043d\u0430 TMP \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u044f \u0441\u043f\u043e\u0441\u043e\u0431\u043d\u043e\u0441\u0442\u0438 \u0438 \u0446\u0438\u0444\u0440\u044b, \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0435\u0439 \u043a\u043b\u0430\u0432\u0438\u0448\u0435 \u043d\u0430 \u043a\u043b\u0430\u0432\u0438\u0430\u0442\u0443\u0440\u0435 \u0434\u043b\u044f \u0430\u043a\u0442\u0438\u0432\u0430\u0446\u0438\u0438 \u0441\u043f\u043e\u0441\u043e\u0431\u043d\u043e\u0441\u0442\u0438.<\/p>\n<pre><code class=\"cs\">namespace Client {     sealed class AbilityView : MonoBehaviour {         \/\/ Ability index for owner.         public int AbilityIdx;         public TextMeshProUGUI Name;         public TextMeshProUGUI KeyIdx;     } }<\/code><\/pre>\n<p>\u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0442\u0430\u043a\u0436\u0435 \u0441\u0435\u0440\u0432\u0438\u0441, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0430\u043a\u0442\u0438\u0432\u043d\u0443\u044e \u0441\u0442\u043e\u0440\u043e\u043d\u0443 \u0438 \u0430\u043a\u0442\u0438\u0432\u043d\u043e\u0433\u043e \u044e\u043d\u0438\u0442\u0430.<\/p>\n<pre><code class=\"cs\">namespace Client {     sealed class RoundService {         public Side ActiveSide;         public readonly int StateMax = 2;          public int ActiveUnit;          public RoundService (Side activeSide) {             ActiveSide = activeSide;         }     } }<\/code><\/pre>\n<p>\u0414\u0432\u0438\u0436\u0435\u043c\u0441\u044f \u0434\u0430\u043b\u044c\u0448\u0435. \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043e\u0431\u043d\u043e\u0432\u0438\u043c<\/p>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-335097","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/335097","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=335097"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/335097\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=335097"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=335097"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=335097"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}