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. 爬虫--requests模块学习

    requests模块 - 基于如下5点展开requests模块的学习 什么是requests模块 requests模块是python中原生的基于网络请求的模块,其主要作用是用来模拟浏览器发起请求.功能 ...

  2. iOS多语言

    https://blog.csdn.net/huangmindong/article/details/53464334 App多语言,字符串统一放在 Localizable.strings 文件里. ...

  3. 飞利浦 PHILIPS 电动牙刷HX6730 拆解

    今日,一直比较喜欢用的电动牙刷,飞利浦HX6730坏掉了,初步感觉考虑飞利浦的保修,但是发现发票找不到了.飞利浦的客服也说,电动牙刷的两年保修依据分别是:1.发票开据日期:2.在无发票的情况下,看底部 ...

  4. 用python实现一个简单的服务器

    打开命令行工具,输入: python3 -m http.server 8000(端口可以自己定) 通过访问:http://ip:8000/,就能给别人快速分享文件了.

  5. NAT与FULL NAT的区别

    LVS 当前应用主要采用 DR 和 NAT 模式,但这 2 种模式要求 RealServer 和 LVS在同一个 vlan中,导致部署成本过高:TUNNEL 模式虽然可以跨 vlan,但RealSer ...

  6. UGUI 判断元素进入舞台

    void LateUpdate () { if(!_isLoaded){ RectTransform rectt=this.GetComponent<RectTransform>(); f ...

  7. Excel导入oracle的几种方法

    http://www.jb51.net/list/list_154_1.htm 方法一.使用SQL*Loader这个是用的较多的方法,前提必须oracle数据中目的表已经存在.大体步骤如下:1.将ex ...

  8. 吴裕雄 10-MySQL插入数据

    语法以下为向MySQL数据表插入数据通用的 INSERT INTO SQL语法:INSERT INTO table_name ( field1, field2,...fieldN ) VALUES ( ...

  9. R语言-画线图

    R语言分高水平作图函数和低水平作图函数 高水平作图函数:可以独立绘图,例如plot() 低水平作图函数:必须先运行高水平作图函数绘图,然后再加画在已有的图上面 第一种方法:plot()函数 > ...

  10. Redis安装完后redis-cli无法使用(redis-cli: command not found)已使用

    wget http://download.redis.io/redis-stable.tar.gz(下载redis-cli的压缩包) tar xvzf redis-stable.tar.gz(解压) ...