121 lines
2.9 KiB
C#
121 lines
2.9 KiB
C#
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;
|
|
public float finishTime;
|
|
|
|
void Awake() {
|
|
vm = gameObject.GetComponent<VideoManager>();
|
|
vm.SetSkin(playerID);
|
|
|
|
gm = GameManager.Instance;
|
|
gm.RegisterBike(this, playerID);
|
|
}
|
|
|
|
// Use this for initialization
|
|
void Start () {
|
|
distanceToRun = gm.GetRaceDistance();
|
|
|
|
taco = gameObject.AddComponent<RAWTachometer>();
|
|
//taco = gameObject.AddComponent<PreciseTachometer>();
|
|
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();
|
|
}
|
|
}
|