public void CreateTrackRings(GameObject go)
        {
            rotationSpawners       = new List <TrackLaneRingsRotationEffectSpawner>();
            stepSpawners           = new List <TrackLaneRingsPositionStepEffectSpawner>();
            trackLaneRingsManagers = new List <TrackLaneRingsManager>();
            trackRingsDescriptors  = new List <TrackRings>();

            TrackRings[] ringsDescriptors = go.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);

                ReflectionUtil.SetPrivateField(ringsManager, "_trackLaneRingPrefab", ring);
                ReflectionUtil.SetPrivateField(ringsManager, "_ringCount", trackRingDesc.ringCount);
                ReflectionUtil.SetPrivateField(ringsManager, "_ringPositionStep", trackRingDesc.ringPositionStep);
                if (trackRingDesc.useRotationEffect)
                {
                    TrackLaneRingsRotationEffect rotationEffect =
                        trackRingDesc.gameObject.AddComponent <TrackLaneRingsRotationEffect>();
                    PlatformManager.SpawnedComponents.Add(rotationEffect);

                    ReflectionUtil.SetPrivateField(rotationEffect, "_trackLaneRingsManager", ringsManager);
                    ReflectionUtil.SetPrivateField(rotationEffect, "_startupRotationAngle", trackRingDesc.startupRotationAngle);
                    ReflectionUtil.SetPrivateField(rotationEffect, "_startupRotationStep", trackRingDesc.startupRotationStep);
                    ReflectionUtil.SetPrivateField(rotationEffect, "_startupRotationPropagationSpeed", (int)Math.Round(trackRingDesc.startupRotationPropagationSpeed));
                    ReflectionUtil.SetPrivateField(rotationEffect, "_startupRotationFlexySpeed", trackRingDesc.startupRotationFlexySpeed);

                    TrackLaneRingsRotationEffectSpawner rotationEffectSpawner =
                        trackRingDesc.gameObject.AddComponent <TrackLaneRingsRotationEffectSpawner>();
                    rotationSpawners.Add(rotationEffectSpawner);
                    PlatformManager.SpawnedComponents.Add(rotationEffectSpawner);
                    ReflectionUtil.SetPrivateField(rotationEffectSpawner, "_beatmapObjectCallbackController", Plugin.bocc);
                    ReflectionUtil.SetPrivateField(rotationEffectSpawner, "_beatmapEventType", (BeatmapEventType)trackRingDesc.rotationSongEventType);
                    ReflectionUtil.SetPrivateField(rotationEffectSpawner, "_rotationStep", trackRingDesc.rotationStep);
                    ReflectionUtil.SetPrivateField(rotationEffectSpawner, "_rotationPropagationSpeed", (int)Math.Round(trackRingDesc.rotationPropagationSpeed));
                    ReflectionUtil.SetPrivateField(rotationEffectSpawner, "_rotationFlexySpeed", trackRingDesc.rotationFlexySpeed);
                    ReflectionUtil.SetPrivateField(rotationEffectSpawner, "_trackLaneRingsRotationEffect", rotationEffect);
                }
                if (trackRingDesc.useStepEffect)
                {
                    TrackLaneRingsPositionStepEffectSpawner stepEffectSpawner =
                        trackRingDesc.gameObject.AddComponent <TrackLaneRingsPositionStepEffectSpawner>();
                    stepSpawners.Add(stepEffectSpawner);
                    PlatformManager.SpawnedComponents.Add(stepEffectSpawner);
                    ReflectionUtil.SetPrivateField(stepEffectSpawner, "_beatmapObjectCallbackController", Plugin.bocc);
                    ReflectionUtil.SetPrivateField(stepEffectSpawner, "_trackLaneRingsManager", ringsManager);
                    ReflectionUtil.SetPrivateField(stepEffectSpawner, "_beatmapEventType", (BeatmapEventType)trackRingDesc.stepSongEventType);
                    ReflectionUtil.SetPrivateField(stepEffectSpawner, "_minPositionStep", trackRingDesc.minPositionStep);
                    ReflectionUtil.SetPrivateField(stepEffectSpawner, "_maxPositionStep", trackRingDesc.maxPositionStep);
                    ReflectionUtil.SetPrivateField(stepEffectSpawner, "_moveSpeed", trackRingDesc.moveSpeed);
                }
            }
        }
Esempio n. 2
0
        /// <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);
                }
            }
        }