using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class BikeManager : MonoBehaviour { [SerializeField] public int playerID; // {get; set; } // external conf private float distanceToRun; public float Speed {get; set; } private float lastTimeImp; private float lastTimeDlt; public float maxTimeDlt = 1.0f; private float filteredSpeed; private Tachometer taco; private VideoManager vm; private GameManager gm; public bool finished = false; void Awake() { vm = gameObject.GetComponent(); vm.SetSkin(playerID); gm = GameManager.Instance; gm.RegisterBike(this, playerID); } // Use this for initialization void Start () { distanceToRun = gm.GetRaceDistance(); //taco = gameObject.AddComponent(); taco = gameObject.AddComponent(); taco.SetPlayer(playerID); } // Update is called once per frame void Update () { } public float GetSpeed() { return taco.GetSpeed (); } public bool LoadingComplete() { return vm.setUp; } void FixedUpdate() { } // int getBikeImpulses(float timeWindow = .5f) { // if (impulses.Count == 0) { // return 0; // } // // float time = Time.time; // float delta = time - impulses.Peek(); // while (delta > timeWindow) { // impulses.Dequeue(); // if (impulses.Count == 0) { // break; // } // delta = time - impulses.Peek(); // } // return impulses.Count; // } // // float getBikeSpeedApproxFiltered(float max = 90 / 3.6f) { // float speed = getBikeSpeedApprox(); // if (speed < max) // filteredSpeed = speed; // return filteredSpeed; // } // // float getBikeSpeedApprox() { // float newTimeDlt = Time.time - lastTimeImp; // // if (lastTimeDlt < 0.01) // return 0f; // if (newTimeDlt < lastTimeDlt) // return distancePerTick / lastTimeDlt; // if (newTimeDlt < maxTimeDlt) // return distancePerTick / newTimeDlt; // return 0f; // } // // float getBikeSpeedLegacy(float timeWindow = .5f) { // int imp = getBikeImpulses(timeWindow); // return imp * distancePerTick / timeWindow; // } // // void WheelTic() { // impulses.Enqueue(Time.time); // distanceRun += distancePerTick; // //Debug.Log(GetProgress()); // // lastTimeDlt = Time.time - lastTimeImp; // lastTimeImp = Time.time; // // Debug.Log(lastTimeDlt); // } public float GetProgress() { return taco.GetDistanceRun() / distanceToRun > 1f ? 1f: taco.GetDistanceRun() / distanceToRun; } public float GetDistance() { return taco.GetDistanceRun(); } }