mirror of
https://github.com/NotAKidoS/NAK_CVR_Mods.git
synced 2025-09-09 01:29:17 +00:00
further cleanup of repo
This commit is contained in:
parent
4f8dcb0cd0
commit
323eb92f2e
140 changed files with 1 additions and 2430 deletions
|
@ -0,0 +1,50 @@
|
|||
using HarmonyLib;
|
||||
using UnityEngine;
|
||||
|
||||
namespace NAK.OriginShift.Hacks;
|
||||
|
||||
#region Harmony Patches
|
||||
|
||||
internal static class OcclusionCullingPatches
|
||||
{
|
||||
// i wish i had this when working on the head hiding & shadow clones... would have had a much better
|
||||
// method of hiding mesh that wouldn't have broken magica cloth :< (one day: make test mod to do that)
|
||||
|
||||
[HarmonyPostfix] // after all onprecull listeners
|
||||
[HarmonyPatch(typeof(Camera), "FireOnPreCull")]
|
||||
private static void OnPreCullPostfix(Camera cam)
|
||||
{
|
||||
OcclusionCullingHack hackInstance = cam.GetComponent<OcclusionCullingHack>();
|
||||
if (hackInstance != null) hackInstance.OnPostFirePreCull(cam);
|
||||
}
|
||||
|
||||
[HarmonyPrefix] // before all onprerender listeners
|
||||
[HarmonyPatch(typeof(Camera), "FireOnPreRender")]
|
||||
private static void OnPreRenderPrefix(Camera cam)
|
||||
{
|
||||
OcclusionCullingHack hackInstance = cam.GetComponent<OcclusionCullingHack>();
|
||||
if (hackInstance != null) hackInstance.OnPreFirePreRender(cam);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion Harmony Patches
|
||||
|
||||
/// <summary>
|
||||
/// Attempted hack to fix occlusion culling for *static* objects. This does not fix dynamic objects, they will be culled
|
||||
/// by the camera's frustum & original baked occlusion culling data. Nothing can be done about that. :>
|
||||
/// </summary>
|
||||
public class OcclusionCullingHack : MonoBehaviour
|
||||
{
|
||||
private Vector3 originalPosition;
|
||||
|
||||
internal void OnPostFirePreCull(Camera cam)
|
||||
{
|
||||
originalPosition = cam.transform.position;
|
||||
cam.transform.position = OriginShiftManager.GetAbsolutePosition(originalPosition);
|
||||
}
|
||||
|
||||
internal void OnPreFirePreRender(Camera cam)
|
||||
{
|
||||
cam.transform.position = originalPosition;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,44 @@
|
|||
using UnityEngine;
|
||||
|
||||
namespace NAK.OriginShift.Hacks;
|
||||
|
||||
public class OriginShiftOcclusionCullingDisabler : MonoBehaviour
|
||||
{
|
||||
private Camera _camera;
|
||||
private bool _originalCullingState;
|
||||
|
||||
#region Unity Events
|
||||
|
||||
private void Start()
|
||||
{
|
||||
_camera = GetComponent<Camera>();
|
||||
if (_camera == null)
|
||||
{
|
||||
Debug.LogError("OriginShiftOcclusionCullingDisabler requires a Camera component on the same GameObject.");
|
||||
enabled = false;
|
||||
return;
|
||||
}
|
||||
_originalCullingState = _camera.useOcclusionCulling;
|
||||
}
|
||||
|
||||
private void Awake() // we want to execute even if the component is disabled
|
||||
{
|
||||
OriginShiftManager.OnStateChanged += OnOriginShiftStateChanged;
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
OriginShiftManager.OnStateChanged -= OnOriginShiftStateChanged;
|
||||
}
|
||||
|
||||
#endregion Unity Events
|
||||
|
||||
#region Origin Shift Events
|
||||
|
||||
private void OnOriginShiftStateChanged(OriginShiftManager.OriginShiftState state)
|
||||
{
|
||||
_camera.useOcclusionCulling = state != OriginShiftManager.OriginShiftState.Forced && _originalCullingState;
|
||||
}
|
||||
|
||||
#endregion Origin Shift Events
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue