Skip to main content

Scripting

Code Snippets

The namespace
using ChocDino.PartyIO;

Examples

Example of low-level enumeration of all mice
using System.Collections.Generic;
using UnityEngine;
using ChocDino.PartyIO;

public class Example : MonoBehaviour
{
private MouseManager _manager;

void Awake()
{
MouseManager.ChangedConnectionState += OnMouseConnectionChanged;
_manager = new MouseManager();
}

void Update()
{
_manager.Update();
LogMiceState();
}

void LogMiceState()
{
List<Mouse> mice = _manager.All;
foreach (var mouse in mice)
{
string text = string.Format("Id: {0} Connection: {1} Position: {2} Scroll; {3}", mouse.DeviceId, mouse.ConnectionState, mouse.PositionDelta, mouse.ScrollDelta);
Debug.Log(text);

if (mouse.IsPressed(MouseButton.Left))
{
Debug.Log("Left button is pressed");
}
if (mouse.WasPressedThisFrame(MouseButton.Left))
{
Debug.Log("Left button was pressed this frame");
}
if (mouse.WasReleasedThisFrame(MouseButton.Left))
{
Debug.Log("Left button was released this frame");
}
}
}

void OnDestroy()
{
_manager.Dispose();
_manager = null;
}

void OnMouseConnectionChanged(Mouse mouse)
{
if (mouse.ConnectionState == MouseConnectionState.Connected)
{
Debug.Log("Mouse with id " + mouse.DeviceId + " just connected.");
}
else if (mouse.ConnectionState == MouseConnectionState.Disconnected)
{
Debug.Log("Mouse with id " + mouse.DeviceId + " just disconnected.");
}
}
}