zoukankan      html  css  js  c++  java
  • 任务框架

    任务模块框架

    #region Class Information
    /*-----------------------------------------
    // File:				ICmd.cs
    // author:				wugang
    // description:			命令策略
    // Date:				2015-9-12
    // ----------------------------------------*/
    # endregion
    using UnityEngine;
    using System.Collections;
    
    /// <summary>
    /// 命令接口 所有策略类基础此接口
    /// </summary>
    public interface ICmd
    {
        //回调
        event Callback callback;
        //初始化、设置参数
        void SetParams(params object[] objs);
        void Update();
        void DoOnce();
        void Stop();
    }
    /// <summary>
    /// 与npc对话策略实现 继承命令接口
    /// </summary>
    public class ChatNpcCmd : ICmd
    {
        public event Callback callback;
    
        int m_mapId;
        int m_npcId;
    
        Vector3 npcPosition;
    
        public void SetParams(params object[] objs)
        {
            m_mapId = (int)objs[0];
            m_npcId = (int)objs[1];
        }
    
        public void Update()
        {
            //执行具体逻辑
            //DOTO:
    
            
            //执行stop
            if (true) { Stop(); }
    
        }
    
        public void DoOnce()
        {
            //执行具体逻辑
        }
    
        public void Stop()
        {
            //执行回调
            if (callback != null)
                callback();
        }
    }
    #region Class Information
    /*-----------------------------------------
    // File:				CmdContext.cs
    // author:				wugang
    // description:			命令中间层
    // Date:				2015-9-12
    // ----------------------------------------*/
    #endregion
    using UnityEngine;
    using System.Collections;
    
    public class CmdContext
    {
        ICmd m_Cmd;
        public CmdContext(ICmd cmd)
        {
            this.m_Cmd = cmd;
        }
    
        public void DoOnce()
        {
            m_Cmd.DoOnce();
        }
    
        public void Update()
        {
            m_Cmd.Update();
        }
    }
    #region Class Information
    /*-----------------------------------------
    // File:				CmdManager.cs
    // author:				wugang
    // description:			命令管理器
    // Date:				2015-9-12
    // ----------------------------------------*/
    # endregion
    using UnityEngine;
    using System.Collections;
    public class CmdManager : MonoBehaviour
    {
        bool m_Running = false;
        CmdContext m_CmdContext;
        public void StartCmd(TaskDataType type, params object[] objs)
        {
            switch (type)
            {
                case TaskDataType.ChatNpc:
                    m_CmdContext = new CmdContext(new ChatNpcCmd());
                    break;
                case TaskDataType.KillMonster:
                    break;
                case TaskDataType.GuildPortal:
                    break;
            }
            m_Running = true;
        }
        public void Stop()
        {
            m_Running = false;
            m_CmdContext = null;
        }
    
        void Update()
        {
            if (!m_Running) return;
            if (m_CmdContext == null)
            {
    #if UNITY_EDITOR
                Debug.LogError("m_CmdContext is null!!!");
    #endif
                return;
            }
            m_CmdContext.Update();
        }
    }


    ------------------2017-2-17

    最近接触IOC比较多,有时间的话可以通过IOC来重构一下该代码。

  • 相关阅读:
    sql基本语法:
    mysqldump: Couldn't execute 'SET OPTION SQL_QUOTE_SHOW_CREATE=1': You have an error in your SQL syntax; check the manual t
    truncate和 delete的区别:
    主流存储引擎详解:Innodb,Tokudb、Memory、MYISAM、Federated
    ant-design-vue表单生成组件form-create快速上手
    vue自定义表单生成器,可根据json参数动态生成表单
    Vue数据驱动表单渲染,轻松搞定form表单
    PHP表单生成器,快速生成现代化的form表单,快速上手
    form-create 组件生成规则说明
    form-create教程:自定义布局,实现一行多个组件
  • 原文地址:https://www.cnblogs.com/wugang/p/14232326.html
Copyright © 2011-2022 走看看