Skip to content
This repository has been archived by the owner on Jan 24, 2023. It is now read-only.

Commit

Permalink
1.1.0
Browse files Browse the repository at this point in the history
Support to UIX
  • Loading branch information
Rafacasari committed Dec 15, 2020
1 parent c294d01 commit 77b8395
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 19 deletions.
52 changes: 38 additions & 14 deletions PlayerspaceMover.cs → Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,46 @@
using UnityEngine;
#endregion

namespace Playerspace_Mover
namespace PlayspaceMover
{
public static class ModInfo
{
public const string Name = "PlayerspaceMover";
public const string Description = "A SteamVR Playerspace clone for Oculus Users";
public const string Name = "PlayspaceMover";
public const string Description = "A SteamVR's Playspace clone for Oculus Users";
public const string Author = "Rafa";
public const string Company = "RBX";
public const string Version = "1.0.1";
public const string Version = "1.1.0";
public const string DownloadLink = null;
}

public class PlayerspaceMover : MelonMod
public class Main : MelonMod
{
public override void OnApplicationStart() => MelonCoroutines.Start(WaitInitialization());
#region Settings
private bool Enabled = true;
private float Strength = 1f;
private float DoubleClickTime = 0.25f;
#endregion

private readonly string Category = "PlayspaceMover";
public override void OnApplicationStart()
{
MelonPrefs.RegisterCategory(Category, "Playspace Mover");
MelonPrefs.RegisterBool(Category, nameof(Enabled), Enabled, "Enabled");
MelonPrefs.RegisterFloat(Category, nameof(Strength), Strength, "Strength");
MelonPrefs.RegisterFloat(Category, nameof(DoubleClickTime), DoubleClickTime, "Double Click Time");
ApplySettings();

MelonCoroutines.Start(WaitInitialization());
}

private void ApplySettings()
{
Enabled = MelonPrefs.GetBool(Category, nameof(Enabled));
Strength = MelonPrefs.GetFloat(Category, nameof(Strength));
DoubleClickTime = MelonPrefs.GetFloat(Category, nameof(DoubleClickTime));
}

public override void OnModSettingsApplied() => ApplySettings();

private VRCVrCameraOculus Camera;
private bool isLeftPressed, isRightPressed = false;
Expand All @@ -37,14 +62,15 @@ private IEnumerator WaitInitialization()
yield break;
}

MelonLogger.LogError("VRCVrCameraOculus has not found, this mod only work in Oculus for now!");
MelonLogger.LogError("VRCVrCameraOculus not found, this mod only work in Oculus for now!");
yield break;
}



public override void OnUpdate()
{
if (Camera == null) return;
if (!Enabled || Camera == null) return;

if (HasDoubleClicked(OVRInput.Button.Three, DoubleClickTime) || HasDoubleClicked(OVRInput.Button.One, DoubleClickTime))
{
Expand All @@ -62,23 +88,22 @@ public override void OnUpdate()

if (leftTrigger)
{

Vector3 currentOffset = OVRInput.GetLocalControllerPosition(OVRInput.Controller.LTouch);
Vector3 calculatedOffset = (currentOffset - startingOffset) * -1.0f;
Vector3 calculatedOffset = (currentOffset - startingOffset) * -Strength;
startingOffset = currentOffset;
Camera.cameraLiftTransform.localPosition += calculatedOffset;
}

if (rightTrigger)
{
Vector3 currentOffset = OVRInput.GetLocalControllerPosition(OVRInput.Controller.RTouch);
Vector3 calculatedOffset = (currentOffset - startingOffset) * -1.0f;
Vector3 calculatedOffset = (currentOffset - startingOffset) * -Strength;
startingOffset = currentOffset;
Camera.cameraLiftTransform.localPosition += calculatedOffset;
}
}

private static Dictionary<OVRInput.Button, bool> PreviousStates = new Dictionary<OVRInput.Button, bool>()
private static readonly Dictionary<OVRInput.Button, bool> PreviousStates = new Dictionary<OVRInput.Button, bool>()
{
{ OVRInput.Button.Three, false }, { OVRInput.Button.One, false }
};
Expand All @@ -91,8 +116,7 @@ private static bool IsKeyJustPressed(OVRInput.Button key)
else return PreviousStates[key] = false;
}

private readonly float DoubleClickTime = 0.25f;
private static Dictionary<OVRInput.Button, float> lastTime = new Dictionary<OVRInput.Button, float>();
private static readonly Dictionary<OVRInput.Button, float> lastTime = new Dictionary<OVRInput.Button, float>();

// Thanks to Psychloor!
// https://github.com/Psychloor/DoubleTapRunner/blob/master/DoubleTapSpeed/Utilities.cs#L30
Expand Down
6 changes: 3 additions & 3 deletions Playerspace Mover.csproj → PlayspaceMover.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
<ProjectGuid>{23CF827E-3738-42E7-AAEF-225CB734A7A8}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Playerspace_Mover</RootNamespace>
<AssemblyName>Playerspace Mover</AssemblyName>
<RootNamespace>PlayspaceMover</RootNamespace>
<AssemblyName>PlayspaceMover</AssemblyName>
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic>
Expand Down Expand Up @@ -65,7 +65,7 @@
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="PlayerspaceMover.cs" />
<Compile Include="Main.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
Expand Down
4 changes: 2 additions & 2 deletions Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Reflection;
using MelonLoader;
using Playerspace_Mover;
using PlayspaceMover;

[assembly: AssemblyTitle(ModInfo.Description)]
[assembly: AssemblyDescription(ModInfo.Description)]
Expand All @@ -10,6 +10,6 @@
[assembly: AssemblyTrademark(ModInfo.Company)]
[assembly: AssemblyVersion(ModInfo.Version)]
[assembly: AssemblyFileVersion(ModInfo.Version)]
[assembly: MelonInfo(typeof(PlayerspaceMover), ModInfo.Name, ModInfo.Version, ModInfo.Author, ModInfo.DownloadLink)]
[assembly: MelonInfo(typeof(PlayspaceMover.Main), ModInfo.Name, ModInfo.Version, ModInfo.Author, ModInfo.DownloadLink)]

[assembly: MelonGame("VRChat", "VRChat")]

0 comments on commit 77b8395

Please sign in to comment.