Skip to content

Instantly share code, notes, and snippets.

View forestrf's full-sized avatar

Andrés Leone Gámez forestrf

View GitHub Profile
@ufcpp
ufcpp / bool.cs
Created April 27, 2017 13:19
bit layout of bool in C#
using System;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
[StructLayout(LayoutKind.Explicit)]
struct Union
{
[FieldOffset(0)]
public byte Byte;
[FieldOffset(0)]
@mtolly
mtolly / vra.hs
Last active August 1, 2018 16:28
Extract game files from Vagante. UPDATE: See https://github.com/mtolly/vagante-extract for new version
{- |
Extracts and injects files from the game Vagante's data.vra.
The format (after a 0x18-byte-long header) is a simple repeating pattern:
- length of filename (4 bytes little-endian)
- filename
- length of file data (4 bytes little-endian)
- file data
The files themselves are all nice standard formats:
OGG, WAV, PNG, JSON, TTF, and OpenGL fragment shader.
-}
using UnityEngine;
using UnityEditor;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Reflection;
[InitializeOnLoad]
public class EditorCameraSpeed
: EditorWindow
@DmitriyYukhanov
DmitriyYukhanov / ObjectTools.cs
Created March 21, 2017 11:18
Updated code to get a Unity object id.
#define UNITY_5_PLUS
#if UNITY_4_5 || UNITY_4_6 || UNITY_4_7 || UNITY_4_8 || UNITY_4_9
#undef UNITY_5_PLUS
#endif
using UnityEngine;
using System.Reflection;
using UnityEditor;
namespace CodeStage.Maintainer.Tools
@ChemiKhazi
ChemiKhazi / EnumFlagAttribute.cs
Created April 29, 2014 09:59
Unity3d property drawer for automatically making enums flags into mask fields in the inspector.
using UnityEngine;
public class EnumFlagAttribute : PropertyAttribute
{
public string enumName;
public EnumFlagAttribute() {}
public EnumFlagAttribute(string name)
{
@NovemberDev
NovemberDev / BehaviourTree.cs
Last active March 11, 2021 10:37
C# Behaviour Tree
using System;
using System.Linq;
using System.Collections.Generic;
public enum BehaviourTreeState
{
Success,
Failure,
Running
}
@Fewes
Fewes / PixelDot.shader
Last active May 12, 2021 04:38
Renders a screen-aligned, distance-independent, resolution-independent, pixel-perfect quad in Unity. Use it with the built-in quad mesh. You don't have to rotate or scale the mesh renderer, the shader will take care of it.
Shader "FX/PixelDot"
{
Properties
{
[NoScaleOffset] _MainTex ("Texture", 2D) = "white" {}
_Color ("Color", Color) = (1, 1, 1, 1)
_Size ("Pixel Size", Range(1, 64)) = 1
}
SubShader
{
@brihernandez
brihernandez / ComputeGunLead.cs
Last active June 1, 2021 03:49
Computes a point for a gun to aim at in order to hit a target using linear prediction.
/// <summary>
/// Computes a point for a gun to aim at in order to hit a target using linear prediction.
/// Assumes a bullet with no gravity or drag. I.e. A bullet that maintains a constant
/// velocity after it's been fired.
/// </summary>
public static Vector3 ComputeGunLead(Vector3 targetPos, Vector3 targetVel, Vector3 ownPos, Vector3 ownVel, float muzzleVelocity)
{
// Extremely low muzzle velocities are unlikely to ever hit. This also prevents a
// possible division by zero if the muzzle velocity is zero for whatever reason.
if (muzzleVelocity < 1f)
@darktable
darktable / PostBuildLog.cs
Created August 29, 2012 01:34
Unity3D: Post-process script that includes a build.log file containing the build summary in the output directory. Based on a method in BuildManager.
/* **************************************************************************
Copyright 2012 Calvin Rien
(http://the.darktable.com)
Derived from a method in BuildManager, part of
VoxelBoy's Unite 2012 Advanced Editor Scripting Talk.
(http://bit.ly/EditorScripting)
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
@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);