/// <summary> /// Transitions to the given colors from the inspector. /// Performs in a ping-pong fashion. /// </summary> /// <returns>The given colors.</returns> private IEnumerator TransitionGivenColors() { //Check the current color change state and perform the color changing as needed if (currentColorState == CurrentColorState.Idle) { currentColorState = CurrentColorState.Changing; while (lerpStep < 1.0f) { skyboxMaterial.SetColor("_Color1", Color.Lerp(skyboxColorBottom, skyboxColorBottom2, lerpStep)); skyboxMaterial.SetColor("_Color2", Color.Lerp(skyboxColorTop, skyboxColorTop2, lerpStep)); globalLight.color = Color.Lerp(skyboxColorTop, skyboxColorTop2, lerpStep); lerpStep += (Time.deltaTime * 1.1f) / colorsSwitchTimer; yield return(null); } lerpStep = 0; } else if (currentColorState == CurrentColorState.Done) { while (lerpStep < 1.0f) { skyboxMaterial.SetColor("_Color1", Color.Lerp(skyboxColorBottom2, skyboxColorBottom, lerpStep)); skyboxMaterial.SetColor("_Color2", Color.Lerp(skyboxColorTop2, skyboxColorTop, lerpStep)); globalLight.color = Color.Lerp(skyboxColorTop2, skyboxColorTop, lerpStep); lerpStep += (Time.deltaTime * 1.1f) / colorsSwitchTimer; yield return(null); } lerpStep = 0; } //Set the state to reflect what the current color state is for future changes if (currentColorState == CurrentColorState.Changing) { currentColorState = CurrentColorState.Done; } else { currentColorState = CurrentColorState.Idle; } }
/// <summary> /// Start this instance. /// </summary> private void Start() { //Set the skybox material from reference if (skybox) { skyboxMaterial = skybox.material; } //Set the skybox settings as given this.SetSkyboxSettings(); //Set the skybox colors to the given top and bottom as the starting colors this.SetSkyboxColors(skyboxColorBottom, skyboxColorTop); //Set the color change style state depending on what the parameter selected has been if (randomColors) { colorChangeStyle = ColorChangeStyle.SnapToRandom; } else if (lerpBetweenGivenColors) { colorChangeStyle = ColorChangeStyle.TransitionToGiven; } else if (lerpRandomColors) { colorChangeStyle = ColorChangeStyle.TransitionToRandom; } else { colorChangeStyle = ColorChangeStyle.None; } //The current color state change is idle currentColorState = CurrentColorState.Idle; //Check to see if the change light option has been selected but no light was given, //Then turn off the global light color change to prevent error if (changeLightColor && globalLight == null) { changeLightColor = false; } //Add a listener for the toggle button change to show the color sliders or not showColorToggle.onValueChanged.AddListener((value) => { ToggleColorSliders(value); }); }