Skip to content

Instantly share code, notes, and snippets.

View forestrf's full-sized avatar

Andrés Leone Gámez forestrf

View GitHub Profile
@forestrf
forestrf / StencilOnPreviewMaterials.cs
Created October 13, 2019 02:42
Enable stencil on preview materials of Unity. Unity hardcoded 16 bit depth buffer instead of 24 for some reason, disabling the stencil.
using UnityEditor;
using UnityEditor.SceneManagement;
using UnityEngine;
public static class StencilOnPreviewMaterials {
[InitializeOnLoadMethod]
private static void Init() {
Camera.onPreCull += OnPreCull;
}
using System.Runtime.CompilerServices;
using Unity.Collections;
public static class MutableNativeContainer {
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public unsafe static ref T GetMutable<T>(this NativeArray<T> arr, int index) where T : unmanaged {
return ref ArrayElement<T>(arr.m_Buffer, index);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
@forestrf
forestrf / SomeSMBEditor.cs
Last active July 13, 2019 15:56
Get the Animator and AnimatorController from the Editor of a StateMachineBehaviour
using System;
using System.Reflection;
using UnityEditor;
using UnityEngine;
[CustomEditor(typeof(SomeSMB))]
public class SomeSMBEditor : Editor {
public override void OnInspectorGUI() {
Type animatorWindowType = Type.GetType("UnityEditor.Graphs.AnimatorControllerTool, UnityEditor.Graphs");
var window = EditorWindow.GetWindow(animatorWindowType);
@forestrf
forestrf / ShowAnimatorWindow.cs
Last active July 5, 2023 08:43
Get Unity's Animator window and show it
Type animatorWindowType = Type.GetType("UnityEditor.Graphs.AnimatorControllerTool, UnityEditor.Graphs");
var window = EditorWindow.GetWindow(animatorWindowType);
window.Show();
using System.Reflection;
using UnityEditor;
using UnityEngine;
[InitializeOnLoad]
public class EditorCameraSpeed
: EditorWindow {
[MenuItem("Tools/Camera Speed &S")]
public static void CameraSpeed() {
var window = GetWindow<EditorCameraSpeed>();
// c# companion script
// SpriteUVToShader.cs -------------------------------------------------------------------------------------------------------------------------------- //
// Save you your project, add to your SpriteRenderer gameObject
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
@forestrf
forestrf / FastByteConverter.cs
Last active June 30, 2022 07:41
c# structs to convert easily and fast between simple types and an array of bytes
using System;
using System.Runtime.InteropServices;
namespace Ashkatchap.BitUtils {
public enum Endianness {
/// <summary>
/// Network Byte order
/// </summary>
Big = 0,
/// <summary>
@forestrf
forestrf / ajax.js
Last active August 30, 2017 11:04
Easy ajax function that supports post data in text form, or a reference to a DOM form object
// callback takes one argument
// http://stackoverflow.com/questions/8567114/how-to-make-an-ajax-call-without-jquery
// data = null or undefined para usar GET
AJAX = function(url, data, callbackOK, callbackFAIL, timeout) {
if (callbackFAIL === undefined) callbackFAIL = function(x){};
if (callbackOK === undefined) callbackOK = function(x){};
if (isNaN(timeout)) timeout = 30000;
var isPost = data !== undefined && data !== null;
var x = new XMLHttpRequest();
if (isPost) x.open('POST', url, true);
@forestrf
forestrf / UnityScriptReloadFixer.cs
Last active July 26, 2018 19:10
[FIXED BY UNITY. This is not needed at all anymore] Unity sometimes does not reload my scripts when reimporting them. Apparently the .dlls inside /Library/ScriptAssemblies are not always replaced by the generated dlls inside /Temp, so this scripts moves those dlls automatically
using System;
using System.IO;
class Program {
static void Main(string[] args) {
Console.WriteLine("Close this window when you are finished doing cool progress");
Console.WriteLine("first argument: path to Library folder");
// Path
string path = new FileInfo(System.Reflection.Assembly.GetEntryAssembly().Location).Directory.FullName;
@forestrf
forestrf / SobelFilter.shader
Created January 27, 2017 21:53 — forked from mattatz/SobelFilter.shader
Sobel filter shader for Unity.
Shader "Mattatz/SobelFilter" {
Properties {
_MainTex ("Base (RGB)", 2D) = "white" {}
_DeltaX ("Delta X", Float) = 0.01
_DeltaY ("Delta Y", Float) = 0.01
}
SubShader {
Tags { "RenderType"="Opaque" }