예제 #1
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)
            {
                foreach (var obj in platformDescriptor.BigRingManager.GetToDestroy())
                {
                    Destroy(obj);
                }
            }

            platformDescriptor.BigRingManager = gameObject.AddComponent <TrackLaneRingsManager>();
            if (platformDescriptor.RotationController == null)
            {
                platformDescriptor.RotationController = gameObject.AddComponent <GridRotationController>();
            }
            if (platformDescriptor.BigRingManager is TrackLaneRingsManager tlrm)
            {
                ringManager = tlrm;
            }
            else
            {
                ringManager = null;
            }
        }
        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_BOOST_LIGHTS;
                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;
                newLightsManager.GroupLightsBasedOnZ();

                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;
            newLightsManager.GroupLightsBasedOnZ();

            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 = Mathf.RoundToInt(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 = Mathf.RoundToInt(trackRings.startupRotationPropagationSpeed);
            rotationEffect.startupRotationFlexySpeed       = trackRings.startupRotationFlexySpeed;
        }
    }