Skip to content

Commit

Permalink
API docs
Browse files Browse the repository at this point in the history
  • Loading branch information
DaXcess committed Mar 5, 2024
1 parent b5c26b8 commit a88da05
Show file tree
Hide file tree
Showing 7 changed files with 184 additions and 35 deletions.
104 changes: 104 additions & 0 deletions Docs/API/LCVRPlugin.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
# LCVRPlugin `Public interface`

## Members
### Methods
#### Public methods
| Returns | Name |
| --- | --- |
| `void` | [`OnConfigChanged`](#onconfigchanged)()<br>Executed whenever the user changes the configuration for LCVR using the Settings Manager. |
| `void` | [`OnLoad`](#onload)()<br>Executed whenever the LCVR API is loaded. Can be used as an entrypoint to your plugin. |
| `void` | [`OnLobbyJoined`](#onlobbyjoined)()<br>Executed whenever the local player joins a lobby. |
| `void` | [`OnLobbyLeft`](#onlobbyleft)()<br>Executed whenever the local player leaves a lobby. |
| `void` | [`OnLocalPlayerDied`](#onlocalplayerdied)()<br>Executed whenever the local player dies. |
| `void` | [`OnPauseMenuClosed`](#onpausemenuclosed)()<br>Executed whenever the pause menu is closed. This method only gets executed when playing in VR. |
| `void` | [`OnPauseMenuOpened`](#onpausemenuopened)()<br>Executed whenever the pause menu is opened. This method only gets executed when playing in VR. |
| `void` | [`OnVRPlayerDied`](#onvrplayerdied)(`VRNetPlayer` player)<br>Executed whenever a VR player dies. |
| `void` | [`OnVRPlayerJoined`](#onvrplayerjoined)(`VRNetPlayer` player)<br>Executed whenever a VR player has joined the lobby. |
| `void` | [`OnVRPlayerLeft`](#onvrplayerleft)(`VRNetPlayer` player)<br>Executed whenever a VR player has left the lobby. |

## Details
### Methods
#### OnLoad
```csharp
public void OnLoad()
```
##### Summary
Executed whenever the LCVR API is loaded. Can be used as an entrypoint to your plugin.

#### OnConfigChanged
```csharp
public void OnConfigChanged()
```
##### Summary
Executed whenever the user changes the configuration for LCVR using the Settings Manager.

#### OnLobbyJoined
```csharp
public void OnLobbyJoined()
```
##### Summary
Executed whenever the local player joins a lobby.

#### OnLobbyLeft
```csharp
public void OnLobbyLeft()
```
##### Summary
Executed whenever the local player leaves a lobby.

#### OnVRPlayerJoined
```csharp
public void OnVRPlayerJoined(VRNetPlayer player)
```
##### Arguments
| Type | Name | Description |
| --- | --- | --- |
| `VRNetPlayer` | player | The VR player that joined |

##### Summary
Executed whenever a VR player has joined the lobby.

#### OnVRPlayerLeft
```csharp
public void OnVRPlayerLeft(VRNetPlayer player)
```
##### Arguments
| Type | Name | Description |
| --- | --- | --- |
| `VRNetPlayer` | player | The VR player that left |

##### Summary
Executed whenever a VR player has left the lobby.

#### OnLocalPlayerDied
```csharp
public void OnLocalPlayerDied()
```
##### Summary
Executed whenever the local player dies.

#### OnVRPlayerDied
```csharp
public void OnVRPlayerDied(VRNetPlayer player)
```
##### Arguments
| Type | Name | Description |
| --- | --- | --- |
| `VRNetPlayer` | player | |

##### Summary
Executed whenever a VR player dies.

#### OnPauseMenuOpened
```csharp
public void OnPauseMenuOpened()
```
##### Summary
Executed whenever the pause menu is opened. This method only gets executed when playing in VR.

#### OnPauseMenuClosed
```csharp
public void OnPauseMenuClosed()
```
##### Summary
Executed whenever the pause menu is closed. This method only gets executed when playing in VR.
28 changes: 25 additions & 3 deletions Docs/API/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

1. [Adding LCVR as a dependency](#adding-lcvr-as-a-dependency)
2. [Checking if VR is active](#checking-if-vr-is-active)
3. [Creating a VR interactable object](#creating-a-vr-interactable-object)
4. [Registering custom doors](#registering-custom-doors)
3. [Creating a VR plugin](#creating-a-vr-plugin)
4. [Creating a VR interactable object](#creating-a-vr-interactable-object)
5. [Registering custom doors](#registering-custom-doors)

## Adding LCVR as a dependency

Expand Down Expand Up @@ -37,6 +38,27 @@ else
}
```

## Creating a VR plugin

LCVR allows you to create a plugin without the need to use BepInEx.

To get started, create a new class, like this:

```cs
using LCVR.API;

[LCVRPlugin]
public class MyVRPlugin : LCVRPlugin
{
public void OnLoad()
{
// Startup code...
}
}
```

For a list of available overrides, check the [LCVRPlugin.md](LCVRPlugin.md) documentation.

## Creating a VR interactable object

By default, most interactions within the game are controlled by an `InteractTrigger`. VR is compatible with these types of interactions, however since v1.2.0 some of these built in triggers have been disabled in favor of using physical interactions (e.g. having to physically press a button instead of using a "point and click" type interaction).
Expand Down Expand Up @@ -108,7 +130,7 @@ As you can see, any VR interactable object must have a script attached which inh
- `OnButtonRelease`
This function gets called after you release the interaction button on the hand that is currently interacting with this object.

> For more in-depth examples, check out the [**built in interactions**](Physics/Interactions).
> For more in-depth examples, check out the [**built in interactions**](../../Source/Physics/Interactions).
### Disabling the flatscreen interaction

Expand Down
46 changes: 33 additions & 13 deletions Source/API/APIManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,58 +80,78 @@ public interface LCVRPlugin
/// <summary>
/// Executed whenever the LCVR API is loaded. Can be used as an entrypoint to your plugin.
/// </summary>
void OnLoad();

void OnLoad()
{
}

/// <summary>
/// Executed whenever the user changes the configuration for LCVR using the Settings Manager.
/// </summary>
void OnConfigChanged();
void OnConfigChanged()
{
}

/// <summary>
/// Executed whenever the local player joins a lobby.
/// </summary>
void OnLobbyJoined();
void OnLobbyJoined()
{
}

/// <summary>
/// Executed whenever the local player leaves a lobby.
/// </summary>
void OnLobbyLeft();

void OnLobbyLeft()
{
}

/// <summary>
/// Executed whenever a VR player has joined the lobby.
/// </summary>
/// <param name="player">The VR player that joined</param>
void OnVRPlayerJoined(VRNetPlayer player);
void OnVRPlayerJoined(VRNetPlayer player)
{
}

/// <summary>
/// Executed whenever a VR player has left the lobby.
/// </summary>
/// <param name="player">The VR player that left</param>
void OnVRPlayerLeft(VRNetPlayer player);
void OnVRPlayerLeft(VRNetPlayer player)
{
}

/// <summary>
/// Executed whenever the local player dies.
/// </summary>
void OnLocalPlayerDied();
void OnLocalPlayerDied()
{
}

/// <summary>
/// Executed whenever a VR player dies.
/// </summary>
void OnVRPlayerDied(VRNetPlayer player);

void OnVRPlayerDied(VRNetPlayer player)
{
}

/// <summary>
/// Executed whenever the pause menu is opened.
///
/// <i>This method only gets executed when playing in VR.</i>
/// </summary>
void OnPauseMenuOpened();
void OnPauseMenuOpened()
{
}

/// <summary>
/// Executed whenever the pause menu is closed.
///
/// <i>This method only gets executed when playing in VR.</i>
/// </summary>
void OnPauseMenuClosed();
void OnPauseMenuClosed()
{
}
}

public class LCVRPluginAttribute : Attribute { }
Expand Down
6 changes: 3 additions & 3 deletions Source/Input/FingerCurler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public FingerCurler(Transform hand, bool isLeft)
}
}

public DNet.Fingers GetCurls()
internal DNet.Fingers GetCurls()
{
return new DNet.Fingers()
{
Expand All @@ -84,7 +84,7 @@ public DNet.Fingers GetCurls()
};
}

public void SetCurls(DNet.Fingers fingers)
internal void SetCurls(DNet.Fingers fingers)
{
thumbFinger.curl = fingers.thumb;
indexFinger.curl = fingers.index;
Expand Down Expand Up @@ -116,7 +116,7 @@ public class VRFingerCurler(Transform hand, bool isLeft) : FingerCurler(hand, is
private InputAction IndexAction => Actions.Instance[$"{actionMap}/Index"];
private InputAction OthersAction => Actions.Instance[$"{actionMap}/Others"];

private bool forceFist = false;
private bool forceFist;

public bool IsFist => indexFinger.curl > 0.75f && middleFinger.curl > 0.75f;
public bool IsPointer => indexFinger.curl <= 0.75f && middleFinger.curl > 0.75f;
Expand Down
6 changes: 3 additions & 3 deletions Source/Items/VRShovelItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,12 @@ protected override void OnUpdate()

if (!IsLocal)
{
transform.position = networkPlayer.leftItemHolder.position;
transform.LookAt(networkPlayer.rightItemHolder.position);
transform.position = networkPlayer.LeftItemHolder.position;
transform.LookAt(networkPlayer.RightItemHolder.position);

var rotation2 = transform.rotation;

transform.eulerAngles = new Vector3(transform.eulerAngles.x, transform.eulerAngles.y, 360 - networkPlayer.leftItemHolder.eulerAngles.z);
transform.eulerAngles = new Vector3(transform.eulerAngles.x, transform.eulerAngles.y, 360 - networkPlayer.LeftItemHolder.eulerAngles.z);
transform.position += rotation2 * positionOffset;

return;
Expand Down
27 changes: 15 additions & 12 deletions Source/Networking/VRNetPlayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@

namespace LCVR.Networking;

/// <summary>
/// A behaviour that is attached to other VR players
/// </summary>
public class VRNetPlayer : MonoBehaviour
{
private ChainIKConstraintData originalLeftArmConstraintData;
Expand All @@ -26,13 +29,10 @@ public class VRNetPlayer : MonoBehaviour
private Transform leftHandVRTarget;
private Transform rightHandVRTarget;

public Transform leftItemHolder;
public Transform rightItemHolder;

private FingerCurler leftFingerCurler;
private FingerCurler rightFingerCurler;

public Transform camera;
private Transform camera;

private float cameraFloorOffset;
private float rotationOffset;
Expand All @@ -45,6 +45,9 @@ public class VRNetPlayer : MonoBehaviour

public PlayerControllerB PlayerController { get; private set; }
public Bones Bones { get; private set; }

public Transform LeftItemHolder { get; private set; }
public Transform RightItemHolder { get; private set; }

private void Awake()
{
Expand Down Expand Up @@ -82,15 +85,15 @@ private void Awake()
var leftHolder = new GameObject("Left Hand Item Holder");
var rightHolder = new GameObject("Right Hand Item Holder");

leftItemHolder = leftHolder.transform;
leftItemHolder.SetParent(Bones.LeftHand, false);
leftItemHolder.localPosition = new Vector3(0.018f, 0.045f, -0.042f);
leftItemHolder.localEulerAngles = new Vector3(360f - 356.3837f, 357.6979f, 0.1453f);
LeftItemHolder = leftHolder.transform;
LeftItemHolder.SetParent(Bones.LeftHand, false);
LeftItemHolder.localPosition = new Vector3(0.018f, 0.045f, -0.042f);
LeftItemHolder.localEulerAngles = new Vector3(360f - 356.3837f, 357.6979f, 0.1453f);

rightItemHolder = rightHolder.transform;
rightItemHolder.SetParent(Bones.RightHand, false);
rightItemHolder.localPosition = new Vector3(-0.002f, 0.036f, -0.042f);
rightItemHolder.localEulerAngles = new Vector3(356.3837f, 357.6979f, 0.1453f);
RightItemHolder = rightHolder.transform;
RightItemHolder.SetParent(Bones.RightHand, false);
RightItemHolder.localPosition = new Vector3(-0.002f, 0.036f, -0.042f);
RightItemHolder.localEulerAngles = new Vector3(356.3837f, 357.6979f, 0.1453f);

// Set up finger curlers
leftFingerCurler = new FingerCurler(Bones.LeftHand, true);
Expand Down
2 changes: 1 addition & 1 deletion Source/Player/Spectating/Patches.cs
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ private static IEnumerator delayedShowDeathScreen()

allowSpectatorActions = true;

// Fixes a bug where if you pick up an item while dying it stays in your inventory
// Fixes an issue where if you pick up an item while dying it stays in your inventory
StartOfRound.Instance.localPlayerController.DropAllHeldItems(false);
}

Expand Down

0 comments on commit a88da05

Please sign in to comment.