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);
                }
            }
        }
Ejemplo n.º 2
0
        internal static void PostfillComponentsData(Transform root, Transform original, List <IComponentData> componentDatas)
        {
            SkipAwake = false;

            TrackLaneRingsManager trackLaneRingsManager = root.GetComponent <TrackLaneRingsManager>();

            if (trackLaneRingsManager != null)
            {
                TrackLaneRingsManager originalManager = original.GetComponent <TrackLaneRingsManager>();
                foreach (TrackLaneRingsManagerComponentData componentData in componentDatas.OfType <TrackLaneRingsManagerComponentData>().Where(n => n.OldTrackLaneRingsManager == originalManager))
                {
                    componentData.NewTrackLaneRingsManager = trackLaneRingsManager;
                }
            }

            TrackLaneRingsRotationEffect rotationEffect = root.GetComponent <TrackLaneRingsRotationEffect>();

            if (rotationEffect != null)
            {
                UnityEngine.Object.Destroy(rotationEffect);
            }

            foreach (Transform transform in root)
            {
                int index = transform.GetSiblingIndex();
                PostfillComponentsData(transform, original.GetChild(index), componentDatas);
            }
        }
 internal void CopyValues(TrackLaneRingsRotationEffect trackLaneRingsRotationEffect)
 {
     _trackLaneRingsManager           = _trackLaneRingsManagerAccessor(ref trackLaneRingsRotationEffect);
     _startupRotationAngle            = _startupRotationAngleAccessor(ref trackLaneRingsRotationEffect);
     _startupRotationStep             = _startupRotationStepAccessor(ref trackLaneRingsRotationEffect);
     _startupRotationPropagationSpeed = _startupRotationPropagationSpeedAccessor(ref trackLaneRingsRotationEffect);
     _startupRotationFlexySpeed       = _startupRotationFlexySpeedAccessor(ref trackLaneRingsRotationEffect);
 }
        private static void Prefix(ref TrackLaneRingsRotationEffect ____trackLaneRingsRotationEffect)
        {
            TrackLaneRingsRotationEffect oldRotationEffect = ____trackLaneRingsRotationEffect;
            ChromaRingsRotationEffect    newRotationEffect = oldRotationEffect.gameObject.AddComponent <ChromaRingsRotationEffect>();

            newRotationEffect.CopyValues(oldRotationEffect);

            ____trackLaneRingsRotationEffect = newRotationEffect;
        }
#pragma warning disable SA1313 // Parameter names should begin with lower-case letter
        private static void Prefix(ref TrackLaneRingsRotationEffect ____trackLaneRingsRotationEffect)
#pragma warning restore SA1313 // Parameter names should begin with lower-case letter
        {
            TrackLaneRingsRotationEffect oldRotationEffect = ____trackLaneRingsRotationEffect;
            ChromaRingsRotationEffect    newRotationEffect = oldRotationEffect.gameObject.AddComponent <ChromaRingsRotationEffect>();

            newRotationEffect.CopyValues(oldRotationEffect);

            ____trackLaneRingsRotationEffect = newRotationEffect;
        }
 private static void TriggerRotation(
     TrackLaneRingsRotationEffect trackLaneRingsRotationEffect,
     bool rotRight,
     float rotation,
     float rotationStep,
     float rotationPropagationSpeed,
     float rotationFlexySpeed)
 {
     ((ChromaRingsRotationEffect)trackLaneRingsRotationEffect).AddRingRotationEffect(trackLaneRingsRotationEffect.GetFirstRingDestinationRotationAngle() + (rotation * (rotRight ? -1 : 1)), rotationStep, rotationPropagationSpeed, rotationFlexySpeed);
 }
#pragma warning disable SA1313 // Parameter names should begin with lower-case letter
        private static void TriggerRotation(
            TrackLaneRingsRotationEffect trackLaneRingsRotationEffect,
            bool rotRight,
            float rotation,
            float rotationStep,
            float rotationPropagationSpeed,
            float rotationFlexySpeed)
#pragma warning restore SA1313 // Parameter names should begin with lower-case letter
        {
            ((ChromaRingsRotationEffect)trackLaneRingsRotationEffect).AddRingRotationEffect(trackLaneRingsRotationEffect.GetFirstRingDestinationRotationAngle() + (rotation * (rotRight ? -1 : 1)), rotationStep, rotationPropagationSpeed, rotationFlexySpeed);
        }
        private static void Prefix(ref TrackLaneRingsRotationEffect ____trackLaneRingsRotationEffect)
        {
            if (____trackLaneRingsRotationEffect.GetType() == typeof(TrackLaneRingsRotationEffect))
            {
                TrackLaneRingsRotationEffect oldRotationEffect = ____trackLaneRingsRotationEffect;
                ChromaRingsRotationEffect    newRotationEffect = oldRotationEffect.gameObject.AddComponent <ChromaRingsRotationEffect>();
                newRotationEffect.CopyValues(oldRotationEffect);
                UnityEngine.Object.Destroy(oldRotationEffect);

                ____trackLaneRingsRotationEffect = newRotationEffect;
            }
        }
        public static RingRotationEffectController Create(TrackLaneRingsRotationEffectSpawner baseEffect)
        {
            BeatmapEventType eventTypeForThisEffect = Helper.GetValue <BeatmapEventType>(baseEffect, "_beatmapEventType");
            RotationStepType stepType = Helper.GetValue <RotationStepType>(baseEffect, "_rotationStepType");
            float            stepMax  = Helper.GetValue <float>(baseEffect, "_rotationStep");
            float            rotation = Helper.GetValue <float>(baseEffect, "_rotation");
            int   propagationSpeed    = Helper.GetValue <int>(baseEffect, "_rotationPropagationSpeed");
            float flexySpeed          = Helper.GetValue <float>(baseEffect, "_rotationFlexySpeed");

            TrackLaneRingsRotationEffect rotationEffect = Helper.GetValue <TrackLaneRingsRotationEffect>(baseEffect, "_trackLaneRingsRotationEffect");

            TrackLaneRingsManager manager = Helper.GetValue <TrackLaneRingsManager>(rotationEffect, "_trackLaneRingsManager");

            float startupAngle            = Helper.GetValue <float>(rotationEffect, "_startupRotationAngle");
            float startupStep             = Helper.GetValue <float>(rotationEffect, "_startupRotationStep");
            int   startupPropagationSpeed = Helper.GetValue <int>(rotationEffect, "_startupRotationPropagationSpeed");
            float startupFlexySpeed       = Helper.GetValue <float>(rotationEffect, "_startupRotationFlexySpeed");

            RotationEffect startupRotationEffect = new RotationEffect
            {
                progress         = 0,
                angle            = startupAngle,
                step             = startupStep,
                propagationSpeed = startupPropagationSpeed,
                flexySpeed       = startupFlexySpeed
            };

            RingRotationEffectController controller = new GameObject("TwitchFXRingRotationController").AddComponent <RingRotationEffectController>();

            controller.eventTypeForThisEffect = eventTypeForThisEffect;
            controller.manager  = manager;
            controller.name     = baseEffect.name;
            controller.isBig    = baseEffect.name.Contains("Big");
            controller.stepType = stepType;
            controller.stepMax  = stepMax;
            controller.startupRotationEffect = startupRotationEffect;
            controller.rotation         = rotation;
            controller.propagationSpeed = propagationSpeed;
            controller.flexySpeed       = flexySpeed;

            return(controller);
        }
        private static bool Prefix(
            TrackLaneRingsRotationEffectSpawner __instance,
            BeatmapEventData beatmapEventData,
            BeatmapEventType ____beatmapEventType,
            TrackLaneRingsRotationEffect ____trackLaneRingsRotationEffect,
            float ____rotation,
            float ____rotationStep,
            int ____rotationPropagationSpeed,
            float ____rotationFlexySpeed,
            TrackLaneRingsRotationEffectSpawner.RotationStepType ____rotationStepType)
        {
            if (beatmapEventData.type == ____beatmapEventType)
            {
                ChromaEventData?chromaData = TryGetEventData(beatmapEventData);
                if (chromaData == null)
                {
                    return(true);
                }

                // Added in 1.8
                float rotationStep = 0f;
                switch (____rotationStepType)
                {
                case TrackLaneRingsRotationEffectSpawner.RotationStepType.Range0ToMax:
                    rotationStep = UnityEngine.Random.Range(0f, ____rotationStep);
                    break;

                case TrackLaneRingsRotationEffectSpawner.RotationStepType.Range:
                    rotationStep = UnityEngine.Random.Range(-____rotationStep, ____rotationStep);
                    break;

                case TrackLaneRingsRotationEffectSpawner.RotationStepType.MaxOr0:
                    rotationStep = (UnityEngine.Random.value < 0.5f) ? ____rotationStep : 0f;
                    break;
                }

                string?nameFilter = chromaData.NameFilter;
                if (nameFilter != null)
                {
                    if (!__instance.name.ToLower().Equals(nameFilter.ToLower()))
                    {
                        return(false);
                    }
                }

                int?dir = chromaData.Direction;

                bool rotRight;
                if (!dir.HasValue)
                {
                    rotRight = UnityEngine.Random.value < 0.5f;
                }
                else
                {
                    rotRight = dir == 1;
                }

                bool?counterSpin = chromaData.CounterSpin;
                if (counterSpin.HasValue && counterSpin == true)
                {
                    if (!__instance.name.Contains("Big"))
                    {
                        rotRight = !rotRight;
                    }
                }

                bool?reset = chromaData.Reset;
                if (reset.HasValue && reset == true)
                {
                    TriggerRotation(____trackLaneRingsRotationEffect, rotRight, ____rotation, 0, 50, 50);
                    return(false);
                }

                float step     = chromaData.Step.GetValueOrDefault(rotationStep);
                float prop     = chromaData.Prop.GetValueOrDefault(____rotationPropagationSpeed);
                float speed    = chromaData.Speed.GetValueOrDefault(____rotationFlexySpeed);
                float rotation = chromaData.Rotation.GetValueOrDefault(____rotation);

                float stepMult  = chromaData.StepMult;
                float propMult  = chromaData.PropMult;
                float speedMult = chromaData.SpeedMult;

                TriggerRotation(____trackLaneRingsRotationEffect, rotRight, rotation, step * stepMult, prop * propMult, speed * speedMult);
                return(false);
            }

            return(true);
        }
Ejemplo n.º 11
0
    private void SetRings(GameObject gameObject, TrackRings trackRings, int ringCount)
    {
        TrackLaneRingsManager ringManager;

        //BigRing
        if (gameObject.name.ToLower().Contains("big") || gameObject.name.ToLower().Contains("outer") || gameObject.name.ToLower().Equals("rings"))
        {
            if (platformDescriptor.BigRingManager != null)
            {
                Destroy(platformDescriptor.BigRingManager.rotationEffect);
                Destroy(platformDescriptor.BigRingManager);
            }

            platformDescriptor.BigRingManager = gameObject.AddComponent <TrackLaneRingsManager>();
            if (platformDescriptor.RotationController == null)
            {
                platformDescriptor.RotationController = gameObject.AddComponent <GridRotationController>();
            }
            ringManager = platformDescriptor.BigRingManager;
        }
        else
        {
            if (platformDescriptor.SmallRingManager != null)
            {
                Destroy(platformDescriptor.SmallRingManager.rotationEffect);
                Destroy(platformDescriptor.SmallRingManager);
            }

            platformDescriptor.SmallRingManager = gameObject.AddComponent <TrackLaneRingsManager>();


            if (platformDescriptor.RotationController == null)
            {
                platformDescriptor.RotationController = gameObject.AddComponent <GridRotationController>();
            }
            ringManager = platformDescriptor.SmallRingManager;
        }

        if (ringManager == null)
        {
            return;
        }

        //Also overwrite LightsManager if applicable
        TubeLight[] tubeRingLights = trackRings.trackLaneRingPrefab.GetComponentsInChildren <TubeLight>();
        foreach (TubeLight tubeLight in tubeRingLights)
        {
            int eventId = -1;
            switch (tubeLight.lightsID)
            {
            case LightsID.Static:
                eventId = MapEvent.EVENT_TYPE_BACK_LASERS;
                break;

            case LightsID.BackLights:
                eventId = MapEvent.EVENT_TYPE_BACK_LASERS;
                break;

            case LightsID.BigRingLights:
                eventId = MapEvent.EVENT_TYPE_RING_LIGHTS;
                break;

            case LightsID.LeftLasers:
                eventId = MapEvent.EVENT_TYPE_LEFT_LASERS;
                break;

            case LightsID.RightLasers:
                eventId = MapEvent.EVENT_TYPE_RIGHT_LASERS;
                break;

            case LightsID.TrackAndBottom:
                eventId = MapEvent.EVENT_TYPE_ROAD_LIGHTS;
                break;

            case LightsID.Unused5:
                eventId = MapEvent.EVENT_TYPE_CUSTOM_LIGHT_1;
                break;

            case LightsID.Unused6:
                eventId = MapEvent.EVENT_TYPE_CUSTOM_LIGHT_2;
                break;

            case LightsID.Unused7:
                eventId = MapEvent.EVENT_TYPE_CUSTOM_LIGHT_3;
                break;

            case LightsID.Unused10:
                eventId = MapEvent.EVENT_TYPE_CUSTOM_LIGHT_4;
                break;

            case LightsID.Unused11:
                eventId = MapEvent.EVENT_TYPE_CUSTOM_LIGHT_5;
                break;

            default:
                break;
            }

            if (eventId > 0)
            {
                LightsManager currentLightsManager = platformDescriptor.LightingManagers[eventId];
                LightsManager newLightsManager     = gameObject.AddComponent <LightsManager>();

                newLightsManager.ControllingLights = currentLightsManager.ControllingLights;
                newLightsManager.RotatingLights    = currentLightsManager.RotatingLights;

                Destroy(currentLightsManager);


                platformDescriptor.LightingManagers[eventId] = newLightsManager;
                break;
            }
        }

        if (tubeRingLights.Length == 0)
        {
            LightsManager  tubeLightsManager = platformDescriptor.LightingManagers[MapEvent.EVENT_TYPE_RING_LIGHTS];
            MeshRenderer[] meshRenderers     = trackRings.trackLaneRingPrefab.GetComponentsInChildren <MeshRenderer>();

            foreach (MeshRenderer renderer in meshRenderers)
            {
                SetRendererMaterials(renderer, tubeLightsManager);
            }

            LightsManager newLightsManager = gameObject.AddComponent <LightsManager>();

            newLightsManager.ControllingLights = tubeLightsManager.ControllingLights;
            newLightsManager.RotatingLights    = tubeLightsManager.RotatingLights;

            Destroy(tubeLightsManager);
            platformDescriptor.LightingManagers[MapEvent.EVENT_TYPE_RING_LIGHTS] = newLightsManager;
        }

        //LightsManager lm = pd.LightingManagers[MapEvent.EVENT_TYPE_RING_LIGHTS];
        ReplaceBetterBlack(trackRings.trackLaneRingPrefab);
        SetLightingEventsForTubeLights(trackRings.trackLaneRingPrefab);

        TrackLaneRing tlr = trackRings.trackLaneRingPrefab.gameObject.AddComponent <TrackLaneRing>();

        ringManager.prefab = tlr;

        ringManager.ringCount = trackRings.ringCount;
        if (trackRings.useStepEffect)
        {
            ringManager.minPositionStep = trackRings.minPositionStep;
            ringManager.maxPositionStep = trackRings.maxPositionStep;
        }
        else
        {
            ringManager.minPositionStep = ringManager.maxPositionStep = trackRings.ringPositionStep;
        }
        ringManager.moveSpeed        = trackRings.moveSpeed;
        ringManager.rotationStep     = trackRings.rotationStep;
        ringManager.propagationSpeed = trackRings.rotationPropagationSpeed;
        ringManager.flexySpeed       = trackRings.rotationFlexySpeed;

        if (trackRings.useRotationEffect)
        {
            TrackLaneRingsRotationEffect rotationEffect = gameObject.AddComponent <TrackLaneRingsRotationEffect>();
            ringManager.rotationEffect = rotationEffect;

            rotationEffect.manager = ringManager;
            rotationEffect.startupRotationAngle            = trackRings.startupRotationAngle;
            rotationEffect.startupRotationStep             = trackRings.startupRotationStep;
            rotationEffect.startupRotationPropagationSpeed = trackRings.startupRotationPropagationSpeed;
            rotationEffect.startupRotationFlexySpeed       = trackRings.startupRotationFlexySpeed;
        }
    }
        private static bool Prefix(
            TrackLaneRingsRotationEffectSpawner __instance,
            BeatmapEventData beatmapEventData,
            BeatmapEventType ____beatmapEventType,
            TrackLaneRingsRotationEffect ____trackLaneRingsRotationEffect,
            float ____rotation,
            float ____rotationStep,
            int ____rotationPropagationSpeed,
            float ____rotationFlexySpeed,
            TrackLaneRingsRotationEffectSpawner.RotationStepType ____rotationStepType)
        {
            if (beatmapEventData.type == ____beatmapEventType)
            {
                if (beatmapEventData is CustomBeatmapEventData customData)
                {
                    // Added in 1.8
                    float rotationStep = 0f;
                    switch (____rotationStepType)
                    {
                    case TrackLaneRingsRotationEffectSpawner.RotationStepType.Range0ToMax:
                        rotationStep = UnityEngine.Random.Range(0f, ____rotationStep);
                        break;

                    case TrackLaneRingsRotationEffectSpawner.RotationStepType.Range:
                        rotationStep = UnityEngine.Random.Range(-____rotationStep, ____rotationStep);
                        break;

                    case TrackLaneRingsRotationEffectSpawner.RotationStepType.MaxOr0:
                        rotationStep = (UnityEngine.Random.value < 0.5f) ? ____rotationStep : 0f;
                        break;
                    }

                    dynamic dynData = customData.customData;

                    string nameFilter = Trees.at(dynData, NAMEFILTER);
                    if (nameFilter != null)
                    {
                        if (!__instance.name.ToLower().Equals(nameFilter.ToLower()))
                        {
                            return(false);
                        }
                    }

                    int?dir = (int?)Trees.at(dynData, DIRECTION);
                    if (!dir.HasValue)
                    {
                        dir = -1;
                    }

                    bool rotRight;
                    if (dir == -1)
                    {
                        rotRight = UnityEngine.Random.value < 0.5f;
                    }
                    else
                    {
                        rotRight = dir == 1 ? true : false;
                    }

                    bool?counterSpin = Trees.at(dynData, COUNTERSPIN);
                    if (counterSpin.HasValue && counterSpin == true)
                    {
                        if (!__instance.name.Contains("Big"))
                        {
                            rotRight = !rotRight;
                        }
                    }

                    bool?reset = Trees.at(dynData, RESET);
                    if (reset.HasValue && reset == true)
                    {
                        TriggerRotation(____trackLaneRingsRotationEffect, rotRight, ____rotation, 0, 50, 50);
                        return(false);
                    }

                    float step     = ((float?)Trees.at(dynData, STEP)).GetValueOrDefault(rotationStep);
                    float prop     = ((float?)Trees.at(dynData, PROP)).GetValueOrDefault(____rotationPropagationSpeed);
                    float speed    = ((float?)Trees.at(dynData, SPEED)).GetValueOrDefault(____rotationFlexySpeed);
                    float rotation = ((float?)Trees.at(dynData, ROTATION)).GetValueOrDefault(____rotation);

                    float stepMult  = ((float?)Trees.at(dynData, STEPMULT)).GetValueOrDefault(1f);
                    float propMult  = ((float?)Trees.at(dynData, PROPMULT)).GetValueOrDefault(1f);
                    float speedMult = ((float?)Trees.at(dynData, SPEEDMULT)).GetValueOrDefault(1f);

                    TriggerRotation(____trackLaneRingsRotationEffect, rotRight, rotation, step * stepMult, prop * propMult, speed * speedMult);
                    return(false);
                }
            }

            return(true);
        }
Ejemplo n.º 13
0
        // 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();
                }
            }
        }
Ejemplo n.º 14
0
        // ReSharper disable once CognitiveComplexity
        public void PlatformEnabled(DiContainer container)
        {
            if (trackLaneRingPrefab is null)
            {
                return;
            }
            container.Inject(this);

            if (_trackLaneRingsManager is null)
            {
                _materialSwapper !.ReplaceMaterials(trackLaneRingPrefab);
                gameObject.SetActive(false);
                TrackLaneRing trackLaneRing = trackLaneRingPrefab.AddComponent <TrackLaneRing>();
                _trackLaneRingsManager = gameObject.AddComponent <TrackLaneRingsManager>();
                _trackLaneRingPrefabAccessor(ref _trackLaneRingsManager) = trackLaneRing;
                _ringCountAccessor(ref _trackLaneRingsManager)           = ringCount;
                _ringPositionStepAccessor(ref _trackLaneRingsManager)    = ringPositionStep;
                _spawnAsChildrenAccessor(ref _trackLaneRingsManager)     = true;
                gameObject.SetActive(true);
                foreach (INotifyPlatformEnabled?notifyEnable in GetComponentsInChildren <INotifyPlatformEnabled>(true).Where(x => !ReferenceEquals(x, this)))
                {
                    notifyEnable?.PlatformEnabled(container);
                }
            }

            if (useRotationEffect)
            {
                if (_trackLaneRingsRotationEffectSpawner is null)
                {
                    TrackLaneRingsRotationEffect trackLaneRingsRotationEffect = gameObject.AddComponent <TrackLaneRingsRotationEffect>();
                    _rotationEffectTrackLaneRingsManagerAccessor(ref trackLaneRingsRotationEffect) = _trackLaneRingsManager;
                    _startupRotationAngleAccessor(ref trackLaneRingsRotationEffect) = startupRotationAngle;
                    _startupRotationStepAccessor(ref trackLaneRingsRotationEffect)  = startupRotationStep;
                    int   timePerRing   = startupRotationPropagationSpeed / ringCount;
                    float ringsPerFrame = Time.fixedDeltaTime / timePerRing;
                    _startupRotationPropagationSpeedAccessor(ref trackLaneRingsRotationEffect) = Mathf.Max((int)ringsPerFrame, 1);
                    _startupRotationFlexySpeedAccessor(ref trackLaneRingsRotationEffect)       = startupRotationFlexySpeed;

                    _trackLaneRingsRotationEffectSpawner         = gameObject.AddComponent <TrackLaneRingsRotationEffectSpawner>();
                    _trackLaneRingsRotationEffectSpawner.enabled = _beatmapCallbacksController is not null;
                    _rotationEffectSpawnerBeatmapCallbacksControllerAccessor(ref _trackLaneRingsRotationEffectSpawner) = _beatmapCallbacksController;
                    _rotationEffectSpawnerBeatmapEventTypeAccessor(ref _trackLaneRingsRotationEffectSpawner)           = (BasicBeatmapEventType)rotationSongEventType;
                    _rotationStepAccessor(ref _trackLaneRingsRotationEffectSpawner) = rotationStep;
                    int   timePerRing2   = rotationPropagationSpeed / ringCount;
                    float ringsPerFrame2 = Time.fixedDeltaTime / timePerRing2;
                    _rotationPropagationSpeedAccessor(ref _trackLaneRingsRotationEffectSpawner)     = Mathf.Max((int)ringsPerFrame2, 1);
                    _rotationFlexySpeedAccessor(ref _trackLaneRingsRotationEffectSpawner)           = rotationFlexySpeed;
                    _trackLaneRingsRotationEffectAccessor(ref _trackLaneRingsRotationEffectSpawner) = trackLaneRingsRotationEffect;
                }
                else if (_beatmapCallbacksController is not null)
                {
                    _trackLaneRingsRotationEffectSpawner.enabled = true;
                    _rotationEffectSpawnerBeatmapCallbacksControllerAccessor(ref _trackLaneRingsRotationEffectSpawner) = _beatmapCallbacksController;
                    _trackLaneRingsRotationEffectSpawner.Start();
                }
            }

            if (useStepEffect)
            {
                if (_trackLaneRingsPositionStepEffectSpawner is null)
                {
                    _trackLaneRingsPositionStepEffectSpawner         = gameObject.AddComponent <TrackLaneRingsPositionStepEffectSpawner>();
                    _trackLaneRingsPositionStepEffectSpawner.enabled = _beatmapCallbacksController is not null;
                    _positionStepEffectSpawnerTrackLaneRingsManagerAccessor(ref _trackLaneRingsPositionStepEffectSpawner)      = _trackLaneRingsManager;
                    _positionStepEffectSpawnerBeatmapCallbacksControllerAccessor(ref _trackLaneRingsPositionStepEffectSpawner) = _beatmapCallbacksController;
                    _positionStepEffectSpawnerBeatmapEventTypeAccessor(ref _trackLaneRingsPositionStepEffectSpawner)           = (BasicBeatmapEventType)stepSongEventType;
                    _minPositionStepAccessor(ref _trackLaneRingsPositionStepEffectSpawner) = minPositionStep;
                    _maxPositionStepAccessor(ref _trackLaneRingsPositionStepEffectSpawner) = maxPositionStep;
                    _moveSpeedAccessor(ref _trackLaneRingsPositionStepEffectSpawner)       = moveSpeed;
                }
                else if (_beatmapCallbacksController is not null)
                {
                    _trackLaneRingsPositionStepEffectSpawner.enabled = true;
                    _positionStepEffectSpawnerBeatmapCallbacksControllerAccessor(ref _trackLaneRingsPositionStepEffectSpawner) = _beatmapCallbacksController;
                    _trackLaneRingsPositionStepEffectSpawner.Start();
                }
            }
        }
#pragma warning disable SA1313 // Parameter names should begin with lower-case letter
        private static bool Prefix(
            TrackLaneRingsRotationEffectSpawner __instance,
            BeatmapEventData beatmapEventData,
            BeatmapEventType ____beatmapEventType,
            TrackLaneRingsRotationEffect ____trackLaneRingsRotationEffect,
            float ____rotation,
            float ____rotationStep,
            int ____rotationPropagationSpeed,
            float ____rotationFlexySpeed,
            TrackLaneRingsRotationEffectSpawner.RotationStepType ____rotationStepType)
#pragma warning restore SA1313 // Parameter names should begin with lower-case letter
        {
            if (beatmapEventData.type == ____beatmapEventType)
            {
                if (beatmapEventData is CustomBeatmapEventData customData)
                {
                    // Added in 1.8
                    float rotationStep = 0f;
                    switch (____rotationStepType)
                    {
                    case TrackLaneRingsRotationEffectSpawner.RotationStepType.Range0ToMax:
                        rotationStep = UnityEngine.Random.Range(0f, ____rotationStep);
                        break;

                    case TrackLaneRingsRotationEffectSpawner.RotationStepType.Range:
                        rotationStep = UnityEngine.Random.Range(-____rotationStep, ____rotationStep);
                        break;

                    case TrackLaneRingsRotationEffectSpawner.RotationStepType.MaxOr0:
                        rotationStep = (UnityEngine.Random.value < 0.5f) ? ____rotationStep : 0f;
                        break;
                    }

                    dynamic dynData = customData.customData;

                    string nameFilter = Trees.at(dynData, "_nameFilter");
                    if (nameFilter != null)
                    {
                        if (!__instance.name.ToLower().Equals(nameFilter.ToLower()))
                        {
                            return(false);
                        }
                    }

                    int?dir = (int?)Trees.at(dynData, "_direction");
                    if (!dir.HasValue)
                    {
                        dir = -1;
                    }

                    bool rotRight;
                    if (dir == -1)
                    {
                        rotRight = UnityEngine.Random.value < 0.5f;
                    }
                    else
                    {
                        rotRight = dir == 1 ? true : false;
                    }

                    bool?counterSpin = Trees.at(dynData, "_counterSpin");
                    if (counterSpin.HasValue && counterSpin == true)
                    {
                        if (!__instance.name.Contains("Big"))
                        {
                            rotRight = !rotRight;
                        }
                    }

                    bool?reset = Trees.at(dynData, "_reset");
                    if (reset.HasValue && reset == true)
                    {
                        TriggerRotation(____trackLaneRingsRotationEffect, rotRight, ____rotation, 0, 50, 50);
                        return(false);
                    }

                    float step  = ((float?)Trees.at(dynData, "_step")).GetValueOrDefault(rotationStep);
                    float prop  = ((float?)Trees.at(dynData, "_prop")).GetValueOrDefault(____rotationPropagationSpeed);
                    float speed = ((float?)Trees.at(dynData, "_speed")).GetValueOrDefault(____rotationFlexySpeed);

                    float stepMult  = ((float?)Trees.at(dynData, "_stepMult")).GetValueOrDefault(1f);
                    float propMult  = ((float?)Trees.at(dynData, "_propMult")).GetValueOrDefault(1f);
                    float speedMult = ((float?)Trees.at(dynData, "_speedMult")).GetValueOrDefault(1f);

                    TriggerRotation(____trackLaneRingsRotationEffect, rotRight, ____rotation, step * stepMult, prop * propMult, speed * speedMult);
                    return(false);
                }
            }

            return(true);
        }
Ejemplo n.º 16
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);
                }
            }
        }
        //Ring rotation
        static bool Prefix(TrackLaneRingsRotationEffectSpawner __instance, ref BeatmapEventData beatmapEventData, ref BeatmapEventType ____beatmapEventType, ref TrackLaneRingsRotationEffect ____trackLaneRingsRotationEffect, ref float ____rotationStep, ref float ____rotationPropagationSpeed, ref float ____rotationFlexySpeed)
        {
            if (ChromaEvent.SimpleEventActivate(__instance, ref beatmapEventData, ref ____beatmapEventType))
            {
                return(false);
            }

            //ChromaLogger.Log("Ring rotation type " + ____beatmapEventType + " v :" + beatmapEventData.value);

            if (beatmapEventData.value == ChromaEvent.CHROMA_EVENT_RING_ROTATE_LEFT || beatmapEventData.value == ChromaEvent.CHROMA_EVENT_RING_ROTATE_RIGHT)
            {
                //ChromaLogger.Log("Ring event " + beatmapEventData.value);
                ____trackLaneRingsRotationEffect.AddRingRotationEffect(____trackLaneRingsRotationEffect.GetFirstRingDestinationRotationAngle() + (float)(90 * ((beatmapEventData.value == ChromaEvent.CHROMA_EVENT_RING_ROTATE_RIGHT) ? -1 : 1)), UnityEngine.Random.Range(0f, ____rotationStep * ChromaRingStepEvent.ringStepMult), ____rotationPropagationSpeed * ChromaRingPropagationEvent.ringPropagationMult, ____rotationFlexySpeed * ChromaRingSpeedEvent.ringSpeedMult);
                return(false);
            }

            if (beatmapEventData.type == ____beatmapEventType && (ChromaRingSpeedEvent.ringSpeedMult != 1f || ChromaRingPropagationEvent.ringPropagationMult != 1f || ChromaRingStepEvent.ringStepMult != 1f))
            {
                ____trackLaneRingsRotationEffect.AddRingRotationEffect(____trackLaneRingsRotationEffect.GetFirstRingDestinationRotationAngle() + (float)(90 * ((UnityEngine.Random.value >= 0.5f) ? -1 : 1)), UnityEngine.Random.Range(0f, ____rotationStep * ChromaRingStepEvent.ringStepMult), ____rotationPropagationSpeed * ChromaRingPropagationEvent.ringPropagationMult, ____rotationFlexySpeed * ChromaRingSpeedEvent.ringSpeedMult);
                return(false);
            }

            return(true);
        }