Skip to content

Instantly share code, notes, and snippets.

@twobob
twobob / A set of Unity3D extension methods
Created August 18, 2018 18:28 — forked from omgwtfgames/A set of Unity3D extension methods
Some useful extension method for Unity3D
A collection of useful C# extension methods for the Unity engine.
@Alex-Huleatt
Alex-Huleatt / dungeon_maker.py
Last active June 19, 2018 15:29
Simple dungeon maker. Guaranteed connectedness.
'''
@author AlexHuleatt
Generate a simple, connected dungeon. Focus is on rooms, not maze-like features.
Output of get_dungeon is two sets:
1. A set of (y,x) tuples representing the position of walls
2. A set of (y,x) tuples representing the walls removed to make doors
'''
from random import randint, sample
@n1ckfg
n1ckfg / ZipExample.cs
Created September 20, 2017 13:36
Compress and decompress using SharpZipLib in Unity
// http://www.sebaslab.com/how-to-compress-and-decompress-binary-stream-in-unity/
using ICSharpCode.SharpZipLib.BZip2;
using System.Runtime.Serialization.Formatters.Binary;
using System.IO;
static void Compress (string nameOfTheFileToSave, ISerializable objectToSerialize)
{
using (FileStream fs = new FileStream(nameOfTheFileToSave, FileMode.Create))
{
using UnityEngine;
public class SimpleSoundManager:MonoBehaviour {
// Audio source
private AudioSource musicSrc;
private AudioSource effectSrc;
// Instance variable
private static SimpleSoundManager instance;
// Instance
@alexcmd
alexcmd / MeshCut.cs
Created December 29, 2015 08:29
Mesh cut algorithm for Unity
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class MeshCut
{
private static Plane blade;
private static Transform victim_transform;
private static Mesh victim_mesh;
#pragma once
// This provides a library for stubbing and mocking C++ code as is. It works by requiring
// explicit hooks to be inserted into the code that is to be mocked. In a regular build,
// these hooks will do nothing. In a testing build, they will expand to calls into the
// framework here to allow the code being executed to be hijacked from outside.
//
// NOTE: Thread-safety! Arranging fakes must be done on a single thread. Using fakes can
// be done from multiple threads concurrently.
//
@paraself
paraself / EditorPlayMode
Last active October 30, 2023 14:38
Unity Play Mode Detection
//originally adopted from
//http://answers.unity3d.com/questions/447701/event-for-unity-editor-pause-and-playstop-events.html
//with a few modifications which makes the event firing nicer and cleaner
//Usage Example :
//
//using UnityEditor;
//using UnityEngine;
//
//[InitializeOnLoad]
//public class SingleEntryPoint
@YoriKv
YoriKv / Force2DSound.cs
Created April 28, 2015 05:44
Unity Editor Script - Force2DSound on Import
using UnityEditor;
using UnityEngine;
public class Force2DSound:AssetPostprocessor {
public void OnPreprocessAudio() {
AudioImporter ai = assetImporter as AudioImporter;
ai.threeD = false;
}
}
@AlexanderDzhoganov
AlexanderDzhoganov / DebugUtil.cs
Created March 14, 2015 14:08
Dump RenderTexture to PNG in Unity
public static class DebugUtil
{
public static void DumpRenderTexture(RenderTexture rt, string pngOutPath)
{
var oldRT = RenderTexture.active;
var tex = new Texture2D(rt.width, rt.height);
RenderTexture.active = rt;
tex.ReadPixels(new Rect(0, 0, rt.width, rt.height), 0, 0);
using System;
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
namespace PvpGame
{
public class GridValue
{
public enum EntityType