当前位置: 首页 > news >正文

禅城做网站聊城做网站的公司效果

禅城做网站,聊城做网站的公司效果,建设厅网站合同备案在哪里,可以查企业备案的网站吗QFramework 除了提供了一套架构之外#xff0c;QFramework 还提供了可以脱离架构使用的工具 TypeEventSystem、EasyEvent、BindableProperty、IOCContainer。 这些工具并不是有意提供#xff0c;而是 QFramework 的架构在设计之初是通过这几个工具组合使用而成的。 内置工具…QFramework 除了提供了一套架构之外QFramework 还提供了可以脱离架构使用的工具 TypeEventSystem、EasyEvent、BindableProperty、IOCContainer。 这些工具并不是有意提供而是 QFramework 的架构在设计之初是通过这几个工具组合使用而成的。 内置工具 TypeEventSystem 基本用法 using UnityEngine;namespace QFramework.Example {public class TypeEventSystemBasicExample : MonoBehaviour{public struct TestEventA{public int Age;}private void Start(){TypeEventSystem.Global.RegisterTestEventA(e {Debug.Log(e.Age);}).UnRegisterWhenGameObjectDestroyed(gameObject);}private void Update(){// 鼠标左键点击if (Input.GetMouseButtonDown(0)){TypeEventSystem.Global.Send(new TestEventA(){Age 18});}// 鼠标右键点击if (Input.GetMouseButtonDown(1)){TypeEventSystem.Global.SendTestEventA();}}} }// 输出结果 // 点击鼠标左键则输出: // 18 // 点击鼠标右键则输出: // 0事件继承支持 除了基本用法TypeEventSystem 的事件还支持继承关系。 using UnityEngine;namespace QFramework.Example {public class TypeEventSystemInheritEventExample : MonoBehaviour{public interface IEventA{}public struct EventB : IEventA{}private void Start(){TypeEventSystem.Global.RegisterIEventA(e {Debug.Log(e.GetType().Name);}).UnRegisterWhenGameObjectDestroyed(gameObject);}private void Update(){if (Input.GetMouseButtonDown(0)){TypeEventSystem.Global.SendIEventA(new EventB());// 无效TypeEventSystem.Global.SendEventB();}}} }// 输出结果: // 当按下鼠标左键时输出: // EventB手动注销 using UnityEngine;namespace QFramework.Example {public class TypeEventSystemUnRegisterExample : MonoBehaviour{public struct EventA{}private void Start(){TypeEventSystem.Global.RegisterEventA(OnEventA);}void OnEventA(EventA e){}private void OnDestroy(){TypeEventSystem.Global.UnRegisterEventA(OnEventA);}} }接口事件 using System; using System.Collections; using System.Collections.Generic; using UnityEngine;namespace QFramework.Example {public struct InterfaceEventA{}public struct InterfaceEventB{}public class InterfaceEventModeExample : MonoBehaviour, IOnEventInterfaceEventA, IOnEventInterfaceEventB{public void OnEvent(InterfaceEventA e){Debug.Log(e.GetType().Name);}public void OnEvent(InterfaceEventB e){Debug.Log(e.GetType().Name);}private void Start(){this.RegisterEventInterfaceEventA().UnRegisterWhenGameObjectDestroyed(gameObject);this.RegisterEventInterfaceEventB();}private void OnDestroy(){this.UnRegisterEventInterfaceEventB();}private void Update(){if (Input.GetMouseButtonDown(0)){TypeEventSystem.Global.SendInterfaceEventA();TypeEventSystem.Global.SendInterfaceEventB();}}} }// 输出结果 // 当按下鼠标左键时输出: // InterfaceEventA // InterfaceEventB同样接口事件也支持事件之间的继承。 非 MonoBehavior 脚本如何自动销毁 public class NoneMonoScript : IUnRegisterList {public ListIUnRegister UnregisterList { get; } new ListIUnRegister();void Start(){TypeEventSystem.Global.RegisterEasyEventExample.EventA(a {}).AddToUnregisterList(this);}void OnDestroy(){this.UnRegisterAll();} }如果想手动注销必须要创建一个用于接收事件的方法。 而用自动注销则直接用委托即可。 这两个各有优劣按需使用。 另外事件的定义最好使用 struct因为 struct 的 gc 更少可以获得更好的性能。 EasyEvent TypeEventSystem 是基于 EasyEvent 实现的。 EasyEvent 也是一个可以脱离架构使用的工具。 基本用法 using UnityEngine;namespace QFramework.Example {public class EasyEventExample : MonoBehaviour{private EasyEvent mOnMouseLeftClickEvent new EasyEvent();private EasyEventint mOnValueChanged new EasyEventint();public class EventA : EasyEventint,int { }private EventA mEventA new EventA();private void Start(){mOnMouseLeftClickEvent.Register(() {Debug.Log(鼠标左键点击);}).UnRegisterWhenGameObjectDestroyed(gameObject);mOnValueChanged.Register(value {Debug.Log($值变更:{value});}).UnRegisterWhenGameObjectDestroyed(gameObject);mEventA.Register((a, b) {Debug.Log($自定义事件:{a} {b});}).UnRegisterWhenGameObjectDestroyed(gameObject);}private void Update(){if (Input.GetMouseButtonDown(0)){mOnMouseLeftClickEvent.Trigger();}if (Input.GetMouseButtonDown(1)){mOnValueChanged.Trigger(10);}// 鼠标中键if (Input.GetMouseButtonDown(2)){mEventA.Trigger(1,2);}}} }// 输出结果 // 按鼠标左键时输出: // 鼠标左键点击 // 按鼠标右键时输出: // 值变更:10 // 按鼠标中键时输出: // 自定义事件:1 2EasyEvent 最多支持三个泛型。  EasyEvent 的优势 EasyEvent 是 C# 委托和事件的替代。 EasyEvent 相比 C# 委托和事件优势是可以自动注销。 相比 TypeEventSystem优势是更轻量大多数情况下不用声明事件类而且性能更好接近 C# 委托。 缺点则是其携带的参数没有名字需要自己定义名字。 在设计一些通用系统的时候EasyEvent 会派上用场比如背包系统、对话系统TypeEventSystem 是一个非常好的例子。 BindableProperty BindableProperty 提供 数据 数据变更事件 的一个对象。 基本用法 var age new BindablePropertyint(10);age.Register(newAge{Debug.Log(newAge) }).UnRegisterWhenGameObjectDestoryed(gameObject);age; age--;// 输出结果 // 11 // 10就是当调用 age 和 age-- 的时候就会触发数据变更事件。 BindableProperty 除了提供 Register 这个 API 之外还提供了 RegisterWithInitValue API,意思是 注册时 先把当前值返回过来。 具体用法如下: var age new BindablePropertyint(5);age.RegisterWithInitValue(newAge {Debug.Log(newAge);});// 输出结果 // 5这个 API 就是没有任何变化的情况下age 先返回一个当前的值比较方便用于显示初始界面。 使用 BindableProperty 优化 CounterApp 的代码 using UnityEngine; using UnityEngine.UI;namespace QFramework.Example {// 1. 定义一个 Model 对象public class CounterAppModel : AbstractModel{public BindablePropertyint Count { get; } new BindablePropertyint();protected override void OnInit(){var storage this.GetUtilityStorage();// 设置初始值不触发事件Count.SetValueWithoutEvent(storage.LoadInt(nameof(Count)));// 当数据变更时 存储数据Count.Register(newCount {storage.SaveInt(nameof(Count),newCount);});}}public class AchievementSystem : AbstractSystem {protected override void OnInit(){this.GetModelCounterAppModel() // -.Count.Register(newCount {if (newCount 10){Debug.Log(触发 点击达人 成就);}else if (newCount 20){Debug.Log(触发 点击专家 成就);}else if (newCount -10){Debug.Log(触发 点击菜鸟 成就);}});}}// 定义 utility 层public class Storage : IUtility{public void SaveInt(string key, int value){PlayerPrefs.SetInt(key,value);}public int LoadInt(string key, int defaultValue 0){return PlayerPrefs.GetInt(key, defaultValue);}}// 2.定义一个架构提供 MVC、分层、模块管理等public class CounterApp : ArchitectureCounterApp{protected override void Init(){// 注册 System this.RegisterSystem(new AchievementSystem()); // // 注册 Modelthis.RegisterModel(new CounterAppModel());// 注册存储工具的对象this.RegisterUtility(new Storage());}}// 引入 Commandpublic class IncreaseCountCommand : AbstractCommand {protected override void OnExecute(){var model this.GetModelCounterAppModel();model.Count.Value; // -}}public class DecreaseCountCommand : AbstractCommand{protected override void OnExecute(){this.GetModelCounterAppModel().Count.Value--; // -}}// Controllerpublic class CounterAppController : MonoBehaviour , IController /* 3.实现 IController 接口 */{// Viewprivate Button mBtnAdd;private Button mBtnSub;private Text mCountText;// 4. Modelprivate CounterAppModel mModel;void Start(){// 5. 获取模型mModel this.GetModelCounterAppModel();// View 组件获取mBtnAdd transform.Find(BtnAdd).GetComponentButton();mBtnSub transform.Find(BtnSub).GetComponentButton();mCountText transform.Find(CountText).GetComponentText();// 监听输入mBtnAdd.onClick.AddListener(() {// 交互逻辑this.SendCommandIncreaseCountCommand();});mBtnSub.onClick.AddListener(() {// 交互逻辑this.SendCommand(new DecreaseCountCommand(/* 这里可以传参如果有 */));});// 表现逻辑mModel.Count.RegisterWithInitValue(newCount // -{UpdateView();}).UnRegisterWhenGameObjectDestroyed(gameObject);}void UpdateView(){mCountText.text mModel.Count.ToString();}// 3.public IArchitecture GetArchitecture(){return CounterApp.Interface;}private void OnDestroy(){// 8. 将 Model 设置为空mModel null;}} } Model 中的 Count 和 mCount 改成了一个叫做 Count 的 BindableProperty删掉了 CountChangeEvent 改用监听 BindablePropertyController 在初始化中去掉一次 UpdateView 的主动调用 由于 Count 数据是单个数据 事件变更的形式所以用 BindableProperty 非常合适可以少写很多代码。 一般情况下像主角的金币、分数等数据非常适合用 BindableProperty 的方式实现。 IOCContainer QFramework 架构的模块注册与获取是通过 IOCContainer 实现的。 IOC 的意思是控制反转即控制反转容器。 其技术的本质很简单本质就是一个字典Key 是 TypeValue 是 Object即DictionaryType,object。 QFramework 架构中的 IOCContainer 是一个非常简易版本的控制翻转容器仅支持了注册对象为单例的模式。 基本使用 using System; using UnityEngine;namespace QFramework.Example {public class IOCContainerExample : MonoBehaviour{public class SomeService{public void Say(){Debug.Log(SomeService Say Hi);}}public interface INetworkService{void Connect();}public class NetworkService : INetworkService{public void Connect(){Debug.Log(NetworkService Connect Succeed);}}private void Start(){var container new IOCContainer();container.Register(new SomeService());container.RegisterINetworkService(new NetworkService());container.GetSomeService().Say();container.GetINetworkService().Connect();}} }// 输出结果: // SomeService Say Hi // NetworkService Connect Succeed使用 IOCContainer 更容易设计出符合依赖倒置原则的模块。 而 QFramework 架构的用接口设计模块的支持就是通过 IOCContainer 支持的同样使用 IOCContainer 也更容易设计出分层的架构。
http://www.zqtcl.cn/news/184139/

相关文章:

  • 做网站熊掌号软件设计公司排名
  • 深圳 做网站学做西点的网站
  • 静态网站安全性百度服务平台
  • 网站vi设计公司网站建设app
  • 书店网站建设策划书总结每天看七个广告赚40元的app
  • 做网站的属于什么专业成都广告制作安装公司
  • 天津市网站建设公司网站制作费用
  • 网站制作公司 郑州wordpress图片中文不显示解决
  • 网站建设模式有哪些方面jquery做的装修网站
  • 佛山手机建网站企业网站公司单位有哪些
  • 给企业做网站的平台有没有专门做衣服搭配的网站
  • 青岛本地网站最近军事新闻大事
  • 潍坊哪里有做360网站的成都官微最新发布
  • 还有哪些网站可以做淘宝活动企业建设网站的方式
  • 上海技术公司做网站2022引流人脉推广软件
  • 网站排名优化技术安徽省城乡和建设厅网站
  • 平阴县建设工程网站英文网站模板制作
  • 网站制作超链接怎么做厦门公司建站
  • 阿里云做的网站怎么备份建筑设计网站issuu
  • 网上做设计网站广西做网站找谁
  • 网站优化成本建设项目网站备案申请表
  • 做公众号首图网站上海短期网站建设培训
  • 网站开发最好佛山优化网站排名
  • 服务器搭建网站打不开网站建设信息平台
  • 宽屏蓝色企业网站源码如何编辑网站标题
  • 免费搭建手机网站广告公司怎么取名
  • 网站抓取超时错误c 高性能网站开发
  • 营销导向企业网站策划wordpress 不显示菜单
  • 特效视频网站用.net做视频网站的案例
  • 网站建设实用的网站视屏网站的审核是怎么做的