博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
PureMVC 开发App应用
阅读量:6676 次
发布时间:2019-06-25

本文共 16962 字,大约阅读时间需要 56 分钟。

链接: https://pan.baidu.com/s/1PxFuikXAlHgJ6xspgokGjw 提取码: nikc

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

在这里插入图片描述

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

/****************************************************    文件:UserVo.cs	作者:唐孝辉    邮箱: 1351105506@qq.com    日期:#CreateTime#	功能:模型类*****************************************************/using System.Runtime.InteropServices;public class UserVo {    public string fristName; //姓    public string lastName; //名字    public bool gender;  //性别    public string deparment; //部门    public string telephone; //电话    public string email;  //邮箱    public string UserName()    {        return fristName + lastName;    }    ///     ///是否有效    ///     /// 
public bool IsValid() { return !string.IsNullOrEmpty(UserName()) && !string.IsNullOrEmpty(deparment); } /// /// 判断两个user是否相等 /// /// ///
public override bool Equals(object obj) { UserVo otherVo=obj as UserVo; if (otherVo.UserName().Equals(UserName())) { return true; } return false; } public UserVo() { } public UserVo(string fristName, string lastName, bool gender, string deparment, string telephone,string email) { this.fristName = fristName; this.lastName = lastName; this.gender = gender; this.deparment = deparment; this.telephone = telephone; this.email = email; }}
/****************************************************    文件:UserProxy.cs	作者:唐孝辉    邮箱: 1351105506@qq.com    日期:#CreateTime#	功能:模型代理类*****************************************************/using System.Collections.Generic;using PureMVC.Patterns;public class UserProxy : Proxy{       public new const string NAME = "UserProxy";    public IList
Users { get { return base.Data as IList
; } } public UserProxy():base(NAME,new List
()) { AddUserItem(new UserVo("小","大地",true, "技术部", "123456","1351105506")); AddUserItem(new UserVo("k", "消息", true, "销售部", "156", "1351105506")); AddUserItem(new UserVo("是", "是", false, "技术部", "15456", "1351105506")); AddUserItem(new UserVo("时", "春天", false, "技术部", "7883456", "1351105506")); AddUserItem(new UserVo("我欧尼", "消息", true, "技术部", "8883456", "1351105506")); } public void AddUserItem(UserVo userVo) { if (Users!=null) { Users.Add(userVo); } } //更新数据 public void UpdateUserItem(UserVo userVo) { for (int i = 0; i < Users.Count; i++) { if (Users[i].Equals(userVo)) { Users[i] = userVo; break; } } } //删除数据 public void DeleteUserItem(UserVo userVo) { for (int i = 0; i < Users.Count; i++) { if (Users[i].Equals(userVo)) { Users.RemoveAt(i); break; } } }}

在这里插入图片描述

/****************************************************    文件:UserListItem.cs	作者:唐孝辉    邮箱: 1351105506@qq.com	功能:一条用户列表*****************************************************/using UnityEngine;using UnityEngine.UI;public class UserListItem : MonoBehaviour{    public Text userName;    public Text gender;    public Text parment;    public Text telephone;    public Text email;    //设置info    public void SetInfo(UserVo userVo)    {        if (userName)        {            userName.text = userVo.UserName().ToString();        }        if (gender)        {            gender.text = userVo.gender.ToString();        }        if (parment)        {            parment.text = userVo.deparment.ToString();        }        if (telephone)        {            telephone.text = userVo.telephone.ToString();        }        if (email)        {          email.text = userVo.email.ToString();        }    }}
/****************************************************    文件:UserList.cs	作者:唐孝辉    邮箱: 1351105506@qq.com	功能:用户列表集合*****************************************************/using System;using System.Collections.Generic;using UnityEngine;using UnityEngine.UI;public class UserList : MonoBehaviour{    public Action newUser;    public Action selectUser;    public Action deleteUser;    public UserListItem userListItem;    public Text userListCount;    public Button newBtn;    public Button deleteBtn;    //用户列表信息集合    private List
userListInfo=new List
(); void Start() { userListCount.text = 0.ToString(); userListItem.gameObject.SetActive(false); newBtn.onClick.AddListener(() => { if (newUser!=null) { newUser.Invoke(); } }); deleteBtn.onClick.AddListener(()=> { if (deleteUser!=null) { deleteUser.Invoke(); } }); } public void LoadAndShowUserListInfo(IList
listInfo) { //清空列表信息 ClearList(); //实例化显示 foreach (UserVo item in listInfo) { UserListItem userListItem=cloneUserListItem(); userListItem.SetInfo(item); userListInfo.Add(userListItem); } //统计数量 userListCount.text = userListInfo.Count.ToString(); } private UserListItem cloneUserListItem() { UserListItem item=GameObject.Instantiate
(userListItem); item.transform.SetParent(userListItem.transform.parent); item.gameObject.SetActive(true); item.transform.localPosition = Vector3.zero; item.transform.localScale=Vector3.one; return item; } private void ClearList() { foreach (UserListItem item in userListInfo) { Destroy(item.gameObject); } userListInfo.Clear(); } private void DisdeleteBtn() { deleteBtn.interactable = true; } private void UnDisdeleteBtn() { deleteBtn.interactable = false; }}
/****************************************************    文件:UserListMediator.cs	作者:唐孝辉    邮箱: 1351105506@qq.com	功能:视图类*****************************************************/using System;using System.Collections.Generic;using PureMVC.Interfaces;using PureMVC.Patterns;public class UserListMediator :Mediator{    public new  const string NAME = "UserListMediator";    public UserProxy userProxy;    private UserList _UserList    {        get { return base.ViewComponent as UserList; }    }    public UserListMediator()    {    }    //注册 userProxy    public override void OnRegister()    {        base.OnRegister();        userProxy = Facade.RetrieveProxy(UserProxy.NAME) as UserProxy;    }    //初始化用户列表    internal void InitUserListMediator(UserList userListObj)    {        if (userListObj!=null)        {            this.m_mediatorName = NAME;            this.m_viewComponent = userListObj;            userListObj.deleteUser += HandleDeleteBtn;            userListObj.newUser += HandleNewBtn;            //加载用户列表显示信息            userListObj.LoadAndShowUserListInfo(userProxy.Users);        }           }    private void HandleNewBtn()    {    }    private void HandleDeleteBtn()    {    }    public override IList
ListNotificationInterests() { IList
list=new List
(); list.Add(StringManager.InitUserListMediator); return list; } public override void HandleNotification(INotification notification) { switch (notification.Name) { case StringManager.InitUserListMediator: UserList userList=notification.Body as UserList; InitUserListMediator(userList); break; } }}
/****************************************************    文件:StringManager.cs	功能:常量*****************************************************/public class StringManager{    public const string InitUserListMediator = "InitUserListMediator";    public const string ComInitMediator = "ComInitMediator";}

在这里插入图片描述

/****************************************************    文件:StartUpAppliation.cs	功能:启动usermediator*****************************************************/using PureMVC.Interfaces;using PureMVC.Patterns;using UnityEngine;public class StartUpAppliation : SimpleCommand{    public UserList userList=null;    public override void Execute(INotification notification)    {       userList=notification.Body as UserList;       if (userList!=null)       {            //发送消息给usermediator            SendNotification(StringManager.InitUserListMediator,userList);       }    }}

在这里插入图片描述

/****************************************************    文件:ApplicationFacade.cs	作者:唐孝辉    邮箱: 1351105506@qq.com	功能:全局管理类*****************************************************/using PureMVC.Interfaces;using PureMVC.Patterns;public class ApplicationFacade : Facade{    public ApplicationFacade()    {    }    private const string obj = "5656";    public new static IFacade Instance    {        get        {            if (m_instance==null)            {                lock (obj)                {                    m_instance = new ApplicationFacade();                }            }            return m_instance;        }    }       protected override void InitializeModel()    {        base.InitializeModel();        RegisterProxy(new UserProxy());    }    protected override void InitializeView()    {        base.InitializeView();        RegisterMediator(new UserListMediator());    }    protected override void InitializeController()    {        base.InitializeController();        RegisterCommand(StringManager.ComInitMediator,typeof(StartUpAppliation));    }}
/****************************************************    文件:GameStart.cs	作者:唐孝辉    邮箱: 1351105506@qq.com    日期:#CreateTime#	功能:游戏入口*****************************************************/using UnityEngine;public class GameStart : MonoBehaviour{    public UserList userList;    private ApplicationFacade applicationFacade;    void Start()    {        applicationFacade=ApplicationFacade.Instance as ApplicationFacade;        if (userList!=null&&applicationFacade!=null)        {            applicationFacade.SendNotification(StringManager.ComInitMediator,userList);        }    }}

在这里插入图片描述

在这里插入图片描述

/****************************************************    文件:UserListItem.cs	功能:一条用户列表*****************************************************/using PureMVC.Patterns;using UnityEngine;using UnityEngine.UI;public class UserListItem : MonoBehaviour{    public Text userName;    public Text gender;    public Text parment;    public Text telephone;    public Text email;    private Toggle toggle;    private UserVo userVo;    void Start()    {        toggle = this.GetComponent
(); toggle.onValueChanged.AddListener((bool click) => { if (click) { //选择的信息发送用户信息 Facade.Instance.SendNotification(StringManager.SeleteUserListInfo,this.userVo); } }); } //设置info public void SetInfo(UserVo userVo) { this.userVo = userVo; if (userName) { userName.text = userVo.UserName().ToString(); } if (gender) { if (userVo.gender) { gender.text = "男"; } else { gender.text = "女"; } } if (parment) { parment.text = userVo.deparment.ToString(); } if (telephone) { telephone.text = userVo.telephone.ToString(); } if (email) { email.text = userVo.email.ToString(); } }}

UserListMediator

public override IList
ListNotificationInterests() { IList
list=new List
(); list.Add(StringManager.InitUserListMediator); list.Add(StringManager.SeleteUserListInfo); return list; } public override void HandleNotification(INotification notification) { switch (notification.Name) { case StringManager.InitUserListMediator: UserList userList=notification.Body as UserList; InitUserListMediator(userList); break; //选择用户信息 case StringManager.SeleteUserListInfo: UserVo userVo1 = notification.Body as UserVo; HandleSeleteUserListInfo(userVo1); break; } } private void HandleSeleteUserListInfo(UserVo userVo) { currentUserVo = userVo; _UserList.DisdeleteBtn(); //发送消息给用户信息窗口 SendNotification(StringManager.SeleteUserListInfoMedia,userVo); }

在这里插入图片描述

/****************************************************    文件:UserFormMediator.cs    功能:用户信息窗口*****************************************************/using System;using UnityEngine;using UnityEngine.UI;public class UserForm : MonoBehaviour{    public InputField name;    public InputField user;    public  Toggle man;    public Toggle women;    public InputField parment;    public InputField telephone;    public InputField email;    public Button sureBtn;    public Action action;    public UserVo userVo;    void Start()    {        sureBtn.onClick.AddListener(() =>        {            if (!Check())            {                Debug.Log("数据不合法!");                return;            }            if (action!=null)            {                action.Invoke();            }        });    }    private bool Check()    {        if (userVo==null)        {            userVo=new UserVo();        }        userVo.fristName = user.text;        userVo.lastName = name.text;        if (man.isOn)        {            userVo.gender = true;        }        else        {            userVo.gender = false;        }        userVo.deparment = parment.text;        userVo.email = email.text;        userVo.telephone = telephone.text;        if (userVo.IsValid())        {            return true;        }        return false;    }    public void ShowInfo(UserFormType type,UserVo obj=null)    {        switch (type)        {            case UserFormType.Create:                Clear();                break;            case UserFormType.Update:                ShowInfo(obj);                break;        }    }    public void Clear()    {        userVo = null;        name.text = "";        user.text = "";        man.isOn = true;        women.isOn = false;        parment.text = "";        telephone.text = "";        email.text = "";    }    private void ShowInfo(UserVo obj)    {        this.userVo = obj;        name.text = obj.lastName.ToString();        user.text= obj.fristName.ToString();        if (obj.gender)        {            man.isOn = true;            women.isOn = false;        }        else        {            man.isOn =false;            women.isOn = true;        }        parment.text = obj.deparment.ToString();        telephone.text = obj.telephone.ToString();        email.text = obj.email.ToString();    }}
/****************************************************    文件:UserFormMediator.cs	作者:唐孝辉    邮箱: 1351105506@qq.com	功能:用户信息窗口视图层*****************************************************/using System.Collections.Generic;using PureMVC.Interfaces;using PureMVC.Patterns;using UnityEngine;public enum UserFormType{    Create,    Update,}public class UserFormMediator : Mediator{    public new const string NAME = "UserFormMediator";    public UserFormType userFormType = UserFormType.Create;    public UserFormMediator():base(NAME)    {    }    private UserForm userForm {         get { return base.ViewComponent as UserForm; }    }    //初始化    internal void InitUserFormMediator(UserForm userFormObj)    {        if (userFormObj!=null)        {            this.m_mediatorName = NAME;            this.m_viewComponent = userFormObj;            //委托注册            userForm.action += HandleSureBtn;        }    }    private void HandleSureBtn()    {        switch (userFormType)        {            case UserFormType.Create:                //增加新用户                AddUser();                break;            case UserFormType.Update:                //更新用户                UpdateUser(userForm.userVo);                break;        }    }    private void AddUser()    {    }    private void UpdateUser(UserVo userVo)    {    }    public override IList
ListNotificationInterests() { IList
list=new List
(); list.Add(StringManager.InitUsrtFormMediator); list.Add(StringManager.SeleteUserListInfoMedia); return list; } public override void HandleNotification(INotification notification) { switch (notification.Name) { case StringManager.InitUsrtFormMediator: InitUserFormMediator(notification.Body as UserForm); break; case StringManager.SeleteUserListInfoMedia: userFormType = UserFormType.Update; UserVo userVo = notification.Body as UserVo; ShowUiform(UserFormType.Update, userVo); break; } } private void ShowUiform(UserFormType type,UserVo userVo=null) { userForm.ShowInfo(type,userVo); }}

在这里插入图片描述

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

转载地址:http://jzrxo.baihongyu.com/

你可能感兴趣的文章
Tinyos Makerules解读
查看>>
安装VS2010 SP1时遇到WCF RIA Service 版本错误
查看>>
UI--普通控件总结1--控件使用
查看>>
【外文翻译】使用Timer类去调度任务 ——java
查看>>
关于CountDownLatch控制线程的执行顺序
查看>>
plsql 乱码 注册表 修改文件
查看>>
Docker集群管理(三)—— docker swarm mode基础教程
查看>>
1.urlencoder和urldecoder的使用
查看>>
web移动端布局方式整理
查看>>
蛤玮学计网 -- 简单的判断ip
查看>>
如何解决div里面img图片下方有空白的问题?
查看>>
P3626 [APIO2009]会议中心
查看>>
防火墙
查看>>
Ubuntu下VIM使用指南
查看>>
QTREE5 - Query on a tree V——LCT
查看>>
spring mvc-使用Servlet原生API作为参数
查看>>
第13章 MySQL数据库与JDBC编程
查看>>
百度地图API使用记录
查看>>
linux docker
查看>>
增量式 爬虫
查看>>