Skip to content

Instantly share code, notes, and snippets.

View thebeardphantom's full-sized avatar

Mika Notarnicola thebeardphantom

View GitHub Profile
@thebeardphantom
thebeardphantom / ZeroAll.cs
Last active December 4, 2023 07:51
A quick way to reset transforms in Unity3D!
using UnityEngine;
using System.Collections;
using UnityEditor;
namespace BSGTools {
namespace EditorUtilities {
public class ZeroAll : Editor {
[MenuItem("GameObject/Reset/Zero All %&a")]
static void ResetAll() {
GameObject[] selection = Selection.gameObjects;
@thebeardphantom
thebeardphantom / TransformExtensions.cs
Created December 10, 2014 18:38
This script has some super useful methods for aligning and moving transforms.
using System;
using UnityEngine;
namespace BSGTools.Extensions {
public static class TransformExtensions {
public static void SetTreePosition(this Transform child, Transform target) {
child.root.position = target.position;
child.root.position += target.position - child.position;
}
@thebeardphantom
thebeardphantom / Normalizer.cs
Last active August 29, 2015 14:11
Ever need to normalize an angle of 1748 or -191857 degrees to 0...360 or -180...180? Now you can!
namespace BSGTools.Math {
public static class Normalizer {
public static float NormalizeAngle(float value) {
return Normalize(value, 0f, 360f);
}
public static float Normalize(float value, float start, float end) {
float width = end - start;
float offsetValue = value - start; // value relative to 0
@thebeardphantom
thebeardphantom / GameState.cs
Last active August 29, 2015 14:13
GameState
using System;
using System.Collections.Generic;
using System.IO;
using UnityEngine;
using SE = System.Environment;
using SF = System.Environment.SpecialFolder;
public static class GameState {
static string _STATE_FOLDER = CombinePaths(SE.GetFolderPath(SF.MyDocuments), "My Games");
public static string STATE_FOLDER { get { return _STATE_FOLDER; } set { _STATE_FOLDER = value; } }
@thebeardphantom
thebeardphantom / .gitignore
Last active April 9, 2017 13:08
Unity GitIgnore
# Ignore everything
/*
/*/
# Inverse ignore some stuff
!/Assets/
!/ProjectSettings/
!.gitignore
# OS Stuff
@thebeardphantom
thebeardphantom / Gamma.cs
Last active August 29, 2015 14:13
Unity Gamma Control
using UnityEngine;
using System.Collections;
using UnitySampleAssets.ImageEffects;
[ExecuteInEditMode]
[AddComponentMenu("Image Effects/Color Adjustments/Gamma")]
public class Gamma : PostEffectsBase {
public enum ColorCorrectionMode {
Simple = 0,
Advanced = 1
@thebeardphantom
thebeardphantom / DistanceAwareOutline.shader
Created February 12, 2015 21:48
Distance Aware Outline
// Shader created with Shader Forge v1.04
// Shader Forge (c) Neat Corporation / Joachim Holmer - http://www.acegikmo.com/shaderforge/
// Note: Manually altering this data may prevent you from opening it in Shader Forge
/*SF_DATA;ver:1.04;sub:START;pass:START;ps:flbk:Diffuse,lico:1,lgpr:1,nrmq:1,limd:1,uamb:True,mssp:True,lmpd:False,lprd:False,rprd:False,enco:False,frtr:True,vitr:True,dbil:False,rmgx:True,rpth:0,hqsc:True,hqlp:False,tesm:0,blpr:0,bsrc:0,bdst:1,culm:0,dpts:2,wrdp:True,dith:2,ufog:True,aust:True,igpj:False,qofs:0,qpre:1,rntp:1,fgom:False,fgoc:False,fgod:False,fgor:False,fgmd:0,fgcr:0.5,fgcg:0.5,fgcb:0.5,fgca:1,fgde:0.01,fgrn:0,fgrf:300,ofsf:0,ofsu:0,f2p0:False;n:type:ShaderForge.SFN_Final,id:2942,x:32753,y:32707,varname:node_2942,prsc:2|diff-1116-RGB,olwid-5129-OUT,olcol-2465-RGB;n:type:ShaderForge.SFN_Color,id:2465,x:32474,y:33133,ptovrint:False,ptlb:lineColor,ptin:_lineColor,varname:_outlineColor,prsc:2,glob:False,c1:1,c2:1,c3:0.5607843,c4:1;n:type:ShaderForge.SFN_Tex2d,id:1116,x:32519,y:326
@thebeardphantom
thebeardphantom / SWSM.js
Last active August 29, 2015 14:15
Steam Workshop Subscription Manager (SWSM)
javascript:(function(){ try { var version="1.1.3";var xmlHttp=null;xmlHttp=new XMLHttpRequest();xmlHttp.open("GET","https://api.github.com/gists/14a1c2ab6d69a832f29b",false);xmlHttp.send(null);var raw=xmlHttp.responseText;var json=JSON.parse(raw);if(json.files["version.txt"]["content"]!=version){prompt("There is a new version of SWSM. The latest script has been retrieved and is in the below text box. Edit your SWSM bookmarklet, replace the current URL value with the value below, and then rerun the bookmarklet.",json.files["SWSM.js"]["content"]);return;} } catch(err){} var unsubAll=false;var wl=window.location.toString();if(wl.toString().indexOf("browsefilter=mysubscriptions")==-1||wl.indexOf("steamcommunity.com")==-1){var uPrompt=prompt("Not on the correct page! Enter your steam username (not account name!). When the workshop page finishes loading, run this bookmarklet again.");if(uPrompt!=null){window.location="http://steamcommunity.com/id/"+uPrompt+"/myworkshopfiles?browsefilter=mysubscriptions&numperpage=3
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
namespace Rubycone.BoltAction {
[ExecuteInEditMode]
[RequireComponent(typeof(LayoutElement))]
public class InferSize : MonoBehaviour {
public Graphic targetGraphic;
@thebeardphantom
thebeardphantom / SceneLoader.cs
Last active August 29, 2015 14:19
SceneLoader
using System.Collections;
using System.Linq;
using UnityEngine;
namespace Rubycone.Utils {
public delegate void LoadComplete(GameObject loaded);
public class SceneLoader : MonoBehaviour {
public event LoadComplete LoadComplete;
public AsyncOperation operation { get; private set; }