Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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;
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)
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;
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)
{
@drZool
drZool / MatchPositionWithChild.cs
Created April 18, 2018 11:31
Keep position/rotation of child object same as a world object by moving/rotating it's parent.
using UnityEngine;
using System.Collections;
[ExecuteInEditMode]
public class MatchPositionWithChild : MonoBehaviour
{
public Transform target;
public Transform follower;
public Transform anchor;
public bool UpdatePositions;
@drZool
drZool / ListExtensions.cs
Created April 20, 2018 09:22
String Join IList extension
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System;
public static class ListExtensions
{
static public string Join<T> (this IList<T> list, string separator)
{
@drZool
drZool / Sounds.cs
Last active March 22, 2019 13:16
Bare bones sound handling. Depends on Pool and LerpHelper.
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
/// <summary>
/// Bare bones sound handling.
/// Init with AddSources(sources), supply the sources you want to be able to play.
/// Depends on
/// Pool: https://gist.github.com/drZool/f9a44489c5e8f815d408642d6d4c46f0
/// LerpHelper: https://gist.github.com/drZool/2938bc198ebccee0931d98798bd86cfa
@drZool
drZool / AnimatorViewTrigger.cs
Last active May 6, 2019 11:54
Simple transition system. Depends on LerpHelper https://gist.github.com/drZool/2938bc198ebccee0931d98798bd86cfa and uses Profiler but that can be removed
using UnityEngine;
using System.Collections;
[RequireComponent(typeof(View))]
public class AnimatorViewTrigger : MonoBehaviour
{
public AnimationEvent[] events;
View view;
public bool debug;
public bool OneActiveTriggerOnly;