|
|
|
|
|
|
using System; |
|
|
|
using System.Collections; |
|
|
|
using System.Collections.Generic; |
|
|
|
using System.IO; |
|
|
|
using UnityEditor; |
|
|
|
|
|
|
|
|
|
|
void Update() |
|
|
|
{ |
|
|
|
// There are two known issues with the starting simulations on the first frame: rendered frames cannot be
|
|
|
|
// captured and the WaitForEndOfFrame will not function properly on the first frame.
|
|
|
|
if (Time.frameCount == 1) |
|
|
|
return; |
|
|
|
|
|
|
|
switch (state) |
|
|
|
{ |
|
|
|
case State.Initializing: |
|
|
|
|
|
|
|
|
|
|
void IterationLoop() |
|
|
|
{ |
|
|
|
// Perform new iteration tasks
|
|
|
|
if (currentIterationFrame == 0) |
|
|
|
{ |
|
|
|
ResetRandomStateOnIteration(); |
|
|
|
OnIterationStart(); |
|
|
|
foreach (var randomizer in activeRandomizers) |
|
|
|
randomizer.IterationStart(); |
|
|
|
} |
|
|
|
|
|
|
|
// Perform new frame tasks
|
|
|
|
OnUpdate(); |
|
|
|
foreach (var randomizer in activeRandomizers) |
|
|
|
randomizer.Update(); |
|
|
|
|
|
|
|
StartCoroutine(EndOfFrameIterationLoop()); |
|
|
|
} |
|
|
|
|
|
|
|
IEnumerator EndOfFrameIterationLoop() |
|
|
|
{ |
|
|
|
yield return new WaitForEndOfFrame(); |
|
|
|
|
|
|
|
// Iterate scenario frame count
|
|
|
|
currentIterationFrame++; |
|
|
|
framesSinceInitialization++; |
|
|
|
|
|
|
|
// Increment iteration and cleanup last iteration
|
|
|
|
if (isIterationComplete) |
|
|
|
{ |
|
|
|
|
|
|
OnComplete(); |
|
|
|
state = State.Idle; |
|
|
|
OnIdle(); |
|
|
|
return; |
|
|
|
|
|
|
|
// Perform new iteration tasks
|
|
|
|
if (currentIterationFrame == 0) |
|
|
|
{ |
|
|
|
ResetRandomStateOnIteration(); |
|
|
|
OnIterationStart(); |
|
|
|
foreach (var randomizer in activeRandomizers) |
|
|
|
randomizer.IterationStart(); |
|
|
|
} |
|
|
|
|
|
|
|
// Perform new frame tasks
|
|
|
|
OnUpdate(); |
|
|
|
foreach (var randomizer in activeRandomizers) |
|
|
|
randomizer.Update(); |
|
|
|
|
|
|
|
// Iterate scenario frame count
|
|
|
|
currentIterationFrame++; |
|
|
|
framesSinceInitialization++; |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|