initial config loading system, shadows cvar, assetmanager

This commit is contained in:
2022-06-12 18:49:19 +03:00
parent 81d754c865
commit ba1688ebbf
18 changed files with 168 additions and 38 deletions

View File

@@ -49,6 +49,7 @@ namespace Game
private Model model;
private MaterialBase missingMaterial;
private bool resetLights = false;
private bool dirtyLights = false;
private float brightnessMultiplier_ = 0.82f;
@@ -62,28 +63,28 @@ namespace Game
public float BrightnessMultiplier
{
get => brightnessMultiplier_;
set { brightnessMultiplier_ = value; dirtyLights = true; }
set { brightnessMultiplier_ = value; resetLights = true; }
}
[Range(0.1f, 40f)]
public float LightRadiusMultiplier
{
get => lightRadiusMultiplier_;
set { lightRadiusMultiplier_ = value; dirtyLights = true; }
set { lightRadiusMultiplier_ = value; resetLights = true; }
}
[Range(2f, 8f)]
public float FallOffExponent
{
get => fallOffExponent_;
set { fallOffExponent_ = value; dirtyLights = true; }
set { fallOffExponent_ = value; resetLights = true; }
}
[Range(0.01f, 1f)]
public float SaturationMultiplier
{
get => saturationMultiplier_;
set { saturationMultiplier_ = value; dirtyLights = true; }
set { saturationMultiplier_ = value; resetLights = true; }
}
@@ -249,6 +250,7 @@ namespace Game
{
if (worldSpawnActor != null)
worldSpawnActor.HideFlags |= HideFlags.DontSave;
dirtyLights = true;
}
catch (Exception e)
{
@@ -274,9 +276,24 @@ namespace Game
LoadMap(false);
}
private bool lastSceneLighting = false;
private bool lastSceneShadows = false;
public override void OnUpdate()
{
if (dirtyLights)
bool sceneLighting = EngineSubsystem.SceneLighting == "1";
if (lastSceneLighting != sceneLighting)
{
lastSceneLighting = sceneLighting;
dirtyLights = true;
}
bool sceneShadows = EngineSubsystem.SceneShadows == "1";
if (lastSceneShadows != sceneShadows)
{
lastSceneShadows = sceneShadows;
dirtyLights = true;
}
if (resetLights)
{
if (worldSpawnActor == null || !worldSpawnActor || root == null)
return;
@@ -297,6 +314,18 @@ namespace Game
// break;
}
resetLights = false;
}
if (dirtyLights)
{
foreach (var light in worldSpawnActor.GetChildren<Light>())
{
light.IsActive = sceneLighting;
if (light is PointLight pointLight)
pointLight.ShadowsStrength = sceneShadows ? 1.0f : 0.0f;
}
dirtyLights = false;
}
}
@@ -314,7 +343,7 @@ namespace Game
else
{
FlaxEngine.Debug.Log("Map already loaded in the scene");
dirtyLights = false;
resetLights = false;
return;
}
}
@@ -322,8 +351,7 @@ namespace Game
FlaxEngine.Debug.Log("Loading map");
{
string workDir = Directory.GetCurrentDirectory();
string matBasePath = Path.Combine(workDir, "Content", "Materials");
string matBasePath = Path.Combine(AssetManager.ContentPath, "Materials");
string assetPath = Path.Combine(matBasePath, "missing.flax");
missingMaterial = Content.Load<MaterialBase>(assetPath);
}
@@ -395,8 +423,7 @@ namespace Game
if (!materials.TryGetValue(textureName, out MaterialBase brushMaterial))
{
string workDir = Directory.GetCurrentDirectory();
string matBasePath = Path.Combine(workDir, "Content", "Materials");
string matBasePath = Path.Combine(AssetManager.ContentPath, "Materials");
string assetPath = Path.Combine(matBasePath, textureName + ".flax");
brushMaterial = Content.Load<MaterialBase>(assetPath);
if (brushMaterial != null)
@@ -768,8 +795,7 @@ namespace Game
childModel.Model = model;
//childModel.SetMaterial(0, missingMaterial);
string workDir = Directory.GetCurrentDirectory();
string matBasePath = Path.Combine(workDir, "Content", "Materials");
string matBasePath = Path.Combine(AssetManager.ContentPath, "Materials");
string assetPath = Path.Combine(matBasePath, "dev/dev_128_gray" + ".flax");
var brushMaterial = Content.Load<MaterialBase>(assetPath);
if (brushMaterial != null)