[AvatarScaleMod] Add settings & cleanup.

why do i obsess with making my mods look pretty when staring them down in dnspy
This commit is contained in:
NotAKidoS 2023-06-23 01:02:46 -05:00
parent e8d3183bc3
commit f92e842f41
7 changed files with 111 additions and 4 deletions

View file

@ -1,15 +1,22 @@
using UnityEngine;
using ABI_RC.Core.Savior;
namespace NAK.AvatarScaleMod;
public static class AvatarScaleGesture
{
public static bool GestureEnabled;
public static bool RequireTriggers = true;
public static float InitialModifier = 1f;
public static float InitialTargetHeight = 1.8f;
public static void OnScaleStart(float modifier, Transform transform1, Transform transform2)
{
// AvatarScaleMod.Logger.Msg("OnScaleStart!");
if (!GestureEnabled)
return;
// you can start the scale, but cant interact with it without holding triggers
if (AvatarScaleManager.LocalAvatar != null)
{
@ -22,6 +29,11 @@ public static class AvatarScaleGesture
public static void OnScaleStay(float modifier, Transform transform1, Transform transform2)
{
// AvatarScaleMod.Logger.Msg("OnScaleStay!");
if (!GestureEnabled)
return;
if (RequireTriggers && !IsBothTriggersDown())
return;
if (AvatarScaleManager.LocalAvatar != null)
{
@ -39,4 +51,9 @@ public static class AvatarScaleGesture
{
// AvatarScaleMod.Logger.Msg("OnScaleEnd!");
}
public static bool IsBothTriggersDown()
{
return CVRInputManager.Instance.interactLeftValue > 0.75f && CVRInputManager.Instance.interactRightValue > 0.75f;
}
}

View file

@ -1,4 +1,6 @@
using ABI.CCK.Components;
using NAK.AvatarScaleMod.ScaledComponents;
using System.Collections;
using UnityEngine;
using UnityEngine.Animations;
@ -19,8 +21,8 @@ public class AvatarScaleManager : MonoBehaviour
typeof(ScaleConstraint),
};
public const float MinimumHeight = 0.25f;
public const float MaximumHeight = 2.5f;
public const float MinimumHeight = 0.1f;
public const float MaximumHeight = 10f;
// Scalable Components
private List<ScaledLight> _lights = new List<ScaledLight>();
@ -104,6 +106,11 @@ public class AvatarScaleManager : MonoBehaviour
LocalAvatar = null;
}
private void OnDisable()
{
ResetAllToInitialScale();
}
private void FindComponentsOfType(params System.Type[] types)
{
foreach (var type in types)
@ -206,4 +213,58 @@ public class AvatarScaleManager : MonoBehaviour
scaledScaleConstraint.Component.scaleOffset = scaledScaleConstraint.InitialScaleOffset * ScaleFactor;
}
}
private void ResetAllToInitialScale()
{
// quick n lazy for right now
transform.localScale = InitialScale;
foreach (var scaledLight in _lights)
{
scaledLight.Component.range = scaledLight.InitialRange;
}
foreach (var scaledAudioSource in _audioSources)
{
scaledAudioSource.Component.minDistance = scaledAudioSource.InitialMinDistance;
scaledAudioSource.Component.maxDistance = scaledAudioSource.InitialMaxDistance;
}
foreach (var scaledParentConstraint in _parentConstraints)
{
scaledParentConstraint.Component.translationAtRest = scaledParentConstraint.InitialTranslationAtRest;
for (int i = 0; i < scaledParentConstraint.InitialTranslationOffsets.Count; i++)
{
scaledParentConstraint.Component.translationOffsets[i] = scaledParentConstraint.InitialTranslationOffsets[i];
}
}
foreach (var scaledPositionConstraint in _positionConstraints)
{
scaledPositionConstraint.Component.translationAtRest = scaledPositionConstraint.InitialTranslationAtRest;
scaledPositionConstraint.Component.translationOffset = scaledPositionConstraint.InitialTranslationOffset;
}
foreach (var scaledScaleConstraint in _scaleConstraints)
{
scaledScaleConstraint.Component.scaleAtRest = scaledScaleConstraint.InitialScaleAtRest;
scaledScaleConstraint.Component.scaleOffset = scaledScaleConstraint.InitialScaleOffset;
}
}
// use for slow transition between avatars initial height & saved height>>>??????????????
public IEnumerator SetTargetHeightOverTime(float newHeight, float duration)
{
float startTime = Time.time;
float startHeight = TargetHeight;
newHeight = Mathf.Clamp(newHeight, MinimumHeight, MaximumHeight);
while (Time.time < startTime + duration)
{
float t = (Time.time - startTime) / duration;
TargetHeight = Mathf.Lerp(startHeight, newHeight, t);
UpdateScaleFactor();
yield return null;
}
TargetHeight = newHeight;
UpdateScaleFactor();
}
}

View file

@ -38,6 +38,7 @@ class GesturePlaneTestPatches
name = "avatarScale",
type = CVRGesture.GestureType.Hold,
};
// TODO: Expose these settings in-game and tune till they feel right
gesture.steps.Add(new CVRGestureStep
{
firstGesture = CVRGestureStep.Gesture.Fist,

View file

@ -13,11 +13,13 @@ public class AvatarScaleMod : MelonMod
Category.CreateEntry("Enabled", true, description: "Toggle AvatarScaleMod entirely.");
public static readonly MelonPreferences_Entry<bool> EntryUseScaleGesture =
Category.CreateEntry("Scale Gesture", true, description: "Use two fists to scale yourself easily.");
Category.CreateEntry("Scale Gesture", false, description: "Use two fists to scale yourself easily.");
public override void OnInitializeMelon()
{
Logger = LoggerInstance;
ModSettings.InitializeModSettings();
ApplyPatches(typeof(HarmonyPatches.PlayerSetupPatches));
ApplyPatches(typeof(HarmonyPatches.GesturePlaneTestPatches));
}

View file

@ -0,0 +1,23 @@
namespace NAK.AvatarScaleMod;
// Another thing i stole from Kafe, this organizes stuff so much moreee
// Should I move the entries here too?
static class ModSettings
{
public static void InitializeModSettings()
{
AvatarScaleMod.EntryEnabled.OnEntryValueChanged.Subscribe(OnEntryEnabledChanged);
AvatarScaleMod.EntryUseScaleGesture.OnEntryValueChanged.Subscribe(OnEntryUseScaleGestureChanged);
}
static void OnEntryEnabledChanged(bool newValue, bool oldValue)
{
if (AvatarScaleManager.LocalAvatar != null)
AvatarScaleManager.LocalAvatar.enabled = newValue;
}
static void OnEntryUseScaleGestureChanged(bool newValue, bool oldValue)
{
AvatarScaleGesture.GestureEnabled = newValue;
}
}

View file

@ -20,6 +20,9 @@ using System.Reflection;
[assembly: MelonGame("Alpha Blend Interactive", "ChilloutVR")]
[assembly: MelonPlatform(MelonPlatformAttribute.CompatiblePlatforms.WINDOWS_X64)]
[assembly: MelonPlatformDomain(MelonPlatformDomainAttribute.CompatibleDomains.MONO)]
[assembly: MelonColor(255, 241, 200, 82)]
[assembly: MelonAuthorColor(255, 114, 17, 25)]
[assembly: HarmonyDontPatchAll]
namespace NAK.AvatarScaleMod.Properties;
internal static class AssemblyInfoParams

View file

@ -1,7 +1,7 @@
using UnityEngine;
using UnityEngine.Animations;
namespace NAK.AvatarScaleMod;
namespace NAK.AvatarScaleMod.ScaledComponents;
public class ScaledAudioSource
{