Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added scene loaded event to reload materials #576

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions Nautilus/Utility/MaterialUtils.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Nautilus.Utility.MaterialModifiers;
using System.Collections;
using UnityEngine;
using UnityEngine.SceneManagement;
using UWE;

namespace Nautilus.Utility;
Expand All @@ -11,18 +12,24 @@ namespace Nautilus.Utility;
public static partial class MaterialUtils
{
private static readonly int _emissionMap = Shader.PropertyToID("_EmissionMap");
private static bool _sceneEventAdded;

internal static void Patch()
{
CoroutineHost.StartCoroutine(LoadReferences());
if (!_sceneEventAdded)
{
SceneManager.sceneLoaded += OnSceneLoaded;
_sceneEventAdded = true;
}
}

private static IEnumerator LoadReferences()
{
yield return PatchInternal();

IsReady = true;

yield break;
}

Expand Down Expand Up @@ -249,7 +256,7 @@ public static void ApplyUBERShader(Material material, float shininess, float spe
{
material.EnableKeyword("MARMO_NORMALMAP");
}

material.enableInstancing = true;
material.globalIlluminationFlags = MaterialGlobalIlluminationFlags.EmissiveIsBlack | MaterialGlobalIlluminationFlags.RealtimeEmissive;

Expand Down Expand Up @@ -325,4 +332,11 @@ public static void SetMaterialCutout(Material material, bool cutout)
material.DisableKeyword("MARMO_ALPHA_CLIP");
}
}

private static void OnSceneLoaded(Scene scene, LoadSceneMode mode)
{
if (scene.name != "MenuEnvironment") return;

CoroutineHost.StartCoroutine(ReloadStaleReferences());
}
}
10 changes: 10 additions & 0 deletions Nautilus/Utility/MaterialUtils_BelowZero.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,16 @@ private static IEnumerator LoadGlassMaterials()
InteriorGlassMaterial.SetFloat("_Shininess", 6f);
InteriorGlassMaterial.SetFloat("_Fresnel", 0.88f);
}

private static IEnumerator ReloadStaleReferences()
{
Object.Destroy(GlassMaterial);
Object.Destroy(ExteriorGlassMaterial);
Object.Destroy(ShinyGlassMaterial);
Object.Destroy(InteriorGlassMaterial);

yield return LoadGlassMaterials();
}
}

#endif
12 changes: 12 additions & 0 deletions Nautilus/Utility/MaterialUtils_Subnautica.cs
Original file line number Diff line number Diff line change
Expand Up @@ -187,5 +187,17 @@ private static void OnCyclopsLoaded(GameObject cyclops)
HolographicUIMaterial = new Material(holoMat);
_cyclopsLoaded = true;
}

private static IEnumerator ReloadStaleReferences()
{
Object.Destroy(GlassMaterial);
Object.Destroy(ExteriorGlassMaterial);
Object.Destroy(ShinyGlassMaterial);
Object.Destroy(InteriorGlassMaterial);
Object.Destroy(HolographicUIMaterial);

yield return LoadGlassMaterials();
yield return LoadUIMaterial();
}
}
#endif
Loading