{"id":347340,"date":"2023-03-27T15:01:38","date_gmt":"2023-03-27T15:01:38","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=347340"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=347340","title":{"rendered":"<span>\u0410\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0430 \u0438\u0433\u0440\u044b \u043d\u0430 Unity \u0431\u0435\u0437 Zenject. \u0427\u0430\u0441\u0442\u044c 1<\/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<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/eb7\/258\/09a\/eb725809a843375d46a211b3116d2da8.png\" width=\"780\" height=\"439\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/eb7\/258\/09a\/eb725809a843375d46a211b3116d2da8.png\"\/><\/figure>\n<div class=\"persona\" persona=\"true\"><img decoding=\"async\" persona=\"true\" class=\"image persona__image\" src=\"https:\/\/habrastorage.org\/r\/w780q1\/getpro\/habr\/upload_files\/2c8\/abc\/125\/2c8abc1257154e783575300b258f691e.jpg\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/2c8\/abc\/125\/2c8abc1257154e783575300b258f691e.jpg\" data-blurred=\"true\"\/><\/p>\n<h5 class=\"persona__heading\" persona=\"true\">\u0410\u0432\u0442\u043e\u0440 \u0441\u0442\u0430\u0442\u044c\u0438: \u0418\u0433\u043e\u0440\u044c \u0413\u0443\u043b\u044c\u043a\u0438\u043d<\/h5>\n<p>Senior Unity Developer<\/p>\n<\/div>\n<p>\u0412\u0441\u0435\u043c \u043f\u0440\u0438\u0432\u0435\u0442!<\/p>\n<p>\u041c\u0435\u043d\u044f \u0437\u043e\u0432\u0443\u0442 \u0418\u0433\u043e\u0440\u044c \u0413\u0443\u043b\u044c\u043a\u0438\u043d, \u0438 \u044f Unity \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a. \u0417\u0430 \u0441\u0432\u043e\u0438 5 \u043b\u0435\u0442 \u043d\u0430\u043a\u043e\u043f\u0438\u043b\u043e\u0441\u044c \u043c\u043d\u043e\u0433\u043e \u043e\u043f\u044b\u0442\u0430, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0432 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u0445\u043e\u0442\u0435\u043b \u0431\u044b \u043f\u043e\u0434\u0435\u043b\u0438\u0442\u044c\u0441\u044f \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u0430\u043c\u0438 \u0438 \u043f\u043e\u0434\u0445\u043e\u0434\u0430\u043c\u0438, \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043c\u043e\u0436\u043d\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0443 \u0438\u0433\u0440\u044b \u043f\u0440\u043e\u0441\u0442\u043e \u0438 \u0433\u0438\u0431\u043a\u043e \u0431\u0435\u0437 \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u0430. \u0426\u0435\u043b\u044c \u0434\u043e\u043a\u043b\u0430\u0434\u0430, \u0434\u0430\u0442\u044c \u043d\u0435 \u043f\u0440\u043e\u0441\u0442\u043e \u0433\u043e\u0442\u043e\u0432\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435, \u0430 \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u044c \u0445\u043e\u0434 \u043c\u044b\u0441\u043b\u0435\u0439, \u043a\u0430\u043a \u043e\u043d\u0430 \u0432\u044b\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u0435\u0442\u0441\u044f.\u00a0 \u041d\u0443 \u0447\u0442\u043e \u0436 \u043f\u043e\u0435\u0445\u0430\u043b\u0438 \ud83d\ude42<\/p>\n<h3>\u041f\u0440\u0438\u043c\u0435\u0440<\/h3>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/373\/9b6\/2aa\/3739b62aaa6b49a7d3adf0b1bd6fea4b.png\" alt=\"\" title=\"\" width=\"1600\" height=\"838\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/373\/9b6\/2aa\/3739b62aaa6b49a7d3adf0b1bd6fea4b.png\"\/><\/figure>\n<p>\u00a0<\/p>\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u043e\u0436\u0438\u043c, \u0447\u0442\u043e \u043c\u044b \u0434\u0435\u043b\u0430\u0435\u043c \u0438\u0433\u0440\u0443, \u0433\u0434\u0435 \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u043c \u043a\u0443\u0431\u0438\u043a\u043e\u043c \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043a\u043b\u0430\u0432\u0438\u0430\u0442\u0443\u0440\u044b. \u041d\u0430 \u0441\u0446\u0435\u043d\u0435 \u0435\u0441\u0442\u044c GameObject\u2019\u044b:\u00a0<\/p>\n<ol>\n<li>\n<p><code>Player<\/code> \u2014 \u043a\u0443\u0431\u0438\u043a, \u043a\u043e\u0442\u043e\u0440\u044b\u043c \u0438\u0433\u0440\u043e\u043a \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442.<\/p>\n<\/li>\n<li>\n<p><code>KeyboardInput<\/code> \u2014 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0439 \u0432\u0432\u043e\u0434 \u0441 \u043a\u043b\u0430\u0432\u0438\u0430\u0442\u0443\u0440\u044b.<\/p>\n<\/li>\n<li>\n<p><code>MoveController<\/code> \u2014 \u0441\u043e\u0435\u0434\u0438\u043d\u044f\u0435\u0442 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0439 \u0432\u0432\u043e\u0434 \u0438 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442 \u0443 \u043a\u0443\u0431\u0438\u043a\u0430 <code>Player.Move().<\/code><\/p>\n<\/li>\n<\/ol>\n<p>\u0412\u043e\u0442 \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u044b\u0435 \u0441\u043a\u0440\u0438\u043f\u0442\u044b \u044d\u0442\u0438\u0445 \u043a\u043b\u0430\u0441\u0441\u043e\u0432:<\/p>\n<p>\u0421\u043a\u0440\u0438\u043f\u0442 \u043a\u0443\u0431\u0438\u043a\u0430:<\/p>\n<pre><code class=\"cpp\">public sealed class Player : MonoBehaviour     {         [SerializeField]         private float speed = 2.0f;              public void Move(Vector3 direction)         {             this.transform.position += direction * this.speed * Time.deltaTime;         }     }<\/code><\/pre>\n<p>\u0421\u043a\u0440\u0438\u043f\u0442 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u043e\u0433\u043e \u0432\u0432\u043e\u0434\u0430:<\/p>\n<pre><code class=\"cpp\">public sealed class KeyboardInput : MonoBehaviour     {         public event Action&lt;Vector3> OnMove;          private void Update()         {             this.HandleKeyboard();         }          private void HandleKeyboard()         {             if (Input.GetKey(KeyCode.UpArrow))             {                 this.Move(Vector3.forward);             }             else if (Input.GetKey(KeyCode.DownArrow))             {                 this.Move(Vector3.back);             }             else if (Input.GetKey(KeyCode.LeftArrow))             {                 this.Move(Vector3.left);             }             else if (Input.GetKey(KeyCode.RightArrow))             {                 this.Move(Vector3.right);             }         }          private void Move(Vector3 direction)         {             this.OnMove?.Invoke(direction);         }     }<\/code><\/pre>\n<p>\u0421\u043a\u0440\u0438\u043f\u0442 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0430 \u043f\u0435\u0440\u0435\u043c\u0435\u0449\u0435\u043d\u0438\u044f:<\/p>\n<pre><code class=\"cpp\">public sealed class MoveController : MonoBehaviour     {         [SerializeField]         private KeyboardInput input;          [SerializeField]         private Player player;          private void OnEnable()         {             this.input.OnMove += this.OnMove;         }          private void OnDisable()         {             this.input.OnMove -= this.OnMove;         }          private void OnMove(Vector3 direction)         {             this.player.Move(direction);         }     } <\/code><\/pre>\n<p>\u0418\u0433\u0440\u0430 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442, \u043d\u043e \u0435\u0441\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u043d\u044b\u0445 \u043d\u0435\u0434\u043e\u0441\u0442\u0430\u0442\u043a\u043e\u0432:<\/p>\n<ol>\n<li>\n<p>\u041d\u0435\u0442 \u0442\u043e\u0447\u043a\u0438 \u0432\u0445\u043e\u0434\u0430 \u0432 \u0438\u0433\u0440\u0443 \u0438 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u044f.<\/p>\n<\/li>\n<li>\n<p>\u0412\u0441\u0435 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043d\u0430 \u043a\u043b\u0430\u0441\u0441\u044b \u043f\u0440\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0432\u0440\u0443\u0447\u043d\u0443\u044e \u0447\u0435\u0440\u0435\u0437 \u0438\u043d\u0441\u043f\u0435\u043a\u0442\u043e\u0440.<\/p>\n<\/li>\n<li>\n<p>\u0412\u0441\u044f \u0438\u0433\u0440\u043e\u0432\u0430\u044f \u043b\u043e\u0433\u0438\u043a\u0430 \u043f\u0440\u0438\u0432\u044f\u0437\u0430\u043d\u0430 \u043a \u043c\u043e\u043d\u043e\u0431\u0435\u0445\u0430\u043c (MonoBehaviour).<\/p>\n<\/li>\n<li>\n<p>\u041d\u0435\u0442 \u043f\u043e\u0440\u044f\u0434\u043a\u0430 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0438\u0433\u0440\u044b.<\/p>\n<\/li>\n<\/ol>\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0443\u043b\u0443\u0447\u0448\u0430\u0442\u044c \u043d\u0430\u0448\u0443 \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0443 \u043f\u043e \u043f\u043e\u0440\u044f\u0434\u043a\u0443.<\/p>\n<h3>\u0421\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0438\u0433\u0440\u044b<\/h3>\n<p>\u0412\u0441\u0435 \u043c\u044b \u0437\u043d\u0430\u0435\u043c, \u0447\u0442\u043e \u0438\u0433\u0440\u0430 \u2014 \u044d\u0442\u043e \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u0443 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u0435\u0441\u0442\u044c \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f. \u0415\u0441\u0442\u044c \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438 \u0438\u0433\u0440\u044b, \u0441\u0442\u0430\u0440\u0442\u0430, \u043f\u0430\u0443\u0437\u044b \u0438 \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u044f. \u041f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0432\u043e \u0432\u0441\u0435\u0445 \u0438\u0433\u0440\u0430\u0445 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0442\u0430\u043a, \u0447\u0442\u043e\u0431\u044b \u044d\u0442\u0438\u043c \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435\u043c \u043c\u043e\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u0431\u0443\u0434\u0435\u0442 \u0437\u0434\u043e\u0440\u043e\u0432\u043e, \u0435\u0441\u043b\u0438 <code>KeyboardInput<\/code> \u0438 MoveController \u0431\u0443\u0434\u0443\u0442 \u0432\u043a\u043b\u044e\u0447\u0430\u0442\u044c\u0441\u044f \u043f\u043e \u0441\u043e\u0431\u044b\u0442\u0438\u044e \u0441\u0442\u0430\u0440\u0442\u0430 \u0438\u0433\u0440\u044b, \u0430 \u043d\u0435 \u043f\u0440\u0438 \u0437\u0430\u043f\u0443\u0441\u043a\u0435 <code>PlayMode<\/code> \u0432 Unity.<\/p>\n<p>\u0422\u043e\u0433\u0434\u0430 \u0434\u0438\u0437\u0430\u0439\u043d \u043a\u043b\u0430\u0441\u0441\u0430 <code>KeyboardInput<\/code> \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0442\u0430\u043a:<\/p>\n<pre><code class=\"cpp\">public sealed class KeyboardInput : MonoBehaviour,          IStartGameListener,         IFinishGameListener     {         public event Action&lt;Vector3> OnMove;          private bool isActive;          void IStartGameListener.OnStartGame()         {             this.isActive = true;         }          void IFinishGameListener.OnFinishGame()         {             this.isActive = false;         }                  private void Update()         {             if (this.isActive)             {                 this.HandleKeyboard();             }         }          \/\/TODO: Rest code\u2026     }<\/code><\/pre>\n<p>\u0410 \u043a\u043b\u0430\u0441\u0441 <code>MoveController<\/code> \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u0442\u0430\u043a:<\/p>\n<pre><code class=\"cpp\">public sealed class MoveController : MonoBehaviour,          IStartGameListener,         IFinishGameListener     {         [SerializeField]         private KeyboardInput input;          [SerializeField]         private Player player;          void IStartGameListener.OnStartGame()         {             this.input.OnMove += this.OnMove;         }          void IFinishGameListener.OnFinishGame()         {             this.input.OnMove -= this.OnMove;         }          private void OnMove(Vector3 direction)         {             this.player.Move(direction);         }     }<\/code><\/pre>\n<p>\u0417\u0434\u0435\u0441\u044c \u043c\u044b \u0432\u0438\u0434\u0438\u043c, \u0447\u0442\u043e <code>KeyboardInput<\/code> \u0438 <code>MoveController<\/code> \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u044e\u0442 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u044b <code>IStartGameListener<\/code> \u0438 <code>IFinishGameListener<\/code>. \u0427\u0435\u0440\u0435\u0437 \u044d\u0442\u0438 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u044b, \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u044b \u0441\u0438\u0441\u0442\u0435\u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0430\u044e\u0442 \u0441\u0438\u0433\u043d\u0430\u043b\u044b \u043e\u0431 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0438 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f \u0438\u0433\u0440\u044b. \u0421\u044e\u0434\u0430 \u0441\u0440\u0430\u0437\u0443 \u0436\u0435 \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u0438\u043a\u0440\u0443\u0442\u0438\u0442\u044c \u0435\u0449\u0435 \u0434\u0432\u0430 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430: <code>IPauseGameListener<\/code>, <code>IResumeGameListener<\/code>. \u041e\u043d\u0438 \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u044e\u0442, \u043a\u043e\u0433\u0434\u0430 \u0438\u0433\u0440\u0430 \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0438\u0442 \u0432 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u043f\u0430\u0443\u0437\u044b \u0438 \u043d\u0430\u043e\u0431\u043e\u0440\u043e\u0442. \u041d\u0438\u0436\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0438\u043b \u043a\u043e\u0434 \u0432\u0441\u0435\u0445 4-\u0445 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u043e\u0432:<\/p>\n<pre><code class=\"cpp\">public interface IStartGameListener     {         void OnStartGame();     }      public interface IPauseGameListener     {         void OnPauseGame();     }      public interface IResumeGameListener     {         void OnResumeGame();     }      public interface IFinishGameListener     {         void OnFinishGame();     } <\/code><\/pre>\n<p>\u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u043f\u0440\u0438\u043d\u0446\u0438\u043f <a href=\"https:\/\/ru.wikipedia.org\/wiki\/%D0%9F%D1%80%D0%B8%D0%BD%D1%86%D0%B8%D0%BF_%D1%80%D0%B0%D0%B7%D0%B4%D0%B5%D0%BB%D0%B5%D0%BD%D0%B8%D1%8F_%D0%B8%D0%BD%D1%82%D0%B5%D1%80%D1%84%D0%B5%D0%B9%D1%81%D0%B0\"><u>Interface Segregation<\/u><\/a> \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u044b \u0431\u0443\u0434\u0443\u0442 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u0442\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f \u0438\u0433\u0440\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043e\u043d\u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u044e\u0442<\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043a\u0442\u043e-\u0442\u043e \u0434\u043e\u043b\u0436\u0435\u043d \u0441\u043e\u043e\u0431\u0449\u0430\u0442\u044c \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430\u043c \u043e\u0431 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0438 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f \u0438\u0433\u0440\u044b. \u0422\u0443\u0442 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043e\u0431\u0440\u0430\u0442\u0438\u0442\u044c\u0441\u044f \u043a \u043f\u0430\u0442\u0442\u0435\u0440\u043d\u0443 <a href=\"https:\/\/refactoring.guru\/ru\/design-patterns\/observer\/csharp\/example\"><u>\u041d\u0430\u0431\u043b\u044e\u0434\u0430\u0442\u0435\u043b\u044c<\/u><\/a> \u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u043a\u043b\u0430\u0441\u0441-\u043f\u0440\u0438\u0435\u043c\u043d\u0438\u043a, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u044c \u0441\u0438\u0433\u043d\u0430\u043b\u044b \u043e\u0431 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0438 \u0444\u0430\u0437\u044b \u0438\u0433\u0440\u044b. \u0421\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 \u043f\u0440\u0438\u0435\u043c\u043d\u0438\u043a\u0430 \u0431\u0443\u0434\u0435\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439:<\/p>\n<pre><code class=\"cpp\">public sealed class GameObservable : MonoBehaviour     {         private readonly List&lt;object> listeners = new();          [ContextMenu(\"Start Game\")]         public void StartGame()         {             foreach (var listener in this.listeners)             {                 if (listener is IStartGameListener startListener)                 {                     startListener.OnStartGame();                 }             }         }          [ContextMenu(\"Pause Game\")]         public void PauseGame()         {             foreach (var listener in this.listeners)             {                 if (listener is IPauseGameListener pauseListener)                 {                     pauseListener.OnPauseGame();                 }             }         }          [ContextMenu(\"Resume Game\")]         public void ResumeGame()         {             foreach (var listener in this.listeners)             {                 if (listener is IResumeGameListener resumeListener)                 {                     resumeListener.OnResumeGame();                 }             }         }          [ContextMenu(\"Finish Game\")]         public void FinishGame()         {             foreach (var listener in this.listeners)             {                 if (listener is IFinishGameListener finishListener)                 {                     finishListener.OnFinishGame();                 }             }         }          public void AddListener(object listener)         {             this.listeners.Add(listener);         }          public void RemoveListener(object listener)         {             this.listeners.Remove(listener);         }     }<\/code><\/pre>\n<p>\u041e\u0442\u043b\u0438\u0447\u043d\u043e! \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0442\u0435\u043f\u0435\u0440\u044c \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u0441\u043a\u0440\u0438\u043f\u0442 <code>GameObservable<\/code> \u043d\u0430 \u0441\u0446\u0435\u043d\u0443:<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/82a\/9ac\/341\/82a9ac341a6ad2f359dbc8a9b777ea27.png\" alt=\"\" title=\"\" width=\"814\" height=\"626\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/82a\/9ac\/341\/82a9ac341a6ad2f359dbc8a9b777ea27.png\"\/><\/figure>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/315\/669\/d5f\/315669d5f0fbdd24fefce0136bd4864c.png\" alt=\"\" title=\"\" width=\"374\" height=\"718\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/315\/669\/d5f\/315669d5f0fbdd24fefce0136bd4864c.png\"\/><\/figure>\n<p>\u0415\u0441\u043b\u0438 \u043d\u0430\u0436\u0430\u0442\u044c \u043d\u0430 \u201c\u0442\u0440\u0438 \u0442\u043e\u0447\u043a\u0438\u201d \u0440\u044f\u0434\u043e\u043c \u0441 \u044d\u0442\u0438\u043c \u0441\u043a\u0440\u0438\u043f\u0442\u043e\u043c, \u0442\u043e \u043c\u043e\u0436\u0435\u043c \u0443\u0432\u0438\u0434\u0435\u0442\u044c, \u0447\u0442\u043e \u0443 \u044d\u0442\u043e\u0433\u043e \u0441\u043a\u0440\u0438\u043f\u0442\u0430 \u043c\u043e\u0436\u043d\u043e \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c \u043c\u0435\u0442\u043e\u0434\u044b \u0437\u0430\u043f\u0443\u0441\u043a\u0430, \u043f\u0430\u0443\u0437\u044b \u0438 \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u044f \u0438\u0433\u0440\u044b.<\/p>\n<p>\u041d\u0430\u0436\u0430\u0432 \u043d\u0430 \u0432\u043e\u043b\u0448\u0435\u0431\u043d\u0443\u044e \u043a\u043d\u043e\u043f\u043e\u0447\u043a\u0443 \u201cPlay\u201d \u0432 Unity, \u043c\u044b \u0432\u0438\u0434\u0438\u043c, \u0447\u0442\u043e \u043f\u0435\u0440\u0435\u043c\u0435\u0449\u0435\u043d\u0438\u0435 \u043a\u0443\u0431\u0438\u043a\u0430 \u043f\u043e \u043d\u0430\u0436\u0430\u0442\u0438\u044e \u043a\u043b\u0430\u0432\u0438\u0430\u0442\u0443\u0440\u044b \u043d\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442. \u041f\u043e\u0447\u0435\u043c\u0443, \u0441\u043f\u0440\u043e\u0441\u0438\u0442\u0435 \u0432\u044b? \u0414\u0430 \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u044b KeyboardInput \u0438 MoveController \u043d\u0435 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u044b \u043a \u043c\u043e\u043d\u043e\u0431\u0435\u0445\u0443 <code>GameObservable<\/code> \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043d\u0430\u0431\u043b\u044e\u0434\u0430\u0442\u0435\u043b\u0435\u0439.<\/p>\n<p>\u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u043d\u0430\u043c \u043d\u0443\u0436\u0435\u043d \u043a\u043b\u0430\u0441\u0441, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0437\u0430\u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u0443\u0435\u0442 <code>KeyboardInput<\/code> \u0438 <code>MoveController<\/code> \u0432 \u043f\u0440\u0438\u0435\u043c\u043d\u0438\u043a <code>GameObservable<\/code>. \u041d\u0430\u0437\u043e\u0432\u0435\u043c \u044d\u0442\u043e\u0442 \u043a\u043b\u0430\u0441\u0441 <code>GameObservableInstaller<\/code>.<\/p>\n<pre><code class=\"cpp\">public sealed class GameObservableInstaller : MonoBehaviour     {         [SerializeField]         private GameObservable gameObservable;                      [SerializeField]         private MonoBehaviour[] gameListeners;          private void Awake()         {             foreach (var listener in this.gameListeners)             {                 this.gameObservable.AddListener(listener);             }         }     }<\/code><\/pre>\n<p>\u0422\u0443\u0442 \u0432\u0441\u0435 \u043e\u0447\u0435\u043d\u044c \u043f\u0440\u043e\u0441\u0442\u043e: \u0438\u043d\u0441\u0442\u0430\u043b\u043b\u0435\u0440 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0432 \u0441\u0435\u0431\u0435 \u0441\u0441\u044b\u043b\u043a\u0443 \u043d\u0430 \u043f\u0440\u0438\u0435\u043c\u043d\u0438\u043a \u0438 \u043c\u0430\u0441\u0441\u0438\u0432 \u0441 \u0434\u0440\u0443\u0433\u0438\u043c\u0438 \u043c\u043e\u043d\u043e\u0431\u0435\u0445\u0430\u043c\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u044e\u0442 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u044b \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0439 \u0438\u0433\u0440\u044b. \u0412 \u043c\u0435\u0442\u043e\u0434\u0435 <code>Awake()<\/code> \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u0443\u0435\u043c \u0432\u0441\u0435 \u043b\u0438\u0441\u0435\u043d\u0435\u0440\u044b \u0432 \u043f\u0440\u0438\u0435\u043c\u043d\u0438\u043a.<\/p>\n<p>\u0417\u0430\u0442\u0435\u043c \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u044e \u0441\u043a\u0440\u0438\u043f\u0442 <code>GameObservableInstaller<\/code> \u043d\u0430 \u0441\u0446\u0435\u043d\u0443 \u0438 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u044e \u0435\u043c\u0443 \u043b\u0438\u0441\u0435\u043d\u0435\u0440\u044b:\u00a0<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/c92\/92d\/408\/c9292d40860113025d6b74d7fb225fd3.png\" alt=\"\" title=\"\" width=\"802\" height=\"660\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/c92\/92d\/408\/c9292d40860113025d6b74d7fb225fd3.png\"\/><\/figure>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043d\u0443\u0436\u043d\u043e \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c, \u0447\u0442\u043e \u0432\u0441\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442!<\/p>\n<ol>\n<li>\n<p>\u0417\u0430\u043f\u0443\u0441\u043a\u0430\u044e PlayMode \u0432 Unity.<\/p>\n<\/li>\n<li>\n<p>\u0412\u044b\u0437\u044b\u0432\u0430\u044e \u0432 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u043d\u043e\u043c \u043c\u0435\u043d\u044e \u043f\u0440\u0438\u0435\u043c\u043d\u0438\u043a\u0430 <code>GameObservable<\/code> \u043c\u0435\u0442\u043e\u0434 <code>StartGame<\/code>.<\/p>\n<\/li>\n<li>\n<p>\u041d\u0430\u0436\u0438\u043c\u0430\u044e \u043d\u0430 \u043a\u043b\u0430\u0432\u0438\u0430\u0442\u0443\u0440\u0443 \u0438 \u0432\u0438\u0436\u0443, \u0447\u0442\u043e \u201c\u043a\u0443\u0431\u0438\u043a \u043f\u043e\u0435\u0445\u0430\u043b\u201d.<\/p>\n<\/li>\n<li>\n<p>\u0412\u0443\u0430\u043b\u044f, \u0432\u0441\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442!<\/p>\n<\/li>\n<\/ol>\n<p>\u0414\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u043c \u0431\u043e\u043d\u0443\u0441\u043e\u043c, \u043c\u043e\u0436\u0435\u043c \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c, \u0447\u0442\u043e \u0435\u0441\u043b\u0438 \u0432\u044b\u0437\u0432\u0430\u0442\u044c \u043c\u0435\u0442\u043e\u0434 <code>GameObservable.FinishGame()<\/code>, \u0442\u043e <code>KeyboardInput<\/code> \u0438 <code>MoveController<\/code> \u043f\u0435\u0440\u0435\u0441\u0442\u0430\u043d\u0443\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c.<\/p>\n<p>\u0412\u0441\u0435 \u0445\u043e\u0440\u043e\u0448\u043e, \u043d\u043e \u0435\u0441\u0442\u044c \u043f\u0430\u0440\u0430 \u043d\u044e\u0430\u043d\u0441\u043e\u0432:<\/p>\n<ul>\n<li>\n<p>\u041d\u0435\u0442 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u0443\u0437\u043d\u0430\u0442\u044c \u0442\u0435\u043a\u0443\u0449\u0435\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0438\u0433\u0440\u044b.<\/p>\n<\/li>\n<li>\n<p>\u041c\u043e\u0436\u043d\u043e \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c \u0441\u043e\u0431\u044b\u0442\u0438\u044f \u0438\u0433\u0440\u044b \u0432 \u043b\u044e\u0431\u043e\u043c \u043f\u043e\u0440\u044f\u0434\u043a\u0435 (\u0442\u0438\u043f\u0430 \u201c\u043f\u0430\u0443\u0437\u0430\u201d \u043f\u043e\u0441\u043b\u0435 \u201c\u043e\u043a\u043e\u043d\u0447\u0430\u043d\u0438\u044f\u201d \u0438 \u0442.\u0434.).<\/p>\n<\/li>\n<\/ul>\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0434\u043e\u0440\u0430\u0431\u043e\u0442\u0430\u0435\u043c \u043d\u0430\u0448 \u043f\u0440\u0438\u0435\u043c\u043d\u0438\u043a:<\/p>\n<pre><code class=\"cpp\">public enum GameState     {         OFF = 0,         PLAY = 1,         PAUSE = 2,         FINISH = 3,     }  public sealed class GameMachine : MonoBehaviour     {         public GameState GameState         {             get { return this.gameState; }         }          private readonly List&lt;object> listeners = new();          private GameState gameState = GameState.OFF;                  [ContextMenu(\"Start Game\")]         public void StartGame()         {             if (this.gameState != GameState.OFF)             {                 Debug.LogWarning($\"You can start game only from {GameState.OFF} state!\");                 return;             }              this.gameState = GameState.PLAY;              foreach (var listener in this.listeners)             {                 if (listener is IStartGameListener startListener)                 {                     startListener.OnStartGame();                 }             }         }          [ContextMenu(\"Pause Game\")]         public void PauseGame()         {             if (this.gameState != GameState.PLAY)             {                 Debug.LogWarning($\"You can pause game only from {GameState.PLAY} state!\");                 return;             }              this.gameState = GameState.PAUSE;              foreach (var listener in this.listeners)             {                 if (listener is IPauseGameListener pauseListener)                 {                     pauseListener.OnPauseGame();                 }             }         }          [ContextMenu(\"Resume Game\")]         public void ResumeGame()         {             if (this.gameState != GameState.PAUSE)             {                 Debug.LogWarning($\"You can resume game only from {GameState.PAUSE} state!\");                 return;             }              this.gameState = GameState.PLAY;              foreach (var listener in this.listeners)             {                 if (listener is IResumeGameListener resumeListener)                 {                     resumeListener.OnResumeGame();                 }             }         }          [ContextMenu(\"Finish Game\")]         public void FinishGame()         {             if (this.gameState != GameState.PLAY)             {                 Debug.LogWarning($\"You can finish game only from {GameState.PLAY} state!\");                 return;             }              this.gameState = GameState.FINISH;              foreach (var listener in this.listeners)             {                 if (listener is IFinishGameListener finishListener)                 {                     finishListener.OnFinishGame();                 }             }         }          public void AddListener(object listener)         {             this.listeners.Add(listener);         }          public void RemoveListener(object listener)         {             this.listeners.Remove(listener);         }     }<\/code><\/pre>\n<p>\u041f\u0435\u0440\u0432\u044b\u043c \u0434\u0435\u043b\u043e\u043c, \u0434\u0443\u043c\u0430\u044e, \u0432\u044b \u0437\u0430\u043c\u0435\u0442\u0438\u043b\u0438, \u0447\u0442\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u043b\u0441\u044f <code>enum GameState<\/code> \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c, \u0443\u043a\u0430\u0437\u0430\u043d\u043e \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0435 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u0445 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0439 \u0438\u0433\u0440\u044b.<\/p>\n<p>\u0412\u043e-\u0432\u0442\u043e\u0440\u044b\u0445, \u043d\u0430\u0448 \u0437\u0430\u043c\u0435\u0447\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u0441\u043a\u0440\u0438\u043f\u0442 <code>GameObservable<\/code> \u043f\u0435\u0440\u0435\u0438\u043c\u0435\u043d\u043e\u0432\u0430\u043b\u0441\u044f \u0432 <code>GameMachine<\/code>. \u042d\u0442\u043e \u0441\u0432\u044f\u0437\u0430\u043d\u043e \u0441 \u0442\u0435\u043c, \u0447\u0442\u043e \u043d\u0430\u0448 \u0442\u0435\u043a\u0443\u0449\u0438\u0439 \u043a\u043b\u0430\u0441\u0441 \u0437\u0430\u043d\u0438\u043c\u0430\u0435\u0442\u0441\u044f \u0443\u0436\u0435 \u043d\u0435 \u0440\u0430\u0441\u0441\u044b\u043b\u043a\u043e\u0439 \u0441\u043e\u0431\u044b\u0442\u0438\u0439, \u0430 \u043f\u0435\u0440\u0435\u043a\u043b\u044e\u0447\u0430\u0435\u0442 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0438\u0433\u0440\u044b \u0432 \u0446\u0435\u043b\u043e\u043c.<\/p>\n<p>\u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u0443 \u043d\u0430\u0441 \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0441\u044f \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c, \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435\u043c \u0438\u0433\u0440\u044b \u0438 \u043e\u043f\u043e\u0432\u0435\u0449\u0430\u0442\u044c \u043e\u0431 \u044d\u0442\u043e\u043c \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u044b \u0441\u0438\u0441\u0442\u0435\u043c\u044b.<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/a2c\/9c0\/6c5\/a2c9c06c571ab6f5bd35372781bb034d.png\" alt=\"\" title=\"\" width=\"1600\" height=\"711\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/a2c\/9c0\/6c5\/a2c9c06c571ab6f5bd35372781bb034d.png\"\/><\/figure>\n<p>\u041d\u0430 \u044d\u0442\u043e\u043c \u043f\u0435\u0440\u0432\u0430\u044f \u0447\u0430\u0441\u0442\u044c \u0441\u0442\u0430\u0442\u044c\u0438 \u0437\u0430\u043a\u043e\u043d\u0447\u0438\u043b\u0430\u0441\u044c, \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0435\u043d\u0438\u0435 \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \ud83d\ude42<\/p>\n<p>\u0412 \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u0435 \u043f\u0440\u0438\u0433\u043b\u0430\u0448\u0430\u044e \u0432\u0430\u0441 \u043d\u0430 <a href=\"https:\/\/otus.pw\/q2ZS\/\">\u0431\u0435\u0441\u043f\u043b\u0430\u0442\u043d\u044b\u0439 \u0443\u0440\u043e\u043a<\/a>, \u0433\u0434\u0435 \u0438\u0437\u0443\u0447\u0438\u043c \u043f\u0430\u0442\u0442\u0435\u0440\u043d Model-View-Adapter \u0432 \u0443\u043f\u0440\u043e\u0449\u0435\u043d\u043d\u043e\u043c \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u0435 \u0431\u0435\u0437 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u043e\u0433\u043e \u0432\u0432\u043e\u0434\u0430 \u043d\u0430 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0432\u0438\u0434\u0436\u0435\u0442\u0430 \u043c\u043e\u043d\u0435\u0442 \u0438\u0433\u0440\u043e\u043a\u0430.<\/p>\n<ul>\n<li>\n<p><a href=\"https:\/\/otus.pw\/q2ZS\/\">\u0417\u0430\u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u043d\u0430 \u0431\u0435\u0441\u043f\u043b\u0430\u0442\u043d\u044b\u0439 \u0443\u0440\u043e\u043a<\/a><\/p>\n<\/li>\n<\/ul>\n<\/div>\n<\/div>\n<\/div>\n<p> <!----> <!----><\/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\/company\/otus\/blog\/725068\/\"> https:\/\/habr.com\/ru\/company\/otus\/blog\/725068\/<\/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<figure class=\"full-width\"><\/figure>\n<div class=\"persona\" persona=\"true\">\n<h5 class=\"persona__heading\" persona=\"true\">\u0410\u0432\u0442\u043e\u0440 \u0441\u0442\u0430\u0442\u044c\u0438: \u0418\u0433\u043e\u0440\u044c \u0413\u0443\u043b\u044c\u043a\u0438\u043d<\/h5>\n<p>Senior Unity Developer<\/p>\n<\/div>\n<p>\u0412\u0441\u0435\u043c \u043f\u0440\u0438\u0432\u0435\u0442!<\/p>\n<p>\u041c\u0435\u043d\u044f \u0437\u043e\u0432\u0443\u0442 \u0418\u0433\u043e\u0440\u044c \u0413\u0443\u043b\u044c\u043a\u0438\u043d, \u0438 \u044f Unity \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a. \u0417\u0430 \u0441\u0432\u043e\u0438 5 \u043b\u0435\u0442 \u043d\u0430\u043a\u043e\u043f\u0438\u043b\u043e\u0441\u044c \u043c\u043d\u043e\u0433\u043e \u043e\u043f\u044b\u0442\u0430, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0432 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u0445\u043e\u0442\u0435\u043b \u0431\u044b \u043f\u043e\u0434\u0435\u043b\u0438\u0442\u044c\u0441\u044f \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u0430\u043c\u0438 \u0438 \u043f\u043e\u0434\u0445\u043e\u0434\u0430\u043c\u0438, \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043c\u043e\u0436\u043d\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0443 \u0438\u0433\u0440\u044b \u043f\u0440\u043e\u0441\u0442\u043e \u0438 \u0433\u0438\u0431\u043a\u043e \u0431\u0435\u0437 \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u0430. \u0426\u0435\u043b\u044c \u0434\u043e\u043a\u043b\u0430\u0434\u0430, \u0434\u0430\u0442\u044c \u043d\u0435 \u043f\u0440\u043e\u0441\u0442\u043e \u0433\u043e\u0442\u043e\u0432\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435, \u0430 \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u044c \u0445\u043e\u0434 \u043c\u044b\u0441\u043b\u0435\u0439, \u043a\u0430\u043a \u043e\u043d\u0430 \u0432\u044b\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u0435\u0442\u0441\u044f.\u00a0 \u041d\u0443 \u0447\u0442\u043e \u0436 \u043f\u043e\u0435\u0445\u0430\u043b\u0438 \ud83d\ude42<\/p>\n<h3>\u041f\u0440\u0438\u043c\u0435\u0440<\/h3>\n<figure class=\"full-width\"><\/figure>\n<p>\u00a0<\/p>\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u043e\u0436\u0438\u043c, \u0447\u0442\u043e \u043c\u044b \u0434\u0435\u043b\u0430\u0435\u043c \u0438\u0433\u0440\u0443, \u0433\u0434\u0435 \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u043c \u043a\u0443\u0431\u0438\u043a\u043e\u043c \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043a\u043b\u0430\u0432\u0438\u0430\u0442\u0443\u0440\u044b. \u041d\u0430 \u0441\u0446\u0435\u043d\u0435 \u0435\u0441\u0442\u044c GameObject\u2019\u044b:\u00a0<\/p>\n<ol>\n<li>\n<p><code>Player<\/code> \u2014 \u043a\u0443\u0431\u0438\u043a, \u043a\u043e\u0442\u043e\u0440\u044b\u043c \u0438\u0433\u0440\u043e\u043a \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442.<\/p>\n<\/li>\n<li>\n<p><code>KeyboardInput<\/code> \u2014 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0439 \u0432\u0432\u043e\u0434 \u0441 \u043a\u043b\u0430\u0432\u0438\u0430\u0442\u0443\u0440\u044b.<\/p>\n<\/li>\n<li>\n<p><code>MoveController<\/code> \u2014 \u0441\u043e\u0435\u0434\u0438\u043d\u044f\u0435\u0442 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0439 \u0432\u0432\u043e\u0434 \u0438 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442 \u0443 \u043a\u0443\u0431\u0438\u043a\u0430 <code>Player.Move().<\/code><\/p>\n<\/li>\n<\/ol>\n<p>\u0412\u043e\u0442 \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u044b\u0435 \u0441\u043a\u0440\u0438\u043f\u0442\u044b \u044d\u0442\u0438\u0445 \u043a\u043b\u0430\u0441\u0441\u043e\u0432:<\/p>\n<p>\u0421\u043a\u0440\u0438\u043f\u0442 \u043a\u0443\u0431\u0438\u043a\u0430:<\/p>\n<pre><code class=\"cpp\">public sealed class Player : MonoBehaviour     {         [SerializeField]         private float speed = 2.0f;              public void Move(Vector3 direction)         {             this.transform.position += direction * this.speed * Time.deltaTime;         }     }<\/code><\/pre>\n<p>\u0421\u043a\u0440\u0438\u043f\u0442 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u043e\u0433\u043e \u0432\u0432\u043e\u0434\u0430:<\/p>\n<pre><code class=\"cpp\">public sealed class KeyboardInput : MonoBehaviour     {         public event Action&lt;Vector3> OnMove;          private void Update()         {             this.HandleKeyboard();         }          private void HandleKeyboard()         {             if (Input.GetKey(KeyCode.UpArrow))             {                 this.Move(Vector3.forward);             }             else if (Input.GetKey(KeyCode.DownArrow))             {                 this.Move(Vector3.back);             }             else if (Input.GetKey(KeyCode.LeftArrow))             {                 this.Move(Vector3.left);             }             else if (Input.GetKey(KeyCode.RightArrow))             {                 this.Move(Vector3.right);             }         }          private void Move(Vector3 direction)         {             this.OnMove?.Invoke(direction);         }     }<\/code><\/pre>\n<p>\u0421\u043a\u0440\u0438\u043f\u0442 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0430 \u043f\u0435\u0440\u0435\u043c\u0435\u0449\u0435\u043d\u0438\u044f:<\/p>\n<pre><code class=\"cpp\">public sealed class MoveController : MonoBehaviour     {         [SerializeField]         private KeyboardInput input;          [SerializeField]         private Player player;          private void OnEnable()         {             this.input.OnMove += this.OnMove;         }          private void OnDisable()         {             this.input.OnMove -= this.OnMove;         }          private void OnMove(Vector3 direction)         {             this.player.Move(direction);         }     } <\/code><\/pre>\n<p>\u0418\u0433\u0440\u0430 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442, \u043d\u043e \u0435\u0441\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u043d\u044b\u0445 \u043d\u0435\u0434\u043e\u0441\u0442\u0430\u0442\u043a\u043e\u0432:<\/p>\n<ol>\n<li>\n<p>\u041d\u0435\u0442 \u0442\u043e\u0447\u043a\u0438 \u0432\u0445\u043e\u0434\u0430 \u0432 \u0438\u0433\u0440\u0443 \u0438 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u044f.<\/p>\n<\/li>\n<li>\n<p>\u0412\u0441\u0435 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043d\u0430 \u043a\u043b\u0430\u0441\u0441\u044b \u043f\u0440\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0432\u0440\u0443\u0447\u043d\u0443\u044e \u0447\u0435\u0440\u0435\u0437 \u0438\u043d\u0441\u043f\u0435\u043a\u0442\u043e\u0440.<\/p>\n<\/li>\n<li>\n<p>\u0412\u0441\u044f \u0438\u0433\u0440\u043e\u0432\u0430\u044f \u043b\u043e\u0433\u0438\u043a\u0430 \u043f\u0440\u0438\u0432\u044f\u0437\u0430\u043d\u0430 \u043a \u043c\u043e\u043d\u043e\u0431\u0435\u0445\u0430\u043c (MonoBehaviour).<\/p>\n<\/li>\n<li>\n<p>\u041d\u0435\u0442 \u043f\u043e\u0440\u044f\u0434\u043a\u0430 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0438\u0433\u0440\u044b.<\/p>\n<\/li>\n<\/ol>\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0443\u043b\u0443\u0447\u0448\u0430\u0442\u044c \u043d\u0430\u0448\u0443 \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0443 \u043f\u043e \u043f\u043e\u0440\u044f\u0434\u043a\u0443.<\/p>\n<h3>\u0421\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0438\u0433\u0440\u044b<\/h3>\n<p>\u0412\u0441\u0435 \u043c\u044b \u0437\u043d\u0430\u0435\u043c, \u0447\u0442\u043e \u0438\u0433\u0440\u0430 \u2014 \u044d\u0442\u043e \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u0443 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u0435\u0441\u0442\u044c \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f. \u0415\u0441\u0442\u044c \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438 \u0438\u0433\u0440\u044b, \u0441\u0442\u0430\u0440\u0442\u0430, \u043f\u0430\u0443\u0437\u044b \u0438 \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u044f. \u041f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0432\u043e \u0432\u0441\u0435\u0445 \u0438\u0433\u0440\u0430\u0445 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0442\u0430\u043a, \u0447\u0442\u043e\u0431\u044b \u044d\u0442\u0438\u043c \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435\u043c \u043c\u043e\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u0431\u0443\u0434\u0435\u0442 \u0437\u0434\u043e\u0440\u043e\u0432\u043e, \u0435\u0441\u043b\u0438 <code>KeyboardInput<\/code> \u0438 MoveController \u0431\u0443\u0434\u0443\u0442 \u0432\u043a\u043b\u044e\u0447\u0430\u0442\u044c\u0441\u044f \u043f\u043e \u0441\u043e\u0431\u044b\u0442\u0438\u044e \u0441\u0442\u0430\u0440\u0442\u0430 \u0438\u0433\u0440\u044b, \u0430 \u043d\u0435 \u043f\u0440\u0438 \u0437\u0430\u043f\u0443\u0441\u043a\u0435 <code>PlayMode<\/code> \u0432 Unity.<\/p>\n<p>\u0422\u043e\u0433\u0434\u0430 \u0434\u0438\u0437\u0430\u0439\u043d \u043a\u043b\u0430\u0441\u0441\u0430 <code>KeyboardInput<\/code> \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0442\u0430\u043a:<\/p>\n<pre><code class=\"cpp\">public sealed class KeyboardInput : MonoBehaviour,          IStartGameListener,         IFinishGameListener     {         public event Action&lt;Vector3> OnMove;          private bool isActive;          void IStartGameListener.OnStartGame()         {             this.isActive = true;         }          void IFinishGameListener.OnFinishGame()         {             this.isActive = false;         }                  private void Update()         {             if (this.isActive)             {                 this.HandleKeyboard();             }         }          \/\/TODO: Rest code\u2026     }<\/code><\/pre>\n<p>\u0410 \u043a\u043b\u0430\u0441\u0441 <code>MoveController<\/code> \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u0442\u0430\u043a:<\/p>\n<pre><code class=\"cpp\">public sealed class MoveController : MonoBehaviour,          IStartGameListener,         IFinishGameListener     {         [SerializeField]         private KeyboardInput input;          [SerializeField]         private Player player;          void IStartGameListener.OnStartGame()         {             this.input.OnMove += this.OnMove;         }          void IFinishGameListener.OnFinishGame()         {             this.input.OnMove -= this.OnMove;         }          private void OnMove(Vector3 direction)         {             this.player.Move(direction);         }     }<\/code><\/pre>\n<p>\u0417\u0434\u0435\u0441\u044c \u043c\u044b \u0432\u0438\u0434\u0438\u043c, \u0447\u0442\u043e <code>KeyboardInput<\/code> \u0438 <code>MoveController<\/code> \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u044e\u0442 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u044b <code>IStartGameListener<\/code> \u0438 <code>IFinishGameListener<\/code>. \u0427\u0435\u0440\u0435\u0437 \u044d\u0442\u0438 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u044b, \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u044b \u0441\u0438\u0441\u0442\u0435\u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0430\u044e\u0442 \u0441\u0438\u0433\u043d\u0430\u043b\u044b \u043e\u0431 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0438 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f \u0438\u0433\u0440\u044b. \u0421\u044e\u0434\u0430 \u0441\u0440\u0430\u0437\u0443 \u0436\u0435 \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u0438\u043a\u0440\u0443\u0442\u0438\u0442\u044c \u0435\u0449\u0435 \u0434\u0432\u0430 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430: <code>IPauseGameListener<\/code>, <code>IResumeGameListener<\/code>. \u041e\u043d\u0438 \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u044e\u0442, \u043a\u043e\u0433\u0434\u0430 \u0438\u0433\u0440\u0430 \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0438\u0442 \u0432 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u043f\u0430\u0443\u0437\u044b \u0438 \u043d\u0430\u043e\u0431\u043e\u0440\u043e\u0442. \u041d\u0438\u0436\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0438\u043b \u043a\u043e\u0434 \u0432\u0441\u0435\u0445 4-\u0445 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u043e\u0432:<\/p>\n<pre><code class=\"cpp\">public interface IStartGameListener     {         void OnStartGame();     }      public interface IPauseGameListener     {         void OnPauseGame();     }      public interface IResumeGameListener     {         void OnResumeGame();     }      public interface IFinishGameListener     {         void OnFinishGame();     } <\/code><\/pre>\n<p>\u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u043f\u0440\u0438\u043d\u0446\u0438\u043f <a href=\"https:\/\/ru.wikipedia.org\/wiki\/%D0%9F%D1%80%D0%B8%D0%BD%D1%86%D0%B8%D0%BF_%D1%80%D0%B0%D0%B7%D0%B4%D0%B5%D0%BB%D0%B5%D0%BD%D0%B8%D1%8F_%D0%B8%D0%BD%D1%82%D0%B5%D1%80%D1%84%D0%B5%D0%B9%D1%81%D0%B0\"><u>Interface Segregation<\/u><\/a> \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u044b \u0431\u0443\u0434\u0443\u0442 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u0442\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f \u0438\u0433\u0440\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043e\u043d\u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u044e\u0442<\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043a\u0442\u043e-\u0442\u043e \u0434\u043e\u043b\u0436\u0435\u043d \u0441\u043e\u043e\u0431\u0449\u0430\u0442\u044c \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430\u043c \u043e\u0431 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0438 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f \u0438\u0433\u0440\u044b. \u0422\u0443\u0442 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043e\u0431\u0440\u0430\u0442\u0438\u0442\u044c\u0441\u044f \u043a \u043f\u0430\u0442\u0442\u0435\u0440\u043d\u0443 <a href=\"https:\/\/refactoring.guru\/ru\/design-patterns\/observer\/csharp\/example\"><u>\u041d\u0430\u0431\u043b\u044e\u0434\u0430\u0442\u0435\u043b\u044c<\/u><\/a> \u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u043a\u043b\u0430\u0441\u0441-\u043f\u0440\u0438\u0435\u043c\u043d\u0438\u043a, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u044c \u0441\u0438\u0433\u043d\u0430\u043b\u044b \u043e\u0431 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0438 \u0444\u0430\u0437\u044b \u0438\u0433\u0440\u044b. \u0421\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 \u043f\u0440\u0438\u0435\u043c\u043d\u0438\u043a\u0430 \u0431\u0443\u0434\u0435\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439:<\/p>\n<pre><code class=\"cpp\">public sealed class GameObservable : MonoBehaviour     {         private readonly List&lt;object> listeners = new();          [ContextMenu(\"Start Game\")]         public void StartGame()         {             foreach (var listener in this.listeners)             {                 if (listener is IStartGameListener startListener)                 {                     startListener.OnStartGame();                 }             }         }          [ContextMenu(\"Pause Game\")]         public void PauseGame()         {             foreach (var listener in this.listeners)             {                 if (listener is IPauseGameListener pauseListener)                 {                     pauseListener.OnPauseGame();                 }             }         }          [ContextMenu(\"Resume Game\")]         public void ResumeGame()         {             foreach (var listener in this.listeners)             {                 if (listener is IResumeGameListener resumeListener)                 {                     resumeListener.OnResumeGame();                 }             }         }          [ContextMenu(\"Finish Game\")]         public void FinishGame()         {             foreach (var listener in this.listeners)             {                 if (listener is IFinishGameListener finishListener)                 {                     finishListener.OnFinishGame();                 }             }         }          public void AddListener(object listener)         {             this.listeners.Add(listener);         }          public void RemoveListener(object listener)         {             this.listeners.Remove(listener);         }     }<\/code><\/pre>\n<p>\u041e\u0442\u043b\u0438\u0447\u043d\u043e! \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0442\u0435\u043f\u0435\u0440\u044c \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u0441\u043a\u0440\u0438\u043f\u0442 <code>GameObservable<\/code> \u043d\u0430 \u0441\u0446\u0435\u043d\u0443:<\/p>\n<figure class=\"full-width\"><\/figure>\n<figure class=\"\"><\/figure>\n<p>\u0415\u0441\u043b\u0438 \u043d\u0430\u0436\u0430\u0442\u044c \u043d\u0430 \u201c\u0442\u0440\u0438 \u0442\u043e\u0447\u043a\u0438\u201d \u0440\u044f\u0434\u043e\u043c \u0441 \u044d\u0442\u0438\u043c \u0441\u043a\u0440\u0438\u043f\u0442\u043e\u043c, \u0442\u043e \u043c\u043e\u0436\u0435\u043c \u0443\u0432\u0438\u0434\u0435\u0442\u044c, \u0447\u0442\u043e \u0443 \u044d\u0442\u043e\u0433\u043e \u0441\u043a\u0440\u0438\u043f\u0442\u0430 \u043c\u043e\u0436\u043d\u043e \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c \u043c\u0435\u0442\u043e\u0434\u044b \u0437\u0430\u043f\u0443\u0441\u043a\u0430, \u043f\u0430\u0443\u0437\u044b \u0438 \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u044f \u0438\u0433\u0440\u044b.<\/p>\n<p>\u041d\u0430\u0436\u0430\u0432 \u043d\u0430 \u0432\u043e\u043b\u0448\u0435\u0431\u043d\u0443\u044e \u043a\u043d\u043e\u043f\u043e\u0447\u043a\u0443 \u201cPlay\u201d \u0432 Unity, \u043c\u044b \u0432\u0438\u0434\u0438\u043c, \u0447\u0442\u043e \u043f\u0435\u0440\u0435\u043c\u0435\u0449\u0435\u043d\u0438\u0435 \u043a\u0443\u0431\u0438\u043a\u0430 \u043f\u043e \u043d\u0430\u0436\u0430\u0442\u0438\u044e \u043a\u043b\u0430\u0432\u0438\u0430\u0442\u0443\u0440\u044b \u043d\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442. \u041f\u043e\u0447\u0435\u043c\u0443, \u0441\u043f\u0440\u043e\u0441\u0438\u0442\u0435 \u0432\u044b? \u0414\u0430 \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u044b KeyboardInput \u0438 MoveController \u043d\u0435 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u044b \u043a \u043c\u043e\u043d\u043e\u0431\u0435\u0445\u0443 <code>GameObservable<\/code> \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043d\u0430\u0431\u043b\u044e\u0434\u0430\u0442\u0435\u043b\u0435\u0439.<\/p>\n<p>\u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u043d\u0430\u043c \u043d\u0443\u0436\u0435\u043d \u043a\u043b\u0430\u0441\u0441, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0437\u0430\u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u0443\u0435\u0442 <code>KeyboardInput<\/code> \u0438 <code>MoveController<\/code> \u0432 \u043f\u0440\u0438\u0435\u043c\u043d\u0438\u043a <code>GameObservable<\/code>. \u041d\u0430\u0437\u043e\u0432\u0435\u043c \u044d\u0442\u043e\u0442 \u043a\u043b\u0430\u0441\u0441 <code>GameObservableInstaller<\/code>.<\/p>\n<pre><code class=\"cpp\">public sealed class GameObservableInstaller : MonoBehaviour     {         [SerializeField]         private GameObservable gameObservable;                      [SerializeField]         private MonoBehaviour[] gameListeners;          private void Awake()         {             foreach (var listener in this.gameListeners)             {                 this.gameObservable.AddListener(listener);             }         }     }<\/code><\/pre>\n<p>\u0422\u0443\u0442 \u0432\u0441\u0435 \u043e\u0447\u0435\u043d\u044c \u043f\u0440\u043e\u0441\u0442\u043e: \u0438\u043d\u0441\u0442\u0430\u043b\u043b\u0435\u0440 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0432 \u0441\u0435\u0431\u0435 \u0441\u0441\u044b\u043b\u043a\u0443 \u043d\u0430 \u043f\u0440\u0438\u0435\u043c\u043d\u0438\u043a \u0438 \u043c\u0430\u0441\u0441\u0438\u0432 \u0441 \u0434\u0440\u0443\u0433\u0438\u043c\u0438 \u043c\u043e\u043d\u043e\u0431\u0435\u0445\u0430\u043c\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u044e\u0442 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u044b \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0439 \u0438\u0433\u0440\u044b. \u0412 \u043c\u0435\u0442\u043e\u0434\u0435 <code>Awake()<\/code> \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u0443\u0435\u043c \u0432\u0441\u0435 \u043b\u0438\u0441\u0435\u043d\u0435\u0440\u044b \u0432 \u043f\u0440\u0438\u0435\u043c\u043d\u0438\u043a.<\/p>\n<p>\u0417\u0430\u0442\u0435\u043c \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u044e \u0441\u043a\u0440\u0438\u043f\u0442 <code>GameObservableInstaller<\/code> \u043d\u0430 \u0441\u0446\u0435\u043d\u0443 \u0438 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u044e \u0435\u043c\u0443 \u043b\u0438\u0441\u0435\u043d\u0435\u0440\u044b:\u00a0<\/p>\n<figure class=\"full-width\"><\/figure>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043d\u0443\u0436\u043d\u043e \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c, \u0447\u0442\u043e \u0432\u0441\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442!<\/p>\n<ol>\n<li>\n<p>\u0417\u0430\u043f\u0443\u0441\u043a\u0430\u044e PlayMode \u0432 Unity.<\/p>\n<\/li>\n<li>\n<p>\u0412\u044b\u0437\u044b\u0432\u0430\u044e \u0432 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u043d\u043e\u043c \u043c\u0435\u043d\u044e \u043f\u0440\u0438\u0435\u043c\u043d\u0438\u043a\u0430 <code>GameObservable<\/code> \u043c\u0435\u0442\u043e\u0434 <code>StartGame<\/code>.<\/p>\n<\/li>\n<li>\n<p>\u041d\u0430\u0436\u0438\u043c\u0430\u044e \u043d\u0430 \u043a\u043b\u0430\u0432\u0438\u0430\u0442\u0443\u0440\u0443 \u0438 \u0432\u0438\u0436\u0443, \u0447\u0442\u043e \u201c\u043a\u0443\u0431\u0438\u043a \u043f\u043e\u0435\u0445\u0430\u043b\u201d.<\/p>\n<\/li>\n<li>\n<p>\u0412\u0443\u0430\u043b\u044f, \u0432\u0441\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442!<\/p>\n<\/li>\n<\/ol>\n<p>\u0414\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u043c \u0431\u043e\u043d\u0443\u0441\u043e\u043c, \u043c\u043e\u0436\u0435\u043c \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c, \u0447\u0442\u043e \u0435\u0441\u043b\u0438 \u0432\u044b\u0437\u0432\u0430\u0442\u044c \u043c\u0435\u0442\u043e\u0434 <code>GameObservable.FinishGame()<\/code>, \u0442\u043e <code>KeyboardInput<\/code> \u0438 <code>MoveController<\/code> \u043f\u0435\u0440\u0435\u0441\u0442\u0430\u043d\u0443\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c.<\/p>\n<p>\u0412\u0441\u0435 \u0445\u043e\u0440\u043e\u0448\u043e, \u043d\u043e \u0435\u0441\u0442\u044c \u043f\u0430\u0440\u0430 \u043d\u044e\u0430\u043d\u0441\u043e\u0432:<\/p>\n<ul>\n<li>\n<p>\u041d\u0435\u0442 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u0443\u0437\u043d\u0430\u0442\u044c \u0442\u0435\u043a\u0443\u0449\u0435\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0438\u0433\u0440\u044b.<\/p>\n<\/li>\n<li>\n<p>\u041c\u043e\u0436\u043d\u043e \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c \u0441\u043e\u0431\u044b\u0442\u0438\u044f \u0438\u0433\u0440\u044b \u0432 \u043b\u044e\u0431\u043e\u043c \u043f\u043e\u0440\u044f\u0434\u043a\u0435 (\u0442\u0438\u043f\u0430 \u201c\u043f\u0430\u0443\u0437\u0430\u201d \u043f\u043e\u0441\u043b\u0435 \u201c\u043e\u043a\u043e\u043d\u0447\u0430\u043d\u0438\u044f\u201d \u0438 \u0442.\u0434.).<\/p>\n<\/li>\n<\/ul>\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0434\u043e\u0440\u0430\u0431\u043e\u0442\u0430\u0435\u043c \u043d\u0430\u0448 \u043f\u0440\u0438\u0435\u043c\u043d\u0438\u043a:<\/p>\n<pre><code class=\"cpp\">public enum GameState     {         OFF = 0,         PLAY = 1,         PAUSE = 2,         FINISH = 3,     }  public sealed class GameMachine : MonoBehaviour     {         public GameState GameState         {             get { return this.gameState; }         }          private readonly List&lt;object> listeners = new();          private GameState gameState = GameState.OFF;                  [ContextMenu(\"Start Game\")]         public void StartGame()         {             if (this.gameState != GameState.OFF)             {                 Debug.LogWarning($\"You can start game only from {GameState.OFF} state!\");                 return;             }              this.gameState = GameState.PLAY;              foreach (var listener in this.listeners)             {                 if (listener is IStartGameListener startListener)                 {                     startListener.OnStartGame();                 }             }         }          [ContextMenu(\"Pause Game\")]         public void PauseGame()         {             if (this.gameState !=<\/code><\/pre>\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-347340","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/347340","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=347340"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/347340\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=347340"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=347340"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=347340"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}