这两天看了下老大的项目,他基本都是用MVC模式,写的很好,在此把我理解的记录下来

Model:实体对象(对应数据库记录的类)

View:视图

presenter(controller):业务处理

view中有present对象,present中有model和view对象

view中UI的交互会调用present相应处理的方法(该方法处理完后会调用view显示处理后的视图(将改变后的model对象传递过去),view显示就会改变显示的内容)

结构是下面这样子的:

IPresenter:

namespace NginAR
{
public interface IPresenter<T> where T : class
{
void Init();
}
}

IView:

namespace NginAR
{
public interface IView<T> where T : class
{
/**
* 设置Presenter
* @param presenter
*/
void setPresenter(T presenter);
}
}

IGlassView:

namespace NginAR
{
public interface IGlassView : IView<IGlassPresenter>
{
// 设置当前步骤内容,用于显示
void setStepContent(string content);
// 设置当前步骤
void setCurrentStep(int currentStep);
}
public interface IGlassPresenter : IPresenter<IGlassView>
{
// 当前步
bool StepCurrent();
// 下一步
bool StepNext();
// 上一步
bool StepLast();
void onStepChange(int currentTaskId, int currentStepId);
}
}

Step:

namespace NginAR
{
public class Step
{
public int id { get; set; }
public string content { get; set; }
public string type { get; set; }
}
}

FileUtil:

namespace NginAR
{
// 读取文件工具
public class FileUtil
{
// 加载脚本文件,用于保存步骤内容
public static void LoadModel(TextAsset asset,List<Step> steps) {
string[] lines = asset.text.Split("\n"[]);
for (int i = ; i < lines.Length; i++)
{
string[] cols = lines[i].Split(" "[]);
Step step = new Step();
step.id = int.Parse(cols[]);
step.content = cols[];
step.type = cols[]; steps.Add(step);
}
LogUtil.i("大小"+ steps.Count);
}
} }

LogUtil:

public class LogUtil
{
private static bool LOGI = true;
private static bool LOGW = true;
private static bool LOGE = true; public static void i(string mess)
{
if (LOGI)
{
Debug.Log(mess);
}
} public static void w(string mess)
{
if (LOGW)
{
Debug.LogWarning(mess);
}
} public static void e(string mess)
{
if (LOGE)
{
Debug.LogError(mess);
}
}
}

MainView(继承IGlassView):

UI事件调用present中对应的处理方法:

   // 新建逻辑管理对象 mvp-p
prenseter = new MainPresenter(asset, this);
// 为刷新当前步骤按钮设置监听回调
btn_text.onClick.AddListener(delegate () {
prenseter.StepCurrent();
});
// 为上一步按钮设置监听回调
btn_last.onClick.AddListener(delegate () {
prenseter.StepLast();
});
// 为下一步按钮设置监听回调
btn_next.onClick.AddListener(delegate () {
prenseter.StepNext();
});

IGlassPresenter(继承IGlassPresenter):

present中UI对应处理方法改变model,处理完调用view中方法显示处理后的视图展示:

 public bool StepLast()
{
currentStep--;
if (currentStep < )
{
currentStep = ;
return false;
}
onStepChange(, currentStep);
return true;
}
// 下一步逻辑
public bool StepNext()
{ if (steps.Count <= )
{
return false;
}
currentStep++;
if (currentStep >= steps.Count)
{
currentStep = steps.Count-;
return false; }
onStepChange(,currentStep);
return true;
}
// 步骤改变调用
public void onStepChange(int currentTaskId, int currentStepId)
{
this.currentStep = currentStepId;
LogUtil.i("currentStepId"+currentStepId);
currentStepContent =steps[currentStep].content;
view.setStepContent(currentStepContent);
view.setCurrentStep(currentStep);
}

同时present中还有加载文件的方法:

文件格式是这样子的:1 1.风险可能导致的后果:倒塌、高处坠落、公路中断运行、跨越架封网脱落等 image1

上面的FileUtil能解析出来并赋值给step(model)对象

view中显示方法(参数为model中的信息):

除了显示model信息之外还会加载其他的UI或者模型

 public void setStepContent(string content)
{
Debug.Log("content:"+content);
// 按钮文本设置为步骤内容
text.text = content;
}
  public void setCurrentStep(int currentStep)
{
currentStep = currentStep + ;
if (Application.loadedLevelName.Equals("KYJ"))
{
if (currentModel != null)
Destroy(currentModel);
Play("kyj_"+ currentStep);
LoadPrefab("Prefabs/Kyj_Step/kyj_" + currentStep, objectTarget.transform);
if (currentStep == )
endStep.SetActive(true);
else
endStep.SetActive(false);
}
}

最新文章

  1. *HDU 2451 数学
  2. 使用fiddler的autoResponder及设置手机端代理实现远程调试,出现的问题及解决办法
  3. Linux服务器管理: 系统的进程管理top命令
  4. 腾讯云CentOS 6.6安装 Nginx
  5. 解释清楚c++的重载操作符【用自己的话,解释清楚】
  6. AM335x(TQ335x)学习笔记——挂载Ramdisk
  7. C#属性总结
  8. usb host鼠标不能使用原因
  9. Netty(一):入门篇
  10. Nginx的负载均衡 - 最少连接 (least_conn)
  11. Monte Carlo Method(蒙特&#183;卡罗方法)
  12. 不可不知的表达式树(1)Expression初探
  13. Jenkins - SSH认证方式拉取Git代码
  14. HAOI(多省联考)2019退役记
  15. pycharm引入numpy报错:ImportError: Importing the multiarray numpy extension module failed. Most likely you are trying to import a failed build of numpy.
  16. Sebastian Ruder : NLP 领域知名博主博士论文面向自然语言处理的神经网络迁移学习
  17. python-day64--web框架
  18. 使用Tensorflow和MNIST识别自己手写的数字
  19. 温习classList api
  20. 【UVa】1601 The Morning after Halloween(双向bfs)

热门文章

  1. where case 使用
  2. https://www.cnblogs.com/yuanchenqi/articles/6755717.html
  3. Java 常用工具类之基本对象包装类
  4. Linux使用SecureCRT上传下载
  5. gophercloud openstack networking 源码分析
  6. 服务系统 server端
  7. python 2.7.11安装pywin32过程中 停止工作问题
  8. Tomcat 安装、配置与部署
  9. mysql安装前的系统准备工作
  10. 吴超老师课程--HBASE的集群安装