/*Returns the time of the next Sunrise*/ public Time getNextSunriseTime() { Time result = null; if (dayTime) { result = getSunriseTime(currentDate.DateWithDays(1)); } else { if (currentTime.CompareTo(new Time(23, 59, 59)) > 0) { Time sunrise = getSunriseTime(); result = sunrise; } else { result = getSunriseTime(currentDate.DateWithDays(1)); } } return(result); }
// Update is called once per frame void Update() { Time midday = clock.GetMiddayTime(); currentTime = clock.getCurrentTime(); if (previousTime.CompareTo(midday) < 0 && currentTime.CompareTo(midday) >= 0) { if (debug) { Debug.Log("MOONPHASES: midday reached"); Debug.Break(); } daysSincePhaseChange++; if (daysSincePhaseChange > phaseLengths[phaseIndex]) { changePhase(); } } previousTime = currentTime.Clone(); }
// Update is called once per frame void Update() { Time previousTime = currentTime.Clone(); int dayChange = 0; seconds += UnityEngine.Time.deltaTime / timeChangeRate; int s = (int)seconds; seconds -= s; dayChange = currentTime.add(s); //updating date if (dayChange > 0) { currentDate.AddDay(dayChange); if (debug) { Debug.Log("CENTRALCLOCK: Midnight reached: " + currentTime + "\n" + "Increase: " + dayChange + "\t New date: " + currentDate); Debug.Log("CENTRALCLOCK: End of season = " + currentSeason.GetEndDate() + "\n" + "Equal to today?: " + currentDate.CompareTo(currentSeason.GetEndDate())); Debug.Break(); } //Updating season if (currentDate.CompareTo(currentSeason.GetEndDate()) == 0) { currentSeason = currentSeason.next_season; if (debug) { Debug.Log("CENTRALCLOCK: Season updated, new Season: " + currentSeason.name); Debug.Break(); } } } if (previousTime.CompareTo(midday) < 0 && currentTime.CompareTo(midday) >= 0) { if (debug) { Debug.Log("CENTRALCLOCK: Miday reached: " + currentTime); Debug.Break(); } } //TODO: eventos de aviso amanecer/atardecer Time todaySunrise = getSunriseTime(); Time todaySunset = getSunsetTime(); if (!dayTime && currentTime.CompareTo(todaySunrise) >= 0 && currentTime.CompareTo(todaySunset) < 0) { if (debug) { Debug.Log("CENTRALCLOCK: It's Sunrise time: \n " + "Sunrise time: " + todaySunrise.ToString() + "\t Current time: " + currentTime.ToString()); Debug.Break(); } dayTime = true; } else { if (dayTime && currentTime.CompareTo(todaySunset) >= 0) { if (debug) { Debug.Log("CENTRALCLOCK: It's sunset time \n " + "Sunset time: " + todaySunset.ToString() + "\t Current time: " + currentTime.ToString()); Debug.Break(); } dayTime = false; } } }
//Parameter checkup and initialization void Awake() { //TODO: comprobar que no hay mas de 1 solo objecto con tag "Clock" //initializing SunriseAndSunsetCollection sunriseTimes = new Dictionary <Date, Time>(); sunsetTimes = new Dictionary <Date, Time>(); //time change rate timeChangeRate = (Day_length_in_minutes / 24.0) / 60.0; //Month checkup GameObject[] m = GameObject.FindGameObjectsWithTag("Month"); monthList = new Month[m.Length]; int daySum = 0; Month auxiliar; for (int i = 0; i < m.Length; i++) { auxiliar = m[i].GetComponent <Month>(); monthList[auxiliar.Month_number - 1] = auxiliar; daySum += auxiliar.Length; // Debug.Log("Month " + auxiliar.name + " set to position " + (auxiliar.Month_number - 1)); } if (daySum != Days_in_Year) { Debug.LogError("CENTRALCLOCK: The specified number of days in a year and the sum of the lengths of all months do not match \n " + " Days in a year = " + Days_in_Year + "Sum of month lengths = " + daySum); Debug.Break(); } ////No null values in day names //for (int i = 0; i < Day_names.Length; i++) //{ // if (Day_names[i] == "") // Debug.LogError("CENTRALCLOCK: All day names must be declared"); //} //initial date Initial_date.Trim(); string[] split = Initial_date.Split('/'); if (split.Length != 3) { Debug.LogError("CENTRALCLOCK: Initial date must follow the format: dd/mm/yyyy"); } int day = int.Parse(split[0]); int month_num = int.Parse(split[1]); int year = int.Parse(split[2]); if (year < 0) { Debug.LogError("CENTRALCLOCK: Negative year numbers are not allowed"); Debug.Break(); } if (year < 2) { Debug.LogWarning("CENTRALCLOCK: It is recomended to introduce a year number greater than 2 for the initial date"); } Month month = null; for (int i = 0; i < monthList.Length; i++) { if (monthList[i].Month_number == month_num) { month = monthList[i]; } } if (month == null) { Debug.LogError("CENTRALCLOCK: Initial date's month could not be found"); } currentDate = new Date(day, month, year); //initial time Initial_time.Trim(); split = Initial_time.Split(':'); if (split.Length != 3) { Debug.LogError("CENTRALCLOCK: Initial time must follow the format: hh:mm:ss"); } int hours = int.Parse(split[0]); int minutes = int.Parse(split[1]); int seconds = int.Parse(split[2]); currentTime = new Time(hours, minutes, seconds); //Summer Solstice summer_solstice_date.Trim(); split = summer_solstice_date.Split('/'); if (split.Length != 3) { Debug.LogError("CENTRALCLOCK: Summer solstice's date must follow the format: dd/mm/yyyy"); } day = int.Parse(split[0]); month_num = int.Parse(split[1]); month = null; for (int i = 0; i < monthList.Length; i++) { if (monthList[i].Month_number == month_num) { month = monthList[i]; } } if (month == null) { Debug.LogError("CENTRALCLOCK: summer solstice's month could not be found"); } summerSolstice = new Date(day, month, -1); if (summer_solstice_hours_light <= 0) { Debug.LogError("CENTRALCLOCK: Summer solstice cannot have negative or 0 hous of light"); } if (summer_solstice_hours_light >= 24) { Debug.LogError("CENTRALCLOCK: Summer solstice cannot have 24 or more hours of light"); } Time summerSolstice_Sunrise = midday.TimeWithSeconds(midday, -(int)((summer_solstice_hours_light * 3600) / 2)); Time summerSolstice_Sunset = midday.TimeWithSeconds(midday, (int)((summer_solstice_hours_light * 3600) / 2)); sunriseTimes.Add(summerSolstice, summerSolstice_Sunrise); sunsetTimes.Add(summerSolstice, summerSolstice_Sunset); //Winter solstice winter_solstice_date.Trim(); split = winter_solstice_date.Split('/'); if (split.Length != 3) { Debug.LogError("CENTRALCLOCK: Winter solstice's date must follow the format: dd/mm/yyyy"); } day = int.Parse(split[0]); month_num = int.Parse(split[1]); month = null; for (int i = 0; i < monthList.Length; i++) { if (monthList[i].Month_number == month_num) { month = monthList[i]; } } if (month == null) { Debug.LogError("CENTRALCLOCK: Winter solstice's month could not be found"); } winterSolstice = new Date(day, month, -1); if (winter_solstice_hours_light <= 0) { Debug.LogError("CENTRALCLOCK: Winter solstice cannot have negative or 0 hous of light"); } if (winter_solstice_hours_light >= 24) { Debug.LogError("CENTRALCLOCK: Winter solstice cannot have 24 or more hours of light"); } Time winterSolstice_Sunrise = midday.TimeWithSeconds(midday, -(int)((winter_solstice_hours_light * 3600) / 2)); Time winterSolstice_Sunset = midday.TimeWithSeconds(midday, (int)((winter_solstice_hours_light * 3600) / 2)); sunriseTimes.Add(winterSolstice, winterSolstice_Sunrise); sunsetTimes.Add(winterSolstice, winterSolstice_Sunset); //Spring equinox spring_equinox_date.Trim(); split = spring_equinox_date.Split('/'); if (split.Length != 3) { Debug.LogError("CENTRALCLOCK: Spring equinox date must follow the format: dd/mm/yyyy"); } day = int.Parse(split[0]); month_num = int.Parse(split[1]); month = null; for (int i = 0; i < monthList.Length; i++) { if (monthList[i].Month_number == month_num) { month = monthList[i]; } } if (month == null) { Debug.LogError("CENTRALCLOCK: Spring equinox month could not be found"); } springEquinox = new Date(day, month, -1); if (spring_equinox_hours_light <= 0) { Debug.LogError("CENTRALCLOCK: Spring equinox cannot have negative or 0 hous of light"); } if (spring_equinox_hours_light >= 24) { Debug.LogError("CENTRALCLOCK: Spring equinox cannot have 24 or more hours of light"); } Time springEquinox_Sunrise = midday.TimeWithSeconds(midday, -(int)((spring_equinox_hours_light * 3600) / 2)); Time springEquinox_Sunset = midday.TimeWithSeconds(midday, (int)((spring_equinox_hours_light * 3600) / 2)); sunriseTimes.Add(springEquinox, springEquinox_Sunrise); sunsetTimes.Add(springEquinox, springEquinox_Sunset); //Autumn equinox autumn_equinox_date.Trim(); split = autumn_equinox_date.Split('/'); if (split.Length != 3) { Debug.LogError("CENTRALCLOCK: autumn equinox date must follow the format: dd/mm/yyyy"); } day = int.Parse(split[0]); month_num = int.Parse(split[1]); month = null; for (int i = 0; i < monthList.Length; i++) { if (monthList[i].Month_number == month_num) { month = monthList[i]; } } if (month == null) { Debug.LogError("CENTRALCLOCK: Spring equinox month could not be found"); } autumnEquinox = new Date(day, month, -1); if (autumn_equinox_hours_light <= 0) { Debug.LogError("CENTRALCLOCK: autumn equinox cannot have negative or 0 hous of light"); } if (autumn_equinox_hours_light >= 24) { Debug.LogError("CENTRALCLOCK: autumn equinox cannot have 24 or more hours of light"); } Time autumnEquinox_Sunrise = midday.TimeWithSeconds(midday, -(int)((spring_equinox_hours_light * 3600) / 2)); Time autumnEquinox_Sunset = midday.TimeWithSeconds(midday, (int)((spring_equinox_hours_light * 3600) / 2)); sunriseTimes.Add(autumnEquinox, autumnEquinox_Sunrise); sunsetTimes.Add(autumnEquinox, autumnEquinox_Sunset); int daysbetween = 0; double LengthDifference = 0; //Winter to Spring time change rate: daysbetween = winterSolstice.DaysBetween(springEquinox); LengthDifference = spring_equinox_hours_light - winter_solstice_hours_light; winterToSpringRate = ((LengthDifference / 2.0) / daysbetween) * 3600; //spring to summer time change rate: daysbetween = springEquinox.DaysBetween(summerSolstice); LengthDifference = summer_solstice_hours_light - spring_equinox_hours_light; springToSummerRate = ((LengthDifference / 2.0) / daysbetween) * 3600; //summer to autumn time change rate: daysbetween = summerSolstice.DaysBetween(autumnEquinox); LengthDifference = autumn_equinox_hours_light - summer_solstice_hours_light; summerToAutumnRate = ((LengthDifference / 2.0) / daysbetween) * 3600; //autumn to winter time change rate: daysbetween = autumnEquinox.DaysBetween(winterSolstice); LengthDifference = winter_solstice_hours_light - autumn_equinox_hours_light; autumnToWinterRate = ((LengthDifference / 2.0) / daysbetween) * 3600; if (currentTime.CompareTo(getSunriseTime()) >= 0 && currentTime.CompareTo(getSunsetTime()) < 0) { dayTime = true; } }
// Use this for initialization void Start() { currentTime = clock.getCurrentTime(); //recordar que tanto el sol como la luna se tienen que dejar en el editor en la posicion de medianoche Time startDaySunrise = clock.getSunriseTime(); Time startDaySunset = clock.getSunsetTime(); Time start = previousTime; Time end = clock.getCurrentTime(); if (debug) { Debug.Log("INITIALIZING SUN/MOON POSITION-----------------------"); Debug.Log("dayTime: " + daytime + "\n" + "start: " + start.ToString() + "\t end: " + end.ToString()); } //the first speed will always be the night speed becouse we are forcing the user to set the environment as midnight //TODO: change sun moon rotation so that the initial position is at midday not midnight //night speed: Date yesterday = clock.getCurrentDate().DateWithDays(-1); Time yesterdaySunset = clock.getSunsetTime(yesterday); if (debug) { Debug.Log(" CALCULATING INITIAL SPEED -------------------------"); Debug.Log("SUN/MOON ROTATION" + this.name + ": yesterday: " + yesterday); Debug.Log("SUN/MOON ROTATION" + this.name + ": Yesterda's sunset: " + yesterdaySunset.ToString() + "\n" + "today sunrise: " + startDaySunrise); Debug.Log("SUN/MOON ROTATION" + this.name + ": Time between them: " + yesterdaySunset.SecondsBetween(startDaySunrise)); } int PhaseTotalTime = yesterdaySunset.SecondsBetween(startDaySunrise); rotationSpeed = 180.0f / PhaseTotalTime; //speed in degrees per second int timePased; float rotationAngle; if (end.CompareTo(startDaySunrise) >= 0) { if (debug) { Debug.Log("SUN/MOON ROTATION" + this.name + ": end time is past sunrise, therefore the total movement will be seccioned. \n" + "the firs secction is from start: " + start.ToString() + " to sunrise: " + startDaySunrise.ToString()); Debug.Break(); } Time provisionalEnd = startDaySunrise.Clone(); timePased = start.SecondsBetween(provisionalEnd); rotationAngle = rotationSpeed * timePased; if (debug) { Debug.Log("SUN/MOON ROTATION" + this.name + ": soconds passed from start to end: " + timePased + "\n" + " the speed used is: " + rotationSpeed + "degrees per second"); Debug.Log("SUN/MOON ROTATION" + this.name + ": new rotation angle generated: " + rotationAngle); Debug.Break(); } transform.RotateAround(Vector3.zero, Vector3.right, rotationAngle); start = startDaySunrise.Clone(); daytime = true; //dayTime speed calculations PhaseTotalTime = startDaySunrise.SecondsBetween(startDaySunset); rotationSpeed = 180.0f / PhaseTotalTime; if (end.CompareTo(startDaySunset) >= 0) { if (debug) { Debug.Log("SUN/MOON ROTATION" + this.name + ": end time is past sunset, therefore the remaining movement will be secctioned. \n" + "The firs section is from start: " + start.ToString() + " to sunset: " + startDaySunset.ToString()); Debug.Break(); } provisionalEnd = startDaySunset.Clone(); timePased = start.SecondsBetween(provisionalEnd); rotationAngle = rotationSpeed * timePased; if (debug) { Debug.Log("SUN/MOON ROTATION" + this.name + ": soconds passed since sunrise: " + timePased + "\n" + "new rotation angle generated: " + rotationAngle); Debug.Break(); } transform.RotateAround(Vector3.zero, Vector3.right, rotationAngle); start = startDaySunset.Clone(); daytime = false; PhaseTotalTime = startDaySunset.SecondsBetween(clock.getNextSunriseTime()); rotationSpeed = 180.0f / PhaseTotalTime; timePased = start.SecondsBetween(end); rotationAngle = rotationSpeed * timePased; if (debug) { Debug.Log("SUN/MOON ROTATION" + this.name + ": soconds passed since sunset: " + timePased + "\n" + "new rotation angle generated: " + rotationAngle); Debug.Break(); } transform.RotateAround(Vector3.zero, Vector3.right, rotationAngle); } else { timePased = start.SecondsBetween(end); rotationAngle = rotationSpeed * timePased; if (debug) { Debug.Log("SUN/MOON ROTATION" + this.name + ": soconds passed since sunrise: " + timePased + "\n" + "new rotation angle generated: " + rotationAngle); Debug.Break(); } transform.RotateAround(Vector3.zero, Vector3.right, rotationAngle); daytime = true; } } else { timePased = start.SecondsBetween(end); rotationAngle = rotationSpeed * timePased; if (debug) { Debug.Log("SUN/MOON ROTATION" + this.name + ": soconds passed since midnight: " + timePased + "\n" + "new rotation angle generated: " + rotationAngle); Debug.Break(); } transform.RotateAround(Vector3.zero, Vector3.right, rotationAngle); daytime = false; } previousTime = currentTime.Clone(); }
void Update() { currentTime = clock.getCurrentTime(); Time sunset = clock.getSunsetTime(); Time sunrise = clock.getSunriseTime(); Time midday = clock.GetMiddayTime(); //SUN AND MOON ROTATION AROUND THE TERRAIN //check if sunset has been reached if (daytime && currentTime.CompareTo(sunset) >= 0) { if (debug) { Debug.Log("REACHED SUNSET -------------------------"); } daytime = false; int timePased = previousTime.SecondsBetween(sunset); float rotationAngle = rotationSpeed * timePased; if (debug) { Debug.Log("SUN/MOON ROTATION" + this.name + ": applying rotation to get to sunset position: " + rotationAngle); Debug.Break(); } transform.RotateAround(Vector3.zero, Vector3.right, rotationAngle); previousTime = sunset.Clone(); //new rotation speed: if (debug) { Debug.Log("SUN/MOON ROTATION" + this.name + ": --Calculating new rotation speed: -------------- "); } Time start = sunset.Clone(); Time end = clock.getNextSunriseTime(); int secondsBetweenPhases = start.SecondsBetween(end); if (debug) { Debug.Log("SUN/MOON ROTATION" + this.name + ": start: " + start.ToString() + "\t end: " + end.ToString() + "\n" + "Seconds between them: " + secondsBetweenPhases); } rotationSpeed = 180.0f / secondsBetweenPhases; if (debug) { Debug.Log("SUN/MOON ROTATION" + this.name + ": new rotationspeed: " + rotationSpeed); Debug.Break(); } //esta parte esta aqui solo para depurar y no llenar la pantalla de mensajes en cada update, pero a la larga hay que quitarlo if (previousTime != currentTime) { if (debug) { Debug.Log("SUN/MOON ROTATION" + this.name + ": Completar la rotacion desde atardecer a currentTime"); } timePased = previousTime.SecondsBetween(currentTime); rotationAngle = rotationSpeed * timePased; transform.RotateAround(Vector3.zero, Vector3.right, rotationAngle); } } //check if sunrise has been reached if (!daytime && currentTime.CompareTo(sunrise) >= 0 && currentTime.CompareTo(sunset) < 0) { if (debug) { Debug.Log("SUN/MOON ROTATION" + this.name + ": REACHED SUNRISE --------------------------"); Debug.Break(); } daytime = true; int timePased = previousTime.SecondsBetween(sunrise); float rotationAngle = rotationSpeed * timePased; if (debug) { Debug.Log("SUN/MOON ROTATION" + this.name + ": applying rotation to get to sunrise position: " + rotationAngle); Debug.Break(); } transform.RotateAround(Vector3.zero, Vector3.right, rotationAngle); previousTime = sunrise.Clone(); //new rotation speed: if (debug) { Debug.Log("SUN/MOON ROTATION" + this.name + ": --Calculating new rotation speed: -------------- "); } Time start = sunrise.Clone(); Time end = clock.getNextSunsetTime(); int secondsBetweenPhases = start.SecondsBetween(end); if (debug) { Debug.Log("SUN/MOON ROTATION" + this.name + ": start: " + start.ToString() + "\t end: " + end.ToString() + "\n" + "Seconds between them: " + secondsBetweenPhases); } rotationSpeed = 180.0f / secondsBetweenPhases; timePased = sunrise.SecondsBetween(currentTime); rotationAngle = rotationSpeed * timePased; if (debug) { Debug.Log("SUN/MOON ROTATION" + this.name + ": new rotationspeed: " + rotationSpeed); Debug.Break(); } } if (previousTime != currentTime) { int timePased = previousTime.SecondsBetween(currentTime); float rotationAngle = rotationSpeed * timePased; transform.RotateAround(Vector3.zero, Vector3.right, rotationAngle); } previousTime = currentTime.Clone(); }
void Update() { currentTime = clock.getCurrentTime(); Time sunset = clock.getSunsetTime(); Time sunrise = clock.getSunriseTime(); Time fadeOutEnd = sunrise.TimeWithSeconds(sunrise, (int)(minutesToFade * 60)); Time fadeInStart = sunset.TimeWithSeconds(sunset, -(int)(minutesToFade * 60)); bool completed; float increase = 0; float decrease = 0; switch (phase) { case FADING_IN: increase = previousTime.SecondsBetween(currentTime) * opacityChangePerSecond; if (debug) { Debug.Log("STARFADE: phase is FADING_IN, currentTime is: " + currentTime.ToString() + "\n" + "\t fadeInStart: " + fadeInStart.ToString() + "\t sunset: " + sunset.ToString()); Debug.Log("STARFADE: current opacity: " + rend.material.color.a + "\n" + "previous time: " + previousTime.ToString() + "\t increase: " + increase); Debug.Break(); } completed = changeOpacity(increase); if (completed) { if (debug) { Debug.Log("STARFADE: After the increase, it is determined that the transition has been completed \n" + "\t opacity: " + rend.material.color.a); Debug.Break(); } //TODO: por paranoia, comprobar que currentTime = sunset o mayor. si es menor la he liado con los calculos if (currentTime.CompareTo(sunset) < 0) { Debug.LogError("Eva eres tonta y tus matematicas necesitan repaso, La fase FADING_IN ha acabado antes de lo que deberia"); Debug.Break(); } phase = SHINING; } break; case FADING_OUT: decrease = -(previousTime.SecondsBetween(currentTime) * opacityChangePerSecond); if (debug) { Debug.Log("STARFADE: phase is FADING_OUT, currentTime is: " + currentTime.ToString() + "\n" + "sunrise: " + sunrise.ToString() + "\t fadeOutEnd: " + fadeOutEnd.ToString()); Debug.Log("STARFADE: current opacity: " + rend.material.color.a + "\n" + "previous time: " + previousTime.ToString() + "\t increase: " + decrease); Debug.Break(); } completed = changeOpacity(decrease); if (completed) { if (debug) { Debug.Log("STARFADE: After the decrease, it is determined that the transition has been completed \n" + "\t opacity: " + rend.material.color.a); Debug.Break(); } if (currentTime.CompareTo(fadeOutEnd) < 0) { Debug.LogError("Eva eres tonta y tus matematicas necesitan repaso, La fase FADING_OUT ha acabado antes de lo que deberia"); Debug.Break(); } phase = FADED; } break; case FADED: if (currentTime.CompareTo(fadeInStart) >= 0) { phase = FADING_IN; increase = fadeInStart.SecondsBetween(currentTime) * opacityChangePerSecond; if (debug) { Debug.Log("STARFADE: while in phase FADED, fadeInStart has been reached \n" + "\t currentTime: " + currentTime.ToString() + "\t fadeInStart: " + fadeInStart); Debug.Log("STARFADE: increase calculated: " + increase); Debug.Break(); } changeOpacity(increase); } break; case SHINING: if (currentTime.CompareTo(sunrise) >= 0 && currentTime.CompareTo(fadeOutEnd) < 0) { phase = FADING_OUT; decrease = 0; int secondsPased = sunrise.SecondsBetween(currentTime); decrease = -secondsPased * opacityChangePerSecond; if (debug) { Debug.Log("STARFADE: while in phase SHINING, sunrise has been reached \n" + "\t currentTime: " + currentTime.ToString() + "\t sunrise: " + sunrise); Debug.Log("STARFADE: seconds pased: " + secondsPased + " compare: " + sunrise.CompareTo(currentTime) + "\n" + "opacity change per second: " + opacityChangePerSecond); Debug.Log("STARFADE: increase calculated: " + increase); Debug.Break(); } changeOpacity(decrease); } break; } previousTime = currentTime.Clone(); }
void Start() { currentTime = clock.getCurrentTime(); Time sunrise = clock.getSunriseTime(); Time sunset = clock.getSunsetTime(); Time fadeOutEnd = sunrise.TimeWithSeconds(sunrise, (int)(minutesToFade * 60)); Time fadeInStart = sunset.TimeWithSeconds(sunset, -(int)(minutesToFade * 60)); if (debug) { Debug.Log("STARFADE: CALCULATING INITIAL STATE ---------------------"); Debug.Log("STARFADE: currentTime: " + currentTime.ToString() + "\n" + "\t Sunrise: " + sunrise + "\t sunset: " + sunset); Debug.Log("STARFADE: Transition length (in minutes): " + minutesToFade + "\n" + "\t Fade out start: " + fadeInStart + "\t Fade in end: " + fadeOutEnd); Debug.Break(); } if (currentTime.CompareTo(sunrise) < 0) { phase = SHINING; if (debug) { Debug.Log("STARFADE: Current time fount out to be bewteen midnight and sunrise\n" + "Phase set to " + phase + " SHINING, \t opacity set to 1"); Debug.Break(); } setOpacity(1); } else if (currentTime.CompareTo(sunrise) >= 0 && currentTime.CompareTo(fadeOutEnd) < 0) { phase = FADING_OUT; float decrease = -currentTime.SecondsBetween(sunrise.TimeWithSeconds(sunrise, -(int)(minutesToFade * 60))) * opacityChangePerSecond; if (debug) { Debug.Log("STARFADE: Current time fount out to be bewteen sunrise and fadeOutEnd\n" + "Phase set to " + phase + " FADING_OUT, \t opacity set to :" + (1 - decrease)); Debug.Break(); } setOpacity(1 - decrease); } else if (currentTime.CompareTo(fadeOutEnd) >= 0 && currentTime.CompareTo(fadeInStart) < 0) { phase = FADED; if (debug) { Debug.Log("STARFADE: Current time fount out to be bewteen fadeOutEnd and fadeInStart \n" + "Phase set to " + phase + " FADED, \t opacity set to :" + (0)); Debug.Break(); } setOpacity(0); } else if (currentTime.CompareTo(fadeInStart) >= 0 && currentTime.CompareTo(sunset) < 0) { phase = FADING_IN; float increase = currentTime.SecondsBetween(sunset) * opacityChangePerSecond; if (debug) { Debug.Log("STARFADE: Current time fount out to be bewteen fadeInStart and sunset \n" + "Phase set to " + phase + " FADING_IN, \t opacity set to :" + (0 + increase)); Debug.Break(); } setOpacity(0 + increase); } else { phase = SHINING; if (debug) { Debug.Log("STARFADE: Current time fount out to be past sunset and before midnight \n" + "Phase set to " + phase + " SHINING, \t opacity set to 1"); Debug.Break(); } setOpacity(1); } previousTime = currentTime.Clone(); }
// Update is called once per frame void Update() { currentTime = clock.getCurrentTime(); Time sunrise = clock.getSunriseTime(); Time sunset = clock.getSunsetTime(); Time dayToDuskEnd = sunset.TimeWithSeconds(sunrise, (int)(endMinutesAfterDawnDusk * 60)); Time dayToDuskStart = sunset.TimeWithSeconds(sunset, -(int)(startMinutesBeforeDawnDusk * 60)); Time nightToDawnEnd = sunrise.TimeWithSeconds(sunrise, (int)(startMinutesBeforeDawnDusk * 60)); Time nightToDawnStart = sunrise.TimeWithSeconds(sunset, -(int)(endMinutesAfterDawnDusk * 60)); bool completed; float increase = 0; float decrease = 0; switch (phase) { case DAY: if (currentTime.CompareTo(dayToDuskStart) >= 0) { phase = DAY_TO_DUSK; if (debug) { Debug.Log("CLOUDCOLOR: Phase changed from DAY to DAY_TO_DUSK"); } ChangeColor(dayToDuskStart.SecondsBetween(currentTime)); } break; case NIGHT: if (currentTime.CompareTo(nightToDawnStart) >= 0 && currentTime.CompareTo(dayToDuskStart) < 0) { phase = NIGHT_TO_DAWN; if (debug) { Debug.Log("CLOUDCOLOR: Phase changed from NIGHT to NIGHT_TO_DAWN"); } ChangeColor(nightToDawnStart.SecondsBetween(currentTime)); } break; case DAY_TO_DUSK: if (currentTime.CompareTo(sunset) >= 0) { phase = DUSK_TO_NIGHT; if (debug) { Debug.Log("CLOUDCOLOR: Phase changed from DAY_TO_DUSK to DUSK_TO_NIGHT"); } ChangeColor(sunset.SecondsBetween(currentTime)); } else { if (debug) { Debug.Log("CLOUDCOLOR: phase is DAY_TO_DUSK, updating color..."); } ChangeColor(dayToDuskStart.SecondsBetween(currentTime)); } break; case DUSK_TO_NIGHT: if (currentTime.CompareTo(dayToDuskEnd) >= 0) { phase = NIGHT; if (debug) { Debug.Log("CLOUDCOLOR: Phase changed from DUSK_TO_NIGHT to NIGHT"); } ChangeColor(dayToDuskEnd.SecondsBetween(currentTime)); } else { ChangeColor(sunset.SecondsBetween(currentTime)); if (debug) { Debug.Log("CLOUDCOLOR: phase is DUSK_TO_NIGHT, updating color..."); } } break; case NIGHT_TO_DAWN: if (currentTime.CompareTo(sunrise) >= 0) { phase = DAWN_TO_DAY; if (debug) { Debug.Log("CLOUDCOLOR: Phase changed from NIGHT_TO_DAWN to DAWN_TO_DAY"); } ChangeColor(sunrise.SecondsBetween(currentTime)); } else { ChangeColor(dayToDuskStart.SecondsBetween(currentTime)); if (debug) { Debug.Log("CLOUDCOLOR: phase is NIGHT_TO_DAWN, updating color..."); } } break; case DAWN_TO_DAY: if (currentTime.CompareTo(nightToDawnEnd) >= 0) { phase = DAY; if (debug) { Debug.Log("CLOUDCOLOR: Phase changed from DAWN_TO_DAY to DAY"); } ChangeColor(sunrise.SecondsBetween(currentTime)); } else { ChangeColor(dayToDuskStart.SecondsBetween(currentTime)); if (debug) { Debug.Log("CLOUDCOLOR: phase is DAWN_TO_DAY, updating color..."); } } break; } previousTime = currentTime.Clone(); }
// Use this for initialization void Start() { currentTime = clock.getCurrentTime(); Time sunrise = clock.getSunriseTime(); Time sunset = clock.getSunsetTime(); Time dayToDuskEnd = sunset.TimeWithSeconds(sunrise, (int)(endMinutesAfterDawnDusk * 60)); Time dayToDuskStart = sunset.TimeWithSeconds(sunset, -(int)(startMinutesBeforeDawnDusk * 60)); Time nightToDawnEnd = sunrise.TimeWithSeconds(sunrise, (int)(startMinutesBeforeDawnDusk * 60)); Time nightToDawnStart = sunrise.TimeWithSeconds(sunset, -(int)(endMinutesAfterDawnDusk * 60)); if (debug) { Debug.Log("CLOUDCOLOR: CALCULATING INITIAL STATE ---------------------"); Debug.Log("CLOUDCOLOR: currentTime: " + currentTime.ToString() + "\n" + "\t Sunrise: " + sunrise + "\t sunset: " + sunset); Debug.Log("CLOUDCOLOR: dayToDuskStart: " + dayToDuskStart.ToString() + "\t dayToDuskEnd: " + dayToDuskEnd + "\n" + "\t nightToDawnStart: " + nightToDawnStart + "\t nightToDawnEnd: " + nightToDawnEnd); Debug.Break(); } if (currentTime.CompareTo(nightToDawnStart) < 0) { phase = NIGHT; if (debug) { Debug.Log("CLOUDCOLOR: Current time fount out to be bewteen midnight and the start of sunrise color change\n" + "Phase set to " + phase + " NIGHT, color set to night"); Debug.Break(); } ChangeColor(0); } else if (currentTime.CompareTo(nightToDawnStart) >= 0 && currentTime.CompareTo(sunrise) < 0) { phase = NIGHT_TO_DAWN; if (debug) { Debug.Log("CLOUDCOLOR: Current time fount out to be bewteen start and end of night to dawn \n" + "Phase set to " + phase + " NIGHT_TO_DAWN"); Debug.Break(); } ChangeColor(nightToDawnStart.SecondsBetween(sunrise)); } else if (currentTime.CompareTo(sunrise) >= 0 && currentTime.CompareTo(nightToDawnEnd) < 0) { phase = DAWN_TO_DAY; if (debug) { Debug.Log("CLOUDCOLOR: Current time fount out to be bewteen start and end of night to dawn \n" + "Phase set to " + phase + " NIGHT_TO_DAWN"); Debug.Break(); } ChangeColor(sunrise.SecondsBetween(nightToDawnEnd)); } else if (currentTime.CompareTo(nightToDawnEnd) >= 0 && currentTime.CompareTo(dayToDuskStart) < 0) { phase = DAY; if (debug) { Debug.Log("CLOUDCOLOR: Current time fount out to be bewteen fadeOutEnd and fadeInStart \n" + "Phase set to " + phase + " DAY"); Debug.Break(); } ChangeColor(0); } else if (currentTime.CompareTo(dayToDuskStart) >= 0 && currentTime.CompareTo(sunset) < 0) { phase = DAY_TO_DUSK; if (debug) { Debug.Log("CLOUDCOLOR: Current time fount out to be bewteen fadeInStart and sunset \n" + "Phase set to " + phase + " DAY_TO_DUSK"); Debug.Break(); } ChangeColor(dayToDuskStart.SecondsBetween(sunset)); } else if (currentTime.CompareTo(sunset) >= 0 && currentTime.CompareTo(dayToDuskEnd) < 0) { phase = DUSK_TO_NIGHT; if (debug) { Debug.Log("CLOUDCOLOR: Current time fount out to be bewteen fadeInStart and sunset \n" + "Phase set to " + phase + " DAY_TO_DUSK"); Debug.Break(); } ChangeColor(sunset.SecondsBetween(dayToDuskEnd)); } else { phase = NIGHT; if (debug) { Debug.Log("CLOUDCOLOR: Current time fount out to be past sunset and before midnight \n" + "Phase set to " + phase + " SHINING, \t opacity set to 1"); Debug.Break(); } ChangeColor(0); } previousTime = currentTime.Clone(); }