Skip to content

Instantly share code, notes, and snippets.

@treefortress
treefortress / ParticleScaler.cs
Last active October 7, 2019 04:29
Scale Unity ParticleSystem at Runtime
using UnityEngine;
public static class ParticleExtensions
{
/// Add Extension to the native ParticleSystem class.
/// eg: myParticleSystem.Scale(2);
public static void Scale(this ParticleSystem particles, float scale, bool includeChildren = true) {
ParticleScaler.Scale(particles, scale, includeChildren);
}
@treefortress
treefortress / LargeTexturePackerPolicy.cs
Created January 4, 2016 18:05
SpritePacker policy for Unity to allow 4K texture atlases.
using UnityEngine;
using System;
using System.Linq;
using UnityEditor;
using System.Collections.Generic;
public class LargeTexturePackerPolicy : UnityEditor.Sprites.IPackerPolicy
{
protected class Entry
@treefortress
treefortress / SimpleTouchManager
Last active August 29, 2015 14:07
Extension for InControl Unity Controller Plugin - Allows creation of Simple Touch Buttons from any GameObject.
using UnityEngine;
using System.Collections;
using InControl;
/** Attach this to some persistent object in your scene **/
public class SimpleTouchManager : MonoBehaviour
{
void Update() {
//All Buttons should exist on the UI layer to avoid collisions with other GameObjects.
int UILayerMask = 1 << LayerMask.NameToLayer("UI");
@treefortress
treefortress / gist:de581564b86401d7e935
Last active February 22, 2017 08:06
StringHash Class for C# - For easy creation of string-based Hashtables
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class StringHash<T> {
Dictionary<string, T> dictionary = new Dictionary<string, T>();
public void Set(string key, T value) {
if (HasKey(key)) {
@treefortress
treefortress / gist:1a9349d9e77e732f1c4a
Created September 15, 2014 16:21
C# - Generic Action Dispatchers w/ Built-in null check
public class ActionDispatcher {
protected void Dispatch(Action action) {
if (action != null) {
action();
}
}
protected void Dispatch<T0>(Action<T0> action, T0 param0) {
if (action != null) {
action(param0);
}
@treefortress
treefortress / AnimatedTilesScript.cs
Last active June 29, 2016 20:00
Animated Tiles with 2dToolkit for Unity
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
//Drop this on the parent of a 2dToolkit TileMap to animate some of the child sprites.
//The name of each sprite must be hardcoded into the Start() fxn.
public class AnimateTileMapScript : MonoBehaviour {
public tk2dSpriteCollectionData spriteCollection;