Skip to content
This repository has been archived by the owner on Jul 27, 2022. It is now read-only.

Commit

Permalink
add near clip module
Browse files Browse the repository at this point in the history
  • Loading branch information
xKiraiChan committed Jun 6, 2022
1 parent 5d6c6b2 commit 15fd91f
Showing 1 changed file with 78 additions and 0 deletions.
78 changes: 78 additions & 0 deletions Modules/Visuals/NearClip.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
using KiraiMod.Core.Utils;
using UnityEngine;

namespace KiraiMod.Modules.Visuals
{
[Module]
public static class NearClip
{
private static bool _enabled;
[Configure<bool>("Visuals.Near Clip.Enabled", true)]
public static bool Enabled
{
get => _enabled;
set
{
_enabled = value;
if (loaded && !menu.active)
camera.nearClipPlane = value ? _target : _regular;
}
}

private static float _target;
[Configure<float>("Visuals.Near Clip.Target", 0.01f)]
public static float Target
{
get => _target;
set
{
_target = value;

if (loaded && !menu.active)
camera.nearClipPlane = value;
}
}

private static float _regular;
[Configure<float>("Visuals.Near Clip.Regular", 0.05f)]
public static float Regular
{
get => _regular;
set
{
_regular = value;

if (loaded && menu.active)
camera.nearClipPlane = value;
}
}

private static bool loaded = false;

private static GameObject menu;
private static Camera camera;

static NearClip() => Events.EmptyLoaded += OnLoaded;

private static void OnLoaded()
{
Events.EmptyLoaded -= OnLoaded;

menu = GameObject.Find("UserInterface").transform.Find("Canvas_QuickMenu(Clone)").gameObject;
camera = Camera.main;

ActivationListener listener = menu.AddComponent<ActivationListener>();
listener.Enabled += ToggleMenu;
listener.Disabled += ToggleMenu;

loaded = true;
}

private static void ToggleMenu()
{
if (!_enabled) return;

camera.nearClipPlane = menu.active ? _regular : _target;
}
}
}

0 comments on commit 15fd91f

Please sign in to comment.