Skip to content

Instantly share code, notes, and snippets.

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
@mstevenson
mstevenson / FindReferences.cs
Last active September 24, 2021 04:31
Find Unity objects that reference a selected asset
using UnityEngine;
using UnityEditor;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
public class FindReferences : EditorWindow, ISerializationCallbackReceiver
{
List<string> displayedRefs = new List<string>();
@ZimM-LostPolygon
ZimM-LostPolygon / UnityGuidRegenerator.cs
Last active February 8, 2024 10:10
Unity asset GUIDs regenerator
// Drop into Assets/Editor, use "Tools/Regenerate asset GUIDs"
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using UnityEditor;
namespace UnityGuidRegenerator {
public class UnityGuidRegeneratorMenu {
Shader "Sprites/Cutout"
{
Properties
{
[PerRendererData] _MainTex ("Sprite Texture", 2D) = "white" {}
_Color ("Tint", Color) = (1,1,1,1)
[MaterialToggle] PixelSnap ("Pixel snap", Float) = 0
_Cutoff ("Shadow alpha cutoff", Range(0,1)) = 0.5
}