Skip to content

Instantly share code, notes, and snippets.

@N-Carter
N-Carter / EndlessTiles.cs
Created March 13, 2013 09:17
Tilemap made up of batched TextMesh prefabs (could also work with other meshes)
using UnityEngine;
using System.Collections;
public class EndlessTiles : MonoBehaviour
{
[SerializeField] protected Tile m_TilePrefab;
[SerializeField] protected Material[] m_Materials;
[SerializeField] protected Material m_TouchedMaterial;
protected Tile[,] m_Tiles;
@N-Carter
N-Carter / FontEditor.cs
Created March 4, 2013 10:21
Adds tools to the Font inspector to let you lay out the character rects in a grid.
using UnityEngine;
using UnityEditor;
using System.Collections;
[CustomEditor(typeof(Font))]
public class FontEditor : Editor
{
Font m_Font;
static bool m_TilingControlsVisible;
@N-Carter
N-Carter / ReferenceRefTest.cs
Created January 28, 2013 11:30
Using the ref keyword with reference types
class ReferenceRefTest
{
class C
{
public int i;
public C(int i) {this.i = i;}
}
static int Main()
@N-Carter
N-Carter / FindMissingScripts.cs
Created November 5, 2012 12:36
Find Missing Scripts by Richard Fine (SuperPig)
// By Richard Fine
[MenuItem("Tools/Find missing scripts")]
public static void FindMissingScripts()
{
var allTransforms = FindSceneObjectsOfType(typeof (Transform));
foreach(Transform t in allTransforms)
{
if(t.gameObject.GetComponents<Component>().Any(c => !c))
Debug.LogError("One or more scripts on " + t.gameObject + " is missing.", t.gameObject);
@N-Carter
N-Carter / Triangulator.cs
Created September 18, 2012 08:45
Alternative Triangulator constructor
public Triangulator(Vector3[] points)
{
m_points = points.Select(vertex => new Vector2(vertex.x, vertex.y)).ToList();
}
@N-Carter
N-Carter / JavascriptProperty.js
Created September 16, 2012 23:49
Properties in Javascript
#pragma strict
var whatever = 0;
function Start()
{
Whatever = 1;
Debug.Log(Whatever);
}
@N-Carter
N-Carter / InputManager.asset
Created August 16, 2012 20:34
A sample text-mode InputManager.asset file
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!13 &1
InputManager:
m_ObjectHideFlags: 0
m_Axes:
- serializedVersion: 3
m_Name: Horizontal
descriptiveName:
descriptiveNegativeName:
protected Bounds OnGetFrameBounds()
{
Bounds bounds;
if(m_SelectedWaypoints.Count > 0)
{
// Focus the selected waypoints:
bounds = new Bounds(m_Path.transform.TransformPoint(m_SelectedWaypoints.First().position), Vector3.zero);
foreach(var waypoint in m_SelectedWaypoints.Skip(1))
@N-Carter
N-Carter / SplineMeshEditor.cs
Created May 14, 2012 23:22
Custom inspector for SplineMesh
using UnityEngine;
using UnityEditor;
using System.Collections;
using System.Linq;
[CustomEditor(typeof(SplineMesh))]
public class SplineMeshEditor : Editor
{
protected SplineMesh m_Target;
protected MeshFilter m_MeshFilter;
@N-Carter
N-Carter / SplineMesh.cs
Created May 14, 2012 23:21
Spline mesh
using UnityEngine;
using System.Collections.Generic;
using System.Linq;
public class SplineMesh : MonoBehaviour
{
[System.Serializable]
public class Node
{
public Vector3 position;