Skip to content

Instantly share code, notes, and snippets.

@birdinforest
Last active June 5, 2016 09:22
Show Gist options
  • Save birdinforest/596299519f684c12b5113d02d84dda12 to your computer and use it in GitHub Desktop.
Save birdinforest/596299519f684c12b5113d02d84dda12 to your computer and use it in GitHub Desktop.
Concept of Model, View, Controller of MVC pattern in Unity.

Credit

Example and Framework NODE: Use a customized notify system to send event and data by views to controller.

#Models

  • Hold the application’s core data and state, such as player health or gun ammo.
  • Serialize, deserialize, and/or convert between types.
  • Load/save data (locally or on the web).
  • Notify Controllers of the progress of operations.
  • Store the Game State for the Game’s Finite State Machine.
  • Never access Views.

#Views

  • Can get data from Models in order to represent up-to-date game state to the user. For example, a View method player.Run() can internally use model.speed to manifest the player abilities.
  • Should never mutate Models.
  • Strictly implements the functionalities of its class. For example:
  • A PlayerView should not implement input detection or modify the Game State.
  • A View should act as a black box that has an interface, and notifies of important events.
  • Does not store core data (like speed, health, lives,…).

#Controllers

  • Do not store core data.
  • Can sometimes filter notifications from undesired Views.
  • Update and use the Model’s data.
  • Manages Unity’s scene workflow.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment