• 【Unity 框架】QFramework v1.0 使用指南 架构篇:14. Command 拦截 | Unity 游戏框架 | Unity 游戏开发 | Unity 独立游戏


    QFramework 提供了拦截 Command 的 API。

    我们尝试在 CounterApp 中实现一个 Command 日志。

    代码很简单,如下:

    public class CounterApp : Architecture<CounterApp>
    {
        protected override void Init()
        {
            // 注册 System 
            this.RegisterSystem<IAchievementSystem>(new AchievementSystem()); 
                 
            // 注册 Model
            this.RegisterModel<ICounterAppModel>(new CounterAppModel());
                
            // 注册存储工具的对象
            this.RegisterUtility<IStorage>(new Storage());
        }
    
        protected override void ExecuteCommand(ICommand command)
        {
            Debug.Log("Before " + command.GetType().Name + "Execute");
            base.ExecuteCommand(command);
            Debug.Log("After " + command.GetType().Name + "Execute");
        }
    }
    

    只需要在 Architecture 中覆写 ExecuteCommand 即可。

    运行之后,笔者随意点击了几次按钮,结果如下:

    image.png

    这样就实现了一个非常简单的 Command 日志功能。

    有了 Command 拦截有什么用?

    有了 Command 拦截功能,我们可以做非常多的事情,比如:

    • Command 日志可以用来方便调试
    • 可以实现 Command 中间件模式 可以写各种各样额度 Command 中间件,比如 Command 日志中间件
    • 可以方便你先撤销功能
    • 可以用 Command 做自动化测试
    • 等等

    好了这篇就介绍到这里。

    更多内容

  • 相关阅读:
    点赞
    js点击事件,数字累加
    html中hr的各种样式使用
    基于Bootstrap垂直响应的jQuery时间轴特效
    bootstrop日历
    前端经验
    bootstrop登陆页面
    bootstrop设置背景图片自适应屏幕
    建立博客的第一天
    php伪静态--隐藏地址实际路径方法
  • 原文地址:https://www.cnblogs.com/liangxiegame/p/16798658.html
Copyright © 2020-2023  润新知