Skip to content

Instantly share code, notes, and snippets.

View radiatoryang's full-sized avatar

Robert Yang radiatoryang

View GitHub Profile
@radiatoryang
radiatoryang / ListDemo.cs
Created April 2, 2015 00:23
simple demo of lists and foreach for my Recursive Reality VR class, spring 2015
using UnityEngine;
using System.Collections;
using System.Collections.Generic; // STEP 1 OF USING A LIST: include this line
// a "List" is like an Array
// an array = "immutable", it cannot be resized
// a list = dynamically resizable, elastic, will stretch or shrink based on item count
// demo: I'm going to instantiate spheres, track the spheres using a list, and
// modify all of the spheres inside the list
@radiatoryang
radiatoryang / LookColorChange.cs
Last active April 23, 2017 07:44
simple script, use it with LookCast.cs
using UnityEngine;
using System.Collections;
// put this script on an object with a COLLIDER
public class LookColorChange : MonoBehaviour {
// ALL CODE IN "ONLOOK" WILL HAPPEN EVERY FRAME THIS THING IS LOOKED AT
void OnLook () {
// if we look in console, we should see this message
Debug.Log ("this thing is getting looked at!!!");
@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 / 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 / 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()
Shader "Custom/Gamma Image Effect" {
Properties
{
_MainTex ("Base (RGB)", 2D) = "white" {}
_SaturationAmount ("Saturation Amount", Range(0.0, 1.0)) = 1.0
_BrightnessAmount ("Brightness Amount", Range(0.0, 1.0)) = 1.0
_ContrastAmount ("Contrast Amount", Range(0.0,1.0)) = 1.0
}
SubShader
{
@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 / 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;
@radiatoryang
radiatoryang / DemoWebcam.cs
Created April 9, 2015 03:21
Unity C# code for grabbing a JPG (or PNG) off the internet and bringing into Unity
using UnityEngine;
using System.Collections;
// full reference: http://docs.unity3d.com/ScriptReference/WWW.html
// usage: place this on a gameObject with Mesh Filter and Mesh Renderer (e.g. a Quad, a Plane, a Cube)
// NOTE: this does NOT work in Web Player (browser security sandbox)
public class DemoWebcam : MonoBehaviour {
@radiatoryang
radiatoryang / VRUtility.cs
Created March 4, 2016 19:30
a script I give to my Unity VR students that demonstrates a few useful "quality of VR" features for their games -- lowering visual quality for higher framerate, and HMD recentering
using UnityEngine;
using System.Collections;
using UnityEngine.VR; // you always need this to use special VR functions
public class VRUtility : MonoBehaviour {
// Use this for initialization
public void Start () {
// set render quality to 50%, sacrificing visual quality for higher FPS