Skip to content

Instantly share code, notes, and snippets.

@LoganBarnett
LoganBarnett / Gif.cs
Created April 22, 2013 18:34
Animate a series of images like a gif.
IEnumerator Start() {
var i = 0;
while (true) {
renderer.material.mainTexture = textures[i];
yield return new WaitForSeconds(delays[i]);
++i;
if(i >= maxFrames) i = 0;
}
}
@LoganBarnett
LoganBarnett / IGenericEditorWindow.cs
Last active December 16, 2015 01:39
A workaround to have generic EditorWindows.
using UnityEditor;
public interface IGenericEditorWindow {
void OnGUI();
void OnFocus();
void OnDisable();
EditorWindow Window { get; set; }
}
@LoganBarnett
LoganBarnett / BackgroundSpawner.cs
Created March 19, 2013 06:23
Background star creator for Roid Miner game. 1 Draw call, 0 texture memory.
using UnityEngine;
using System.Collections.Generic;
using System.Collections;
using System.Linq;
using GoodStuff.NaturalLanguage;
public class BackgroundSpawner : MonoBehaviour {
public int seed = 1;
public float starDensityThreshold = 1f;
public float starCreationMaxCutoff = 0.5f;
Shader "Custom/SensorRadius" {
Properties {
_MainTex ("Main Texture", 2D) = "white" {}
_RampTex ("Ramp Txture", 2D) = "white" {}
_ScreenX ("Screen X", Float) = 0
_ScreenY ("Screen Y", Float) = 0
_Radius ("Cutoff Radius", Range(0, 1)) = 0.5
}
SubShader {
Tags { "RenderType"="Transparent" "Queue"="Transparent"}
@LoganBarnett
LoganBarnett / TractorBeam.cs
Created December 21, 2012 23:19
Some code demonstrating the use of Linq, Lamdas, and GoodStuff
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using GoodStuff.NaturalLanguage;
public class TractorBeam : MonoBehaviour {
public float tractorBeamRange = 10f;
public GameObject tractorBeamPrefab;
public GameObject tractorAudioPrefab;
@LoganBarnett
LoganBarnett / PostIncrement.cs
Created April 28, 2012 15:41
A time when the post increment operator is actually used to post increment
var colorIndex = 0;
var colorsDifferent = originalStarColors.Any(c => c != starColors[colorIndex++]);
@LoganBarnett
LoganBarnett / AlignedCompassRings.cs
Created April 5, 2012 15:37
A compass ring that points itself to an object in 3D space
using UnityEngine;
using System.Collections;
public class AlignedCompassRings : MonoBehaviour {
public GameObject yRing;
public GameObject north;
public float zOffset = 0.0f;
void Awake() {
yRing.SetActiveRecursively(false);
@LoganBarnett
LoganBarnett / DroidController.cs
Created April 1, 2012 22:25
Syncs Droid movement over the network using dead reckoning
void OnSerializeNetworkView(BitStream stream, NetworkMessageInfo info) {
if (stream.isWriting) {
var position = transform.position;
var rotation = transform.rotation;
stream.Serialize(ref movementSpeed);
stream.Serialize(ref currentHorizontalMovement);
stream.Serialize(ref currentVerticalMovement);
stream.Serialize(ref position);
stream.Serialize(ref rotation);
@LoganBarnett
LoganBarnett / config.cs
Created April 1, 2012 21:20
Example of configuring the OData service to use verbose errors
config.UseVerboseErrors = true;
@LoganBarnett
LoganBarnett / maincontent.html
Created April 1, 2012 21:03
Example of page that consumes an OData service
<asp:content contentplaceholderid="MainContent" id="Content2" runat="server">
<script id="user-table-template" type="text/html">
<tr id="user-row-${Id}">
<td>
<span id="user-first-name-span-${Id}">${FirstName}</span>
<input id="user-first-name-text-${Id}" type="text" style="display:none;" value="${FirstName}"/>
</td>
<td>