Skip to content

Instantly share code, notes, and snippets.

View liamcary's full-sized avatar

Liam liamcary

View GitHub Profile
@liamcary
liamcary / ReverseNetworkBehaviour.cs
Created September 26, 2025 02:03
Mirror NetworkBehaviour where SyncVars are Serialized/Deserialized before SyncObjects
using Mirror;
/// <summary>
/// A network behaviour that serializes SyncVars before SyncObjects (SyncList, SyncDictionary, etc), instead of the other way around.
/// This is handy if you want the client to receive a sync var before processing operations to a sync list.
/// </summary>
public class ReverseNetworkBehaviour : NetworkBehaviour
{
readonly SyncList<int> _exampleList1 = new(); // Serialized/Deserialized 3rd
readonly SyncList<int> _exampleList2 = new(); // Serialized/Deserialized 4th
@liamcary
liamcary / IObjectRegistry.cs
Last active August 4, 2025 03:07
Generic ObjectRegistry for Unity to track instances of a type, with Mirror example
// IObjectRegistry.cs
using System;
using System.Collections.Generic;
public interface IObjectRegistry<T>
{
IReadOnlyCollection<T> Instances { get; }
event Action<T> OnInstanceRegistered;
event Action<T> OnInstanceUnregistered;
@liamcary
liamcary / LODGroupCustomEditor.cs
Created February 8, 2024 07:16
Custom LODGroup Inspector with fields for entering distances instead of screen size percentages.
using UnityEngine;
namespace UnityEditor
{
/// NOTE: This needs to be in an editor folder with an Assembly Definition Reference referencing
/// the UnityEditor.UI assembly. This is because it uses internal extension methods which are inaccessible
/// outside of UnityEditor.UI.
[CustomEditor(typeof(LODGroup))]
internal class LODGroupCustomEditor : LODGroupEditor
{
@liamcary
liamcary / DynamicResolutionScaler.cs
Last active September 26, 2025 19:42
Dynamic Resolution for Oculus Quest with Unity 2021.3 LTS and URP 12
using System;
using UnityEngine;
using UnityEngine.Rendering;
using UnityEngine.Rendering.Universal;
using UnityEngine.XR;
public class DynamicResolutionScaler : MonoBehaviour
{
[SerializeField, Range(0f, 1f)] float _minResolutionScale;
@liamcary
liamcary / BaseComponentRealtime.cs
Created June 14, 2023 02:15
A generic, abstract base class for Normcore RealtimeComponents that handles OnRealtimeModelReplaced and calls more self-explanatory methods for common usages.
using Normal.Realtime;
using System;
public abstract class BaseComponentRealtime<TModelRealtime> : RealtimeComponent<TModelRealtime>
where TModelRealtime : RealtimeModel, new()
{
public bool IsOwnershipSupported => model.hasMetaModel;
public bool PreventOwnershipTakeover
{
get => model.preventOwnershipTakeover;
@liamcary
liamcary / RealtimeTransformOptimizer.cs
Last active October 8, 2024 01:42
A script to improve performance of RealtimeTransforms in Rigidbody mode. See comments for fixes required for the latest Normcore versions.
using Normal.Realtime;
using System;
using System.Collections;
using System.Reflection;
using UnityEngine;
namespace Normcore.Realtime
{
/// <summary>
/// This script is intended to be attached to an object with a RealtimeTransform in Rigidbody mode. We have to use reflection