123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- using System;
- using UnityEngine;
- namespace SicknessReduction.Haptic
- {
- public abstract class EspController : MonoBehaviour
- {
- protected DataBroker Broker;
- protected bool DoUpdate { private set; get; }
- protected bool PreviousUpdateActive;
- private bool brokerAvailable;
- private float publishWaitTime = 0.05f; //20Hz
- private float lastTs = 0f;
- protected virtual async void Start()
- {
- Broker = DataBroker.Instance;
- await Broker.AwaitServerStarted();
- brokerAvailable = true;
- }
- protected virtual void Update()
- {
- if (!brokerAvailable)
- {
- DoUpdate = false;
- return;
- }
- var t = Time.time;
- if (t - lastTs >= publishWaitTime)
- {
- lastTs = t;
- DoUpdate = true;
- }
- else
- {
- DoUpdate = false;
- }
- }
- protected virtual void OnDestroy()
- {
- DataBroker.DisposeInstance();
- }
- }
- }
|