mirror of
https://github.com/NotAKidoS/NAK_CVR_Mods.git
synced 2025-09-03 06:49:22 +00:00
Custom Components & Managed Libs
This commit is contained in:
parent
d5a2b8d2df
commit
abad2dfb8a
12 changed files with 413 additions and 8 deletions
109
NAK.CustomComponents/Components/NAKPointerTracker.cs
Normal file
109
NAK.CustomComponents/Components/NAKPointerTracker.cs
Normal file
|
@ -0,0 +1,109 @@
|
|||
using ABI.CCK.Components;
|
||||
using UnityEngine;
|
||||
|
||||
namespace NAK.CCK.CustomComponents;
|
||||
|
||||
public class NAKPointerTracker : MonoBehaviour
|
||||
{
|
||||
// Configuration
|
||||
public Transform referenceTransform;
|
||||
public string pointerType = "";
|
||||
public float radius = 0.1f;
|
||||
public Vector3 offset = Vector3.zero;
|
||||
|
||||
// Animator module
|
||||
public Animator animator;
|
||||
public string parameterName;
|
||||
|
||||
// Internal stuff
|
||||
float initialAngle;
|
||||
CVRPointer trackedPointer;
|
||||
|
||||
void Start()
|
||||
{
|
||||
// Create collider
|
||||
Collider collider = base.gameObject.GetComponent<Collider>();
|
||||
if (collider == null)
|
||||
{
|
||||
SphereCollider sphereCollider = base.gameObject.AddComponent<SphereCollider>();
|
||||
sphereCollider.isTrigger = true;
|
||||
Vector3 lossyScale = base.transform.lossyScale;
|
||||
sphereCollider.radius = radius / Mathf.Max(Mathf.Max(lossyScale.x, lossyScale.y), lossyScale.z);
|
||||
sphereCollider.center = offset;
|
||||
}
|
||||
|
||||
// Create rigidbody (required for triggers)
|
||||
Rigidbody rigidbody = base.gameObject.GetComponent<Rigidbody>();
|
||||
if (rigidbody == null)
|
||||
{
|
||||
rigidbody = base.gameObject.AddComponent<Rigidbody>();
|
||||
rigidbody.useGravity = false;
|
||||
rigidbody.isKinematic = true;
|
||||
}
|
||||
|
||||
// Initial setup
|
||||
if (referenceTransform == null) referenceTransform = transform;
|
||||
Vector3 direction = (transform.TransformPoint(offset) - referenceTransform.position);
|
||||
Vector3 projectedDirection = Vector3.ProjectOnPlane(direction, referenceTransform.up);
|
||||
initialAngle = Vector3.SignedAngle(referenceTransform.forward, projectedDirection, referenceTransform.up);
|
||||
}
|
||||
|
||||
void OnDrawGizmosSelected()
|
||||
{
|
||||
if (base.isActiveAndEnabled)
|
||||
{
|
||||
Gizmos.color = Color.red;
|
||||
Gizmos.matrix = Matrix4x4.TRS(base.transform.position, base.transform.rotation, Vector3.one);
|
||||
Gizmos.DrawWireSphere(offset, radius);
|
||||
}
|
||||
}
|
||||
|
||||
void OnTriggerEnter(Collider other)
|
||||
{
|
||||
if (trackedPointer != null) return;
|
||||
|
||||
// generic pointer or specific pointer
|
||||
CVRPointer pointer = other.gameObject.GetComponent<CVRPointer>();
|
||||
if (pointer != null && (String.IsNullOrEmpty(pointerType) || pointer.type == pointerType))
|
||||
{
|
||||
trackedPointer = pointer;
|
||||
}
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
if (trackedPointer == null) return;
|
||||
|
||||
// Check if tracked pointer was disabled
|
||||
if (!trackedPointer.isActiveAndEnabled)
|
||||
{
|
||||
ReleasePointer();
|
||||
return;
|
||||
}
|
||||
|
||||
TrackPointer();
|
||||
}
|
||||
|
||||
void TrackPointer()
|
||||
{
|
||||
if (animator != null)
|
||||
{
|
||||
float angle = GetAngleFromPosition(trackedPointer.transform.position, initialAngle);
|
||||
animator.SetFloat(parameterName + "_Angle", angle / 360);
|
||||
}
|
||||
}
|
||||
|
||||
void ReleasePointer()
|
||||
{
|
||||
trackedPointer = null;
|
||||
}
|
||||
|
||||
float GetAngleFromPosition(Vector3 trackedPos, float offset = 0)
|
||||
{
|
||||
Vector3 direction = (trackedPos - referenceTransform.position);
|
||||
Vector3 projectedDirection = Vector3.ProjectOnPlane(direction, referenceTransform.up);
|
||||
float angle = Vector3.SignedAngle(referenceTransform.forward, projectedDirection, referenceTransform.up) - offset;
|
||||
if (angle < 0) angle += 360f;
|
||||
return angle;
|
||||
}
|
||||
}
|
53
NAK.CustomComponents/CustomComponents.csproj
Normal file
53
NAK.CustomComponents/CustomComponents.csproj
Normal file
|
@ -0,0 +1,53 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net472</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<LangVersion>latest</LangVersion>
|
||||
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
|
||||
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Remove="SFX\**" />
|
||||
<EmbeddedResource Remove="SFX\**" />
|
||||
<None Remove="SFX\**" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Reference Include="0Harmony">
|
||||
<HintPath>..\_ManagedLibs\0Harmony.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Assembly-CSharp">
|
||||
<HintPath>..\_ManagedLibs\Assembly-CSharp.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Assembly-CSharp-firstpass">
|
||||
<HintPath>..\_ManagedLibs\Assembly-CSharp-firstpass.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="DarkRift">
|
||||
<HintPath>..\_ManagedLibs\DarkRift.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="MelonLoader">
|
||||
<HintPath>..\_ManagedLibs\MelonLoader.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="UnityEngine.AnimationModule">
|
||||
<HintPath>..\_ManagedLibs\UnityEngine.AnimationModule.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="UnityEngine.CoreModule">
|
||||
<HintPath>..\_ManagedLibs\UnityEngine.CoreModule.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="UnityEngine.InputLegacyModule">
|
||||
<HintPath>..\_ManagedLibs\UnityEngine.InputLegacyModule.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="UnityEngine.PhysicsModule">
|
||||
<HintPath>..\_ManagedLibs\UnityEngine.PhysicsModule.dll</HintPath>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
|
||||
<Target Name="Deploy" AfterTargets="Build">
|
||||
<Copy SourceFiles="$(TargetPath)" DestinationFolder="C:\Program Files (x86)\Steam\steamapps\common\ChilloutVR\Mods\" />
|
||||
<Message Text="Copied $(TargetPath) to C:\Program Files (x86)\Steam\steamapps\common\ChilloutVR\Mods\" Importance="high" />
|
||||
</Target>
|
||||
|
||||
</Project>
|
25
NAK.CustomComponents/CustomComponents.sln
Normal file
25
NAK.CustomComponents/CustomComponents.sln
Normal file
|
@ -0,0 +1,25 @@
|
|||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 17
|
||||
VisualStudioVersion = 17.2.32630.192
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CustomComponents", "CustomComponents.csproj", "{D83D5845-288A-4783-993D-09364AA48593}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{D83D5845-288A-4783-993D-09364AA48593}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{D83D5845-288A-4783-993D-09364AA48593}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{D83D5845-288A-4783-993D-09364AA48593}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{D83D5845-288A-4783-993D-09364AA48593}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {A05CB0F0-E92F-4634-AA89-357AA256AD29}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
15
NAK.CustomComponents/Main.cs
Normal file
15
NAK.CustomComponents/Main.cs
Normal file
|
@ -0,0 +1,15 @@
|
|||
using ABI_RC.Core.Util.AssetFiltering;
|
||||
using MelonLoader;
|
||||
using NAK.CCK.CustomComponents;
|
||||
|
||||
namespace NAK.Melons.CustomComponents;
|
||||
|
||||
public class CustomComponents : MelonMod
|
||||
{
|
||||
public override void OnInitializeMelon()
|
||||
{
|
||||
// Add our CCK component to the prop whitelist
|
||||
var propWhitelist = SharedFilter._spawnableWhitelist;
|
||||
propWhitelist.Add(typeof(NAKPointerTracker));
|
||||
}
|
||||
}
|
30
NAK.CustomComponents/Properties/AssemblyInfo.cs
Normal file
30
NAK.CustomComponents/Properties/AssemblyInfo.cs
Normal file
|
@ -0,0 +1,30 @@
|
|||
using MelonLoader;
|
||||
using NAK.Melons.CustomComponents.Properties;
|
||||
using System.Reflection;
|
||||
|
||||
[assembly: AssemblyVersion(AssemblyInfoParams.Version)]
|
||||
[assembly: AssemblyFileVersion(AssemblyInfoParams.Version)]
|
||||
[assembly: AssemblyInformationalVersion(AssemblyInfoParams.Version)]
|
||||
[assembly: AssemblyTitle(nameof(NAK.Melons.CustomComponents))]
|
||||
[assembly: AssemblyCompany(AssemblyInfoParams.Author)]
|
||||
[assembly: AssemblyProduct(nameof(NAK.Melons.CustomComponents))]
|
||||
|
||||
[assembly: MelonInfo(
|
||||
typeof(NAK.Melons.CustomComponents.CustomComponents),
|
||||
nameof(NAK.Melons.CustomComponents),
|
||||
AssemblyInfoParams.Version,
|
||||
AssemblyInfoParams.Author,
|
||||
downloadLink: "https://github.com/NotAKidOnSteam/UndoPropButton"
|
||||
)]
|
||||
|
||||
[assembly: MelonGame("Alpha Blend Interactive", "ChilloutVR")]
|
||||
[assembly: MelonPlatform(MelonPlatformAttribute.CompatiblePlatforms.WINDOWS_X64)]
|
||||
[assembly: MelonPlatformDomain(MelonPlatformDomainAttribute.CompatibleDomains.MONO)]
|
||||
[assembly: HarmonyDontPatchAll]
|
||||
|
||||
namespace NAK.Melons.CustomComponents.Properties;
|
||||
internal static class AssemblyInfoParams
|
||||
{
|
||||
public const string Version = "1.0.0";
|
||||
public const string Author = "NotAKidoS";
|
||||
}
|
23
NAK.CustomComponents/format.json
Normal file
23
NAK.CustomComponents/format.json
Normal file
|
@ -0,0 +1,23 @@
|
|||
{
|
||||
"_id": 147,
|
||||
"name": "PropUndoButton",
|
||||
"modversion": "1.0.1",
|
||||
"gameversion": "2022r170",
|
||||
"loaderversion": "0.5.7",
|
||||
"modtype": "Mod",
|
||||
"author": "NotAKidoS",
|
||||
"description": "**CTRL+Z** to undo latest spawned prop. **CTRL+SHIFT+Z** to redo deleted prop.\nIncludes optional SFX for prop spawn, undo, redo, warn, and deny, which can be disabled in settings.\n\nYou can replace the sfx in 'ChilloutVR\\ChilloutVR_Data\\StreamingAssets\\Cohtml\\UIResources\\GameUI\\mods\\PropUndo\\audio'.",
|
||||
"searchtags": [
|
||||
"prop",
|
||||
"undo",
|
||||
"bind",
|
||||
"button"
|
||||
],
|
||||
"requirements": [
|
||||
"None"
|
||||
],
|
||||
"downloadlink": "https://github.com/NotAKidOnSteam/PropUndoButton/releases/download/v1.0.1/PropUndoButton.dll",
|
||||
"sourcelink": "https://github.com/NotAKidOnSteam/PropUndoButton/",
|
||||
"changelog": "- Initial Release\n- Added redo button.\n- Mitigated issue of props getting stuck locally if deleting them before they fully spawn.\n- Lowered SFX volume to match existing UI sounds.",
|
||||
"embedcolor": "#00FFFF"
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue