Skip to content

Commit

Permalink
Added scene loaded event to reload materials
Browse files Browse the repository at this point in the history
  • Loading branch information
Indigocoder1 committed Dec 24, 2024
1 parent d6bc4ab commit 0186f5e
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 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(LoadReferences());
}
}

0 comments on commit 0186f5e

Please sign in to comment.