Skip to content

Instantly share code, notes, and snippets.

// The MIT License (MIT) - https://gist.github.com/bcatcho/1926794b7fd6491159e7
// Copyright (c) 2015 Brandon Catcho
using System;
// Place this file in any folder that is or is a descendant of a folder named "Scripts"
namespace CatchCo
{
// Restrict to methods only
[AttributeUsage(AttributeTargets.Method)]
public class ExposeMethodInEditorAttribute : Attribute
using UnityEngine;
using System;
namespace CatchCo
{
public class InspectorTypeEnforcerAttribute : PropertyAttribute
{
public Type EnforcedType;
public InspectorTypeEnforcerAttribute(Type enforcedType)
@bcatcho
bcatcho / CardFactory.cs
Last active August 29, 2015 13:57
An example off the top of my head to show how to use a single mesh to make many with different textures from an atlas. Is a reply to a reddit thread: http://www.reddit.com/r/Unity3D/comments/2199b2/a_little_help_with_playing_cards/
using UnityEngine;
public class CardFactory : MonoBehaviour
{
// this will be the source mesh that every card will be based off of
public Mesh SourceMesh;
// the number of rows & columns in your texture atlas
public int AtlasRows;
public int AtlasColumns;
@bcatcho
bcatcho / WorldXZTilingExample.shader
Created February 14, 2014 04:33
World Tiling example
// Shader created with Shader Forge Beta 0.23
// Shader Forge (c) Joachim Holmer - http://www.acegikmo.com/shaderforge/
// Note: Manually altering this data may prevent you from opening it in Shader Forge
/*SF_DATA;ver:0.23;sub:START;pass:START;ps:lgpr:1,nrmq:1,limd:1,blpr:0,bsrc:0,bdst:0,culm:0,dpts:2,wrdp:True,uamb:True,mssp:True,ufog:True,aust:True,igpj:False,qofs:0,lico:1,qpre:1,flbk:,rntp:1,lmpd:False,lprd:False,enco:False,frtr:True,vitr:True,dbil:False,rmgx:True,hqsc:True,hqlp:False,fgom:False,fgoc:False,fgod:False,fgor:False,fgmd:0,fgcr:0.7098039,fgcg:0.7098039,fgcb:0.7098039,fgca:1,fgde:0.01,fgrn:41.4,fgrf:400,ofsf:0,ofsu:0;n:type:ShaderForge.SFN_Final,id:1,x:32411,y:32654|diff-3-RGB,amdfl-12-RGB;n:type:ShaderForge.SFN_Tex2dAsset,id:2,x:33131,y:32604,ptlb:node_2,tex:8993b617f08498f43adcbd90697f1c5d;n:type:ShaderForge.SFN_Tex2d,id:3,x:32767,y:32694,tex:8993b617f08498f43adcbd90697f1c5d,ntxv:0,isnm:False|UVIN-23-OUT,TEX-2-TEX;n:type:ShaderForge.SFN_FragmentPosition,id:11,x:33302,y:32976;n:type:ShaderFor
@bcatcho
bcatcho / ScriptableObj2Asset Readme.md
Created January 26, 2014 20:18
This utility script will give you an option in the Assets/Create menu that will allow one to instantiate a selected scriptable object script and save it as an asset. It also works by right clicking on the file in the project window and selecting

What it does

This script provides a context menu item in the Project window (as well as an extra option in the Assets>Create menu) that will instantiate the selected Scriptable object and save it as an asset to a folder of your choosing.

How to install

Throw this script in any folder called Editor in your assets folder.

How to use

@bcatcho
bcatcho / 0_reuse_code.js
Created November 23, 2013 23:34
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@bcatcho
bcatcho / AttackAbility.cs
Created November 9, 2013 21:09
This is a response to a r/Unity3d post that talked about many issues. The main issue I saw was how to separate responsibilities in your components. The example below is not *exactly* what I would do but it get's the point across.
public class AttackAbility : MonoBehaviour
{
// this is how you declare a delgate (in case you didn't know)
public delegate void OnDidAttackDelegate(GameObject target, AttackAbility attackAbility);
// this the event that other scripts will subscribe on to know when we have attacked
public event OnDidAttackDelegate OnDidAttack;
private void Update()
{
@bcatcho
bcatcho / EditorRenderer.cs
Created November 2, 2013 23:29
The beginnings of a helper class to render procedural meshes in edit mode. (unity3d)
public class EditorRenderer
{
public Mesh Mesh {get;set;}
public Material Material {get;set;}
private Transform _transform;
public Transform Transform
{
@bcatcho
bcatcho / LightProbeManager.cs
Created October 27, 2013 17:32
lightprobe lighting in unity3d: This was a quick test made in a couple of hours. Seems to get the job done.
using UnityEngine;
using System.Collections;
public class lightprobemanager : MonoBehaviour
{
public Color ambient;
public Light[] lights;
private float[] _coefficients;
private int _probeCount;
private const int _coefficientsPerProbe = 27;
@bcatcho
bcatcho / ConcreteClasses.cs
Last active December 25, 2015 09:39
Read the Readme.md near the bottom
public class LocalSerializer: ILocalSerializer
{
public void LoadSomeStuff(DataManager dataManager)
{
/* Pretend this loads resources*/
List<Resources> resources = Resources.Load("thestuff.ini");
manager.LoadResources(resources);
}
}