Unity of Advanced: MVC programming ideas

Copyright Notice:

  • Original article published on the blog Park "You dream maker culture," the blog space (URL: http://www.cnblogs.com/raymondking123/) and micro-channel public number "dream maker culture"
  • You are free to reprint, but must include the full copyright notice!

MVC

Game initialization

In unity-start scenario, in order to make the game initialization, you need to create an empty object
null object to bind a script that
MainInitialicer: MonoBehavior inherited from MonoBehavior
first create a PlayerController Controller object
then define a method

void start()
{
     控制器初始化
     Controller = new PlayerController();
     调用显示视图界面方法
     Controller.ShowView
}

MVC practice

Create a panel, create a button to set the name for the attack next panel, adjusted to best fit
the next Mainpanel add a text control input EXP best fit
to create a my folder, there Scenes Script
Script there are application application framework Framework folder
Framework inside writing the MVC framework
requires several scripts:
modelbase model layer base class,
ViewBase interface base class,
ControllerBase control layer base class,
MVC outer class
can be unified access to the various components of the three layers through a facade
MVC external class, is the MVC framework, Foreign simple operation, inner classes can not be seen
followed by three write code like

ControllerBase:

public abstract class ControllerBase
{
// 执行命令(一段功能代码)
    public abstract void Execute(object param); // 对谁攻击,用什么技能攻击,技能的id
// 执行一个功能
}
//public class AttackController : ControllerBase
//{
//  public override void Execute()
//  {
//      throw new System.NotImplementedException();
//  }
//}
//var ac = new AttackController();
//ac.Execute()

viewbase:

View class:
1, each class that inherits from ViewBase must provide a name for each view has its own name
2, each class that inherits from ViewBase must register an event he cares "AttackEvent" such as increased sense of experience interests
3, each class inherits from ViewBase have to deal with the event they are concerned "attackevent"

public abstract class ViewBase : MonoBehaviour
{
    public IList interestedEvents; // 保存关心的事件列表
    public abstract string Name { get; }
// 每个view的名字,把取得name的方法交给子类做
// 属性的方法抽象就不用实现,不然get方法必须要实现,返回一个名字
// Get {return name;}
    public abstract IList GetInterestedEvents(); 
// 方法:返回一个我关心的事件
    public abstract void HandleEvents(string eventName, object eventParam);
// 处理自己关心的事件,关心的事件名(攻击),事件的信息(攻击造成的伤害值)
}

View registered to the MVC classes, then whenever the data changes, the notification interface updates, a message will be sent over MVC class, is an event of interest

base model:

/// <summary>
/// 数据模型,每个模型必须有一个名称
/// </summary>
public abstract class ModelBase {
    public abstract string Name { get; } 
// 背包数据有背包模型,副本数据有副本模型,这是他们的名字
}

Guess you like

Origin www.cnblogs.com/raymondking123/p/11355911.html