123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- using Study;
- using SchoenLogger.HOHCI;
- using UnityEngine;
- public enum WaypointType { slalom1, slalom2, finish};
- namespace SchoenLogger.HOHCI
- {
- public class SlalomPassed : MonoBehaviour
- {
- public WaypointType type;
- public Logger<HOHCIEntry, HOHCICondition> Logger;
- public GameObject bikePlayer;
- // Only relevant to check finish
- public int routeId;
- // Start is called before the first frame update
- void Start()
- {
- bikePlayer = GameObject.Find("bike");
- }
- // Update is called once per frame
- void Update()
- {
- }
- private void OnTriggerEnter(Collider other)
- {
- if (other.CompareTag("bike"))
- {
- // Set finished in statistics, so success is logged
- var bikePlayer = GameObject.Find("bike");
- var playerStats = bikePlayer.GetComponent<PlayerStats>();
- Debug.Log("Waypoint passed");
- if (type == WaypointType.finish)
- {
- var cm = GameObject.Find("ExperimentManager").GetComponent<ConditionManager>();
- int routeNbr = cm.GetRouteNumber();
- // If type is finish, we need to make sure we only set for right finish
- // because routes are overlapping
- if (routeId == routeNbr)
- {
- playerStats.SetWaypointPassed(type);
- }
- }
- else
- {
- playerStats.SetWaypointPassed(type);
- }
- // we want to write a log entry each time a waypoint is passed
- WriteToLog();
- }
- }
- private void WriteToLog()
- {
- if (Logger == null) return;
- var playerStats = bikePlayer.GetComponent<PlayerStats>();
- HOHCIEntry entry = new HOHCIEntry();
- entry.Time = Time.time;
- entry.ParticipantID = playerStats.participantId;
- entry.steeringCondition = playerStats.condition;
- entry.ReachedFinish = playerStats.hasFinished;
- entry.ReachedSlalom1 = playerStats.hasFinishedSlalom1;
- entry.ReachedSlalom2 = playerStats.hasFinishedSlalom2;
- entry.CoinCount = playerStats.coinCounter;
- entry.CollisionCount = playerStats.collisionCounter;
- Logger.Log(entry);
- }
- }
- }
|