This repository has been archived by the owner on Jul 27, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5d6c6b2
commit 15fd91f
Showing
1 changed file
with
78 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} |