Skip to content

Instantly share code, notes, and snippets.

@thallippoli
thallippoli / InitializationWithReflection
Created November 14, 2012 06:49
Initializing private members using reflection
public void Initialize()
{
FieldInfo[] fields = this.GetType().GetFields( BindingFlags.NonPublic | BindingFlags.Instance );
for( int i = 0; i < fields.Length; i++ )
{
if( fields[ i ].Name == "m_baz" )
fields[ i ].SetValue( this, 42 );
}
}
// first column has the gamename, the second has the metascore
var scores = File.ReadAllLines( filename )
.Skip( 1 )
.Select( x => x.Split( ',' ) )
.Select( x => new { Game = x[ 0 ], Metascore = x[ 1 ] } );
foreach( var score in scores )
Debug.Log( score.Game + " : " + score.Metascore );
@thallippoli
thallippoli / gist:4671282
Created January 30, 2013 06:52
For any enumeration with a non-trivial wrap where you need the current and prev and/or next index in the loop. (by @cmuratori )
for( i = 0, j = n - 1; i < n; j = i++ )
{
}
@thallippoli
thallippoli / BlinkShader
Created January 31, 2013 11:23
Simple parameter based blink shader in Unity
Shader "Custom/Blink" {
Properties {
_MainTex ("Base (RGB)", 2D) = "white" {}
_Blink ( "Blink", Float ) = 0
}
SubShader {
Tags { "RenderType"="Opaque" }
LOD 200
CGPROGRAM
@thallippoli
thallippoli / gist:8506757
Created January 19, 2014 15:55
ReadOnlyProperty
using System;
using UnityEngine;
#if UNITY_EDITOR
using UnityEditor;
#endif
public abstract class ReadOnlyPropertyAttribute : PropertyAttribute
{
public string Displayname { get; private set; }
public ReadOnlyPropertyAttribute( string displayName )
{
@thallippoli
thallippoli / gist:8506758
Created January 19, 2014 15:55
ReadOnlyProperty
using System;
using UnityEngine;
#if UNITY_EDITOR
using UnityEditor;
#endif
public abstract class ReadOnlyPropertyAttribute : PropertyAttribute
{
public string Displayname { get; private set; }
public ReadOnlyPropertyAttribute( string displayName )
{
@thallippoli
thallippoli / Pulse
Last active July 11, 2022 07:04
Pulsing shader in Unity
Shader "Custom/Glow" {
Properties {
_MainTex ("Base (RGB)", 2D) = "white" {}
_GlowColor ("Glow Color", Color ) = ( 1.0, 1.0, 1.0, 1.0 )
_Frequency( "Glow Frequency", Float ) = 1.0
_MinPulseVal( "Minimum Glow Multiplier", Range( 0, 1 ) ) = 0.5
}
SubShader {
Tags { "RenderType"="Opaque" }
LOD 200
@thallippoli
thallippoli / Coroutine.cs
Last active August 29, 2015 14:01
Jump as Update and as a coroutine
bool mJumping;
void JumpCo()
{
float jumpProgress = 0.0f;
Vector3 jumpStartPos = transform.position;
mJumping = True;
while( mJumping && jumpProgress < 1.0f )
{
@thallippoli
thallippoli / ConstFunc
Created July 14, 2014 13:20
The Other Side of Const
using namespace std;
#include <iostream>
class Foo
{
public:
void SetX( int x )
{
m_x = x;
}
1. "പോളണ്ടിനെ കുറിച്ചൊരക്ഷരം മിണ്ടരുത്!"
2. എസ് എല്‍ പുരം (?)
3.
4. സംഗീതസംബന്ധിയായ നാഷണല്‍ അവാര്‍ഡ്
5. സ്റ്റാനിസ്ലാവ്സ്കി ("ഉദയനാണ്‌ താര"ത്തിലെ വിസ്കി)
6. ബൈരി (?)
7. ഓട്ടക്കാലണ
8.
9.
10. "ബോയിങ് ബോയിങ്" ലെ ജഗതി