Skip to content

Instantly share code, notes, and snippets.

View radiatoryang's full-sized avatar

Robert Yang radiatoryang

View GitHub Profile
@radiatoryang
radiatoryang / TriplanarWorld.shader
Created February 6, 2013 19:24
a triplanar / procedural UV / world space UV shader for Unity, cobbled together bits from @quickfingerz and @Farfarer
Shader "Tri-Planar World" {
Properties {
_Side("Side", 2D) = "white" {}
_Top("Top", 2D) = "white" {}
_Bottom("Bottom", 2D) = "white" {}
_SideScale("Side Scale", Float) = 2
_TopScale("Top Scale", Float) = 2
_BottomScale ("Bottom Scale", Float) = 2
}
@radiatoryang
radiatoryang / GPL.md
Created February 20, 2013 20:39 — forked from jnrbsn/GPL.md

GNU GENERAL PUBLIC LICENSE

Version 3, 29 June 2007

Copyright © 2007 Free Software Foundation, Inc. <http://fsf.org/>

Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed.

@radiatoryang
radiatoryang / GLShape.cs
Created March 9, 2013 08:02
The start of an all-purpose GLShape thing. MIT license. Tabs are all messed up. Oh well.
/* copyright Robert Yang 2013
use at your own risk
*/
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class GLShape : MonoBehaviour { // all-purpose interface for drawing stuff, PUT THIS ON YOUR CAMERA OBJECT
static Material lineMaterial; // init in Start()
@radiatoryang
radiatoryang / EnvCubemap.cs
Created May 27, 2013 23:01
Use with the rest of the EnvCubemap*.cs scripts to implement an environment probe system in your Unity project, with models that'll automatically fetch the closest visible probe. For more info, see: http://www.blog.radiator.debacle.us/2013/05/cubemapped-environment-probes-source.html
using UnityEngine;
using System.Collections;
public class EnvCubemap : MonoBehaviour {
public Cubemap cubemap;
public int cubemapRes = 128; // powers of two only
public CameraClearFlags clearFlags = CameraClearFlags.Color;
public Color clearColor = Color.black;
public LayerMask cullingMask;
public float near = 0.1f;
@radiatoryang
radiatoryang / ForceDirectedGraph.cs
Created May 30, 2013 23:20
method for doing force directed graph stuff with NGenerics + Unity... to make it 3D, just change Vector2's to Vector3's
IEnumerator ForceDirectGraph<T>( Graph<T> graph, Dictionary<T, Vector3> graphPositions ) {
// settings
float attractToCenter = 15f;
float repulsion = 10f;
float spacing = 0.1f;
float stiffness = 100f;
float damping = 0.9f;
// initialize velocities and positions
Dictionary<Vertex<T>, Vector2> velocity = new Dictionary<Vertex<T>, Vector2>();
@radiatoryang
radiatoryang / Terrain_FirstPass.shader
Last active June 17, 2018 22:57
A masked-blend terrain shader hack for Unity.
Shader "Nature/Terrain/Diffuse" {
Properties {
[HideInInspector] _Control ("Control (RGBA)", 2D) = "red" {}
[HideInInspector] _Splat3 ("Layer 3 (A)", 2D) = "white" {}
[HideInInspector] _Splat2 ("Layer 2 (B)", 2D) = "white" {}
[HideInInspector] _Splat1 ("Layer 1 (G)", 2D) = "white" {}
[HideInInspector] _Splat0 ("Layer 0 (R)", 2D) = "white" {}
// used in fallback on old cards & base map
[HideInInspector] _MainTex ("BaseMap (RGB)", 2D) = "white" {}
[HideInInspector] _Color ("Main Color", Color) = (1,1,1,1)
@radiatoryang
radiatoryang / GDocService.cs
Created November 27, 2013 22:18
Fetches a public Google Spreadsheet in Unity. (Doesn't work in Webplayer due to the security sandbox.)
// To prepare a Google Spreadsheet for this:
// make sure the spreadsheet has been published to web (FILE >> PUBLISH TO WEB), which is NOT the same as sharing to web
// To use in a different script:
// 1) include "using Google.GData.Client;"
// 2) include "using Google.GData.Spreadsheets;"
// 3) call "GDocService.GetSpreadsheet( string spreadsheetKey );", see DebugTest section for sample usage
using UnityEngine;
using System.Collections;
@radiatoryang
radiatoryang / WordWrapping.cs
Created December 28, 2013 07:42
Word Wrapping in Unity C#, based on some Tale of Tales code
// courtesy of Tale of Tales!
string WordWrap(string text, int lineLength) {
for (int i = lineLength; i < text.Length; i += lineLength) {
int returnSpot = text.LastIndexOf(" ", i);
if (returnSpot >= 0){
text = text.Substring(0, returnSpot) + "\n" + text.Substring(returnSpot, text.Length-returnSpot);
i = returnSpot;
}
}
return text;
@radiatoryang
radiatoryang / GuessingGame.cs
Created February 5, 2014 05:06
This is a class assignment for my Unity classes about code. It's full of errors and typos.
using UnityEngine;
using System.Collections;
// THIS CODE IS FULL OF ERRORS! DEBUG IT!
// 0) first, copy and paste this into a file in a Unity project
// 1) read the comments and variable names to figure out the coder's intention
// 2) go to the "Console" tab in Unity, look for stop sign icons -- these are code compile errors.
// the error will tell you the filename, then the line number and column, e.g. "GuessingGame.cs (8,100)"
// 3) double-click on an error in the Console to go to it in MonoDevelop
@radiatoryang
radiatoryang / FileManager.cs
Last active July 31, 2018 00:39
a bare bones data loading / saving (for game levels, savegames, etc.) example using the built-in binary serialization in Unity... I'd suggest hooking it up to the file browser OnGUI thing here: http://forum.unity3d.com/attachment.php?attachmentid=87628&d=1392756207 (from http://forum.unity3d.com/threads/84601-File-Browser/page2)
using System;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;
using System.Reflection;
using System.Text;
using System.IO;
using UnityEngine;
using System.Collections;
using System.Collections.Generic;