Skip to content

Instantly share code, notes, and snippets.

View fuzzblob's full-sized avatar
🐙
they/them

Maris Tammik fuzzblob

🐙
they/them
  • Vancouver, BC
View GitHub Profile
@fuzzblob
fuzzblob / FlatPanning.cs
Created March 4, 2019 16:37
Some methods to use the cameras Viewport to apply panning and distnace attenuation to audio
/*
* ABOUT:
*
* Simple script to convert Vector3 position to 2D panning position and distance
* attenuation based on the camera viewport. useful for 2D and isometric games.
*
* ############################################################
*
* MIT License
*
@fuzzblob
fuzzblob / AudioVoices.cs
Last active January 11, 2019 02:50
simple approach to limiting how many AudioSources play a specific clip in Unity
/*
* Usage:
*
* in some other script create an AudioVoices object
*
* public AudioVoices voiceLimiting = new AudioVoices();
*
* then when playing a sound first add the AudioSource to the AudioVoices
* passing the maximum amount of instances and only play it if the source got added:
*
@fuzzblob
fuzzblob / EditorUtil.Waveform.cs
Created October 29, 2018 22:19
Unity Waveform UI with customizable resolution
/*
// UI inspector example implementation
Rect waveformRect = GUILayoutUtility.GetRect(waveformSize.x, waveformSize.y, GUIStyle.none);
EditorUtil.Waveform(waveformRect, clip, waveformSize);
float playMarker = 0f; // replace with a 0-1 seek position
if (playMarker >= 0f) {
Rect progressRect = new Rect(waveformRect);
float width = progressRect.width * playMarker;
progressRect.width = Mathf.Clamp(width, 6, width);
@fuzzblob
fuzzblob / HashedList.cs
Created July 11, 2018 16:41
A data structure with fast Conains check (through HashSet<T>) that also allows fast iteration (through List<T>)
using System.Collections.Generic;
public class HashedList<T>
{
private List<T> _list;
private HashSet<T> _set;
public List<T> Elements { get { return _list; } }
public T this[int i]
@fuzzblob
fuzzblob / EditorHelper.cs
Created October 20, 2017 05:21
simple Unity inpector GUI element for a value and a random offset in a single range slider
#if UNITY_EDITOR
using UnityEngine;
using UnityEditor;
public class EditorHelper
{
public static GUILayoutOption[] __buttonOptions = new GUILayoutOption[] { GUILayout.Width(120f), GUILayout.ExpandWidth(false) };
public static void RandomRangeSlider(string propertyName, ref float val, ref float rand, ref bool randomEnabled, float min, float max, float resetValue)
{
@fuzzblob
fuzzblob / Unity_CSV.cs
Last active March 14, 2017 21:28
Two classes to make generating report and exporting data for debugging etc easy
public class CsvHandler
{
public static void ExportStringData(string filename, string data, string defaultPath = "Assets/Debug/Log/")
{
filename += "_" + MUtil.DateStamp();
string path = defaultPath;
#if UNITY_EDITOR
path = UnityEditor.EditorUtility.SaveFilePanel("Save Data", defaultPath, filename, "csv");
#else
path += filename + ".csv";
@fuzzblob
fuzzblob / EditorUtils.cs
Created March 10, 2017 16:54
a collection of Unity editor scripting calls for custom inspectors and tools
public class EditorUtils
{
public static bool WarningDialog(string message = "")
{
if (message == "")
message = "Are you sure you want to Continue?";
if (EditorUtility.DisplayDialog("Continue ?", message, "Continue", "Cancel"))
{
return true;
}
@fuzzblob
fuzzblob / MidiHelper.cs
Created March 6, 2017 20:05
A small helper class to help deal with midi information
public class MidiHelper
{
static string[] __notesShatp = new string[] { "C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "B" };
static string[] __notesFlat = new string[] { "C", "Db", "D", "Eb", "E", "F", "Gb", "G", "Ab", "A", "Bb", "B" };
public static string MidiCodeToString(int midiCode, bool flats = false)
{
int octave = midiCode / 12 - 1;
if (octave < 0)
@fuzzblob
fuzzblob / BasicAudioConversions.cs
Created February 18, 2017 04:03
A little collection of handy conversions to do randomisation and control audio properties
using UnityEngine;
public class BasicAudioConversions
{
private static float twelfthRootOfTwo = Mathf.Pow(2, 1.0f / 12);
public static float St2pitch(float st)
{
return Mathf.Clamp(Mathf.Pow(twelfthRootOfTwo, st), 0f, 4f);
}
public static float Pitch2st(float pitch)
@fuzzblob
fuzzblob / WeightedPlayback
Created September 23, 2016 01:04
logic to randomize between sound (or other things) with weighted priorities
bool WeightedPlaylist()
{
bool playlistResult = false;
int playListLength = _playlist.Clips.Count;
int totalWeight = 0;
for (int i = 0; i < _playlist.Clips.Count; i++) {
totalWeight += _playlist.Weights[i];
}
int choice = 0;