public void CopyFrom(SceneAmbientSettings source)
 {
     skyColor                 = source.skyColor;
     bottomColor              = source.bottomColor;
     horizonColor             = source.horizonColor;
     lightIntensityMultiplier = source.lightIntensityMultiplier;
 }
 public void Lerp(SceneAmbientSettings target, float val)
 {
     lightIntensityMultiplier = Mathf.MoveTowards(lightIntensityMultiplier, target.lightIntensityMultiplier, val);
     bottomColor  = Vector4.MoveTowards(bottomColor, target.bottomColor, val);
     skyColor     = Vector4.MoveTowards(skyColor, target.skyColor, val);
     horizonColor = Vector4.MoveTowards(horizonColor, target.horizonColor, val);
 }
    public override bool Equals(object obj)
    {
        // Check for null values and compare run-time types.
        if (obj == null || GetType() != obj.GetType())
        {
            return(false);
        }

        SceneAmbientSettings b = (SceneAmbientSettings)obj;

        return(lightIntensityMultiplier == b.lightIntensityMultiplier && bottomColor == b.bottomColor &&
               skyColor == b.skyColor && horizonColor == b.horizonColor);
    }
    private Environment(System.IO.Stream fs)
    {
        presetType = EnvironmentPreset.Custom;
        var data = new byte[16];

        fs.Read(data, 0, data.Length);
        int i = 0;

        conditions       = System.BitConverter.ToSingle(data, i); i += 4;
        richness         = System.BitConverter.ToSingle(data, i); i += 4;
        lifepowerSupport = System.BitConverter.ToSingle(data, i); i += 4;
        stability        = System.BitConverter.ToSingle(data, i); i += 4;
        data             = null;
        lightSettings    = new SceneAmbientSettings(fs);
    }
    /// <summary>
    /// returns true if all values are equal
    /// </summary>
    public bool MoveTo(SceneAmbientSettings target, float speed)
    {
        int equalsCount = 0;

        if (lightIntensityMultiplier != target.lightIntensityMultiplier)
        {
            lightIntensityMultiplier = Mathf.MoveTowards(lightIntensityMultiplier, target.lightIntensityMultiplier, speed);
        }
        else
        {
            equalsCount++;
        }
        if (bottomColor != target.bottomColor)
        {
            bottomColor = Vector4.MoveTowards(bottomColor, target.bottomColor, speed);
        }
        else
        {
            equalsCount++;
        }
        if (skyColor != target.skyColor)
        {
            skyColor = Vector4.MoveTowards(skyColor, target.skyColor, speed);
        }
        else
        {
            equalsCount++;
        }
        if (horizonColor != target.horizonColor)
        {
            horizonColor = Vector4.MoveTowards(horizonColor, target.horizonColor, speed);
        }
        else
        {
            equalsCount++;
        }
        return(equalsCount == 4);
    }
    private Environment(EnvironmentPreset ep)
    {
        presetType = ep;
        switch (ep)
        {
        case EnvironmentPreset.Desert:
            conditions       = 0.3f;
            lifepowerSupport = 0.1f;
            stability        = 0.4f;
            lightSettings    = new SceneAmbientSettings(new Color(1f, 0.74f, 0.65f), Color.white, new Color(1f, 0.95f, 0.74f), 1.1f);
            break;

        case EnvironmentPreset.WhiteSpace:
            conditions       = 1f;
            lifepowerSupport = 0.01f;
            stability        = 0f;
            var wc = Color.white;
            lightSettings = new SceneAmbientSettings(wc, wc, wc, 1.5f);
            break;

        case EnvironmentPreset.Pipe:
            conditions       = DEFAULT_CONDITIONS;
            lifepowerSupport = DEFAULT_LP_SUPPORT / 2f;
            stability        = 0.98f;
            lightSettings    = new SceneAmbientSettings(
                new Color(0.58f, 1f, 0.75f),
                new Color(0.22f, 0.46f, 0.29f),
                new Color(0f, 0.65f, 0.4f),
                0.25f);
            break;

        case EnvironmentPreset.Ice:
            conditions       = 0.25f;
            lifepowerSupport = 0.2f;
            stability        = 0.55f;
            lightSettings    = new SceneAmbientSettings(
                new Color(0.588f, 0.853f, 0.952f),
                Color.white,
                Color.blue,
                0.7f);
            break;

        case EnvironmentPreset.Pollen:
            conditions       = 0.4f;
            lifepowerSupport = 0.6f;
            stability        = 0.3f;
            lightSettings    = new SceneAmbientSettings(
                new Color(1f, 0.99f, 0.86f),
                new Color(0.96f, 0.79f, 0.4f),
                new Color(0.58f, 0.58f, 0.52f),
                0.8f);
            break;

        case EnvironmentPreset.Forest:
            conditions       = 0.89f;
            lifepowerSupport = 0.8f;
            stability        = DEFAULT_STABILITY;
            lightSettings    = new SceneAmbientSettings(
                new Color(1f, 0.96f, 0.74f),
                new Color(0.07f, 0.43f, 0.07f),
                new Color(0.57f, 0.84f, 0.57f),
                1f);
            break;

        case EnvironmentPreset.Ruins:
            conditions       = 0.4f;
            lifepowerSupport = 0.3f;
            stability        = 0.6f;
            lightSettings    = new SceneAmbientSettings(
                new Color(0.6f, 0.6f, 0.2f),
                new Color(0.25f, 0.25f, 0.15f),
                new Color(0.82f, 0.83f, 0.17f),
                0.9f);
            break;

        case EnvironmentPreset.Crystal:
            conditions       = 0.5f;
            lifepowerSupport = 0.1f;
            stability        = 0.85f;
            lightSettings    = new SceneAmbientSettings(
                new Color(0.27f, 0.83f, 0.85f),
                new Color(0.04f, 0.91f, 0.95f),
                new Color(0.73f, 0.83f, 0.83f),
                0.85f);
            break;

        case EnvironmentPreset.Meadows:
            conditions       = DEFAULT_CONDITIONS * 1.1f;
            lifepowerSupport = DEFAULT_LP_SUPPORT * 1.2f;
            stability        = DEFAULT_STABILITY;
            lightSettings    = new SceneAmbientSettings(
                new Color(1f, 0.94f, 0.71f),
                new Color(2f, 0.84f, 0f),
                new Color(0.88f, 0.82f, 0.54f),
                1f);
            break;

        case EnvironmentPreset.Space:
            conditions       = 0f;
            lifepowerSupport = 0f;
            stability        = 0.1f;
            lightSettings    = new SceneAmbientSettings(
                Color.white,
                Color.cyan * 0.25f,
                Color.black,
                1f);
            break;

        case EnvironmentPreset.Fire:
            conditions       = 0.2f;
            lifepowerSupport = 0.1f;
            stability        = 0.33f;
            lightSettings    = new SceneAmbientSettings(
                new Color(0.93f, 0.26f, 0.11f),
                Color.yellow,
                new Color(0.31f, 0.07f, 0.05f),
                1.1f);
            break;

        case EnvironmentPreset.Ocean:
            conditions       = DEFAULT_CONDITIONS * 0.9f;
            lifepowerSupport = DEFAULT_LP_SUPPORT * 0.75f;
            stability        = 0.8f;
            lightSettings    = new SceneAmbientSettings(
                new Color(0.61f, 0.99f, 0.94f),
                new Color(0.61f, 0.99f, 0.94f),
                new Color(0f, 0f, 0.65f),
                0.5f);
            break;

        case EnvironmentPreset.FoundationSkies:
            presetType       = EnvironmentPreset.FoundationSkies;
            conditions       = DEFAULT_CONDITIONS * 1.1f;
            lifepowerSupport = DEFAULT_LP_SUPPORT;
            stability        = 1f;
            lightSettings    = new SceneAmbientSettings(
                new Color(0.1647059f, 0.6964906f, 1f),
                new Color(0.631052f, 0.7755874f, 0.8207547f),
                new Color(0.7224546f, 0.7693326f, 0.8018868f),
                1f);
            lightSettings.SetAdditionalValues(
                1f, 1f, 1f, 1f, 0f
                );
            break;

        default:
            presetType       = EnvironmentPreset.Default;
            conditions       = DEFAULT_CONDITIONS;
            lifepowerSupport = DEFAULT_LP_SUPPORT;
            stability        = DEFAULT_STABILITY;
            lightSettings    = new SceneAmbientSettings(
                Color.black,
                Color.cyan * 0.75f,
                Color.white,
                0.72f);   // на планшетах смотрится тусклее
            break;
        }
    }