private void MaybeInitiate() { if (initiated) { return; } int n = spawnPatterns.Length; for (int i = 0; i < n; i++) { SpawnPattern pattern = spawnPatterns[i]; int count = pattern.GetSpawnCount(); float startTime = patternStartTimes[i]; totalSpawnCount += count; spawnTimes.AddRange(pattern.GetSpawnTimes().Take(count).Select(t => t + startTime)); prefabs.AddRange(pattern.GetPrefabs().Take(count)); trajectoryOffsets.AddRange(pattern.GetTrajectoryOffsets().Take(count)); trajectoryRotations.AddRange(pattern.GetTrajectoryRotations().Take(count)); trajectories.AddRange(pattern.GetTrajectories().Take(count)); targets.AddRange(pattern.GetTargets().Take(count)); } var indexes = new List <int>( spawnTimes .Select((time, index) => new { time, index }) .OrderBy(pair => pair.time) .Select(pair => pair.index)); spawnTimes = new List <float>(indexes.Select(i => spawnTimes[i])); prefabs = new List <GameObject>(indexes.Select(i => prefabs[i])); trajectoryOffsets = new List <Vector3>(indexes.Select(i => trajectoryOffsets[i])); trajectoryRotations = new List <Quaternion>(indexes.Select(i => trajectoryRotations[i])); trajectories = new List <Trajectory>(indexes.Select(i => trajectories[i])); targets = new List <Target>(indexes.Select(i => targets[i])); initiated = true; }