void OnDayChanged( uint _val )
 {
     if( WorldTime.Instance.CurrentTimeType == WorldTime.DayTimeTypes.Twilight )
     {
         FromSetting = TwilightWrapped;
         ToSetting = Midnight;
     }
 }
    DaylightTimeSetting LerpedSetting( DaylightTimeSetting from, DaylightTimeSetting to, float t )
    {
        DaylightTimeSetting lerp = new DaylightTimeSetting();

        float absDelta = to.time - from.time;
        float absT = t - from.time;
        float perc = absT / absDelta;

        lerp.color = Color.Lerp( from.color, to.color, perc );
        lerp.intensity = Mathf.Lerp( from.intensity, to.intensity, perc );
        lerp.range = Mathf.Lerp( from.range, to.range, perc );
        lerp.spotAngle = Mathf.Lerp( from.range, to.range, perc );
        lerp.direction = Vector3.Lerp( from.direction, to.direction, perc );

        return lerp;
    }
    void OnDayTimeChanged( WorldTime.DayTimeTypes type )
    {
        DayTimeType = WorldTime.Instance.CurrentTimeType;

        if( DebugPrintTransition )
            Console.Instance.addGameChatMessage( type.ToString() );

        // Tests from largest to least times
        // doing reverse order in this way is slightly faster
        switch( type )
        {
        case WorldTime.DayTimeTypes.Midnight:
            FromSetting = Midnight;
            ToSetting = Dawn;
            break;

        case WorldTime.DayTimeTypes.Dawn:
            FromSetting = Dawn;
            ToSetting = Sunrise;
            break;

        case WorldTime.DayTimeTypes.Sunrise:
            FromSetting = Sunrise;
            ToSetting = Noon;
            break;

        case WorldTime.DayTimeTypes.Noon:
            FromSetting = Noon;
            ToSetting = Sunset;
            break;

        case WorldTime.DayTimeTypes.Sunset:
            FromSetting = Sunset;
            ToSetting = Twilight;
            break;

        case WorldTime.DayTimeTypes.Twilight:

            if( DayPercent >= WorldTime.Instance.TwilightTime )
            {
                FromSetting = Twilight;
                ToSetting = MidnightWrapped;
            }
            else
            {
                FromSetting = TwilightWrapped;
                ToSetting = Midnight;
            }

            break;
        }
    }
    void UpdateUserSettings()
    {
        WorldTime time = WorldTime.Instance;

        Midnight.time = time.MidnightTime;
        Midnight.color = MidnightColor;
        Midnight.intensity = MidnightIntensity;
        Midnight.range = MidnightRange;
        Midnight.spotAngle = MidnightSpotAngle;
        Midnight.direction = MidnightDirection;

        Dawn.time = time.DawnTime;
        Dawn.color = DawnColor;
        Dawn.intensity = DawnIntensity;
        Dawn.range = DawnRange;
        Dawn.spotAngle = DawnSpotAngle;
        Dawn.direction = DawnDirection;

        Sunrise.time = time.SunriseTime;
        Sunrise.color = SunriseColor;
        Sunrise.intensity = SunriseIntensity;
        Sunrise.range = SunriseRange;
        Sunrise.spotAngle = SunriseSpotAngle;
        Sunrise.direction = SunriseDirection;

        Noon.time = time.NoonTime;
        Noon.color = NoonColor;
        Noon.intensity = NoonIntensity;
        Noon.range = NoonRange;
        Noon.spotAngle = NoonSpotAngle;
        Noon.direction = NoonDirection;

        Sunset.time = time.SunsetTime;
        Sunset.color = SunsetColor;
        Sunset.intensity = SunsetIntensity;
        Sunset.range = SunsetRange;
        Sunset.spotAngle = SunsetSpotAngle;
        Sunset.direction = SunsetDirection;

        Twilight.time = time.TwilightTime;
        Twilight.color = TwilightColor;
        Twilight.intensity = TwilightIntensity;
        Twilight.range = TwilightRange;
        Twilight.spotAngle = TwilightSpotAngle;
        Twilight.direction = TwilightDirection;

        MidnightWrapped = Midnight;
        MidnightWrapped.time += 1.0f;

        if( FlipMidnightRotationX )
            MidnightWrapped.direction.x += 360;

        if( FlipMidnightRotationY )
            MidnightWrapped.direction.y += 360;

        if( FlipMidnightRotationZ )
            MidnightWrapped.direction.z += 360;

        TwilightWrapped = LerpedSetting( Twilight, MidnightWrapped, 1.0f );
    }