Skip to content

Instantly share code, notes, and snippets.

/* SmoothSwitcher.cs
* Copyright Eddie Cameron 2015
* ----------------------------
* When you want some value to switch slowly between on and off without all that fuss about whether it's already changing or whatnot
* (eg: light dimmer switch, audio fade in/out, zoom)
* -----------------------------
* Can be added to an object at runtime, with SmoothSwitcher.SetupSmoothSwitcher(...)
* Otherwise, make sure to set the SmoothSwitcher's onAmountSet event in the inspector, which will be called whenever the 'on amount' changes
* (when setting an event listener method, make sure to choose a 'dynamic' method in the selection menu, otherwise it'll just call whatever number is in the box)
* -----------------------------
/// <summary>
/// Convert a KeyCode into the string that Unity uses in GetKeyString
/// (ToString returns a different value -_-)
/// </summary>
/// <param name="kc"></param>
/// <returns></returns>
public static string KeycodeToKeyString( KeyCode kc ) {
switch ( kc ) {
// numerals
case KeyCode.Alpha0:
@EddieCameron
EddieCameron / GroupSelected.cs
Last active October 13, 2020 17:37
Unity Group Selected GameObjects Command
/* GroupSelected.cs
* © Eddie Cameron 2020
* ----------------------------
*/
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
/// <summary>
/// Groups all selected scene transforms under a single parent.
@EddieCameron
EddieCameron / SceneViewShaderKeyword.cs
Last active November 26, 2020 20:20
Add to your scene to have a shader keyword enabled/disabled only for the scene view. Use for debug materials, scene visualisations
/* SceneViewShaderKeyword.cs
* © Eddie Cameron 2020
* ----------------------------
*/
using System;
using UnityEngine;
#if UNITY_EDITOR
using UnityEditor;
@EddieCameron
EddieCameron / CanvasMesh.cs
Last active April 25, 2023 08:02 — forked from YclepticStudios/CanvasMesh.cs
Unity script for rendering a mesh inside the canvas UI.
/**
* ============================================================================
* MIT License
*
* Copyright (c) 2017 Eric Phillips
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
@EddieCameron
EddieCameron / ReorderableList.cs
Last active August 7, 2023 09:36
ReorderableList Property Drawer
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
/// In Unity pre 2020, each different type you want to make a list from needs its own subclass, like UnityEvents.
/// eg :
/// [Serializable] public class IntReorderableList : ReorderableList<int> {}
[Serializable]
@EddieCameron
EddieCameron / EdgeDetect.cs
Created September 3, 2017 00:08
EdgeDetection in new Unity Postprocessing Stack
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Rendering.PostProcessing;
[Serializable]
[PostProcess( typeof( EdgeDetectRenderer ), PostProcessEvent.BeforeStack, "Custom/EdgeDetectNormals" )]
public sealed class EdgeDetect : PostProcessEffectSettings {
public enum EdgeDetectMode {