Karma is an MVC framework for Unity3D. Because of how Unity is structured, it actually turns out to be an MVCP architecture (Model/View/Controller/Presenter) where the Presenter is a MonoBehaviour that serves as an intermediary between the Controller and the View. You can read more about this in MODEL VIEW CONTROLLER PATTERN FOR UNITY3D USER INTERFACES.

Based on Zenject
 
It's built on top of Zenject which provides Dependency Injection (DI). DI is mainly used to route the app to the desired view, it also enables us to build composable and testable systems.
 
Inspired by AngularJS and ASP vNext
 
Some of the basic constructs and code layout is inspired by other MVC frameworks such as AngularJS and ASP vNext.
 
Note to Game Developers
 
Karma uses concepts like views and presenters instead of scenes. The problem with scenes is that they are too heavy weight, there is no good way to communicate between them, changing scenes is slow (especially if you are doing UI stuff), and they aren't composable. The "Karmic" way of doing a game would be to store each level/scene in a prefab, treat it as a MVC View, store all your characters/entities in separate prefabs, and get them instantiated onto the level's view through DI.
 
Simple Routing System
 
Karma has a built in routing system that enables you to create isolated views/scenes as prefabs and easily switch between them. Using an http-like flow, a presenter can Request the router to render another view.
 
As Stateless as possible
 
Karma aims to be as stateless as possible to try to give you the guarantee that if you entered a view once with certain Request parameters and reached a successful state, then you will always reach that same state if you pass the the same parameters. Unity3D doesn't provide by default a best practice changing from a view to another. A common way to do this is to have all possible views instantiated in the scene but only enable the current one, the problem is that you maintain state when reusing Game Objects and often end in bad states because of the many paths you need to account for. Karma keeps things simple and functional by just destroying the current view and instantiates a new next view when changing views.
 
Message Passing
 
In Karma state is mainly maintained through message passing, being as true as possible to Go's philosophy:
 
Don't communicate by sharing memory; share memory by communicating.
The added benefit of this is that views become configurable without depending on local storage or static variables, is in turn is very important to keep a system testable.
 
Pub/Sub System
 
All Presenters integrate a pub/sub system that enables the communication between entities on different branches and levels in the dependency hierarchy. It's a simple yet powerful message passing mechanism on channels by topic where any Presenter can subscribe and broadcast. By convention the top level application is used as the main channel.
 
Folder Structure + Conventions
 
As many MVC frameworks, Karma tries to keep the developers sane by establishing conventions. Among these conventions are the folder structure, concepts (presenters, controllers, services, etc), code organization, a configuration mechanism (dev, prod, test environments).
 
Parts
 
Views
Plain old prefabs
Presenters
Handle the presentation layer
Extend MonoBehaviour
Are tied to a Prefab
Get instantiated on Game Objects
Integrate a Pub/Sub mechanism
Are Transient
Are divided as:
Plain Presenter (Routable)
Elements (Reusable)
Layouts (Provide context)
Controllers
Handle the logic layer
Don't extend MonoBehaviour
Are Transient
Are 100% testable
Are usually coupled to a Presenter
Services
Handle Resources
Should be Stateless
Are Singleton
Usually handle communication with a server on a particular resource, local storage, specialized logic for e.g. handling certain user inputs, etc.
Applications
Handle general configuration
Are Presenters
Contain the current view
Can be nested to create subviews
Router
Belongs to a specific Application
Tells the application which view to render next
Can store request history
Middleware
Each application can configure its one pipeline
Each middleware can modify the Request and Response
Enables to e.g. create an authentication layer separate from the view itself
It's asynchronous so e.g. http requests can be made to the server to get extra information

下载

Karma - MVC Framework for Unity3D的更多相关文章

  1. 理解ASP.NET MVC Framework Action Filters

    原文:http://www.cnblogs.com/darkdawn/archive/2009/03/13/1410477.html 本指南主要解释action filters,action filt ...

  2. Spring MVC Framework 注解

    ControllerAdvice Spring MVC Framework会把 @ControllerAdvice注解内部使用 @ExceptionHandler.@InitBinder.@Model ...

  3. WebWork2和Spring MVC Framework的比较

    http://daihaixiang.blog.163.com/blog/static/3830134200711411515336/ WebWork2和Spring MVC Framework的比较 ...

  4. ASP.NET MVC Framework

    ASP.NET MVC Framework是微软在ASP.NET中所添加的一组类库,这组类库可以使用Model-View-Controller的设计模式来开发ASP.NET的应用程序.它与现有的ASP ...

  5. How to create a site with AJAX enabled in MVC framework.

    How to create a site with AJAX enabled in MVC framework. The Project illustrates how to create a web ...

  6. 【转】Code Your Own PHP MVC Framework in 1 Hour

      原文: https://www.codeproject.com/Articles/1080626/Code-Your-Own-PHP-MVC-Framework-in-Hour --------- ...

  7. TreeFrog Framework : High-speed C++ MVC Framework for Web Application http://www.treefrogframework.org

    TreeFrog Framework : High-speed C++ MVC Framework for Web Application http://www.treefrogframework.o ...

  8. [转载]Spring Web MVC Framework

    Required Configuration You need to map requests that you want the DispatcherServlet to handle, by us ...

  9. Spring Framework Part4 self-summeries-a simplified MVC framework

    1.关于Spring Framework xml的头部 <?xml version="1.0" encoding="UTF-8"?> <bea ...

随机推荐

  1. JSONArray 遍历

    JSONArray 遍历   刚遇到一个接接口任务,发现其中返回数据中,是个字符串数组,数组中就是单个json形式的内容,其实应该也可以称这种数据叫做json数组吧,只不过是字符串形式.而我需要的是将 ...

  2. Leetcode 题解 reverse List II

    这个题确实太容易错了. 我已经做了2遍了,之前都是套用reverse List 1中的函数. 现在尝试用新方法,在一个函数里完成,结果又错了. 事实证明,永远不要想当然!!!白板编程真的是要求,你对每 ...

  3. iOS设计标注处理方法

    如果设计只给3x的设计图 在做2x适配时有几种处理方法: 按逻辑像素,大小不变,比如3x手机上一张图的逻辑像素设为24x24point,那么2x手机上这张图的大小也设为24x24point,一般适用于 ...

  4. 一例对一个或多个实体的验证失败。有关详细信息,请参阅“EntityValidationErrors”属性的解决

    这个问题相信只要是做MVC的,都碰到过,也都知道错误的原因,就是触发了定义的实例字段校验规则.比如定义的不为空,但是为空了,或者定义的字段长度为50,但是超过50了. 可是有时虽然知道是这样,但是具体 ...

  5. Grafana分析Nginx日志

    配置Groub by -Terms时报错,提示需要设置fielddata=true,报错内容大概如下: "Fielddata is disabled on text fields by de ...

  6. hadoop搭建部署

    HDFS(Hadoop Distributed File System)和Mapreduce是hadoop的两大核心: HDFS(文件系统)实现分布式存储的底层支持 Mapreduce(编程模型)实现 ...

  7. 使用pt-table-checksum及pt-table-sync校验复制一致性

    一.简介 pt-table-checksum是percona-toolkit系列工具中的一个, 可以用来检测主. 从数据库中数据的一致性.其原理是在主库上运行, 对同步的表进行checksum, 记录 ...

  8. Linux后门入侵检测工具

    一.rootkit简介 rootkit是Linux平台下最常见的一种木马后门工具,它主要通过替换系统文件来达到入侵和和隐蔽的目的,这种木马比普通木马后门更加危险和隐蔽,普通的检测工具和检查手段很难发现 ...

  9. Android签名

    参考文档:http://blog.csdn.net/u010316858/article/details/53159678 http://www.cnblogs.com/wanqieddy/p/355 ...

  10. 吴裕雄 30-MySQL 及 SQL 注入

    如果您通过网页获取用户输入的数据并将其插入一个MySQL数据库,那么就有可能发生SQL注入安全的问题.本章节将为大家介绍如何防止SQL注入,并通过脚本来过滤SQL中注入的字符.所谓SQL注入,就是通过 ...