コード例 #1
0
        // 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();
        }
コード例 #2
0
        // 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();
        }