三国卡牌客户端基础资源仓库
yyl
1 天以前 cec146fc3fe287928e075c79ece20a20a9b16b20
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Threading;
using System;
 
    public class LogicUpdate
    {
        public readonly float stepInterval = 0.033333f;
 
        public bool destroyDirty { get; private set; }
        float nextUpdateTime = 0f;
        Action update;
 
        public LogicUpdate(float stepInterval = 0.033333f)
        {
            this.stepInterval = Mathf.Clamp(stepInterval, 0.033333f, float.MaxValue);
        }
 
        public void Start(Action updateCallBack)
        {
            this.destroyDirty = false;
            this.update = updateCallBack;
            LogicEngine.Instance.Register(this);
        }
 
        public void Destroy()
        {
            this.update = null;
            if (!this.destroyDirty)
            {
                this.destroyDirty = true;
                OnDestroy();
            }
        }
 
        public virtual void OnDestroy()
        {
 
        }
 
        public void Update()
        {
            if (Time.time >= nextUpdateTime)
            {
                nextUpdateTime = Time.time + stepInterval;
                if (update != null)
                {
                    this.update();
                }
            }
        }
 
    }