Skip to content

Instantly share code, notes, and snippets.

View AldeRoberge's full-sized avatar
💛
.

Alexandre D. Roberge AldeRoberge

💛
.
View GitHub Profile
@AldeRoberge
AldeRoberge / ChatRowDrawer.cs
Created February 10, 2025 20:18
Allows to wrap long lines in Unity IMGUI TextArea
GUIStyle myStyle = new GUIStyle(EditorStyles.textField)
{
wordWrap = true
};
chatRow.Text = EditorGUILayout.TextArea(chatRow.Text, myStyle, GUILayout.Height(100));
@AldeRoberge
AldeRoberge / OpenInTerminal.cs
Last active February 7, 2025 18:47
Right click Project folder to open in terminal. Supports Linux, Mac and Windows.
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Runtime.InteropServices;
using UnityEditor;
using UnityEngine;
using Debug = UnityEngine.Debug;
namespace ADG.Scripts.Editor
@AldeRoberge
AldeRoberge / ObsService.cs
Created February 7, 2025 16:06
Set the OBS output file name
using FluentResults;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using OBSStudioClient;
using OBSStudioClient.Enums;
using Polly;
namespace ADG.Recording.OBS
{
public class ObsServiceOptions
@AldeRoberge
AldeRoberge / IsPointerOverGameObjectUtils.cs
Created January 14, 2025 01:21
Allows to check if a pointer is over a UI (works on touch devices too)
using UnityEngine;
using UnityEngine.EventSystems;
namespace Wikwemot_AR.Modules.Input.Runtime.Scripts
{
// See : https://discussions.unity.com/t/ispointerovergameobject-not-working-with-touch-input/155469/3
public static class IsPointerOverGameObjectUtils
{
/// <returns>true if mouse or first touch is over any event system object ( usually gui elements )</returns>
public static bool IsPointerOverGameObject()
namespace Wikwemot_AR.Modules.UI.Runtime.Scripts
{
public class DisableScreenTimeout : MonoBehaviour
{
private void Start()
{
DisableScreenSleep();
}
private void DisableScreenSleep()
@AldeRoberge
AldeRoberge / Monitor-USB-Activity.ps1
Created January 6, 2025 18:53
This PowerShell script monitors and logs USB device connection and disconnection events on the system. Whenever a USB device is plugged in or removed, the script captures relevant details and logs them.
# Function to display USB event information
function Display-USBEvent {
param (
[string]$EventType,
[string]$DeviceName
)
Write-Host "[$(Get-Date -Format 'HH:mm:ss')] ${EventType}: ${DeviceName}" -ForegroundColor Yellow
}
@AldeRoberge
AldeRoberge / DeviceOrientation.cs
Created December 10, 2024 00:51
Allows to give permission to the user (or disallow) screen rotation on a per scene basis (add the script to a game object in the scene)
using Sirenix.OdinInspector;
using System;
using UnityEngine;
namespace Runtime.Scripts.Device
{
// Allows to give permission to the user (or disallow) screen rotation on a per scene basis (add the script to a game object in the scene)
public class DeviceOrientation : MonoBehaviour
{
[SerializeField] private bool _isLocked;
@AldeRoberge
AldeRoberge / Hosted-Service-DI.md
Created November 18, 2024 15:15
Different instance C# .NET dependency injection DI register hosted service singleton

Using .NET Dependency Injection (DI) for Shared Instances

When using .NET Dependency Injection (DI), if you register a HostedService and also register it as a Singleton, the consuming classes might not get the same instance because the DI container creates separate instances for each registration by default.

services.AddHostedService<Database>();
services.AddSingleton<IDatabase, Database>();

To fix this, you need to ensure the same instance is shared between the IHostedService and the IDatabase. Here’s how you can do it:

@AldeRoberge
AldeRoberge / CopyToUnity.csproj
Created November 14, 2024 19:26
Copy DLLs into Unity Library folder
<!-- To following is useful if you need to copy built .DLLs into Unity. -->
<!-- Adapt this script depending on where you want your DLLs copied. -->
<!-- You might need to manually add dependencies (other DLLs) inside of the folder. -->
<!-- You can check out NuGet For Unity for this, or simply build the libs with .NET Framework 2.1 and import them. -->
<!-- -->
<!-- Example -->
<!-- -->
<!-- ADG -->
<!-- ├── ADG.FMOD -->
@AldeRoberge
AldeRoberge / LoggingConfig.cs
Last active November 15, 2024 21:26
The Logging config I use for all my apps
using Microsoft.Extensions.DependencyInjection;
using Serilog;
using Serilog.Events;
using Serilog.Exceptions;
using Serilog.Sinks.SystemConsole.Themes;
namespace ADG.Library.Logging
{
public static class LoggingConfig
{