Game Framework 设计思想研究(零点一) TimerManager(定时器)

本文探讨了Game Framework的设计思想,并重点讲解了TimerManager的实现,这是一个用于定时任务的组件。TimerComponent的注册方式包括指定时间、完成方法、轮询方法等参数,可选择是否循环和使用真实时间,还能关联到特定的游戏对象进行销毁。
摘要由CSDN通过智能技术生成

资源管理器太大了,想要快速理解还是需要时间,正赶上最近GF有加上了个VFS(虚拟文件系统),所以嘛,再等等。

今天就送大家一个 我写的Component,这个是原UGF里没有的,我自己扩展的,说是自己扩展的其实也是Github上抄下来,做了一些改动和适配,我用着挺好的。

 

Timer.cs

#region << 版 本 注 释 >>
/*----------------------------------------------------------------
* 类 名 称 :Timer
* 作    者 :L.Chen
* 创建时间 :2019/12/17 13:49:06
* 版 本 号 :v1.0.0.0
* 类 描 述 :
*******************************************************************
//----------------------------------------------------------------*/
#endregion

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;

public class Timer
{
    private bool m_IsOwnerDestroyed
    {
        get
        {
            return m_HasAutoDestroyOwner && m_AutoDestroyOwner == null;
        }
    }

    private readonly Action m_OnComplete = null;
    private readonly Action<float> m_OnUpdate = null;
    private float m_StartTime = 0f;
    private float m_LastUpdateTime = 0f;
    private float? m_TimeElapsedBeforeCancel = null;
    private float? m_TimeElapsedBeforePause = null;
    private readonly UnityEngine.MonoBehaviour m_AutoDestroyOwner = null;
    private readonly bool m_HasAutoDestroyOwner = false;

    public Timer(float duration, Action onComplete, Action<float> onUpdate,
        bool isLooped, bool usesRealTime, MonoBehaviour autoDestroyOwner)
    {
        Duration = duration;
        m_OnComplete = onComplete;
        m_OnUpdate = onUpdate;

        IsLooped = isLooped;
        UsesRealTime = usesRealTime;

        m_AutoDestroyOwner = autoDestroyOwner;
        m_HasAutoDestroyOwner = autoDestroyOwner != null;

        
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值