Skip to content

Instantly share code, notes, and snippets.

View pbhogan's full-sized avatar

Patrick Hogan pbhogan

View GitHub Profile
@NoelFB
NoelFB / TerrainEditor.cs
Last active January 22, 2021 02:13
Terrain Thingy
using UnityEngine;
using System.Collections;
using UnityEditor;
[CustomEditor(typeof(TerrainManager))]
public class TerrainEditor : Editor
{
private TerrainManager terrain { get { return (TerrainManager)target; } }
private Vector2Int? selected;
@HybridDog
HybridDog / ssim_perceptual_downscaling.c
Last active March 25, 2025 21:43
SSIM-based perceptual image downscaling for PNG images
// SPDX-License-Identifier: MIT
//
// This program contains an implementation of SSIM-based perceptual image
// downscaling for PNG images.
// The program can be twice as fast when compiled with -Ofast.
// The program behaviour can be adjusted with predefined preprocessor macros:
// * -DTILEABLE: Assume images wrap around at corners. This should be enabled
// when downscaling tileable textures.
// * -DGAMMA_INCORRECT: Downscale without applying the sRGB EOTF and OETF.
// When downscaling images with symbolic meaning, e.g. screenshots of text or
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
public class RingColliderWindow : EditorWindow {
private GameObject _parentObj;
private int _numColliders = 6;
private float _ringRadius = 2.0f;
private float _colliderRadius = 0.5f;
@yagero
yagero / EventSystemManaged.cs
Created November 7, 2017 10:14
EventSystemManaged
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
public class EventSystemManaged : EventSystem
{
static Stack<EventSystem> ms_PrevEventSystem = new Stack<EventSystem>();
static bool ms_Forced = false;
protected override void OnEnable()
@cmdr2
cmdr2 / GenerateMesh02.cs
Last active November 1, 2023 14:28
A mesh extrusion along a bezier curve (Unity3d)
[RequireComponent(typeof(MeshFilter))]
public class GenerateMesh02 : MonoBehaviour {
/* scratchpad */
private MeshFilter mf;
void Start () {
mf = GetComponent<MeshFilter> ();
GenerateMesh ();
@phosphoer
phosphoer / GravityItem.cs
Last active August 18, 2024 12:04
Mario Galaxy Gravity for Unity
// The MIT License (MIT)
// Copyright (c) 2016 David Evans @phosphoer
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
@FreyaHolmer
FreyaHolmer / RigidbodyMassCalculator.cs
Created December 18, 2015 19:54
Used to approximate a proper mass value for all the colliders in a given Rigidbody
using UnityEngine;
using System.Linq;
[RequireComponent(typeof(Rigidbody))]
public class RigidbodyMassCalculator : MonoBehaviour {
public float density = 1f;
public bool recalculateOnAwake = true;
Rigidbody rb;
@slembcke
slembcke / NearlyNearestNeighborFiltering.glsl
Last active December 27, 2020 21:19
Anti-aliased Nearest Neighbor Filtering.
uniform sampler2D texture;
varying vec2 uv;
void main(){
vec2 size = textureSize(texture);
vec2 puv = uv*size;
vec2 hfw = 0.5*fwidth(puv);
vec2 fl = floor(puv - 0.5) + 0.5;
@HilariousCow
HilariousCow / IntRangeDrawer
Last active September 26, 2021 13:57
A random int range unity data type with property drawer. FloatRange version here: https://gist.github.com/HilariousCow/1d056da2e3324670a087. Adapted from http://www.grapefruitgames.com/blog/2013/11/a-min-max-range-for-unity/
using UnityEngine;
using UnityEditor;
using System.Collections;
using System.Collections.Generic;
[CustomPropertyDrawer(typeof(IntRangeAttribute))]
public class IntRangeDrawer : PropertyDrawer
{
public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
{
@Bradshaw
Bradshaw / OneEuroExtensions.cs
Created November 28, 2014 10:18
Unity Implementation of the 1€ filter for input smoothing
using UnityEngine;
using System.Collections;
public struct FloatOneEuroData
{
public float dx;
public float edx;
public float cutoff;
public float filthatxprev;
public float dfilthatxprev;