using System.Collections;  
 | 
using System.Collections.Generic;  
 | 
using UnityEngine;  
 | 
using System.Threading;  
 | 
using System;  
 | 
  
 | 
  
 | 
namespace StartAot  
 | 
{  
 | 
    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();  
 | 
                }  
 | 
            }  
 | 
        }  
 | 
  
 | 
    }  
 | 
  
 | 
  
 | 
} 
 |