{"id":342816,"date":"2022-12-17T21:00:50","date_gmt":"2022-12-17T21:00:50","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=342816"},"modified":"-0001-11-30T00:00:00","modified_gmt":"2022-12-17T21:00:50","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=342816","title":{"rendered":"<span>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u044b Composition root \u0432 Unity. \u0427\u0430\u0441\u0442\u044c 1. \u041d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430 \u043f\u0440\u043e\u0435\u043a\u0442\u0430 \u0441 \u043d\u0443\u043b\u044f<\/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>\u041f\u0440\u0438\u0432\u0435\u0442 \u0432\u0441\u0435\u043c, \u043a\u0442\u043e \u043d\u0435\u0440\u0430\u0432\u043d\u043e\u0434\u0443\u0448\u0435\u043d \u043a \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u043d\u044b\u043c \u0440\u0435\u0448\u0435\u043d\u0438\u044f\u043c \u0432 \u0440\u0430\u043c\u043a\u0430\u0445 \u043f\u0440\u043e\u0435\u043a\u0442\u043e\u0432 \u043d\u0430 Unity \u0438 \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e. \u0415\u0441\u043b\u0438 \u0432\u043e\u043f\u0440\u043e\u0441 \u0432\u044b\u0431\u043e\u0440\u0430 \u0434\u043b\u044f \u0432\u0430\u0441 \u0435\u0449\u0451 \u0430\u043a\u0442\u0443\u0430\u043b\u0435\u043d \u0438\u043b\u0438 \u043f\u0440\u043e\u0441\u0442\u043e \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u0443\u0435\u0442\u0435\u0441\u044c \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u0430\u043c\u0438, \u0442\u043e \u0433\u043e\u0442\u043e\u0432 \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u0430\u0442\u044c \u043e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u044b Composition root \u0441 \u043f\u0440\u0438\u043c\u0435\u0440\u0430\u043c\u0438 \u043f\u0440\u043e\u0441\u0442\u0435\u0439\u0448\u0435\u0439 \u043b\u043e\u0433\u0438\u043a\u0438. \u0417\u0434\u0435\u0441\u044c \u0435\u0441\u0442\u044c \u0435\u0434\u0438\u043d\u0430\u044f \u0442\u043e\u0447\u043a\u0430 \u0432\u0445\u043e\u0434\u0430 \u0438 Dependency Injection, \u0442\u043e \u0435\u0441\u0442\u044c \u0432\u0441\u0451 \u043a\u0430\u043a \u043c\u044b \u043b\u044e\u0431\u0438\u043c. \u0421\u0430\u043c \u044f \u0443\u0436\u0435 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043b\u0435\u0442 \u043f\u0440\u0438\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u044e\u0441\u044c \u0434\u0430\u043d\u043d\u043e\u0439 \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u044b \u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043b \u043d\u0430 \u043d\u0435\u0439 \u043d\u0435 \u043c\u0430\u043b\u043e \u043f\u0440\u043e\u0435\u043a\u0442\u043e\u0432, \u043e\u0442 \u0413\u041a \u043f\u0440\u043e\u0442\u043e\u0442\u0438\u043f\u043e\u0432, \u0434\u043e pvp \u0438\u0433\u0440.<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w780q1\/getpro\/habr\/upload_files\/221\/346\/249\/221346249ff2ac3d7b250d79bb8a4e47.jpeg\" alt=\"\" title=\"\" width=\"750\" height=\"413\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/221\/346\/249\/221346249ff2ac3d7b250d79bb8a4e47.jpeg\" data-blurred=\"true\"\/><figcaption><\/figcaption><\/figure>\n<p>Composition root \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u043e\u0431\u043e\u0439 \u0441\u043c\u0435\u0441\u044c \u043c\u043e\u0434\u0435\u043b\u0435\u0439 MVP \u0438 MVVM \u0438 \u0430\u043a\u0442\u0438\u0432\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u0448\u0430\u0431\u043b\u043e\u043d Observer, \u0432 \u0434\u0430\u043d\u043d\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u044f \u043d\u0435 \u0431\u0443\u0434\u0443 \u0443\u0433\u043b\u0443\u0431\u043b\u044f\u0442\u044c\u0441\u044f \u0432 \u0441\u0443\u0442\u044c \u044d\u0442\u0438\u0445 \u0442\u0435\u0440\u043c\u0438\u043d\u043e\u0432, \u0430 \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u044e \u043d\u0430\u0433\u043b\u044f\u0434\u043d\u043e \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u044c \u043a\u0430\u043a \u044d\u0442\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442. \u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b \u043f\u0440\u043e\u0435\u043a\u0442\u0430 \u0438\u0434\u0451\u0442 \u0447\u0435\u0440\u0435\u0437 \u0441\u0432\u044f\u0437\u043a\u0443 \u0431\u0430\u0437\u043e\u0432\u044b\u0445 \u043f\u043e\u043d\u044f\u0442\u0438\u0439:\u00a0 Entity &#8212; Presenter Model (PM) &#8212; View.<\/p>\n<p><strong>Entity<\/strong> &#8212; \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u044c, \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u0430\u044f \u043b\u043e\u0433\u0438\u0447\u0435\u0441\u043a\u0430\u044f \u0435\u0434\u0438\u043d\u0438\u0446\u0430, \u0441\u043b\u0443\u0436\u0430\u0449\u0430\u044f \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f PM \u0438 View \u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u044e\u0449\u0430\u044f \u0438\u043c \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438<\/p>\n<p><strong>Presenter Model<\/strong> &#8212; \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0431\u0438\u0437\u043d\u0435\u0441 \u043b\u043e\u0433\u0438\u043a\u0443, \u043d\u0435 \u0438\u043c\u0435\u044e\u0449\u0443\u044e \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u0435 \u043a Monobehaviour \u043a\u043b\u0430\u0441\u0441\u0430\u043c<\/p>\n<p><strong>View<\/strong> &#8212; Gameobject \u043d\u0430 \u0441\u0446\u0435\u043d\u0435<\/p>\n<h2>\u041f\u0443\u0442\u044c \u043e\u0442 \u0435\u0434\u0438\u043d\u043e\u0439 \u0442\u043e\u0447\u043a\u0438 \u0432\u0445\u043e\u0434\u0430, \u0434\u043e \u043f\u0435\u0440\u0432\u043e\u0439 \u0438\u0433\u0440\u043e\u0432\u043e\u0439 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438<\/h2>\n<p>\u041f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0430 \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0435, \u043a\u0430\u043a \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043f\u0435\u0440\u0432\u044b\u0435 \u0448\u0430\u0433\u0438. \u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0434\u0432\u0430 \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u043d\u0430 \u0441\u0446\u0435\u043d\u0435: \u043f\u0443\u0441\u0442\u043e\u0439 Canvas \u0438 GameObject Entry Point \u0441 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u043e\u043c \u043d\u0430 \u043d\u0451\u043c \u0441 \u0442\u0430\u043a\u0438\u043c \u0436\u0435 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435\u043c.<\/p>\n<p>\u041a\u043b\u0430\u0441\u0441 EntryPoint \u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u044c \u0441\u043e\u0432\u0441\u0435\u043c \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u043a\u043e\u0434\u0430<\/p>\n<details class=\"spoiler\">\n<summary>EntryPoint<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"cs\">public class EntryPoint : MonoBehaviour {    [SerializeField] private ContentProvider _contentProvider;    [SerializeField] private RectTransform _uiRoot;     private Root _root;     private void Start()    {        var rootCtx = new Root.Ctx        {            contentProvider = _contentProvider,            uiRoot = _uiRoot,        };           _root = Root.CreateRoot(rootCtx);    }     private void OnDestroy()    {        _root.Dispose();    } } <\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<p>\u0422\u0443\u0442 \u0441\u0442\u043e\u0438\u0442 \u043f\u043e\u044f\u0441\u043d\u0438\u0442\u044c, \u0447\u0442\u043e <code>_uiRoot<\/code> &#8212; \u044d\u0442\u043e\u0442 \u0442\u043e\u0442 \u0441\u0430\u043c\u044b\u0439 \u043f\u0443\u0441\u0442\u043e\u0439 \u043a\u0430\u043d\u0432\u0430\u0441, \u0430 <code>_contentProvider<\/code> &#8212; \u044d\u0442\u043e scriptable object, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0431\u0443\u0434\u0435\u0442 \u043b\u0435\u0436\u0430\u0442\u044c \u0432\u0441\u0451, \u0447\u0442\u043e \u0432 \u0434\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0435\u043c \u0434\u043e\u043b\u0436\u043d\u043e \u043f\u043e\u044f\u0432\u0438\u0442\u044c\u0441\u044f \u043d\u0430 \u0441\u0446\u0435\u043d\u0435. \u041a\u043b\u0430\u0441\u0441\u0430 Root \u0443 \u043d\u0430\u0441 \u0435\u0449\u0451 \u043d\u0435\u0442 \u0438 \u0434\u0430\u043b\u044c\u0448\u0435 \u043c\u044b \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0438 \u0435\u0433\u043e.<\/p>\n<figure class=\"bordered full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/821\/600\/3ff\/8216003ff9502e425984f8364bff4361.png\" alt=\"\u0412 \u0431\u0443\u0434\u0443\u0449\u0435\u043c \u043e\u0441\u0432\u0435\u0449\u0435\u043d\u0438\u0435 \u0438 \u043a\u0430\u043c\u0435\u0440\u0443 \u0442\u043e\u0436\u0435 \u0441\u0442\u043e\u0438\u0442 \u043f\u043e\u0434\u0433\u0440\u0443\u0436\u0430\u0442\u044c \u0438\u0437 Content Provider\" title=\"\u0412 \u0431\u0443\u0434\u0443\u0449\u0435\u043c \u043e\u0441\u0432\u0435\u0449\u0435\u043d\u0438\u0435 \u0438 \u043a\u0430\u043c\u0435\u0440\u0443 \u0442\u043e\u0436\u0435 \u0441\u0442\u043e\u0438\u0442 \u043f\u043e\u0434\u0433\u0440\u0443\u0436\u0430\u0442\u044c \u0438\u0437 Content Provider\" width=\"1352\" height=\"478\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/821\/600\/3ff\/8216003ff9502e425984f8364bff4361.png\"\/><figcaption>\u0412 \u0431\u0443\u0434\u0443\u0449\u0435\u043c \u043e\u0441\u0432\u0435\u0449\u0435\u043d\u0438\u0435 \u0438 \u043a\u0430\u043c\u0435\u0440\u0443 \u0442\u043e\u0436\u0435 \u0441\u0442\u043e\u0438\u0442 \u043f\u043e\u0434\u0433\u0440\u0443\u0436\u0430\u0442\u044c \u0438\u0437 Content Provider<\/figcaption><\/figure>\n<p>\u0422\u0443\u0442 \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u0442\u0441\u044f \u0432\u0441\u0451 \u0441\u0430\u043c\u043e\u0435 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e\u0435, \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u0441\u043e\u0437\u0434\u0430\u0451\u043c \u043a\u043b\u0430\u0441\u0441 DisposableObject , \u043e\u0442 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u0431\u0443\u0434\u0443\u0442 \u0443\u043d\u0430\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043d\u044b \u0432\u0441\u0435 \u043d\u0430\u0448\u0438 \u0431\u0443\u0434\u0443\u0449\u0438\u0435 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438 \u0438 PM, \u0432\u043a\u043b\u044e\u0447\u0430\u044f Root. \u041d\u0430\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 DisposableObject \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e\u0431\u044b \u043f\u0440\u0438 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u0441\u0443\u043c\u0435\u0442\u044c \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e \u0443\u043d\u0438\u0447\u0442\u043e\u0436\u0438\u0442\u044c \u0441\u0432\u043e\u0438 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u044b \u0438 \u043f\u043e\u0434\u043f\u0438\u0441\u043a\u0438 \u0432\u043d\u0443\u0442\u0440\u0438 \u043d\u0438\u0445. \u0422\u0443\u0442 \u043c\u044b \u043f\u043e\u0441\u0442\u0435\u043f\u0435\u043d\u043d\u043e \u043f\u043e\u0434\u0445\u043e\u0434\u0438\u043c \u043a \u043f\u0430\u0442\u0442\u0435\u0440\u043d\u0443 Observer, \u043d\u043e \u043e\u0431\u043e \u0432\u0441\u0451\u043c \u043f\u043e \u043f\u043e\u0440\u044f\u0434\u043a\u0443.\u00a0<\/p>\n<details class=\"spoiler\">\n<summary>\u041a\u043b\u0430\u0441\u0441 DisposableObject<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"cs\">public abstract class DisposableObject : IDisposable {    private bool _isDisposed;    private List&lt;IDisposable> _mainThreadDisposables;    private List&lt;Object> _unityObjects;       public void Dispose()    {        if (_isDisposed)            return;        _isDisposed = true;        if (_mainThreadDisposables != null)        {            var mainThreadDisposables = _mainThreadDisposables;            for (var i = mainThreadDisposables.Count - 1; i >= 0; i--)                mainThreadDisposables[i]?.Dispose();            mainThreadDisposables.Clear();        }        try        {            OnDispose();        }        catch (Exception e)        {            Debug.Log($\"This exception can be ignored. Disposable of {GetType().Name}: {e}\");        }         if (_unityObjects == null) return;        foreach (var obj in _unityObjects.Where(obj => obj))        {            Object.Destroy(obj);        }    }     protected virtual void OnDispose() {}     protected TDisposable AddToDisposables&lt;TDisposable>(TDisposable disposable) where TDisposable : IDisposable    {        if (_isDisposed)        {            Debug.Log(\"disposed\");            return default;        }        if (disposable == null)        {            return default;        }         _mainThreadDisposables ??= new List&lt;IDisposable>(1);        _mainThreadDisposables.Add(disposable);        return disposable;    } } <\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<p>\u041e\u0434\u0438\u043d \u0438\u0437 \u043d\u0430\u0438\u0431\u043e\u043b\u0435\u0435 \u043f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u044b\u0445 \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u043e\u0432 \u0434\u043b\u044f \u0440\u0435\u0430\u043a\u0442\u0438\u0432\u043d\u043e\u0433\u043e \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0432 Unity \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f <a href=\"https:\/\/github.com\/neuecc\/UniRx\" rel=\"noopener noreferrer nofollow\">UniRx<\/a>, \u0438\u043c\u0435\u043d\u043d\u043e \u043e\u043d \u043f\u043e\u043c\u043e\u0436\u0435\u0442 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c \u043b\u043e\u0433\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u0441\u0432\u044f\u0437\u0438 \u043c\u0435\u0436\u0434\u0443 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u044f\u043c\u0438 \u0438 \u0438\u0445 \u043f\u043e\u0440\u043e\u0436\u0434\u0435\u043d\u0438\u044f\u043c\u0438. \u041f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435 \u043e \u043d\u0451\u043c \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0447\u0438\u0442\u0430\u0442\u044c \u0432\u043e\u0442 <a href=\"https:\/\/habr.com\/ru\/post\/342660\/\" rel=\"noopener noreferrer nofollow\">\u0437\u0434\u0435\u0441\u044c<\/a>. \u0418\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 IDisposable \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0447\u0430\u0441\u0442\u044c\u044e UniRx.<\/p>\n<details class=\"spoiler\">\n<summary>\u041a\u043b\u0430\u0441\u0441 Root<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"cs\">public class Root : DisposableObject {    public struct Ctx    {        public ContentProvider contentProvider;        public RectTransform uiRoot;    }    private readonly Ctx _ctx;       private Root(Ctx ctx)    {        _ctx = ctx;        CreateGameEntity();    }     private void CreateGameEntity()    {        var ctx = new GameEntity.Ctx        {            contentProvider = _ctx.contentProvider,            uiRoot = _ctx.uiRoot        };           AddToDisposables(new GameEntity(ctx));    } }<\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c <code>contentProvider<\/code> \u0438 <code>uiRoot<\/code> \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u043c\u0438 \u0432 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0435 Ctx (\u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u0441\u043e\u043a\u0440\u0430\u0449\u0435\u043d\u043d\u043e \u043e\u0442 Context). \u042d\u0442\u0430 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 \u0431\u044b\u043b\u0430 \u0441\u043e\u0437\u0434\u0430\u043d\u0430 \u0432 EntryPoint \u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u043d\u0430 \u0432 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 \u043a\u043b\u0430\u0441\u0441\u0430 Root, \u0447\u0442\u043e \u043f\u043e\u043b\u043e\u0436\u0438\u043b\u043e \u043e\u0441\u043d\u043e\u0432\u0443 \u201c\u043a\u043e\u0440\u043d\u044e\u201d \u0434\u043b\u044f \u0431\u0443\u0434\u0443\u0449\u0435\u0433\u043e \u0434\u0435\u0440\u0435\u0432\u0430 \u043d\u0430\u0448\u0435\u0433\u043e \u043f\u0440\u043e\u0435\u043a\u0442\u0430.<\/p>\n<details class=\"spoiler\">\n<summary>\u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c Game Entity <\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"cs\">public class GameEntity : DisposableObject {    public struct Ctx    {        public ContentProvider contentProvider;        public RectTransform uiRoot;    }       private readonly Ctx _ctx;    private UIEntity _uiEntity;       public GameEntity(Ctx ctx)    {        _ctx = ctx;        CreateUIEntity();    }     private void CreateUIEntity()    {        var UIEntityCtx = new UIEntity.Ctx()        {            contentProvider = _ctx.contentProvider,            uiRoot = _ctx.uiRoot        };        _uiEntity = new UIEntity(UIEntityCtx);        AddToDisposables(_uiEntity);    } }<\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<h2>\u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043f\u0440\u043e\u0441\u0442\u0435\u0439\u0448\u0435\u0439 \u043b\u043e\u0433\u0438\u043a\u0438<\/h2>\n<p>\u041d\u0430 \u0434\u0430\u043d\u043d\u043e\u043c \u044d\u0442\u0430\u043f\u0435 Game Entity \u043f\u043e\u0440\u043e\u0436\u0434\u0430\u0435\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0434\u043d\u0443 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u044c UIEntity, \u0432\u043d\u0443\u0442\u0440\u0438 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0431\u0443\u0434\u0435\u0442 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u0430 \u043f\u0440\u043e\u0441\u0442\u0430\u044f \u043b\u043e\u0433\u0438\u043a\u0430 \u043f\u043e\u0434\u0441\u0447\u0451\u0442\u0430 \u043a\u043b\u0438\u043a\u043e\u0432 \u043f\u043e \u043a\u043d\u043e\u043f\u043a\u0435. \u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e UIEntity \u0438 \u043b\u043e\u0433\u0438\u043a\u0443 \u0441\u0432\u044f\u0437\u0435\u0439 \u0432\u043d\u0443\u0442\u0440\u0438 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438 \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 \u0440\u0435\u0430\u043a\u0442\u0438\u0432\u043d\u043e\u0439 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439.<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/a01\/59d\/72d\/a0159d72df107b78d17624e2c322c597.png\" width=\"2666\" height=\"1160\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/a01\/59d\/72d\/a0159d72df107b78d17624e2c322c597.png\"\/><figcaption><\/figcaption><\/figure>\n<details class=\"spoiler\">\n<summary>\u041a\u043b\u0430\u0441\u0441 UIEntity<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"cs\">public class UIEntity : DisposableObject {    public struct Ctx    {        public ContentProvider contentProvider;        public RectTransform uiRoot;    }     private readonly Ctx _ctx;    private UIPm _pm;    private UIviewWithButton _view;    private readonly ReactiveProperty&lt;int> _buttonClickCounter = new ReactiveProperty&lt;int>();    public UIEntity(Ctx ctx)    {        _ctx = ctx;        CreatePm();        CreateView();    }     private void CreatePm()    {        var uiPmCtx = new UIPm.Ctx()        {            buttonClickCounter = _buttonClickCounter        };        _pm = new UIPm(uiPmCtx);        AddToDisposables(_pm);    }     private void CreateView()    {        _view = Object.Instantiate(_ctx.contentProvider.uIviewWithButton, _ctx.uiRoot);        _view.Init(new UIviewWithButton.Ctx()        {            buttonClickCounter = _buttonClickCounter        });    }     protected override void OnDispose()    {        base.OnDispose();        if(_view != null)            Object.Destroy(_view.gameObject);    } } <\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<details class=\"spoiler\">\n<summary>\u041a\u043b\u0430\u0441\u0441 UIPm<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"cs\">public class UIPm : DisposableObject {    public struct Ctx    {        public ReactiveProperty&lt;int> buttonClickCounter;    }     private Ctx _ctx;       public UIPm(Ctx ctx)    {        _ctx = ctx;        _ctx.buttonClickCounter.Subscribe(ShowClicks);    }     private void ShowClicks(int click)    {        Debug.Log($\"clicks: {click}\");    } } <\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<details class=\"spoiler\">\n<summary>\u041a\u043b\u0430\u0441\u0441 UIViewWithButton<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"cs\">public class UIviewWithButton : MonoBehaviour {    public struct Ctx    {        public ReactiveProperty&lt;int> buttonClickCounter;    }     private Ctx _ctx;    [SerializeField] private Button button;     public void Init(Ctx ctx)    {        _ctx = ctx;        button.onClick.AddListener( () => _ctx.buttonClickCounter.Value++);    } } <\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<p>\u0421\u0443\u0449\u043d\u043e\u0441\u0442\u044c \u043f\u043e\u0440\u043e\u0436\u0434\u0430\u0435\u0442 PM c \u043b\u043e\u0433\u0438\u043a\u043e\u0439 \u0432\u044b\u0432\u043e\u0434\u0430 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0430 \u043a\u043b\u0438\u043a\u043e\u0432 \u0432 Debug.Log. \u0417\u0434\u0435\u0441\u044c \u0432\u0441\u0451 \u043f\u0440\u043e\u0441\u0442\u043e \u0438 \u0430\u043a\u0446\u0435\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u043d\u0435 \u043d\u0430 \u0447\u0435\u043c. \u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0432\u044c\u044e\u0445\u0438 \u0447\u0443\u0442\u044c \u0431\u043e\u043b\u0435\u0435 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u0430\u044f. \u0414\u043b\u044f \u0435\u0451 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043f\u0440\u0438\u0433\u043e\u0434\u0438\u043b\u0438\u0441\u044c <code>content provider<\/code>, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043b\u0435\u0436\u0430\u043b \u043f\u0440\u0435\u0444\u0430\u0431 \u0441 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u043c \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u043e\u043c \u0438 <code>uiRoot<\/code>, \u043f\u043e\u0441\u043b\u0443\u0436\u0438\u0432\u0448\u0438\u0439 \u0440\u043e\u0434\u0438\u0442\u0435\u043b\u0435\u043c \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043f\u0440\u0435\u0444\u0430\u0431\u0430.<\/p>\n<p><code>buttonClickCounter<\/code> \u00a0&#8212; \u0440\u0435\u0430\u043a\u0442\u0438\u0432\u043d\u0430\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f, \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u0430\u044f \u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u043e\u043c UniRx, \u0441\u0442\u0430\u0432\u0448\u0430\u044f \u0447\u0430\u0441\u0442\u044c\u044e \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430 \u0434\u043b\u044f \u0432\u044c\u044e\u0445\u0438 \u0438 pm. \u041e\u043d\u0430 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u0432 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438 \u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u0451\u0442\u0441\u044f \u0434\u0430\u043b\u044c\u0448\u0435. UIViewWithButton \u043d\u0430 \u043a\u0430\u0436\u0434\u044b\u0439 \u043a\u043b\u0438\u043a \u0438\u043d\u043a\u0440\u0438\u043c\u0438\u043d\u0438\u0440\u0443\u0435\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439, UIPm \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u044d\u0442\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435. \u0414\u043b\u044f \u044d\u0442\u043e \u0432 Pm \u043d\u0443\u0436\u043d\u043e \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043f\u043e\u0434\u043f\u0438\u0441\u043a\u0443 \u043d\u0430 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439. \u042d\u0442\u0430 \u043f\u043e\u0434\u043f\u0438\u0441\u043a\u0430 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0432 \u0441\u043f\u0438\u0441\u043e\u043a \u0432\u043d\u0443\u0442\u0440\u0438 DisposableObject \u0438 \u0431\u0443\u0434\u0435\u0442 \u0443\u043d\u0438\u0447\u0442\u043e\u0436\u0435\u043d\u0430, \u043f\u0440\u0438 \u0440\u0430\u0437\u0440\u0443\u0448\u0435\u043d\u0438\u0438 \u043e\u0431\u044a\u0435\u043a\u0442\u0430.\u00a0<\/p>\n<p>\u0415\u0441\u0442\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u043e, \u0432 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0435 \u043c\u043e\u0436\u043d\u043e \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0442\u044c \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u043b\u044e\u0431\u043e\u0433\u043e \u0442\u0438\u043f\u0430, \u043d\u043e \u0438\u043c\u0435\u043d\u043d\u043e \u0440\u0435\u0430\u043a\u0442\u0438\u0432\u043d\u044b\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u0438 \u0441\u043e\u0431\u044b\u0442\u0438\u044f \u043d\u0430\u0438\u0431\u043e\u043b\u0435\u0435 \u0443\u0434\u043e\u0431\u043d\u044b \u0434\u043b\u044f \u043e\u0440\u0433\u0430\u043d\u0438\u0437\u0430\u0446\u0438\u0438 \u0441\u0432\u044f\u0437\u0435\u0439 \u043c\u0435\u0436\u0434\u0443 \u043b\u043e\u0433\u0438\u0447\u0435\u0441\u043a\u0438\u043c\u0438 \u0435\u0434\u0438\u043d\u0438\u0446\u0430\u043c\u0438.\u00a0<\/p>\n<p>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0442\u0430\u043a\u0443\u044e \u0441\u0432\u044f\u0437\u044c, \u043c\u043e\u0436\u043d\u043e \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u043a\u0440\u0430\u0442\u043a\u0438\u0435 \u0438\u043d\u043a\u0430\u043f\u0441\u0443\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u0432\u044c\u044e\u0445\u0438, \u043e\u0441\u0442\u0430\u0432\u043b\u044f\u044f \u0438\u043c \u0442\u043e\u043b\u044c\u043a\u043e \u043c\u043e\u043c\u0435\u043d\u0442\u044b \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u0441 \u0438\u0433\u0440\u043e\u043a\u043e\u043c, \u0430 \u0432\u0441\u044e \u043b\u043e\u0433\u0438\u043a\u0443 \u043f\u0440\u044f\u0442\u0430\u0442\u044c \u0432 pm. \u0421\u0443\u0449\u043d\u043e\u0441\u0442\u0438 \u043c\u043e\u0433\u0443\u0442 \u043f\u043e\u0440\u043e\u0436\u0434\u0430\u0442\u044c \u0434\u0440\u0443\u0433\u0438\u0435 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438, \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0438\u0435 \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0443\u0433\u043e\u0434\u043d\u043e \u0432\u044c\u044e\u0445 \u0438 pm. \u0422\u0443\u0442 \u0443\u0436\u0435 \u0432\u0441\u0451 \u0437\u0430\u0432\u0438\u0441\u0438\u0442 \u043e\u0442 \u043c\u0430\u0441\u0442\u0435\u0440\u0441\u0442\u0432\u0430 \u0434\u0435\u043a\u043e\u043c\u043e\u0437\u0438\u0446\u0438\u0438 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0441\u0442\u0430. \u0421\u0432\u044f\u0437\u0438 \u043c\u0435\u0436\u0434\u0443 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u044f\u043c\u0438 \u0442\u0430\u043a \u0436\u0435 \u043b\u0435\u0433\u043a\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u044e\u0442\u0441\u044f \u0447\u0435\u0440\u0435\u0437 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u044b \u0438 \u0440\u0435\u0430\u043a\u0442\u0438\u0432\u043d\u044b\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435.<\/p>\n<h2>\u0420\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u0435 \u043b\u043e\u0433\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u0447\u0430\u0441\u0442\u0438<\/h2>\n<p>\u0414\u043e\u0431\u0430\u0432\u0438\u043c \u043b\u043e\u0433\u0438\u043a\u0443 \u0432\u0440\u0430\u0449\u0435\u043d\u0438\u044f \u043a\u0443\u0431\u0430 \u043f\u043e \u043d\u0430\u0436\u0430\u0442\u0438\u044e \u043d\u0430 \u0443\u0436\u0435 \u0438\u043c\u0435\u044e\u0449\u0443\u044e\u0441\u044f \u043a\u043d\u043e\u043f\u043a\u0443.<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/59d\/8e6\/e29\/59d8e6e2956660ee7eaae2a87e96987b.png\" width=\"2672\" height=\"1008\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/59d\/8e6\/e29\/59d8e6e2956660ee7eaae2a87e96987b.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u0414\u043b\u044f \u044d\u0442\u043e \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0435\u0449\u0451 \u043e\u0434\u043d\u0443 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u044c \u0438 \u043e\u043f\u0438\u0448\u0435\u043c \u0432 \u043d\u0435\u0439 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0438\u0433\u0440\u043e\u0432\u043e\u0433\u043e \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u0438 \u0435\u0433\u043e \u0440\u0435\u0430\u043a\u0446\u0438\u044e \u043d\u0430 \u043d\u0430\u0436\u0430\u0442\u0438\u0435 \u043a\u043d\u043e\u043f\u043a\u0438. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e <code>buttonClickCounter<\/code> \u00a0\u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0432\u044b\u043d\u0435\u0441\u0442\u0438 \u043d\u0430 \u0443\u0440\u043e\u0432\u0435\u043d\u044c \u0432\u044b\u0448\u0435 \u0432 Game Entity \u0438 \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0435\u0451 \u0432 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442 UIEntity.<\/p>\n<details class=\"spoiler\">\n<summary>\u041e\u0431\u043d\u043e\u0432\u043b\u0451\u043d\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441 Game Entity<\/summary>\n<div class=\"spoiler__content\">\n<\/p>\n<pre><code class=\"cs\">public class GameEntity : DisposableObject {    public struct Ctx    {        public ContentProvider contentProvider;        public RectTransform uiRoot;    }       private readonly Ctx _ctx;    private UIEntity _uiEntity;    private CubeEntity _cubeEntity;    private readonly ReactiveProperty&lt;int> _buttonClickCounter = new ReactiveProperty&lt;int>();        public GameEntity(Ctx ctx)    {        _ctx = ctx;        CreateUIEntity();        CreteCubeEntity();    }     private void CreateUIEntity()    {        var UIEntityCtx = new UIEntity.Ctx()        {            contentProvider = _ctx.contentProvider,            uiRoot = _ctx.uiRoot,            buttonClickCounter = _buttonClickCounter        };        _uiEntity = new UIEntity(UIEntityCtx);        AddToDisposables(_uiEntity);    }     private void CreteCubeEntity()    {        var cubeEntityCtx = new CubeEntity.Ctx()        {            contentProvider = _ctx.contentProvider,            buttonClickCounter = _buttonClickCounter        };        _cubeEntity = new CubeEntity(cubeEntityCtx);        AddToDisposables(_cubeEntity);    } } <\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<details class=\"spoiler\">\n<summary>\u041a\u043b\u0430\u0441\u0441 CubeEntity<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"cs\">public class CubeEntity : DisposableObject {    public struct Ctx    {        public ContentProvider contentProvider;        public ReactiveProperty&lt;int> buttonClickCounter;     }     private Ctx _ctx;    private CubePm _pm;    private CubeView _view;    private readonly ReactiveProperty&lt;float> _rotateAngle = new ReactiveProperty&lt;float>();       public CubeEntity(Ctx ctx)    {        _ctx = ctx;        CreatePm();        CreteView();    }     private void CreatePm()    {        var cubePmCtx = new CubePm.Ctx()        {            buttonClickCounter = _ctx.buttonClickCounter,            rotateAngle = _rotateAngle        };        _pm = new CubePm(cubePmCtx);        AddToDisposables(_pm);    }     private void CreteView()    {        _view = Object.Instantiate(_ctx.contentProvider.cubeView, Vector3.zero, Quaternion.identity);        _view.Init(new CubeView.Ctx()        {            rotateAngle = _rotateAngle        });    }       protected override void OnDispose()    {        base.OnDispose();        if(_view != null)            Object.Destroy(_view.gameObject);    } } <\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<p>\u0412 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442 \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u043e\u0439 CubeEntity \u0442\u043e\u0436\u0435 \u0432\u0445\u043e\u0434\u0438\u0442 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f <code>buttonClickCounter<\/code>, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0434\u043e\u0445\u043e\u0434\u0438\u0442 \u0434\u043e CubePm. \u0422\u0430\u043c \u0436\u0435 \u043d\u0430 \u043d\u0435\u0451 \u043f\u043e\u0434\u043f\u0438\u0441\u0430\u043d \u043c\u0435\u0442\u043e\u0434 \u0437\u0430\u0434\u0430\u044e\u0449\u0438\u0439 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0434\u043b\u044f \u0434\u0440\u0443\u0433\u043e\u0439 \u0440\u0435\u0430\u043a\u0442\u0438\u0432\u043d\u043e\u0439 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 <code>rotateAngle<\/code>, \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u0443\u044e, \u0432 \u0441\u0432\u043e\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u044c, \u043f\u043e\u0434\u043f\u0438\u0441\u0430\u043d\u0430 CubeView.\u00a0<\/p>\n<p>\u041e\u0431\u0440\u0430\u0449\u0443 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u0447\u0442\u043e \u0441\u043f\u043e\u0441\u043e\u0431\u044b \u043e\u0440\u0433\u0430\u043d\u0438\u0437\u0430\u0446\u0438\u0438 \u043f\u043e\u0434\u043f\u0438\u0441\u043a\u0438 \u0432 Pm \u0438 View \u0440\u0430\u0437\u043b\u0438\u0447\u0430\u044e\u0442\u0441\u044f. \u0415\u0441\u043b\u0438 \u0432\u043d\u0443\u0442\u0440\u0438 pm \u043f\u043e\u0434\u043f\u0438\u0441\u043a\u0443 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0432 \u0441\u043f\u0438\u0441\u043e\u043a \u043d\u0430 \u201c\u0440\u0430\u0437\u0440\u0443\u0448\u0435\u043d\u0438\u0435\u201d, \u0442\u043e \u0432\u043d\u0443\u0442\u0440\u0438 MonoBehaviour\u00a0 \u0432\u044c\u044e\u0445\u0438, \u043f\u043e\u0434\u043f\u0438\u0441\u043a\u0435 \u043d\u0443\u0436\u043d\u043e \u0443\u043a\u0430\u0437\u0430\u0442\u044c, \u0447\u0442\u043e \u043e\u043d\u0430 \u043f\u0440\u0438\u043d\u0430\u0434\u043b\u0435\u0436\u0438\u0442 \u0438\u043c\u0435\u043d\u043d\u043e \u044d\u0442\u043e\u043c\u0443 \u043e\u0431\u044a\u0435\u043a\u0442\u0443, \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u043e \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <code>.addTo(this)<\/code>. \u0422\u0430\u043a\u0430\u044f \u043f\u0440\u0438\u0432\u044f\u0437\u043a\u0430 \u043f\u043e\u043c\u043e\u0436\u0435\u0442 \u0443\u043d\u0438\u0447\u0442\u043e\u0436\u0438\u0442\u044c \u043f\u043e\u0434\u043f\u0438\u0441\u043a\u0443 \u0432\u043c\u0435\u0441\u0442\u0435 \u0441 GameObject, \u043a\u043e\u0433\u0434\u0430 \u0434\u043e \u044d\u0442\u043e\u0433\u043e \u0434\u043e\u0439\u0434\u0451\u0442 \u0434\u0435\u043b\u043e.<\/p>\n<details class=\"spoiler\">\n<summary>\u041a\u043b\u0430\u0441\u0441 CubePm<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"cs\">public class CubePm : DisposableObject {    public struct Ctx    {        public ReactiveProperty&lt;float> rotateAngle;        public ReactiveProperty&lt;int> buttonClickCounter;    }     private Ctx _ctx;       public CubePm(Ctx ctx)    {        _ctx = ctx;        AddToDisposables(_ctx.buttonClickCounter.Subscribe(AddRotationAngle));    }     private void AddRotationAngle(int clickCount)    {        _ctx.rotateAngle.Value = clickCount * 30;    } } <\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<details class=\"spoiler\">\n<summary>\u041a\u043b\u0430\u0441\u0441 CubeView<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"cs\">public class CubeView: MonoBehaviour {    public struct Ctx    {        public ReactiveProperty&lt;float> rotateAngle;    }     private Ctx _ctx;     public void Init(Ctx ctx)    {        _ctx = ctx;        _ctx.rotateAngle.Subscribe(RotateMe).AddTo(this);    }     private void RotateMe(float angle)    {        transform.eulerAngles = new Vector3(0, angle, 0);    } } <\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<p>\u0418\u0442\u0430\u043a, \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0438 \u043f\u0440\u043e\u0435\u043a\u0442 \u0432\u043e\u0442 \u0441 \u0442\u0430\u043a\u043e\u0439 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u043e\u0439. \u0413\u043b\u044f\u0434\u044f \u043d\u0430 \u043a\u043e\u0434 \u043d\u0435 \u0432\u0441\u0435\u0433\u0434\u0430 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442\u0441\u044f \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u043e\u043f\u0438\u0441\u0430\u043d\u043d\u0443\u044e \u043b\u043e\u0433\u0438\u043a\u0443 \u0432 \u0432\u0438\u0434\u0435 \u0441\u0445\u0435\u043c\u044b, \u0430 \u043d\u0430 \u043d\u0430 \u044d\u0442\u043e\u043c \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0438 \u0445\u043e\u0440\u043e\u0448\u043e \u043f\u043e\u043d\u044f\u0442\u0435\u043d \u043f\u0440\u0438\u043d\u0446\u0438\u043f \u043e\u0440\u0433\u0430\u043d\u0438\u0437\u0430\u0446\u0438\u0438 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0435\u0439 \u0432 Composition root. <\/p>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/851\/51d\/7a6\/85151d7a65a148c72ddaf71384298146.png\" width=\"450\" height=\"278\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/851\/51d\/7a6\/85151d7a65a148c72ddaf71384298146.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u0421\u043a\u0430\u0447\u0430\u0442\u044c \u0438 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043f\u0440\u043e\u0435\u043a\u0442 \u0432 \u0440\u0430\u0431\u043e\u0447\u0435\u043c \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0438 \u043c\u043e\u0436\u043d\u043e <a href=\"https:\/\/github.com\/laststare\/CompositionRootProject\" rel=\"noopener noreferrer nofollow\">\u0442\u0443\u0442<\/a>.<\/p>\n<h2>\u041d\u0430\u043f\u043e\u0441\u043b\u0435\u0434\u043e\u043a<\/h2>\n<p>\u042f \u0437\u043d\u0430\u044e, \u0447\u0442\u043e \u043c\u043d\u043e\u0433\u043e \u0447\u0435\u0433\u043e \u043d\u0435 \u0443\u043a\u0430\u0437\u0430\u043b, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043c\u043e\u0436\u043d\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c singleton \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0443 \u0432 \u043a\u043b\u0430\u0441\u0441\u0435 root, \u0447\u0442\u043e\u0431\u044b \u0443\u0431\u0435\u0440\u0435\u0447\u044c \u043a\u043e\u0440\u043d\u0435\u0432\u043e\u0439 \u043a\u043b\u0430\u0441\u0441 \u043e\u0442 \u0434\u0443\u0431\u043b\u0438\u043a\u0430\u0442\u0430 \u0438\u043b\u0438 \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u0430\u0442\u044c \u043f\u043e\u0431\u043e\u043b\u044c\u0448\u0435 \u043e\u00a0 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044f\u0445 UniRx, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043e \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0438 \u0440\u0435\u0430\u043a\u0442\u0438\u0432\u043d\u044b\u0445 \u0441\u043e\u0431\u044b\u0442\u0438\u0439. \u041d\u043e \u043e\u0431 \u044d\u0442\u043e\u043c, \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e, \u0432 \u0434\u0440\u0443\u0433\u043e\u0439 \u0440\u0430\u0437. \u0417\u0434\u0435\u0441\u044c \u044f \u0445\u043e\u0442\u0435\u043b \u0434\u0430\u0442\u044c \u0431\u043e\u043b\u044c\u0448\u0435 \u043f\u0440\u0438\u043a\u043b\u0430\u0434\u043d\u043e\u0433\u043e \u043c\u0430\u0442\u0435\u0440\u0438\u0430\u043b\u0430, \u043e \u0442\u043e\u043c \u043a\u0430\u043a \u0441\u0442\u0430\u0440\u0442\u0430\u043d\u0443\u0442\u044c \u043f\u0440\u043e\u0435\u043a\u0442 \u0441 \u043d\u0443\u043b\u044f \u0441 \u043f\u043e\u043d\u044f\u0442\u043d\u043e\u0439 \u0438 \u0443\u0441\u0442\u043e\u0439\u0447\u0438\u0432\u043e\u0439 \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u043e\u0439.<\/p>\n<p>\u0412 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439 \u0447\u0430\u0441\u0442\u0438 \u0441\u0442\u0430\u0442\u044c\u0438 \u044f \u0440\u0430\u0441\u0441\u043a\u0430\u0436\u0443 \u043e \u0442\u043e\u043c \u043a\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u0432 \u0440\u0430\u043c\u043a\u0430\u0445 composition root \u0441\u043c\u0435\u043d\u0438\u0442\u044c \u0437\u043d\u0430\u0447\u0438\u043c\u044b\u0435 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b \u043d\u0430 \u0441\u0441\u044b\u043b\u043e\u0447\u043d\u044b\u0435 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u044b \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430. \u042d\u0442\u043e \u0438\u043c\u0435\u0435\u0442 \u0441\u0432\u043e\u0438 \u043f\u043b\u044e\u0441\u044b \u0438 \u043c\u0438\u043d\u0443\u0441\u044b \u0438 \u043a\u0430\u043a \u043c\u0438\u043d\u0438\u043c\u0443\u043c, \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e \u0434\u043b\u044f \u0438\u0437\u0443\u0447\u0435\u043d\u0438\u044f.<\/p>\n<\/p>\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\/post\/706140\/\"> https:\/\/habr.com\/ru\/post\/706140\/<\/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>\u041f\u0440\u0438\u0432\u0435\u0442 \u0432\u0441\u0435\u043c, \u043a\u0442\u043e \u043d\u0435\u0440\u0430\u0432\u043d\u043e\u0434\u0443\u0448\u0435\u043d \u043a \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u043d\u044b\u043c \u0440\u0435\u0448\u0435\u043d\u0438\u044f\u043c \u0432 \u0440\u0430\u043c\u043a\u0430\u0445 \u043f\u0440\u043e\u0435\u043a\u0442\u043e\u0432 \u043d\u0430 Unity \u0438 \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e. \u0415\u0441\u043b\u0438 \u0432\u043e\u043f\u0440\u043e\u0441 \u0432\u044b\u0431\u043e\u0440\u0430 \u0434\u043b\u044f \u0432\u0430\u0441 \u0435\u0449\u0451 \u0430\u043a\u0442\u0443\u0430\u043b\u0435\u043d \u0438\u043b\u0438 \u043f\u0440\u043e\u0441\u0442\u043e \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u0443\u0435\u0442\u0435\u0441\u044c \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u0430\u043c\u0438, \u0442\u043e \u0433\u043e\u0442\u043e\u0432 \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u0430\u0442\u044c \u043e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u044b Composition root \u0441 \u043f\u0440\u0438\u043c\u0435\u0440\u0430\u043c\u0438 \u043f\u0440\u043e\u0441\u0442\u0435\u0439\u0448\u0435\u0439 \u043b\u043e\u0433\u0438\u043a\u0438. \u0417\u0434\u0435\u0441\u044c \u0435\u0441\u0442\u044c \u0435\u0434\u0438\u043d\u0430\u044f \u0442\u043e\u0447\u043a\u0430 \u0432\u0445\u043e\u0434\u0430 \u0438 Dependency Injection, \u0442\u043e \u0435\u0441\u0442\u044c \u0432\u0441\u0451 \u043a\u0430\u043a \u043c\u044b \u043b\u044e\u0431\u0438\u043c. \u0421\u0430\u043c \u044f \u0443\u0436\u0435 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043b\u0435\u0442 \u043f\u0440\u0438\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u044e\u0441\u044c \u0434\u0430\u043d\u043d\u043e\u0439 \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u044b \u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043b \u043d\u0430 \u043d\u0435\u0439 \u043d\u0435 \u043c\u0430\u043b\u043e \u043f\u0440\u043e\u0435\u043a\u0442\u043e\u0432, \u043e\u0442 \u0413\u041a \u043f\u0440\u043e\u0442\u043e\u0442\u0438\u043f\u043e\u0432, \u0434\u043e pvp \u0438\u0433\u0440.<\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>Composition root \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u043e\u0431\u043e\u0439 \u0441\u043c\u0435\u0441\u044c \u043c\u043e\u0434\u0435\u043b\u0435\u0439 MVP \u0438 MVVM \u0438 \u0430\u043a\u0442\u0438\u0432\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u0448\u0430\u0431\u043b\u043e\u043d Observer, \u0432 \u0434\u0430\u043d\u043d\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u044f \u043d\u0435 \u0431\u0443\u0434\u0443 \u0443\u0433\u043b\u0443\u0431\u043b\u044f\u0442\u044c\u0441\u044f \u0432 \u0441\u0443\u0442\u044c \u044d\u0442\u0438\u0445 \u0442\u0435\u0440\u043c\u0438\u043d\u043e\u0432, \u0430 \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u044e \u043d\u0430\u0433\u043b\u044f\u0434\u043d\u043e \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u044c \u043a\u0430\u043a \u044d\u0442\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442. \u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b \u043f\u0440\u043e\u0435\u043a\u0442\u0430 \u0438\u0434\u0451\u0442 \u0447\u0435\u0440\u0435\u0437 \u0441\u0432\u044f\u0437\u043a\u0443 \u0431\u0430\u0437\u043e\u0432\u044b\u0445 \u043f\u043e\u043d\u044f\u0442\u0438\u0439:\u00a0 Entity &#8212; Presenter Model (PM) &#8212; View.<\/p>\n<p><strong>Entity<\/strong> &#8212; \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u044c, \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u0430\u044f \u043b\u043e\u0433\u0438\u0447\u0435\u0441\u043a\u0430\u044f \u0435\u0434\u0438\u043d\u0438\u0446\u0430, \u0441\u043b\u0443\u0436\u0430\u0449\u0430\u044f \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f PM \u0438 View \u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u044e\u0449\u0430\u044f \u0438\u043c \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438<\/p>\n<p><strong>Presenter Model<\/strong> &#8212; \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0431\u0438\u0437\u043d\u0435\u0441 \u043b\u043e\u0433\u0438\u043a\u0443, \u043d\u0435 \u0438\u043c\u0435\u044e\u0449\u0443\u044e \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u0435 \u043a Monobehaviour \u043a\u043b\u0430\u0441\u0441\u0430\u043c<\/p>\n<p><strong>View<\/strong> &#8212; Gameobject \u043d\u0430 \u0441\u0446\u0435\u043d\u0435<\/p>\n<h2>\u041f\u0443\u0442\u044c \u043e\u0442 \u0435\u0434\u0438\u043d\u043e\u0439 \u0442\u043e\u0447\u043a\u0438 \u0432\u0445\u043e\u0434\u0430, \u0434\u043e \u043f\u0435\u0440\u0432\u043e\u0439 \u0438\u0433\u0440\u043e\u0432\u043e\u0439 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438<\/h2>\n<p>\u041f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0430 \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0435, \u043a\u0430\u043a \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043f\u0435\u0440\u0432\u044b\u0435 \u0448\u0430\u0433\u0438. \u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0434\u0432\u0430 \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u043d\u0430 \u0441\u0446\u0435\u043d\u0435: \u043f\u0443\u0441\u0442\u043e\u0439 Canvas \u0438 GameObject Entry Point \u0441 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u043e\u043c \u043d\u0430 \u043d\u0451\u043c \u0441 \u0442\u0430\u043a\u0438\u043c \u0436\u0435 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435\u043c.<\/p>\n<p>\u041a\u043b\u0430\u0441\u0441 EntryPoint \u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u044c \u0441\u043e\u0432\u0441\u0435\u043c \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u043a\u043e\u0434\u0430<\/p>\n<details class=\"spoiler\">\n<summary>EntryPoint<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"cs\">public class EntryPoint : MonoBehaviour {    [SerializeField] private ContentProvider _contentProvider;    [SerializeField] private RectTransform _uiRoot;     private Root _root;     private void Start()    {        var rootCtx = new Root.Ctx        {            contentProvider = _contentProvider,            uiRoot = _uiRoot,        };           _root = Root.CreateRoot(rootCtx);    }     private void OnDestroy()    {        _root.Dispose();    } } <\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<p>\u0422\u0443\u0442 \u0441\u0442\u043e\u0438\u0442 \u043f\u043e\u044f\u0441\u043d\u0438\u0442\u044c, \u0447\u0442\u043e <code>_uiRoot<\/code> &#8212; \u044d\u0442\u043e\u0442 \u0442\u043e\u0442 \u0441\u0430\u043c\u044b\u0439 \u043f\u0443\u0441\u0442\u043e\u0439 \u043a\u0430\u043d\u0432\u0430\u0441, \u0430 <code>_contentProvider<\/code> &#8212; \u044d\u0442\u043e scriptable object, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0431\u0443\u0434\u0435\u0442 \u043b\u0435\u0436\u0430\u0442\u044c \u0432\u0441\u0451, \u0447\u0442\u043e \u0432 \u0434\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0435\u043c \u0434\u043e\u043b\u0436\u043d\u043e \u043f\u043e\u044f\u0432\u0438\u0442\u044c\u0441\u044f \u043d\u0430 \u0441\u0446\u0435\u043d\u0435. \u041a\u043b\u0430\u0441\u0441\u0430 Root \u0443 \u043d\u0430\u0441 \u0435\u0449\u0451 \u043d\u0435\u0442 \u0438 \u0434\u0430\u043b\u044c\u0448\u0435 \u043c\u044b \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0438 \u0435\u0433\u043e.<\/p>\n<figure class=\"bordered full-width\"><figcaption>\u0412 \u0431\u0443\u0434\u0443\u0449\u0435\u043c \u043e\u0441\u0432\u0435\u0449\u0435\u043d\u0438\u0435 \u0438 \u043a\u0430\u043c\u0435\u0440\u0443 \u0442\u043e\u0436\u0435 \u0441\u0442\u043e\u0438\u0442 \u043f\u043e\u0434\u0433\u0440\u0443\u0436\u0430\u0442\u044c \u0438\u0437 Content Provider<\/figcaption><\/figure>\n<p>\u0422\u0443\u0442 \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u0442\u0441\u044f \u0432\u0441\u0451 \u0441\u0430\u043c\u043e\u0435 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e\u0435, \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u0441\u043e\u0437\u0434\u0430\u0451\u043c \u043a\u043b\u0430\u0441\u0441 DisposableObject , \u043e\u0442 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u0431\u0443\u0434\u0443\u0442 \u0443\u043d\u0430\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043d\u044b \u0432\u0441\u0435 \u043d\u0430\u0448\u0438 \u0431\u0443\u0434\u0443\u0449\u0438\u0435 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438 \u0438 PM, \u0432\u043a\u043b\u044e\u0447\u0430\u044f Root. \u041d\u0430\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 DisposableObject \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e\u0431\u044b \u043f\u0440\u0438 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u0441\u0443\u043c\u0435\u0442\u044c \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e \u0443\u043d\u0438\u0447\u0442\u043e\u0436\u0438\u0442\u044c \u0441\u0432\u043e\u0438 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u044b \u0438 \u043f\u043e\u0434\u043f\u0438\u0441\u043a\u0438 \u0432\u043d\u0443\u0442\u0440\u0438 \u043d\u0438\u0445. \u0422\u0443\u0442 \u043c\u044b \u043f\u043e\u0441\u0442\u0435\u043f\u0435\u043d\u043d\u043e \u043f\u043e\u0434\u0445\u043e\u0434\u0438\u043c \u043a \u043f\u0430\u0442\u0442\u0435\u0440\u043d\u0443 Observer, \u043d\u043e \u043e\u0431\u043e \u0432\u0441\u0451\u043c \u043f\u043e \u043f\u043e\u0440\u044f\u0434\u043a\u0443.\u00a0<\/p>\n<details class=\"spoiler\">\n<summary>\u041a\u043b\u0430\u0441\u0441 DisposableObject<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"cs\">public abstract class DisposableObject : IDisposable {    private bool _isDisposed;    private List&lt;IDisposable> _mainThreadDisposables;    private List&lt;Object> _unityObjects;       public void Dispose()    {        if (_isDisposed)            return;        _isDisposed = true;        if (_mainThreadDisposables != null)        {            var mainThreadDisposables = _mainThreadDisposables;            for (var i = mainThreadDisposables.Count - 1; i >= 0; i--)                mainThreadDisposables[i]?.Dispose();            mainThreadDisposables.Clear();        }        try        {            OnDispose();        }        catch (Exception e)        {            Debug.Log($\"This exception can be ignored. Disposable of {GetType().Name}: {e}\");        }         if (_unityObjects == null) return;        foreach (var obj in _unityObjects.Where(obj => obj))        {            Object.Destroy(obj);        }    }     protected virtual void OnDispose() {}     protected TDisposable AddToDisposables&lt;TDisposable>(TDisposable disposable) where TDisposable : IDisposable    {        if (_isDisposed)        {            Debug.Log(\"disposed\");            return default;        }        if (disposable == null)        {            return default;        }         _mainThreadDisposables ??= new List&lt;IDisposable>(1);        _mainThreadDisposables.Add(disposable);        return disposable;    } } <\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<p>\u041e\u0434\u0438\u043d \u0438\u0437 \u043d\u0430\u0438\u0431\u043e\u043b\u0435\u0435 \u043f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u044b\u0445 \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u043e\u0432 \u0434\u043b\u044f \u0440\u0435\u0430\u043a\u0442\u0438\u0432\u043d\u043e\u0433\u043e \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0432 Unity \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f <a href=\"https:\/\/github.com\/neuecc\/UniRx\" rel=\"noopener noreferrer nofollow\">UniRx<\/a>, \u0438\u043c\u0435\u043d\u043d\u043e \u043e\u043d \u043f\u043e\u043c\u043e\u0436\u0435\u0442 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c \u043b\u043e\u0433\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u0441\u0432\u044f\u0437\u0438 \u043c\u0435\u0436\u0434\u0443 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u044f\u043c\u0438 \u0438 \u0438\u0445 \u043f\u043e\u0440\u043e\u0436\u0434\u0435\u043d\u0438\u044f\u043c\u0438. \u041f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435 \u043e \u043d\u0451\u043c \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0447\u0438\u0442\u0430\u0442\u044c \u0432\u043e\u0442 <a href=\"https:\/\/habr.com\/ru\/post\/342660\/\" rel=\"noopener noreferrer nofollow\">\u0437\u0434\u0435\u0441\u044c<\/a>. \u0418\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 IDisposable \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0447\u0430\u0441\u0442\u044c\u044e UniRx.<\/p>\n<details class=\"spoiler\">\n<summary>\u041a\u043b\u0430\u0441\u0441 Root<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"cs\">public class Root : DisposableObject {    public struct Ctx    {        public ContentProvider contentProvider;        public RectTransform uiRoot;    }    private readonly Ctx _ctx;       private Root(Ctx ctx)    {        _ctx = ctx;        CreateGameEntity();    }     private void CreateGameEntity()    {        var ctx = new GameEntity.Ctx        {            contentProvider = _ctx.contentProvider,            uiRoot = _ctx.uiRoot        };           AddToDisposables(new GameEntity(ctx));    } }<\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c <code>contentProvider<\/code> \u0438 <code>uiRoot<\/code> \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u043c\u0438 \u0432 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0435 Ctx (\u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u0441\u043e\u043a\u0440\u0430\u0449\u0435\u043d\u043d\u043e \u043e\u0442 Context). \u042d\u0442\u0430 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 \u0431\u044b\u043b\u0430 \u0441\u043e\u0437\u0434\u0430\u043d\u0430 \u0432 EntryPoint \u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u043d\u0430 \u0432 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 \u043a\u043b\u0430\u0441\u0441\u0430 Root, \u0447\u0442\u043e \u043f\u043e\u043b\u043e\u0436\u0438\u043b\u043e \u043e\u0441\u043d\u043e\u0432\u0443 \u201c\u043a\u043e\u0440\u043d\u044e\u201d \u0434\u043b\u044f \u0431\u0443\u0434\u0443\u0449\u0435\u0433\u043e \u0434\u0435\u0440\u0435\u0432\u0430 \u043d\u0430\u0448\u0435\u0433\u043e \u043f\u0440\u043e\u0435\u043a\u0442\u0430.<\/p>\n<details class=\"spoiler\">\n<summary>\u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c Game Entity <\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"cs\">public class GameEntity : DisposableObject {    public struct Ctx    {        public ContentProvider contentProvider;        public RectTransform uiRoot;    }       private readonly Ctx _ctx;    private UIEntity _uiEntity;       public GameEntity(Ctx ctx)    {        _ctx = ctx;        CreateUIEntity();    }     private void CreateUIEntity()    {        var UIEntityCtx = new UIEntity.Ctx()        {            contentProvider = _ctx.contentProvider,            uiRoot = _ctx.uiRoot        };        _uiEntity = new UIEntity(UIEntityCtx);        AddToDisposables(_uiEntity);    } }<\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<h2>\u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043f\u0440\u043e\u0441\u0442\u0435\u0439\u0448\u0435\u0439 \u043b\u043e\u0433\u0438\u043a\u0438<\/h2>\n<p>\u041d\u0430 \u0434\u0430\u043d\u043d\u043e\u043c \u044d\u0442\u0430\u043f\u0435 Game Entity \u043f\u043e\u0440\u043e\u0436\u0434\u0430\u0435\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0434\u043d\u0443 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u044c UIEntity, \u0432\u043d\u0443\u0442\u0440\u0438 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0431\u0443\u0434\u0435\u0442 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u0430 \u043f\u0440\u043e\u0441\u0442\u0430\u044f \u043b\u043e\u0433\u0438\u043a\u0430 \u043f\u043e\u0434\u0441\u0447\u0451\u0442\u0430 \u043a\u043b\u0438\u043a\u043e\u0432 \u043f\u043e \u043a\u043d\u043e\u043f\u043a\u0435. \u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e UIEntity \u0438 \u043b\u043e\u0433\u0438\u043a\u0443 \u0441\u0432\u044f\u0437\u0435\u0439 \u0432\u043d\u0443\u0442\u0440\u0438 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438 \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 \u0440\u0435\u0430\u043a\u0442\u0438\u0432\u043d\u043e\u0439 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439.<\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<details class=\"spoiler\">\n<summary>\u041a\u043b\u0430\u0441\u0441 UIEntity<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"cs\">public class UIEntity : DisposableObject {    public struct Ctx    {        public ContentProvider contentProvider;        public RectTransform uiRoot;    }     private readonly Ctx _ctx;    private UIPm _pm;    private UIviewWithButton _view;    private readonly ReactiveProperty&lt;int> _buttonClickCounter = new ReactiveProperty&lt;int>();    public UIEntity(Ctx ctx)    {        _ctx = ctx;        CreatePm();        CreateView();    }     private void CreatePm()    {        var uiPmCtx = new UIPm.Ctx()        {            buttonClickCounter = _buttonClickCounter        };        _pm = new UIPm(uiPmCtx);        AddToDisposables(_pm);    }     private void CreateView()    {        _view = Object.Instantiate(_ctx.contentProvider.uIviewWithButton, _ctx.uiRoot);        _view.Init(new UIviewWithButton.Ctx()        {            buttonClickCounter = _buttonClickCounter        });    }     protected override void OnDispose()    {        base.OnDispose();        if(_view != null)            Object.Destroy(_view.gameObject);    } } <\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<details class=\"spoiler\">\n<summary>\u041a\u043b\u0430\u0441\u0441 UIPm<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"cs\">public class UIPm : DisposableObject {    public struct Ctx    {        public ReactiveProperty&lt;int> buttonClickCounter;    }     private Ctx _ctx;       public UIPm(Ctx ctx)    {        _ctx = ctx;        _ctx.buttonClickCounter.Subscribe(ShowClicks);    }     private void ShowClicks(int click)    {        Debug.Log($\"clicks: {click}\");    } } <\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<details class=\"spoiler\">\n<summary>\u041a\u043b\u0430\u0441\u0441 UIViewWithButton<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"cs\">public class UIviewWithButton : MonoBehaviour {    public struct Ctx    {        public ReactiveProperty&lt;int> buttonClickCounter;    }     private Ctx _ctx;    [SerializeField] private Button button;     public void Init(Ctx ctx)    {        _ctx = ctx;        button.onClick.AddListener( () => _ctx.buttonClickCounter.Value++);    } } <\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<p>\u0421\u0443\u0449\u043d\u043e\u0441\u0442\u044c \u043f\u043e\u0440\u043e\u0436\u0434\u0430\u0435\u0442 PM c \u043b\u043e\u0433\u0438\u043a\u043e\u0439 \u0432\u044b\u0432\u043e\u0434\u0430 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0430 \u043a\u043b\u0438\u043a\u043e\u0432 \u0432 Debug.Log. \u0417\u0434\u0435\u0441\u044c \u0432\u0441\u0451 \u043f\u0440\u043e\u0441\u0442\u043e \u0438 \u0430\u043a\u0446\u0435\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u043d\u0435 \u043d\u0430 \u0447\u0435\u043c. \u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0432\u044c\u044e\u0445\u0438 \u0447\u0443\u0442\u044c \u0431\u043e\u043b\u0435\u0435 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u0430\u044f. \u0414\u043b\u044f \u0435\u0451 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043f\u0440\u0438\u0433\u043e\u0434\u0438\u043b\u0438\u0441\u044c <code>content provider<\/code>, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043b\u0435\u0436\u0430\u043b \u043f\u0440\u0435\u0444\u0430\u0431 \u0441 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u043c \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u043e\u043c \u0438 <code>uiRoot<\/code>, \u043f\u043e\u0441\u043b\u0443\u0436\u0438\u0432\u0448\u0438\u0439 \u0440\u043e\u0434\u0438\u0442\u0435\u043b\u0435\u043c \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043f\u0440\u0435\u0444\u0430\u0431\u0430.<\/p>\n<p><code>buttonClickCounter<\/code> \u00a0&#8212; \u0440\u0435\u0430\u043a\u0442\u0438\u0432\u043d\u0430\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f, \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u0430\u044f \u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u043e\u043c UniRx, \u0441\u0442\u0430\u0432\u0448\u0430\u044f \u0447\u0430\u0441\u0442\u044c\u044e \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430 \u0434\u043b\u044f \u0432\u044c\u044e\u0445\u0438 \u0438 pm. \u041e\u043d\u0430 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u0432 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438 \u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u0451\u0442\u0441\u044f \u0434\u0430\u043b\u044c\u0448\u0435. UIViewWithButton \u043d\u0430 \u043a\u0430\u0436\u0434\u044b\u0439 \u043a\u043b\u0438\u043a \u0438\u043d\u043a\u0440\u0438\u043c\u0438\u043d\u0438\u0440\u0443\u0435\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439, UIPm \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u044d\u0442\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435. \u0414\u043b\u044f \u044d\u0442\u043e \u0432 Pm \u043d\u0443\u0436\u043d\u043e \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043f\u043e\u0434\u043f\u0438\u0441\u043a\u0443 \u043d\u0430 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439. \u042d\u0442\u0430 \u043f\u043e\u0434\u043f\u0438\u0441\u043a\u0430 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0432 \u0441\u043f\u0438\u0441\u043e\u043a \u0432\u043d\u0443\u0442\u0440\u0438 DisposableObject \u0438 \u0431\u0443\u0434\u0435\u0442 \u0443\u043d\u0438\u0447\u0442\u043e\u0436\u0435\u043d\u0430, \u043f\u0440\u0438 \u0440\u0430\u0437\u0440\u0443\u0448\u0435\u043d\u0438\u0438 \u043e\u0431\u044a\u0435\u043a\u0442\u0430.\u00a0<\/p>\n<p>\u0415\u0441\u0442\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u043e, \u0432 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0435 \u043c\u043e\u0436\u043d\u043e \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0442\u044c \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u043b\u044e\u0431\u043e\u0433\u043e \u0442\u0438\u043f\u0430, \u043d\u043e \u0438\u043c\u0435\u043d\u043d\u043e \u0440\u0435\u0430\u043a\u0442\u0438\u0432\u043d\u044b\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u0438 \u0441\u043e\u0431\u044b\u0442\u0438\u044f \u043d\u0430\u0438\u0431\u043e\u043b\u0435\u0435 \u0443\u0434\u043e\u0431\u043d\u044b \u0434\u043b\u044f \u043e\u0440\u0433\u0430\u043d\u0438\u0437\u0430\u0446\u0438\u0438 \u0441\u0432\u044f\u0437\u0435\u0439 \u043c\u0435\u0436\u0434\u0443 \u043b\u043e\u0433\u0438\u0447\u0435\u0441\u043a\u0438\u043c\u0438 \u0435\u0434\u0438\u043d\u0438\u0446\u0430\u043c\u0438.\u00a0<\/p>\n<p>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0442\u0430\u043a\u0443\u044e \u0441\u0432\u044f\u0437\u044c, \u043c\u043e\u0436\u043d\u043e \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u043a\u0440\u0430\u0442\u043a\u0438\u0435 \u0438\u043d\u043a\u0430\u043f\u0441\u0443\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u0432\u044c\u044e\u0445\u0438, \u043e\u0441\u0442\u0430\u0432\u043b\u044f\u044f \u0438\u043c \u0442\u043e\u043b\u044c\u043a\u043e \u043c\u043e\u043c\u0435\u043d\u0442\u044b \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u0441 \u0438\u0433\u0440\u043e\u043a\u043e\u043c, \u0430 \u0432\u0441\u044e \u043b\u043e\u0433\u0438\u043a\u0443 \u043f\u0440\u044f\u0442\u0430\u0442\u044c \u0432 pm. \u0421\u0443\u0449\u043d\u043e\u0441\u0442\u0438 \u043c\u043e\u0433\u0443\u0442 \u043f\u043e\u0440\u043e\u0436\u0434\u0430\u0442\u044c \u0434\u0440\u0443\u0433\u0438\u0435 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438, \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0438\u0435 \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0443\u0433\u043e\u0434\u043d\u043e \u0432\u044c\u044e\u0445 \u0438 pm. \u0422\u0443\u0442 \u0443\u0436\u0435 \u0432\u0441\u0451 \u0437\u0430\u0432\u0438\u0441\u0438\u0442 \u043e\u0442 \u043c\u0430\u0441\u0442\u0435\u0440\u0441\u0442\u0432\u0430 \u0434\u0435\u043a\u043e\u043c\u043e\u0437\u0438\u0446\u0438\u0438 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0441\u0442\u0430. \u0421\u0432\u044f\u0437\u0438 \u043c\u0435\u0436\u0434\u0443 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u044f\u043c\u0438 \u0442\u0430\u043a \u0436\u0435 \u043b\u0435\u0433\u043a\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u044e\u0442\u0441\u044f \u0447\u0435\u0440\u0435\u0437 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u044b \u0438 \u0440\u0435\u0430\u043a\u0442\u0438\u0432\u043d\u044b\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435.<\/p>\n<h2>\u0420\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u0435 \u043b\u043e\u0433\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u0447\u0430\u0441\u0442\u0438<\/h2>\n<p>\u0414\u043e\u0431\u0430\u0432\u0438\u043c \u043b\u043e\u0433\u0438\u043a\u0443 \u0432\u0440\u0430\u0449\u0435\u043d\u0438\u044f \u043a\u0443\u0431\u0430 \u043f\u043e \u043d\u0430\u0436\u0430\u0442\u0438\u044e \u043d\u0430 \u0443\u0436\u0435 \u0438\u043c\u0435\u044e\u0449\u0443\u044e\u0441\u044f \u043a\u043d\u043e\u043f\u043a\u0443.<\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u0414\u043b\u044f \u044d\u0442\u043e \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0435\u0449\u0451 \u043e\u0434\u043d\u0443 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u044c \u0438 \u043e\u043f\u0438\u0448\u0435\u043c \u0432 \u043d\u0435\u0439 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0438\u0433\u0440\u043e\u0432\u043e\u0433\u043e \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u0438 \u0435\u0433\u043e \u0440\u0435\u0430\u043a\u0446\u0438\u044e \u043d\u0430 \u043d\u0430\u0436\u0430\u0442\u0438\u0435 \u043a\u043d\u043e\u043f\u043a\u0438. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e <code>buttonClickCounter<\/code> \u00a0\u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0432\u044b\u043d\u0435\u0441\u0442\u0438 \u043d\u0430 \u0443\u0440\u043e\u0432\u0435\u043d\u044c \u0432\u044b\u0448\u0435 \u0432 Game Entity \u0438 \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0435\u0451 \u0432 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442 UIEntity.<\/p>\n<details class=\"spoiler\">\n<summary>\u041e\u0431\u043d\u043e\u0432\u043b\u0451\u043d\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441 Game Entity<\/summary>\n<div class=\"spoiler__content\">\n<\/p>\n<pre><code class=\"cs\">public class GameEntity : DisposableObject {    public struct Ctx    {        public ContentProvider contentProvider;        public RectTransform uiRoot;    }       private readonly Ctx _ctx;    private UIEntity _uiEntity;    private CubeEntity _cubeEntity;    private readonly ReactiveProperty&lt;int> _buttonClickCounter = new ReactiveProperty&lt;int>();        public GameEntity(Ctx ctx)    {        _ctx = ctx;        CreateUIEntity();        CreteCubeEntity();    }     private void CreateUIEntity()    {        var UIEntityCtx = new UIEntity.Ctx()        {            contentProvider = _ctx.contentProvider,            uiRoot = _ctx.uiRoot,            buttonClickCounter = _buttonClickCounter        };        _uiEntity = new UIEntity(UIEntityCtx);        AddToDisposables(_uiEntity);    }     private void CreteCubeEntity()    {        var cubeEntityCtx = new CubeEntity.Ctx()        {      <\/code><\/pre>\n<\/div>\n<\/details>\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-342816","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/342816","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=342816"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/342816\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=342816"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=342816"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=342816"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}