{"id":15035719,"url":"https://github.com/dancher743/unity-mvp","last_synced_at":"2026-01-24T14:45:23.412Z","repository":{"id":228286548,"uuid":"772067512","full_name":"dancher743/unity-mvp","owner":"dancher743","description":"Implementation of MVP (Model-View-Presenter) architectural pattern via Unity engine.","archived":false,"fork":false,"pushed_at":"2024-05-06T16:11:57.000Z","size":11879,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-05-14T14:33:20.576Z","etag":null,"topics":["architectural-pattern","csharp-code","framework","model-view-presenter","mvp","unity","unity-framework","unity-mvp"],"latest_commit_sha":null,"homepage":"","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dancher743.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-03-14T13:27:32.000Z","updated_at":"2024-12-24T13:31:11.000Z","dependencies_parsed_at":"2024-03-18T03:32:08.232Z","dependency_job_id":"ffff4a34-5187-4b69-92fb-f147e861c08c","html_url":"https://github.com/dancher743/unity-mvp","commit_stats":null,"previous_names":["dancher743/unity-mvp"],"tags_count":6,"template":false,"template_full_name":null,"purl":"pkg:github/dancher743/unity-mvp","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dancher743%2Funity-mvp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dancher743%2Funity-mvp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dancher743%2Funity-mvp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dancher743%2Funity-mvp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dancher743","download_url":"https://codeload.github.com/dancher743/unity-mvp/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dancher743%2Funity-mvp/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28730186,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-24T10:24:43.181Z","status":"ssl_error","status_checked_at":"2026-01-24T10:24:36.112Z","response_time":89,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["architectural-pattern","csharp-code","framework","model-view-presenter","mvp","unity","unity-framework","unity-mvp"],"created_at":"2024-09-24T20:29:18.739Z","updated_at":"2026-01-24T14:45:23.393Z","avatar_url":"https://github.com/dancher743.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# unity-mvp\nImplementation of MVP (Model-View-Presenter) architectural pattern via Unity engine.\n\nSample\n---\nBefore to start, it's recommended to get [sample project](https://github.com/dancher743/unity-mvp/releases/tag/sample-project) with the latest version of the package.\n\nGetting Started\n---\n### What is MVP?\n**MVP** or **Model-View-Presenter** is an architectural pattern, which consists of three components: _Model_, _View_ and _Presenter_.\n\n* _Model_ is a data.\n* _View_ is an interface that displays data and routes user commands to Presenter.\n* _Presenter_ wires up Model and View together and thereby creates a functioning entity.\n\n[![MVP-diagram.png](https://i.postimg.cc/jSCcjt5W/MVP-diagram.png)](https://postimg.cc/w18LfKDH)\n\nFor more information about MVP, check an original source - [\"MVP: Model-View-Presenter. The Taligent Programming Model for C++ and Java.\" Mike Potel](http://www.wildcrest.com/Potel/Portfolio/mvp.pdf).\n\n### Creating a Model\nImplement `IModel` interface to create a _Model_ -\n\n```\npublic class CubeModel : IModel\n{\n\t// ...\n}\n```\n\n### Creating a View\nImplement `IView` interface to create a _View_ -\n\n```\npublic class CubeView : MonoBehaviour, IView\n{\n\t// ...\n}\n```\n\nYou can also use `MonoView` class as an \"stub\" instead of `MonoBehaviour` -\n\n`public class CubeView : MonoView, IView`\n\n### Creating a Presenter\nCreate a `CubePresenter` class and derive it from `Presenter\u003cTView, TModel\u003e`. Specify types: `TView` and `TModel`. In our case `TModel` is `CubeModel` and `TView` is `CubeView` -\n\n`CubePresenter : Presenter\u003cCubeView, CubeModel\u003e`\n\n```\npublic class CubePresenter : Presenter\u003cCubeView, CubeModel\u003e\n{\n\tpublic CubePresenter(CubeView cubeView, CubeModel cubeModel) : base(cubeView, cubeModel)\n\t{\n\t\t// ...\n\t}\n}\n```\n\nAt this point we're done with the main components of MVP - `CubeModel`, `CubeView` and `CubePresenter`!\n\nInstancing\n---\nTo create an instance of a `Presenter` use `Create\u003cTPresenter\u003e()` method in `PresenterFactory` -\n\n```\n[SerializeField]\nprivate CubeView cubeView;\n\n// ...\n\nprivate CubePresenter cubePresenter;\n\n// ...\n\nvoid Start()\n{\n\tcubePresenter = presenterFactory.Create\u003cCubePresenter\u003e(cubeView, new CubeModel());\n}\n```\n`PresenterFactory` is built-in implementation of `IPresenterFactory` interface -\n\n```\npublic interface IPresenterFactory\n{\n\tpublic TPresenter Create\u003cTPresenter\u003e(params object[] data) where TPresenter : IPresenter;\n}\n```\n\nBut you can implement your own factory.\n\nMessaging\n---\n### Message Dispatcher\nEach `Presenter` should interact with another `Presenter`. One possible way to do it is to use messages. `MessageDispatcher` is a class which provides needed functionality for messaging.\n\nBut to receive a _Message_ we need a _Subscriber_.\n\n### Receive a Message\nImplement `IMessageSubscriber` interface to make some class available for message receiving -\n\n```\npublic interface IMessageSubscriber\n{\n\tvoid ReceiveMessage\u003cTMessage\u003e(TMessage message);\n}\n```\n\nIn the example we have `UIPresenter` -\n\n```\npublic class UIPresenter : Presenter\u003cUIView, UIModel\u003e, IMessageSubscriber\n{\n\t// ...\n\t\n\tvoid IMessageSubscriber.ReceiveMessage\u003cTMessage\u003e(TMessage message)\n\t{\n\t\tswitch (message)\n\t\t{\n\t\t\tcase CubeColorMessage cubeColorMessage:\n\t\t\t\tmodel.ColorText = cubeColorMessage.Color.ToString();\n\t\t\t\tbreak;\n\t\t}\n\t}\n}\n```\n\nSwitch-case is used here as a way to handle a message from `CubePresenter`.\n\n### Send a Message\nTo send a _Message_ to some `Presenter` use `DispatchMessageTo\u003cTSubscriber, TMessage\u003e(TMessage message)` method in `MessageDispatcher` -\n\n`MessageDispatcher.DispatchMessageTo\u003cUIPresenter, CubeColorData\u003e(new CubeColorData(color))`\n\nIn the example where `CubePresenter` class is -\n\n```\npublic class CubePresenter : Presenter\u003cCubeView, CubeModel\u003e\n{\n  \t// ...\n\n\tprivate void OnModelColorChanged(Color color)\n\t{\n\t\tview.Color = color;\n\t\tmessageDispatcher.DispatchMessageTo\u003cUIPresenter, CubeColorMessage\u003e(new CubeColorMessage { Color = color });\n\t}\n}\n```\n\nClearing\n---\nTo clear a `Presenter` (or some class) you can use built-in `IClearable` interface -\n\n```\npublic interface IClearable\n{\n\tpublic void Clear();\n}\n```\n\nBase `Presenter` class implements `IClearable` interface -\n\n`Presenter\u003cTView, TModel\u003e : IPresenter, IClearable`\n\nIn the example, inside of `EntryPoint.OnDestroy()` method `Clear` is used to free up resources -\n\n```\npublic class EntryPoint : MonoBehaviour\n{\n\t// ...\n\t\n\tprivate CubePresenter cubePresenter;\n\tprivate UIPresenter UIPresenter;\n\n\t// ...\n\n\tprivate void OnDestroy()\n\t{\n\t\tcubePresenter.Clear();\n\t\tUIPresenter.Clear();\n\t}\n{\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdancher743%2Funity-mvp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdancher743%2Funity-mvp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdancher743%2Funity-mvp/lists"}