unity自制延迟定时回调
来源:互联网 发布:linux oracle09925 编辑:程序博客网 时间:2024/04/29 20:29
如下:
using UnityEngine;using System.Collections;public class DelayCallCtrler :MonoBehaviour{ private static DelayCallCtrler s_instance = null; private static DelayCallCtrler GetInstance() { if (null == s_instance) { GameObject go = new GameObject("DelayCallCtrler"); s_instance = go.AddComponent<DelayCallCtrler>(); } return s_instance; } private BehavTimer m_invoke_timer = new BehavTimer(); public static void Call(System.Action func, float delay) { if (null == func) return; if (0 > delay) { func(); return; } var instance = GetInstance(); instance.enabled = true; instance.m_invoke_timer.Invoke(func, delay); } public static void Clear() { var instance = GetInstance(); instance.m_invoke_timer.Clear(); instance.enabled = false; } protected void Update() { m_invoke_timer.Update(Time.deltaTime); if (m_invoke_timer.count <= 0) { enabled = false; } }}
using UnityEngine;using System.Collections;using System.Collections.Generic;public class TimerData{ public float time; public System.Action cb;}public class BehavTimer { private List<TimerData> m_list = new List<TimerData>(); private float m_dt = 0; public int count { get { return m_list.Count; } } public void Invoke(System.Action cb,float delay) { if (null == cb) return; m_list.Add(new TimerData() { cb = cb, time = delay }); } public void Clear() { m_list.Clear(); } public void Update(float dt) { if (m_list.Count <= 0) return; m_dt = dt; m_list.ForEach(UpdateData); m_list.RemoveAll(RemoveDataCdt); } static bool RemoveDataCdt(TimerData td) { return td.time < 0; } protected void UpdateData(TimerData td) { td.time -= m_dt; if (td.time <= 0) { if (null != td.cb) { td.cb(); } } }}
0 0
- unity自制延迟定时回调
- unity 自制小荷花
- Unity自制小时钟
- 系统延迟及定时
- 定时延迟任务
- 延迟与定时任务
- Unity延迟调用
- Unity 函数延迟调用
- ActiveMQ延迟和定时投递
- AlarmManager定时任务延迟执行
- 系统延迟及定时机制
- 系统延迟及定时机制
- 系统延迟及定时机制
- 系统延迟及定时机制
- 系统延迟及定时机制
- 系统延迟及定时机制
- 系统延迟及定时机制
- 系统延迟及定时任务
- UUID做主键,好还是不好?这是个问题。
- 解决无法用windows资源管理器打开ftp
- 小明滚出去全集
- Android配置文件分享和JSON数据生成与解析
- 最新手势跟踪与识别
- unity自制延迟定时回调
- "给我评分" 模块,跳转到相应的应用商店--apk展示详情页面
- 正则表达式基础
- android sdk离线安装
- webapi上传图片的两种方式
- MongoDB的部署及java访问
- Qt之命令行参数
- 推理问题
- mahout之推荐系统源码笔记(1) ---预处理之PreparePreferenceMatrixJob