Skip to content

Instantly share code, notes, and snippets.

View mminer's full-sized avatar

Matthew Miner mminer

View GitHub Profile
@mminer
mminer / BezierControlPointMode.cs
Last active July 5, 2021 23:17
Unity spline / Bezier curves adapted from Catlike Coding's "Curves and Splines" tutorial.
/// <summary>
/// Modes that specify how the control points affect a Bezier curve.
/// </summary>
public enum BezierControlPointMode
{
Aligned,
Free,
Mirrored,
}
@mminer
mminer / AddressablesSizeAnalyzeRule.cs
Created June 24, 2021 21:59
Unity Addressables Analyze rule that reports the size of bundles after building them.
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
using UnityEditor;
using UnityEditor.AddressableAssets.Build;
using UnityEditor.AddressableAssets.Build.AnalyzeRules;
using UnityEditor.AddressableAssets.Settings;
using UnityEngine;
@mminer
mminer / OffsetGrabInteractable.cs
Created June 7, 2021 22:54
Unity XR component to move objects relative to their original position.
using UnityEngine;
using UnityEngine.XR.Interaction.Toolkit;
public class OffsetGrabInteractable : XRGrabInteractable
{
Vector3 interactorPosition;
Quaternion interactorRotation;
protected override void OnSelectEntered(XRBaseInteractor interactor)
{
@mminer
mminer / VisualEffectPlayRate.cs
Created June 1, 2021 18:00
Unity component to change a visual effect's play rate.
using UnityEngine;
using UnityEngine.VFX;
[ExecuteInEditMode]
[RequireComponent(typeof(VisualEffect))]
public class VisualEffectPlayRate : MonoBehaviour
{
[SerializeField, Range(0, 10)] float playRate = 1f;
VisualEffect vfx;
@mminer
mminer / RotateAroundCircle.cs
Created May 18, 2021 19:26
Unity scene view handles to rotate an object around a circle.
using UnityEditor;
using UnityEditor.IMGUI.Controls;
using UnityEngine;
public class RotateAroundCircle : MonoBehaviour
{
public Color color = Color.cyan;
public Vector3 pivot;
}
@mminer
mminer / Pathfinding.cs
Created March 19, 2021 04:51
A* pathfinding implementation.
using System;
using System.Linq;
using System.Collections.Generic;
public static class Pathfinding
{
/// <summary>
/// A* implementation. Finds a path from start to goal.
/// </summary>
/// <param name="start">Where to begin.</param>
@mminer
mminer / VerticallyFlipRenderTexture.cs
Created February 18, 2021 21:39
Unity function to vertically flip a render texture.
/// <summary>
/// Vertically flips a render texture in-place.
/// </summary>
/// <param name="target">Render texture to flip.</param>
public static void VerticallyFlipRenderTexture(RenderTexture target)
{
var temp = RenderTexture.GetTemporary(target.descriptor);
Graphics.Blit(target, temp, new Vector2(1, -1), new Vector2(0, 1));
Graphics.Blit(temp, target);
RenderTexture.ReleaseTemporary(temp);
@mminer
mminer / YouTubePlayerResponse.cs
Created January 28, 2021 00:58
YouTube video player for Unity.
using System;
using System.Text.RegularExpressions;
using UnityEngine;
/// <summary>
/// Holds the result of parsing the ytInitialPlayerResponse JSON from a YouTube page.
/// </summary>
/// <remarks>
/// This is an incomplete list of fields in ytInitialPlayerResponse.
/// The full object contains many more, but we only care about a few.
@mminer
mminer / KeepWindowsSessionAlive.ps1
Created October 2, 2020 00:08
PowerShell script to keep Windows session alive by repeatedly toggling numlock.
$wshell = New-Object -ComObject WScript.Shell
while ($true) {
Write-Output "$(Get-Date) Toggling numlock"
$whell.SendKeys('{NUMLOCK}')
Start-Sleep -Seconds 10
}
@mminer
mminer / convert_to_image_sequence.sh
Created August 10, 2020 03:39
Converts .mov files to image sequences using FFmpeg.
#!/usr/bin/env bash
for filename in "$@"; do
base=$(basename "$filename" .mov)
mkdir "$base"
ffmpeg -i "$filename" "$base/$base-%03d.png"
done