/// <summary> /// Creates and stores references to multiple objects (of different types) per <see cref="TrackRings"/> on the <paramref name="gameObject"/> /// </summary> /// <param name="gameObject">What <see cref="GameObject"/> to create TrackRings for</param> internal void CreateTrackRings(GameObject gameObject) { rotationSpawners = new List <TrackLaneRingsRotationEffectSpawner>(); stepSpawners = new List <TrackLaneRingsPositionStepEffectSpawner>(); trackLaneRingsManagers = new List <TrackLaneRingsManager>(); trackRingsDescriptors = new List <TrackRings>(); TrackRings[] ringsDescriptors = gameObject.GetComponentsInChildren <TrackRings>(); foreach (TrackRings trackRingDesc in ringsDescriptors) { trackRingsDescriptors.Add(trackRingDesc); TrackLaneRingsManager ringsManager = trackRingDesc.gameObject.AddComponent <TrackLaneRingsManager>(); trackLaneRingsManagers.Add(ringsManager); PlatformManager.SpawnedComponents.Add(ringsManager); TrackLaneRing ring = trackRingDesc.trackLaneRingPrefab.AddComponent <TrackLaneRing>(); PlatformManager.SpawnedComponents.Add(ring); ringsManager.SetField("_trackLaneRingPrefab", ring); ringsManager.SetField("_ringCount", trackRingDesc.ringCount); ringsManager.SetField("_ringPositionStep", trackRingDesc.ringPositionStep); ringsManager.SetField("_spawnAsChildren", true); if (trackRingDesc.useRotationEffect) { TrackLaneRingsRotationEffect rotationEffect = trackRingDesc.gameObject.AddComponent <TrackLaneRingsRotationEffect>(); PlatformManager.SpawnedComponents.Add(rotationEffect); rotationEffect.SetField("_trackLaneRingsManager", ringsManager); rotationEffect.SetField("_startupRotationAngle", trackRingDesc.startupRotationAngle); rotationEffect.SetField("_startupRotationStep", trackRingDesc.startupRotationStep); int timePerRing = trackRingDesc.startupRotationPropagationSpeed / trackRingDesc.ringCount; float ringsPerFrame = Time.fixedDeltaTime / timePerRing; rotationEffect.SetField("_startupRotationPropagationSpeed", Math.Max((int)ringsPerFrame, 1)); rotationEffect.SetField("_startupRotationFlexySpeed", trackRingDesc.startupRotationFlexySpeed); TrackLaneRingsRotationEffectSpawner rotationEffectSpawner = trackRingDesc.gameObject.AddComponent <TrackLaneRingsRotationEffectSpawner>(); rotationSpawners.Add(rotationEffectSpawner); PlatformManager.SpawnedComponents.Add(rotationEffectSpawner); rotationEffectSpawner.SetField("_beatmapObjectCallbackController", _beatmapObjectCallbackController); rotationEffectSpawner.SetField("_beatmapEventType", (BeatmapEventType)trackRingDesc.rotationSongEventType); rotationEffectSpawner.SetField("_rotationStep", trackRingDesc.rotationStep); int timePerRing2 = trackRingDesc.rotationPropagationSpeed / trackRingDesc.ringCount; float ringsPerFrame2 = Time.fixedDeltaTime / timePerRing2; rotationEffectSpawner.SetField("_rotationPropagationSpeed", Math.Max((int)ringsPerFrame2, 1)); rotationEffectSpawner.SetField("_rotationFlexySpeed", trackRingDesc.rotationFlexySpeed); rotationEffectSpawner.SetField("_trackLaneRingsRotationEffect", rotationEffect); } if (trackRingDesc.useStepEffect) { TrackLaneRingsPositionStepEffectSpawner stepEffectSpawner = trackRingDesc.gameObject.AddComponent <TrackLaneRingsPositionStepEffectSpawner>(); stepSpawners.Add(stepEffectSpawner); PlatformManager.SpawnedComponents.Add(stepEffectSpawner); stepEffectSpawner.SetField("_beatmapObjectCallbackController", _beatmapObjectCallbackController); stepEffectSpawner.SetField("_trackLaneRingsManager", ringsManager); stepEffectSpawner.SetField("_beatmapEventType", (BeatmapEventType)trackRingDesc.stepSongEventType); stepEffectSpawner.SetField("_minPositionStep", trackRingDesc.minPositionStep); stepEffectSpawner.SetField("_maxPositionStep", trackRingDesc.maxPositionStep); stepEffectSpawner.SetField("_moveSpeed", trackRingDesc.moveSpeed); } } }
// ReSharper disable once CognitiveComplexity public async void PlatformEnabled(DiContainer container) { if (trackLaneRingPrefab is null) { return; } container.Inject(this); if (_trackLaneRingsManager is null) { await _materialSwapper !.ReplaceMaterialsAsync(trackLaneRingPrefab); gameObject.SetActive(false); TrackLaneRing trackLaneRing = trackLaneRingPrefab.AddComponent <TrackLaneRing>(); _trackLaneRingsManager = gameObject.AddComponent <TrackLaneRingsManager>(); _trackLaneRingsManager.SetField("_trackLaneRingPrefab", trackLaneRing); _trackLaneRingsManager.SetField("_ringCount", ringCount); _trackLaneRingsManager.SetField("_ringPositionStep", ringPositionStep); _trackLaneRingsManager.SetField("_spawnAsChildren", true); gameObject.SetActive(true); foreach (INotifyPlatformEnabled notifyEnable in GetComponentsInChildren <INotifyPlatformEnabled>(true)) { if (!ReferenceEquals(this, notifyEnable)) { notifyEnable?.PlatformEnabled(container); } } } if (useRotationEffect) { if (_trackLaneRingsRotationEffectSpawner is null) { TrackLaneRingsRotationEffect trackLaneRingsRotationEffect = gameObject.AddComponent <TrackLaneRingsRotationEffect>(); trackLaneRingsRotationEffect.SetField("_trackLaneRingsManager", _trackLaneRingsManager); trackLaneRingsRotationEffect.SetField("_startupRotationAngle", startupRotationAngle); trackLaneRingsRotationEffect.SetField("_startupRotationStep", startupRotationStep); int timePerRing = startupRotationPropagationSpeed / ringCount; float ringsPerFrame = Time.fixedDeltaTime / timePerRing; trackLaneRingsRotationEffect.SetField("_startupRotationPropagationSpeed", Mathf.Max((int)ringsPerFrame, 1)); trackLaneRingsRotationEffect.SetField("_startupRotationFlexySpeed", startupRotationFlexySpeed); _trackLaneRingsRotationEffectSpawner = gameObject.AddComponent <TrackLaneRingsRotationEffectSpawner>(); _trackLaneRingsRotationEffectSpawner.enabled = _beatmapObjectCallbackController is not null; _trackLaneRingsRotationEffectSpawner.SetField("_beatmapObjectCallbackController", _beatmapObjectCallbackController); _trackLaneRingsRotationEffectSpawner.SetField("_beatmapEventType", (BeatmapEventType)rotationSongEventType); _trackLaneRingsRotationEffectSpawner.SetField("_rotationStep", rotationStep); int timePerRing2 = rotationPropagationSpeed / ringCount; float ringsPerFrame2 = Time.fixedDeltaTime / timePerRing2; _trackLaneRingsRotationEffectSpawner.SetField("_rotationPropagationSpeed", Mathf.Max((int)ringsPerFrame2, 1)); _trackLaneRingsRotationEffectSpawner.SetField("_rotationFlexySpeed", rotationFlexySpeed); _trackLaneRingsRotationEffectSpawner.SetField("_trackLaneRingsRotationEffect", trackLaneRingsRotationEffect); } else if (_beatmapObjectCallbackController is not null) { _trackLaneRingsRotationEffectSpawner.enabled = true; _trackLaneRingsRotationEffectSpawner.SetField("_beatmapObjectCallbackController", _beatmapObjectCallbackController); _trackLaneRingsRotationEffectSpawner.Start(); } } if (useStepEffect) { if (_trackLaneRingsPositionStepEffectSpawner is null) { _trackLaneRingsPositionStepEffectSpawner = gameObject.AddComponent <TrackLaneRingsPositionStepEffectSpawner>(); _trackLaneRingsPositionStepEffectSpawner.enabled = _beatmapObjectCallbackController is not null; _trackLaneRingsPositionStepEffectSpawner.SetField("_beatmapObjectCallbackController", _beatmapObjectCallbackController); _trackLaneRingsPositionStepEffectSpawner.SetField("_trackLaneRingsManager", _trackLaneRingsManager); _trackLaneRingsPositionStepEffectSpawner.SetField("_beatmapEventType", (BeatmapEventType)stepSongEventType); _trackLaneRingsPositionStepEffectSpawner.SetField("_minPositionStep", minPositionStep); _trackLaneRingsPositionStepEffectSpawner.SetField("_maxPositionStep", maxPositionStep); _trackLaneRingsPositionStepEffectSpawner.SetField("_moveSpeed", moveSpeed); } else if (_beatmapObjectCallbackController is not null) { _trackLaneRingsPositionStepEffectSpawner.enabled = true; _trackLaneRingsPositionStepEffectSpawner.SetField("_beatmapObjectCallbackController", _beatmapObjectCallbackController); _trackLaneRingsPositionStepEffectSpawner.Start(); } } }