Skip to content

Commit 9fc189b

Browse files
committed
Runner初期化処理見直し
1 parent b7e3143 commit 9fc189b

File tree

4 files changed

+62
-36
lines changed

4 files changed

+62
-36
lines changed

Packages/com.mimylab.raceassemblytoolkit/Runtime/Scripts/Core/RaceDriverAsPlayer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public class RaceDriverAsPlayer : RaceDriver
1919
{
2020
private void Start()
2121
{
22-
_SetDriver();
22+
SendCustomEventDelayedFrames(nameof(_SetDriver), 1);
2323
}
2424
}
2525
}

Packages/com.mimylab.raceassemblytoolkit/Runtime/Scripts/Core/RaceRunner.asset

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -350,19 +350,19 @@ MonoBehaviour:
350350
Data:
351351
- Name: $k
352352
Entry: 1
353-
Data: timeDisplay
353+
Data: playerRecord
354354
- Name: $v
355355
Entry: 7
356356
Data: 21|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
357357
- Name: <Name>k__BackingField
358358
Entry: 1
359-
Data: timeDisplay
359+
Data: playerRecord
360360
- Name: <UserType>k__BackingField
361361
Entry: 7
362362
Data: 22|System.RuntimeType, mscorlib
363363
- Name:
364364
Entry: 1
365-
Data: MimyLab.RaceAssemblyToolkit.RaceRunnerTimeDisplay, RaceAssemblyToolkit
365+
Data: MimyLab.RaceAssemblyToolkit.PlayerRecord, RaceAssemblyToolkit
366366
- Name:
367367
Entry: 8
368368
Data:
@@ -410,19 +410,19 @@ MonoBehaviour:
410410
Data:
411411
- Name: $k
412412
Entry: 1
413-
Data: playerRecord
413+
Data: _timeDisplay
414414
- Name: $v
415415
Entry: 7
416416
Data: 25|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
417417
- Name: <Name>k__BackingField
418418
Entry: 1
419-
Data: playerRecord
419+
Data: _timeDisplay
420420
- Name: <UserType>k__BackingField
421421
Entry: 7
422422
Data: 26|System.RuntimeType, mscorlib
423423
- Name:
424424
Entry: 1
425-
Data: MimyLab.RaceAssemblyToolkit.PlayerRecord, RaceAssemblyToolkit
425+
Data: MimyLab.RaceAssemblyToolkit.RaceRunnerTimeDisplay, RaceAssemblyToolkit
426426
- Name:
427427
Entry: 8
428428
Data:

Packages/com.mimylab.raceassemblytoolkit/Runtime/Scripts/Core/RaceRunner.cs

Lines changed: 54 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Packages/com.mimylab.raceassemblytoolkit/Runtime/Scripts/Core/RaceRunnerTimeDisplay.cs

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -167,16 +167,7 @@ public TimeSpan LastLapTime
167167

168168
private void Start()
169169
{
170-
if (_runnerNameText) { _runnerName = _runnerNameText.text; }
171-
if (_driverNameText) { _driverName = _driverNameText.text; }
172-
if (_entriedCourseNameText) { _entriedCourseName = _entriedCourseNameText.text; }
173-
SetLapCountText(_currentLap, _lapCount);
174-
if (_currentTimeText) { _currentTimeText.text = _currentTime.ToString(_timeFormat); }
175-
if (_lastSectionTimeText) { _lastSectionTimeText.text = _lastSectionTime.ToString(_timeFormat); }
176-
if (_lastSplitTimeText) { _lastSplitTimeText.text = _lastSplitTime.ToString(_timeFormat); }
177-
if (_lastLapTimeText) { _lastLapTimeText.text = _lastLapTime.ToString(_timeFormat); }
178-
179-
_targetRunner.timeDisplay = this;
170+
_targetRunner.SetTimeDisplay(this);
180171
}
181172

182173
private void SetLapCountText(int current, int count)

0 commit comments

Comments
 (0)