Skip to content

Instantly share code, notes, and snippets.

@yagero
Created November 27, 2017 22:14
Show Gist options
  • Save yagero/42dec2690c6975ff471c7f9fb054964d to your computer and use it in GitHub Desktop.
Save yagero/42dec2690c6975ff471c7f9fb054964d to your computer and use it in GitHub Desktop.
Simple struct to save and restore Unity's fog properties
using UnityEngine;
public struct FogProperties
{
public float EndDistance;
public float StartDistance;
public float Density;
public Color Color;
public FogMode Mode;
public bool Enabled;
public static FogProperties NewFromRenderSettings()
{
var props = new FogProperties();
props.EndDistance = RenderSettings.fogEndDistance;
props.StartDistance = RenderSettings.fogStartDistance;
props.Density = RenderSettings.fogDensity;
props.Color = RenderSettings.fogColor;
props.Mode = RenderSettings.fogMode;
props.Enabled = RenderSettings.fog;
return props;
}
public void ApplyToRenderSettings()
{
RenderSettings.fogEndDistance = EndDistance;
RenderSettings.fogStartDistance = StartDistance;
RenderSettings.fogDensity = Density;
RenderSettings.fogColor = Color;
RenderSettings.fogMode = Mode;
RenderSettings.fog = Enabled;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment