Skip to content

Instantly share code, notes, and snippets.

View StagPoint's full-sized avatar

StagPoint Software StagPoint

  • StagPoint Software
  • Seattle, WA
View GitHub Profile
@StagPoint
StagPoint / OuterGlow.cs
Last active April 25, 2024 20:05
Custom VisualElement for Unity's UI Toolkit which is useful for creating an "outer glow" effect for buttons, or a "drop shadow" effect for popups, windows, and dialogs.
// Created 2024 StagPoint. Released to the public domain.
using System;
using System.Runtime.CompilerServices;
using Unity.Collections;
using UnityEngine;
using UnityEngine.Scripting;
using UnityEngine.UIElements;
@StagPoint
StagPoint / AddAnimationClipsToControllerAsset.cs
Created December 5, 2021 18:50
Unity editor script that adds existing AnimationClip assets to the AnimationController asset that uses them, cutting down on clutter and making it easier to manage your controllers and their associated animation clips.
namespace StagPoint.EditorUtils
{
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using UnityEditor.Animations;
@StagPoint
StagPoint / NativePriorityQueue.cs
Last active March 7, 2024 20:34
Priority queue implementation for Unity that uses Native Containers for data storage. This version relies on the stored type implementing the IComparable<T> interface.
// Copyright 2017-2021 StagPoint Software
namespace StagPoint.Collections
{
using System;
using System.Diagnostics;
using System.Runtime.CompilerServices;
using Unity.Collections;
using Unity.Collections.LowLevel.Unsafe;
@StagPoint
StagPoint / SimplePathSmoother.cs
Last active June 17, 2022 10:59
Implements a simplistic 3D curve smoother for Unity. Depending on the intended use case, best results might be achieved by preprocessing the curve to have equally-spaced points, or using the Ramer-Douglas-Peucker algorithm to remove unnecessary points. It wasn't needed for my use case, so I didn't include that code here. YMMV.
namespace StagPoint.Math
{
using Unity.Collections;
using Unity.Mathematics;
/// <summary>
/// Implements a simplistic 3D curve smoother
/// </summary>
public static class CurveSmoother
{
@StagPoint
StagPoint / Morton2D.cs
Last active September 21, 2021 20:57
Represents 2D Morton Codes by interleaving two 16-bit unsigned integer values into a 32-bit unsigned integer.
// **************************************************
// EXAMPLE USAGE:
//
// // Returns a single value with arguments x and y interleaved
// var code = MortonCode2D.Interleave( 123, 456 );
//
// // Extracts the interleaved values (123 and 456) into integer variables x and y
// MortonCode2D.Deinterleave( code, out int x, out int y )
//
// **************************************************
@StagPoint
StagPoint / CameraMath.cs
Created December 2, 2020 23:20
Small collection of utility functions for calculating screen size of objects, size of camera frustum at a distance, etc.
using System;
using System.Runtime.InteropServices;
using System.Runtime.CompilerServices;
using Unity.Burst;
using Unity.Mathematics;
public static class CameraMath
{
/// <summary>
@StagPoint
StagPoint / DustyNebula.shader
Created May 7, 2020 00:09
Unity Port of "Dusty Nebula 4" by Duke ( https://www.shadertoy.com/view/MsVXWW )
// "Dusty nebula 4" by Duke
// https://www.shadertoy.com/view/MsVXWW
//-------------------------------------------------------------------------------------
// Based on "Dusty nebula 3" (https://www.shadertoy.com/view/lsVSRW)
// and "Protoplanetary disk" (https://www.shadertoy.com/view/MdtGRl)
// otaviogood's "Alien Beacon" (https://www.shadertoy.com/view/ld2SzK)
// and Shane's "Cheap Cloud Flythrough" (https://www.shadertoy.com/view/Xsc3R4) shaders
// Some ideas came from other shaders from this wonderful site
// Press 1-2-3 to zoom in and zoom out.
// License: Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License
@StagPoint
StagPoint / DisableXMLWarningsUnity.cs
Created September 27, 2018 16:10
Use "#pragma warning disable 1591" to suppress "Missing XML comment for publicly visible type or member" warnings in Visual Studio when using Unity
// Disable all XML Comment warnings in this file, because Unity won't allow us to turn this bullshit off and keeps overwriting our settings //
#pragma warning disable 1591
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class NewBehaviourScript : MonoBehaviour
{
// Use this for initialization
@StagPoint
StagPoint / DoPlanesIntersectAtSinglePoint.cs
Created September 25, 2018 17:57
Find intersection point of three planes in C# for Unity
private bool planesIntersectAtSinglePoint( Plane p0, Plane p1, Plane p2, out Vector3 intersectionPoint )
{
const float EPSILON = 1e-4f;
var det = Vector3.Dot( Vector3.Cross( p0.normal, p1.normal ), p2.normal );
if( det < EPSILON )
{
intersectionPoint = Vector3.zero;
return false;
}
@StagPoint
StagPoint / ObjectPool.cs
Created April 2, 2017 14:21
Bare-bones generic object pooling. Object pools can improve application performance and memory footprint in many gamedev situations. When a client program requests a new object, the object pool first attempts to provide one that has already been created and returned to the pool. If none is available, only then is a new instance created.
// Copyright (c) 2017 StagPoint Software
namespace StagPoint.ObjectPooling
{
using System;
using System.Collections.Generic;
public class ObjectPool<T> where T : class
{
#region Static variables