Skip to content

Instantly share code, notes, and snippets.

View HilariousCow's full-sized avatar

Aubrey Hesselgren HilariousCow

  • Seattle
View GitHub Profile
@HilariousCow
HilariousCow / AnimatorExtensions.cs
Last active January 30, 2017 17:05
Some Animator extensions I use to reduce the clutter involved in setting up a hashed call to an animator parameter
using System;
using UnityEngine;
using System.Collections;
[Serializable]
public class AnimParam
{
private readonly int _hashed;//a cached off version of the hashed string
private readonly string _paramName;//don't really need but good for debug?
private readonly Animator _anim;
@HilariousCow
HilariousCow / CopyAssetPathContextMenu.cs
Last active November 22, 2016 15:15
Unity3d utility thing. Right Click an asset-> Copy Asset Path. - ideal for use with AssetDatabase.LoadAssetAtPath<>
using UnityEngine;
using UnityEditor;
public static class CopyAssetPathContextMenu
{
[MenuItem("Assets/Copy Asset Path")]
public static void CopyAssetPath()
{
if (Selection.activeObject != null)
@HilariousCow
HilariousCow / InteractionRaycaster.cs
Last active October 15, 2023 23:29
If you are finding that PhysicsRaycaster isn't working when you use Cursor.lockstate (i.e. an FPS game), use this instead.
using System;
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using UnityEngine.EventSystems;
//I used ILSpy on the Unity UI dll to copy out the Physicsraycaster code and fix where the ray eminates from (in this case, always the center of the screen)
public class InteractionRaycaster : PhysicsRaycaster {
[Range(0.0f, 0.5f)]
@HilariousCow
HilariousCow / Example use
Last active August 12, 2021 23:39
AnimParam TidyUp code - so that your controller scripts aren't dripping in hashed versions of Animator parameters.
class MyControllerComponent : MonoBehaviour{
Animator _anim;
AnimParam _myTrigger;
void Awake()
{
_anim = GetComponent<Animator>();
_playbackDurations = GetComponent<PlaybackDurationManager>();
_myTrigger = _anim.AnimParam("StartThings");
}
@HilariousCow
HilariousCow / VertexAlphaPlusColor
Last active December 16, 2015 13:14
So, blender doesn't do vertex alpha, annoyingly, which would be great, as it's a good way to mask out edges of meshs when you have other groovey effects going on the surface (think skyrim's wind gusts). This shader will just take blender's RGB values (i.e. luminescance) and use THAT as the alpha mask. It's otherwise a bog standard Texture * colo…
Shader "Unlit/VertexAlphaPlusColour"
{
Properties
{
_MainTex ("Texture", 2D) = "white" {}
_Color("Color", Color) = (1,1,1,1)
}
SubShader
{
Tags { "Queue"="Transparent" "RenderType"="Opaque" }
@HilariousCow
HilariousCow / gist:7f301b04c28fdf61e71f
Last active March 31, 2024 18:33
Load All Prefabs In Directory
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using System.IO;
public static class PrefabLoader
{
//So, there's no "load all assets in directory" function in unity.
//I guess this is to avoid people using Prefabs as "data blobs".
//They'd rather you use ScriptableObjects... which is fine in some cases,
public class OneOneOneTwoThree
{
bool[] Null(bool[] t)
{
return t;// lol
}
bool[] Swap(bool[] t)
{
bool[] s = new bool[4];
@HilariousCow
HilariousCow / Vector3Extensions
Last active July 5, 2018 15:21
Just some handy vector3 extensions I use a lot. I like using "FlatY" a lot for games on 2D planes.
using UnityEngine;
using System.Collections;
public static class Vector3Extensions {
public static Vector3 Flattened(this Vector3 vec, Vector3 planeNormal)
{
return Vector3.ProjectOnPlane(vec, planeNormal);
}
@HilariousCow
HilariousCow / BoundsHelperExtensions
Created February 24, 2015 10:19
A few helpful extensions to get the render bounds (world space) of a game object, including all its children. Handy for placement at the edges of groups of meshes/text, or finding dead center.
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public static class BoundsHelperExtensions
{
public static Bounds WorldBounds<T>(this List<T> listOfThings) where T : MonoBehaviour
{
Bounds bounds = new Bounds(listOfThings[0].transform.position, Vector3.zero);
foreach (T thing in listOfThings)
@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)
{