Skip to content

Instantly share code, notes, and snippets.

View MattRix's full-sized avatar

Matt Rix MattRix

View GitHub Profile
@MattRix
MattRix / InspectorHelper.cs
Last active March 14, 2025 01:30
Put a debug mode button in the inspector and lets you toggle debug mode with alt+d
#if UNITY_EDITOR
using System;
using System.Collections;
using System.Collections.Generic;
using System.Reflection;
using UnityEditor;
using UnityEngine;
//UNFORTUNATELY this doesn't work right now because the inspector doesn't get refreshed properly in debug mode
//I'm sure it's fixable but I haven't bothered looking into it yet
@MattRix
MattRix / OmniAsset.cs
Last active March 8, 2025 16:11
An example of a really simple asset importer that just reads in text files with a custom .omni extension
using UnityEngine;
#if UNITY_EDITOR
using UnityEditor.AssetImporters;
using System.IO;
[ScriptedImporter(1, "omni")]
public class OmniAssetImporter : ScriptedImporter
{
public override void OnImportAsset(AssetImportContext ctx)
@MattRix
MattRix / AssetLibrary.cs
Last active March 7, 2025 12:35
Generate ScriptableObjects that have named and typed references to assets in their folder
using System.IO;
using System.Text;
using System.Collections.Generic;
using UnityEngine;
#if UNITY_EDITOR
using UnityEditor;
#endif
[CreateAssetMenu(menuName = "AssetLibrary")]
public class AssetLibrary : ScriptableObject
@MattRix
MattRix / PrefabClassGenerator.cs
Last active February 14, 2025 17:52
Generate classes for prefabs so that you get named and typed references to their components and children.
#if UNITY_EDITOR
using UnityEngine;
using UnityEditor;
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
public class PrefabClassGenerator
@MattRix
MattRix / wrap_subscribe.verse
Last active October 13, 2024 18:45
Send additional data to Subscribe() listeners in Verse
#usage example (when subscribing to an event that returns an agent)
ButtonDevice.InteractedWithEvent.SubscribeAgent(OnButtonInteract, "Hello!")
OnButtonInteract(Agent : agent, Text : string) : void =
Print("Button interacted with {Text}!")
#usage example (when subscribing to an event that returns tuple(), aka an empty tuple)
CampfireDevice.CampfirePulseEvent.SubscribeEmpty(OnCampfirePulse, 90210)
OnCampfirePulse(Number : int) : void =
@MattRix
MattRix / SingleImagePostMaterial.txt
Created May 2, 2023 22:17
Post processing material for UE5/UEFN material graph to show an image on screen (copy and paste into the graph editor)
Begin Object Class=/Script/UnrealEd.MaterialGraphNode_Root Name="MaterialGraphNode_Root_16"
Material=/Script/UnrealEd.PreviewMaterial'"/Engine/Transient.PreviewMaterial_2"'
NodePosX=144
NodePosY=-80
NodeGuid=DA645A0D405D999F05550EB2B20E74E3
CustomProperties Pin (PinId=94B10B244638D93ADC813DA0DB8A360A,PinName="Base Color",PinType.PinCategory="materialinput",PinType.PinSubCategory="5",PinType.PinSubCategoryObject=None,PinType.PinSubCategoryMemberReference=(),PinType.PinValueType=(),PinType.ContainerType=None,PinType.bIsReference=False,PinType.bIsConst=False,PinType.bIsWeakPointer=False,PinType.bIsUObjectWrapper=False,PinType.bSerializeAsSinglePrecisionFloat=False,PersistentGuid=00000000000000000000000000000000,bHidden=False,bNotConnectable=False,bDefaultValueIsReadOnly=False,bDefaultValueIsIgnored=False,bAdvancedView=False,bOrphanedPin=False,)
CustomProperties Pin (PinId=2BA1B6FE4FAF4CE973853CAD1EB7925E,PinName="Metallic",PinType.PinCategory="materialinput",PinType.PinSubCategory="6",PinType.P
@MattRix
MattRix / singleton.verse
Created April 24, 2023 15:27
Singleton in Verse
global := class<varies><concrete>():
var MaybeMainDevice : ?main_device = false
GetMainDevice():main_device =
if(MainDevice := Global.MaybeMainDevice?) then MainDevice else main_device{}
Global : global = global{}
#in the device's OnBegin you call
set Global.MaybeMainDevice = option{Self}
@MattRix
MattRix / routine.verse
Last active October 13, 2024 18:50
Cancelable Spawned Coroutines in Verse (advanced version)
<#> Usage
MyRoutine := SpawnRoutine(SomeLongRunningTask)
MyRoutine.Cancel()
SpawnRoutine<public>(Func : type{_()<suspends>:void}):routine =
Routine := routine{Func := Func}
Routine.Start()
return Routine
routine<public> := class():
@MattRix
MattRix / routine.verse
Created April 21, 2023 16:19
Cancelable Coroutines with Verse (using race)
<#> Usage
Routine := SpawnRoutine(SomeLongTask)
Routine.Cancel()
SpawnRoutine(Func : type{_()<suspends>:void}):routine =
Routine := routine{Func := Func}
Routine.Start()
return Routine
routine := class():
@MattRix
MattRix / sort.verse
Created April 21, 2023 15:43
Parmetric Quicksort for Arrays in Verse
<#> Usage:
SortedItems := Sort(Items, true, CompareInt)
Sort(Items : []t, IsAscending : logic, Comparer: type{_(:t, :t)<computes> : int} where t : type)<computes> : []t =
if (Items.Length > 1, Pivot := Items[Floor(Items.Length/2)]):
Left := for(Item : Items, Comparer(Item, Pivot) = -1) do Item
Middle := for(Item : Items, Comparer(Item, Pivot) = 0) do Item
Right := for(Item : Items, Comparer(Item, Pivot) = 1) do Item