Skip to content

Instantly share code, notes, and snippets.

View MattRix's full-sized avatar

Matt Rix MattRix

View GitHub Profile
@MattRix
MattRix / RXDivider.cs
Last active May 1, 2024 18:15
Adds dividers into the inspector. Based on a brilliant idea by Matthew Wegner, see: https://twitter.com/mwegner/status/355147544818495488
//Based on a brilliant idea by Matthew Wegner - https://twitter.com/mwegner/status/355147544818495488
//Code for drawing the base PropertyDrawers is from here: http://forum.unity3d.com/threads/173401-Getting-Default-SerializedProperty-Drawing-within-a-PropertyDrawer?p=1186347&viewfull=1#post1186347
//My implementation is super lazy with magic numbers everywhere! :D
#if UNITY_EDITOR
using System;
using UnityEngine;
using System.Collections.Generic;
using UnityEditor;
@MattRix
MattRix / UnityEditorIcons.txt
Last active April 26, 2024 18:52
A list of all the built-in EdtiorGUI icons in Unity. Use EditorGUIUtility.IconContent([icon name]) to access them.
ScriptableObject Icon
_Popup
_Help
Clipboard
SocialNetworks.UDNOpen
SocialNetworks.Tweet
SocialNetworks.FacebookShare
SocialNetworks.LinkedInShare
SocialNetworks.UDNLogo
animationvisibilitytoggleoff
@MattRix
MattRix / EditorZoomer.cs
Created October 27, 2019 23:18
EditorZoomer - an easy way to do panning and zooming inside Unity Editor IMGUI
using UnityEngine;
using System.Collections;
using System;
//based on the code in this post: http://martinecker.com/martincodes/unity-editor-window-zooming/
//but I changed how the API works and made it much more flexible
//usage: create an EditorZoomer instance wherever you want to use it (it tracks the pan + zoom state)
//in your OnGUI, draw your scrollable content between zoomer.Begin() and zoomer.End();
//you also must offset your content by zoomer.GetContentOffset();
@MattRix
MattRix / EmoPacker.cs
Last active March 13, 2024 17:02
Packing a folder of images into a sprite atlas for use with TextMeshPro
using System.IO;
using System.Text;
using System.Collections;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using System.Linq;
using UnityEngine;
using UnityEditor;
using UnityEditor.Callbacks;
@MattRix
MattRix / CurvatureImageEffect.shader
Last active February 2, 2024 20:15
Cavity/Curvature image effect shader based on the Blender node graph in this post: https://blender.community/c/rightclickselect/J9bbbc/
Shader "Milkbag/CurvatureImageEffect"
{
Properties
{
_MainTex ("Texture", 2D) = "white" {}
_LightStrength ("LightStrength", Float) = 0.3
_DarkStrength ("DarkStrength", Float) = 0.3
_Spread ("Spread", Float) = 1.0
[Toggle(USE_MULTIPLY)] _UseMultiply("Use Multiply", Float) = 0
[Toggle(CURVATURE_ONLY)] _CurvatureOnly("Curvature Only", Float) = 0
@MattRix
MattRix / cellular_noise.cginc
Created March 1, 2021 23:10
Worley cellular noise for HLSL (and Unity), translated from from Stefan Gustavson's GLSL version
// Cellular noise ("Worley noise") in 2D in GLSL.
// Copyright (c) Stefan Gustavson 2011-04-19. All rights reserved.
// This code is released under the conditions of the MIT license.
// See LICENSE file for details.
// https://github.com/stegu/webgl-noise
// Modulo 289 without a division (only multiplications)
float3 mod289(float3 x) {
return x - floor(x * (1.0 / 289.0)) * 289.0;
@MattRix
MattRix / RXLookingGlass.cs
Created November 3, 2014 21:09
This class wraps an internal Unity method that lets you to check if a ray intersects a mesh. Place it in an Editor folder.
using UnityEngine;
using UnityEditor;
using System.Collections;
using System;
using System.Linq;
using System.Reflection;
[InitializeOnLoad]
public class RXLookingGlass
{
@MattRix
MattRix / PhysicsFollower.cs
Last active October 1, 2023 03:22
A thing you can use to make a rigidbody move towards a position reliably
using UnityEngine;
using System.Collections;
using System;
[RequireComponent (typeof(Rigidbody))]
public class PhysicsFollower : MonoBehaviour
{
public Transform target;
Rigidbody rb;
@MattRix
MattRix / ReadOnlyAttribute.cs
Last active September 23, 2023 16:34
Read Only Attribute for Unity (just mark stuff as [ReadOnly] the same way you would use [HideInInspector])
using UnityEngine;
using System;
using System.Reflection;
using System.Text.RegularExpressions;
[AttributeUsage (AttributeTargets.Field,Inherited = true)]
public class ReadOnlyAttribute : PropertyAttribute {}
#if UNITY_EDITOR
[UnityEditor.CustomPropertyDrawer (typeof(ReadOnlyAttribute))]
@MattRix
MattRix / VertBend.cs
Created December 30, 2016 02:37
Example of doing a vertex modifer for Unity UI stuff
using UnityEngine.UI;
using System.Collections.Generic;
using System;
using UnityEngine;
public class VertBend : BaseMeshEffect
{
public override void ModifyMesh(VertexHelper vh)
{
if(!IsActive()) return;