private void HandleNewLevels() { List <TWLevel> levels = TWGameManager.instance.TimeWalkLevels; if (levels == null || levelTextPrefab == null || slider == null) { return; } if (levels.Count <= 1) { slider.gameObject.SetActive(false); return; } slider.gameObject.SetActive(true); RectTransform lastItemRectTransform = null; Slider sliderComp = slider.GetComponent <Slider>(); Rect sliderRect = slider.GetComponent <RectTransform>().rect; float levelItemHeight = levelTextPrefab.GetComponent <RectTransform>().rect.height; int maxYear = levels[0].year; int minYear = levels[levels.Count - 1].year; levelYearRange = new TWRange(minYear, maxYear); // Figured out the appropriate pixel range through trial and error... // There MUST be a better way. slidePixelRange = new TWRange(levelItemHeight * 2, sliderRect.height + levelItemHeight + 10); ClearLevels(); sliderComp.maxValue = maxYear; sliderComp.minValue = minYear; levels.ForEach(delegate(TWLevel l) { // Create menu item Button item = Instantiate(levelTextPrefab, track.transform).GetComponent <Button>(); item.GetComponent <Text>().text = l.year.ToString(); item.name = "LevelTextItem" + l.year.ToString(); // TODO Listen for button clicks RectTransform itemRect = item.GetComponent <RectTransform>(); Vector3 pos = itemRect.position; // Convert current year to corresponding pixel in y range float yearInPixels = levelYearRange.Translate(l.year, slidePixelRange); // Place level on slide as close as possible to year in pixels pos.y = yearInPixels; itemRect.position = pos; lastItemRectTransform = itemRect; }); }
private void RotateSun() { // Rotate sun to new position based on time of day. float hours = TWGameManager.instance.CurrentTimeHours; // Convert hours to angle, but add time of sunrise to account for sunrise being = 180 degrees. float angle = twentyFour.Translate((hours + sunrise) % 24, fullRotation); //Debug.Log(String.Format("{0} hours = {1} angle ", hours, angle)); transform.rotation = Quaternion.Euler(angle * -1f, 0, 0); }
// Update is called once per frame void Update() { // We use the direction of the main light as the basis for updating lighting // values (eg. the closer the light is to overhead the more intense it should be). // mainLight.transform.forward.y gives us how much the light is pointing // up (1 is straight up, -1 is straight down). The dot product with Vector3.down // gives us the inverse (1 is down, -1 is up) float down = Vector3.Dot(mainLight.transform.forward, Vector3.down); // Update sun intensity float tRange = 1 - intensityCutOff; float dot = Mathf.Clamp01((down - intensityCutOff) / tRange); float i = ((maxIntensity - minIntensity) * dot) + minIntensity; mainLight.intensity = i; // Update ambient intensity tRange = 1 - ambientCutOff; dot = Mathf.Clamp01((down - ambientCutOff) / tRange); i = ((maxAmbient - minAmbient) * dot) + minAmbient; RenderSettings.ambientIntensity = i; // Update light color mainLight.color = nightDayColor.Evaluate(dot); RenderSettings.ambientLight = mainLight.color; // Update fog RenderSettings.fogColor = nightDayFogColor.Evaluate(dot); RenderSettings.fogDensity = fogDensityCurve.Evaluate(dot) * fogScale; // Update atmosphere thickness i = ((dayAtmosphereThickness - nightAtmosphereThickness) * dot) + nightAtmosphereThickness; skyMat.SetFloat("_AtmosphereThickness", i); // Update main light rotation RotateSun(); // Update flare color and make sure it is off when sun is below horizon if (down > flareReductionPoint) { flare.enabled = true; flare.color = mainLight.color; if (down < 0f) { flare.brightness = Mathf.Clamp(downRangeForFlare.Translate(down, flareBrightnessRange), 0f, flareBrightness); } } else { flare.enabled = false; flare.brightness = flareBrightness; } // Update stars with same rotation if (stars != null) { stars.transform.rotation = transform.rotation; } // TODO Update moon }