Skip to content

Instantly share code, notes, and snippets.

using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public static class TransformExtensions
{
static Stack<Transform> moveTargets = new Stack<Transform> (); //This is only used by SetLayerToThisAndChildren
public static void SetLayerToThisAndChildren (this Transform root, int layer)
{
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[ExecuteInEditMode]
public class TubeTrail : MonoBehaviour
{
public int sections = 16;
public float radius = 0.5f;
public int columns = 8;
using UnityEngine;
using System.Collections;
public static class ComponentExtensions
{
static public T GetChildComponent<T> (this Component parent, string path, bool ignoreErrors = false) where T:Component
{
var child = parent.transform.Find (path);
if (child == null) {
if (!ignoreErrors)
@drZool
drZool / MathUtils.cs
Last active April 30, 2020 20:35
Commonly used math functions not included in unity
using UnityEngine;
using System.Collections;
public static class MathUtils
{
public const float TAU = Mathf.PI * 2;
public static float MoveTowards (float current, float goal, float amount)
{
var delta = goal - current;
@drZool
drZool / SuspendCompileInPlayMode.cs
Created June 30, 2017 09:43
Suspends compilation in play mode but also suspends live reload of other assets such as textures and shaders.
using UnityEngine;
using UnityEditor;
[InitializeOnLoad]
public class SuspendCompileInPlayMode
{
#pragma warning disable 0414
private static SuspendCompileInPlayMode _instance = null;
#pragma warning restore 0414
@drZool
drZool / TerrainSplatShader.shader
Created May 31, 2017 14:50
Shader for replicating Unitys terrain. 4 splatmaps supported.
Shader "TerrainSplatShader" {
Properties {
_MainTex ("Base (RGBa)", 2D) = "white" {}
_Smoothness1 ("_Smoothness1", Range(0, 1.0)) = 0.3
_Metallic1 ("_Metallic1", Range(0, 1.0)) = 0.3
_MainTex2 ("Base2 (RGBq)", 2D) = "white" {}
_Smoothness2 ("_Smoothness2", Range(0, 1.0)) = 0.3
_Metallic2 ("_Metallic2", Range(0, 1.0)) = 0.3
@drZool
drZool / TerrainTexturing.cs
Created May 26, 2017 13:38
Auto texture terrain based on steepness and existing textures
using UnityEngine;
using System.Collections;
using UnityEditor;
public class TerrainTexturing : EditorWindow
{
[MenuItem ("Hello/Terrain/Texturing")]
static void OpenEditor ()
{
EditorWindow.GetWindow<TerrainTexturing> ();
@drZool
drZool / Graph.cs
Last active April 27, 2017 13:56
Write a graph to a texture
/*
Write a graph to a texture
Usage:
void Start(){
graph = new Graph (512, 256, new Color[]{ Color.red, Color.green, Color.blue });
graphRenderer.material.mainTexture = graph.texture;
}
void Update(){
@drZool
drZool / Pool.cs
Last active June 24, 2019 08:48
A pool that gets unloaded if the scene is unloaded.
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class Pool : MonoBehaviour
{
static Pool instance;
static public Pool Instance
{
@drZool
drZool / CameraListEditor.cs
Created April 11, 2017 13:01
List cameras
using UnityEditor;
using System.Collections.Generic;
using UnityEngine;
public class CameraListEditor : EditorWindow
{
private List<Camera> cameras = new List<Camera>();
[MenuItem("Hello/Scene/Camera List")]
public static void Init()