@@ -30,9 +30,9 @@ public class RaceRunner : UdonSharpBehaviour
3030 [ SerializeField ]
3131 private AudioClip _soundGoal ;
3232
33- internal RaceRunnerTimeDisplay timeDisplay ;
3433 internal PlayerRecord playerRecord ;
3534
35+ private RaceRunnerTimeDisplay _timeDisplay ;
3636 private VRCPlayerApi _driver ;
3737 private CourseDescriptor _entriedCourse ;
3838 private Checkpoint [ ] _entriedCheckpoints = new Checkpoint [ 0 ] ;
@@ -49,7 +49,7 @@ private void Update()
4949 if ( currentTime != _currentTime )
5050 {
5151 _currentTime = currentTime ;
52- if ( timeDisplay ) { timeDisplay . CurrentTime = currentTime ; }
52+ if ( _timeDisplay ) { _timeDisplay . CurrentTime = currentTime ; }
5353 }
5454 }
5555
@@ -158,14 +158,27 @@ public TimeSpan GetGoalTime()
158158 return GetSplitTime ( _sectionClocks . Length - 1 ) ;
159159 }
160160
161- public void SetDriver ( VRCPlayerApi driver )
161+ internal void SetTimeDisplay ( RaceRunnerTimeDisplay timeDisplay )
162+ {
163+ if ( ! timeDisplay ) { return ; }
164+
165+ _timeDisplay = timeDisplay ;
166+ _timeDisplay . RunnerName = runnerName ;
167+ }
168+
169+ internal void SetDriver ( VRCPlayerApi driver )
162170 {
163171 if ( ! Utilities . IsValid ( driver ) ) { return ; }
164172
165173 if ( _driver != driver )
166174 {
167175 _driver = driver ;
168- if ( timeDisplay ) { timeDisplay . DriverName = driver . displayName ; }
176+ CountReset ( ) ;
177+
178+ if ( _timeDisplay )
179+ {
180+ _timeDisplay . DriverName = driver . displayName ;
181+ }
169182 }
170183 }
171184
@@ -181,11 +194,10 @@ private void EntryCourse(CourseDescriptor course)
181194
182195 _nextCheckpoint = GetNextCheckpoint ( _entriedCheckpoints [ 0 ] ) ;
183196
184- if ( timeDisplay )
197+ if ( _timeDisplay )
185198 {
186- timeDisplay . RunnerName = runnerName ;
187- timeDisplay . EntriedCourseName = _entriedCourse . courseName ;
188- timeDisplay . LapCount = _lapCount ;
199+ _timeDisplay . EntriedCourseName = _entriedCourse . courseName ;
200+ _timeDisplay . LapCount = _lapCount ;
189201 }
190202 }
191203
@@ -204,19 +216,42 @@ private Checkpoint GetNextCheckpoint(Checkpoint currentCheckpoint)
204216
205217 private bool _isCounting ;
206218
219+ private void CountReset ( )
220+ {
221+ _entriedCourse = null ;
222+ _entriedCheckpoints = new Checkpoint [ 0 ] ;
223+ _lapCount = 0 ;
224+ playerRecord = null ;
225+ _nextCheckpoint = null ;
226+ _currentLap = 0 ;
227+ _currentSection = 0 ;
228+ _sectionClocks = new double [ 1 ] ;
229+ _isCounting = false ;
230+
231+ if ( _timeDisplay )
232+ {
233+ _timeDisplay . EntriedCourseName = "" ;
234+ _timeDisplay . LapCount = _lapCount ;
235+ _timeDisplay . CurrentLap = _currentLap ;
236+ _timeDisplay . LastSectionTime = GetCurrentSectionTime ( ) ;
237+ _timeDisplay . LastSplitTime = GetCurrentSplitTime ( ) ;
238+ _timeDisplay . LastLapTime = GetCurrentLapTime ( ) ;
239+ }
240+ }
241+
207242 private void CountStart ( double triggerClock )
208243 {
209244 _currentLap = 0 ;
210245 _currentSection = 0 ;
211246 _sectionClocks [ _currentSection ] = triggerClock ;
212247 _isCounting = true ;
213248
214- if ( timeDisplay )
249+ if ( _timeDisplay )
215250 {
216- timeDisplay . CurrentLap = _currentLap ;
217- timeDisplay . LastSectionTime = GetCurrentSectionTime ( ) ;
218- timeDisplay . LastSplitTime = GetCurrentSplitTime ( ) ;
219- timeDisplay . LastLapTime = GetCurrentLapTime ( ) ;
251+ _timeDisplay . CurrentLap = _currentLap ;
252+ _timeDisplay . LastSectionTime = GetCurrentSectionTime ( ) ;
253+ _timeDisplay . LastSplitTime = GetCurrentSplitTime ( ) ;
254+ _timeDisplay . LastLapTime = GetCurrentLapTime ( ) ;
220255 }
221256
222257 if ( _speaker && _soundStart ) { _speaker . PlayOneShot ( _soundStart ) ; }
@@ -227,10 +262,10 @@ private void CountSection(double triggerClock)
227262 _currentSection ++ ;
228263 _sectionClocks [ _currentSection ] = triggerClock ;
229264
230- if ( timeDisplay )
265+ if ( _timeDisplay )
231266 {
232- timeDisplay . LastSectionTime = GetCurrentSectionTime ( ) ;
233- timeDisplay . LastSplitTime = GetCurrentSplitTime ( ) ;
267+ _timeDisplay . LastSectionTime = GetCurrentSectionTime ( ) ;
268+ _timeDisplay . LastSplitTime = GetCurrentSplitTime ( ) ;
234269 }
235270
236271 if ( _speaker && _soundCheckpoint ) { _speaker . PlayOneShot ( _soundCheckpoint ) ; }
@@ -240,10 +275,10 @@ private void CountLap()
240275 {
241276 _currentLap ++ ;
242277
243- if ( timeDisplay )
278+ if ( _timeDisplay )
244279 {
245- timeDisplay . CurrentLap = _currentLap ;
246- timeDisplay . LastLapTime = GetCurrentLapTime ( ) ;
280+ _timeDisplay . CurrentLap = _currentLap ;
281+ _timeDisplay . LastLapTime = GetCurrentLapTime ( ) ;
247282 }
248283 }
249284
0 commit comments