Skip to content

Instantly share code, notes, and snippets.

@renaudbedard
renaudbedard / ADSR.cs
Last active August 3, 2023 09:14
ADSR Envelope for Unity
using System;
using System.Collections.Generic;
using UnityEngine;
/* ****************
* Sample Usage *
****************
// prerequisite : put a gameobject with the ADSR script on it in your scene
// this enables the update loop that transparently updates Envelope objects
@renaudbedard
renaudbedard / gist:7a90ec4a5a7359712202
Created September 11, 2014 18:39
Billboarding for Unity surface shaders
void vert(inout appdata_full v, out Input o)
{
UNITY_INITIALIZE_OUTPUT(Input, o);
// get the camera basis vectors
float3 forward = -normalize(UNITY_MATRIX_V._m20_m21_m22);
float3 up = float3(0, 1, 0); //normalize(UNITY_MATRIX_V._m10_m11_m12);
float3 right = normalize(UNITY_MATRIX_V._m00_m01_m02);
// rotate to face camera
@renaudbedard
renaudbedard / AstcStuff.cs
Created May 30, 2020 19:53
Import Remapping
public class AstcImporterMapper : AssetPostprocessor
{
private void OnPreprocessTexture()
{
// TODO: this should be using the TextureImporterConfiguration
if (assetPath.Contains("_XXXY") || assetPath.Contains("_SME") || assetPath.Contains("_A"))
AssetDatabaseExperimental.SetImporterOverride<AstcTextureImporter>(assetPath);
else if (AssetDatabaseExperimental.GetImporterOverride(assetPath) != null)
AssetDatabaseExperimental.ClearImporterOverride(assetPath);
}
float4x4 WorldViewProj : WorldViewProjection;
texture ColorTexture;
sampler2D ColorSampler = sampler_state {
Texture = <ColorTexture>;
FILTER = MIN_MAG_MIP_LINEAR;
AddressU = Wrap;
AddressV = Wrap;
};
@renaudbedard
renaudbedard / Waiters.cs
Created May 6, 2015 14:55
Stateful and stateless waiting classes
using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.GamerServices;
using XnaCommons.Structure;
using XnaCommons.Tools;
namespace XnaCommons.Components
{
public static class Waiters
{
@renaudbedard
renaudbedard / WaveformDisplay.cs
Created September 25, 2014 03:37
Waveform visualizer
using System;
using System.Collections;
using System.Threading;
using UnityEngine;
class WaveformDisplay : MonoBehaviour
{
public Tracker Tracker;
public int LineSegments;
static void SetupDpiAwareness()
{
bool success = false;
List<string> errorCauses = new List<string>();
string successfulMethod = null;
try
{
var result = DpiAwareness.SetProcessDpiAwareness(DpiAwareness.PROCESS_DPI_AWARENESS.PROCESS_PER_MONITOR_DPI_AWARE);
if (result == DpiAwareness.HRESULT.E_ACCESSDENIED)
{
@renaudbedard
renaudbedard / gist:71b80bd7d76e4967376c
Created September 17, 2014 04:16
Barely tested Unity "Rich Text" substring tool
struct SubstringInfo
{
public int StartsAt;
public string TagSuffix;
public SubstringInfo(int startsAt, IEnumerable<string> tagSuffixChain)
{
StartsAt = startsAt;
TagSuffix = string.Empty;
foreach (var tagSuffix in tagSuffixChain)
@renaudbedard
renaudbedard / ActivityLog.xml
Last active March 8, 2017 17:00
VSTU Errors
<entry>
<record>566</record>
<time>2017/03/08 16:55:29.708</time>
<type>Error</type>
<source>Microsoft.VisualStudio.CommonIDE.ExtensibilityHosting.VsShellComponentModelHost</source>
<description>A MEF Component threw an exception at runtime: System.IO.FileLoadException: Could not load file or assembly &apos;SyntaxTree.VisualStudio.Unity, Version=2.8.2.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35&apos; or one of its dependencies. The located assembly&apos;s manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)&#x000D;&#x000A;File name: &apos;SyntaxTree.VisualStudio.Unity, Version=2.8.2.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35&apos;&#x000D;&#x000A; at System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark&amp; stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)&#x00
@renaudbedard
renaudbedard / Foo.cs
Created September 2, 2016 14:58
El cheapo way to fix the nested stopcoroutine problem
class Foo : MonoBehaviour
{
Coroutine m_coroutine;
readonly HashSet<IEnumerator> m_innerCoroutines = new HashSet<IEnumerator>();
public void StartThing()
{
m_coroutine = StartCoroutine(ParentCoroutine());
}