Skip to content

Instantly share code, notes, and snippets.

@miguel12345
miguel12345 / TangentSpaceBasisVisualizer.cs
Created June 26, 2017 08:07
Tangent space basis visualizer
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class TangentSpaceBasisVisualizer : MonoBehaviour
{
void GetTangentSpaceBasis(Mesh mesh, int triangleIndex, Vector3 barycentricCoordinates,out Vector3 tangent,out Vector3 binormal, out Vector3 normal) {
Vector3[] normals = mesh.normals;
Vector4[] tangents = mesh.tangents;
using UnityEngine;
using System.Collections;
using UnityEngine.EventSystems;
using UnityEngine.UI;
using UnityEngine.Events;
public static class PointerCallbackExtensions {
static void AddPointerEventCallback(this GameObject obj,EventTriggerType triggerType,UnityAction<BaseEventData> ev) {
@miguel12345
miguel12345 / ExclusiveChildren.cs
Last active August 29, 2015 14:26
A Proper ExclusiveChildren script for Unity Editor
using UnityEngine;
using System.Collections;
#if UNITY_EDITOR
using UnityEditor;
#endif
//See http://g.recordit.co/sYme8QQg2L.gif for an example of usage
public class ExclusiveChildren : MonoBehaviour {
#if UNITY_EDITOR
Shader "Custom/SeeThrough" {
Properties {
_MainTex ("Base (RGB)", 2D) = "white" {}
_NormalColor ("Normal Color", Color) = (1.0,0.0,0.0)
_SeeThroughColor ("See-trough Color", Color) = (0.0,1.0,0.0)
}
SubShader {
Tags { "Queue"="Overlay" }
LOD 200
@miguel12345
miguel12345 / CancellabeEnumeratorTest.cs
Created July 8, 2015 07:28
MonoBehaviour's CancelRoutine() that doesn't just pause a routine like StopRoutine() does
using System.Collections;
using UnityEngine;
//Now Debug.Log ("End printing") will be shown when you cancel the inner coroutine
public class CancellabeEnumeratorTest : MonoBehaviour {
static int a = 0;
IEnumerator printRoutine = null;
void Start() {
using System.Collections;
//Shouldn't we see the Debug.Log ("End printing") ?
public class EnumTest : MonoBehaviour {
static int a = 0;
IEnumerator printRoutine = null;
void Start() {
StartCoroutine (main ());
@miguel12345
miguel12345 / gist:d30301fce263ddbd46e4
Last active August 29, 2015 14:07
Generic Currying in Objective-c
//The magic method
-(id (^)(id,...)) getSelector:(SEL) aSelector forTarget:(id) target withFirstArguments:(id) firstArguments, ... {
NSMutableArray* firstArgumentsArray = [NSMutableArray array];
va_list first_args;
va_start(first_args, firstArguments);
do
{
[firstArgumentsArray addObject:firstArguments];
}
@miguel12345
miguel12345 / gist:60e9872adb04f81ea5eb
Last active August 29, 2015 14:06
Currying in Objective-c
//Define the methods
-(int) sumA:(int) a withB:(int)b {
return a + b;
}
-(int (^)(int)) sumWithA:(int)a {
int (^blockName)(int) = ^int(int b) {
return [self sumA:a withB:b];
@miguel12345
miguel12345 / angular_directive_test
Created December 23, 2013 22:10
Angular Directive Testing Example
describe('tabs', function() {
var elm, scope;
// load the tabs code
beforeEach(module('tabs'));
// load the templates
// beforeEach(module('tpl/tabs.html', 'tpl/pane.html'));
beforeEach(inject(function($rootScope, $compile) {
@miguel12345
miguel12345 / new_gist_file_0
Created December 3, 2013 18:44
Blogs Web Dev
http://webreflection.blogspot.pt/
http://perfectionkills.com/
http://www.quirksmode.org/blog/