Coder Social home page Coder Social logo

hnmvc's Introduction

Welcome to HnMVC

HnMVC is a super-lightweight mvc framework base on delegate and event, written specifically for C# and Unity.

Key features

  • Event system
  • View mediation

image

To get started:

1.Create Contex

  • Create a new empty gameobject and add a c# script component.
  • Create a contex class drive from class "HnFramework.MVC.Contex", e.g. "XXContex".
  • Override function "InitCommand".

2.Create Command

  • Create a SceneCommand or StartCommand class drive from class "HnFramework.MVC.Command", e.g. "XXCommand".
  • Override function "InitModel".
  • Call function "BindCommand(new XXCommand(this));" in the function "InitCommand" of "XXContex".
public override void InitCommand() {
      // Initialize command function, All command class should be create here.
      // Command类初始化函数,所有的Command类应当在此进行创建.
      BindCommand(new Test1Command(this));
      BindCommand(new CubeCommand(this));
  }
  • Create other bussiness Command class drive from class "HnFramework.MVC.Command".
  • Override function "OnStart", and add listener.
public override void OnStart() {
      AddListener(CommandEvent.GetScore, OnGetScore);
      AddListener(CommandEvent.AddScore, OnAddScore);
  }

3.Create Model

  • Create model class drive from class "HnFramework.MVC.Model", e.g. "XXModel".
  • Call function "BindModel(enum, XXModel.GetSingleton());" in the function "InitModel" of "SceneCommand".
public override void InitModel() {
      // Bind model function, model instance will be destroy with the scene 
      // while you call the method Model.GetInstance, and it works in whole life time 
      // while you call the method Model.GetSingleton.
      // Model数据类在此进行绑定,调用GetSingleton则该数据类全局有效,GetInstance则只在当前场景有效,
      // 场景销毁则该数据类也进行销毁.

      //BindModel(ModelType.ScoreModel, ScoreModel.GetInstance<ScoreModel>());
      BindModel(ModelType.ScoreModel, ScoreModel.GetSingleton<ScoreModel>());
      // BindModel(ModelType.OtherModel,
      // BindModel(...
  }

4.Create Mediator

  • Create mediator class drive from class "HnFramework.MVC.Mediator", e.g. "XXMediator".
  • Override function "OnInit", then get view class and add listener.
CubeView _cubeView;
public override void OnInit() {
      _cubeView = View as CubeView;
      if (null == _cubeView) {
          Debug.LogError("cube view is null");
          return;
      }
      AddListener(MediatorEvent.GetScore, OnGetScore);
  }

5.Create View

  • Create view class drive from class "HnFramework.MVC.View", e.g. "XXView" and add the script component to any ui gameobject.
  • Override function "InitMediator", and bind mediator.
protected override void InitMediator() {
      BindMediator(typeof(CubeMediator));
  }

6.Dispatch

  • You can call function "DispatchCommand(enum)" to make command work(e.g. get model datas) in view or mediator class.
  • You can call function "DispatchMediator(enum)" to update UI in command class.

For more details see Gitbook documentation.

Support or Contact

Contact me

hnmvc's People

Contributors

2011fuzhou avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.