结合使用MVVM模式和Unity Engine作为前端 [英] Using the MVVM pattern with Unity Engine as front end

查看:113
本文介绍了结合使用MVVM模式和Unity Engine作为前端的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我计划制作一些应用程序,使我可以在家中或其他地方组织任务.为此,我需要一个数据库服务器(在家中运行的虚拟服务器),后端部分(业务逻辑)和前端部分(视图).在学校,我们通过WPF学习了MVVM,但坦率地说,我仅在明确需要时才使用它.

I plan to make some applications that will let me organize tasks from home or from somewhere else. For this I need a database server (a virtual one running at home), a backend part (the business logic) and the front end (the view). At school we learned the MVVM via WPF, but to be frank I use it only when it is explicitely required.

像Unity一样,有很多有利于Unity的好处

There are a lot of benefits in favour of Unity like

  • 对艺术家友好
  • 可以编译为手机,网络和台式机
  • 快速发展(至少就我而言)
  • 具有许多我可以利用的内置功能.<​​/li>
  • Artist friendly
  • Can compile to mobile, web and desktop
  • Fast development (in my case at least)
  • Has a lot of built in features I can harness.

现在,即使像我将要制作的这样的应用程序一样简单,有时我可能仍想扩展它,改进它或完全更改某些组件. 我知道如何在WPF中使用MVVM,但是我对Unity实现只有一些模糊的想法,我希望有经验的人来概述一下.

Now, even as simple as I will make an app like this, sometimes I might want to extend it, improve it or change some components entirely. I know how to use MVVM in WPF but I only have some vague ideas for the Unity implementation which I would like someone skilled to overview.

前端(Unity)将负责声音管理,精美的动画以及UI本身.但是UI按钮事件无法直接访问数据库,因此我想到了构建一些桥类.假设我想删除一个提醒,作为一个简单的例子.在OnButtonClicked()方法中,我只调用BridgeClassPleaseDeleteThis(MyReminder),在该方法内部,有一个后端解决方案,该解决方案实际上是通过id找到该提醒并将其从数据库中删除的,然后发送一个everything all right标志到前端应用程序,所以我知道它成功了.

The front end (Unity) would take care of sound management, fancy animations and the UI itself. But UI button events cannot access directly the database, so I thought of building some bridge classes. Say I want to delete a reminder, as an easy example. In an OnButtonClicked() method I would just call a BridgeClass's PleaseDeleteThis(MyReminder) and inside that method there's the backend solution that actually finds that reminder by id and removes from the database, then sends an everything all right flag back to the front end app so I know it was successful.

我想到的是,使用这些桥类,我不必担心如果更改数据库服务器或前端会发生什么,因为他们所需要知道的就是bridge通信.我知道该示例过于简化,但是该示例在组件完整性和MVVM模式方面的可行性如何?

What I thought of is that using these bridge classes I wouldn't have to worry about what happens if I change the database server or the front end, as all they have to know is communicating with the bridge. I know the example was over simplified, but how doable would this one be regarding the component integrity and the MVVM pattern?

推荐答案

MVVM已被AAA软件公司成功用于构建游戏. 《 Shipbreakers》 (又称《 Homeworld:哈拉克沙漠》 )的开发者编写了代码,使View成为MonoBehavor,我相信,VM和M是在外部且独立编写的POCO类统一,以加快发展.他们可以在Unity外部拥有自己的原型制作视图.

MVVM has been successfully used by AAA software houses to build games. The makers of Shipbreakers (aka Homeworld: Deserts of Kharak) wrote their code such that the View was a MonoBehavor I believe, VM and M were POCO classes written external to and independent to Unity so as to speed development. They can have their own Views for prototyping external to Unity.

他们还为Unity编写了自己的调试可视化工具和属性编辑器.

They also wrote their own debugging visualisers and property editors for Unity.

https://www.youtube.com/watch?v=q9aeNtKKXeo

MVVM大约位于 19:18 标记处,尽管我建议您观看整个内容因为那里还有其他很棒的东西.

MVVM is about at the 19:18 mark though I do recommend to watch the whole thing as there are some other great things in there.

这篇关于结合使用MVVM模式和Unity Engine作为前端的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆