Skip to content

Instantly share code, notes, and snippets.

View radiatoryang's full-sized avatar

Robert Yang radiatoryang

View GitHub Profile
@radiatoryang
radiatoryang / BuildRadiator.cs
Last active April 14, 2024 22:33
This is my Unity Editor build script that I use for my games, to automatically build out players and package them in ZIP files.
using UnityEngine;
using UnityEditor;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.IO.Compression;
using Ionic.Zip; // this uses the Unity port of DotNetZip https://github.com/r2d2rigo/dotnetzip-for-unity
@radiatoryang
radiatoryang / DemoSpreadsheet.cs
Created April 9, 2015 03:22
Unity C# code for grabbing a publicly published Google Docs spreadsheet
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
// usage: place on a UI Text object to visualize spreadsheet data
// preparing a Google Doc: make sure you go to File >> Publish... "Share" does NOT work for this
// publicly editable: https://docs.google.com/spreadsheets/d/1QDaGFXxh3zbVTcQKXygKZ67_EFXjUlGbHbK21ICvv-k/edit?usp=sharing
// view as HTML: https://docs.google.com/spreadsheets/d/1QDaGFXxh3zbVTcQKXygKZ67_EFXjUlGbHbK21ICvv-k/pubhtml
@radiatoryang
radiatoryang / SkinnedMeshCombiner.cs
Last active August 9, 2023 04:12
example code for combining SkinnedMeshRenderers at runtime (for optimization reasons usually), which I use in my games for Mixamo Fuse models specifically... PLEASE DON'T ASK ME FOR HELP WITH THIS, this is more for learning purposes, and it's not really an easy-to-use Asset Store thing? also I have a lot of weird hacks specific for my uses... ag…
// this code is under MIT License, by Robert Yang + others (credits in comments)
// a lot of this is based on http://wiki.unity3d.com/index.php?title=SkinnedMeshCombiner
// but I removed the atlasing stuff because I don't need it
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
@radiatoryang
radiatoryang / BuildWebGLDual.cs
Created December 11, 2022 00:58
Fixed version of Unity WebGL dual build editor script example (https://docs.unity3d.com/2022.2/Documentation/Manual/webgl-texture-compression.html) which lets you make WebGL builds with both DXT and ASTC compressed textures... Don't forget to update your WebGL template HTML too.
using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using System.IO;
public class BuildWebGLDual
{
[MenuItem("Build/WebGL Dual Build")]
public static void BuildGame()
{
@radiatoryang
radiatoryang / SmoothVideoPlaylist.cs
Last active April 4, 2023 07:35
short Unity C# script example for smoothly cutting / playing a playllist of VideoClips, by using one VideoPlayer (activeCam) to play the video and another VideoPlayer (otherCam) to cue up the next video... MIT License.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Video;
public class SmoothVideoPlaylist : MonoBehaviour {
// to smoothly cut between two videos, we need two VideoPlayers
// make sure you create two VideoPlayers and assign them in the Inspector
public VideoPlayer activeCam, otherCam;
@radiatoryang
radiatoryang / SkinnedMeshObjectPreviewExample.cs
Last active October 7, 2022 10:07
An example of a custom ObjectPreview rendering out a SkinnedMesh for Unity Editor C#... I used it for facial expressions and blendshape editing, you might want to use it for something else. I hereby place it under MIT License. Full write-up here: http://www.blog.radiator.debacle.us/2016/06/working-with-custom-objectpreviews-and.html
using UnityEngine;
using UnityEditor;
using System;
using System.Collections;
[CustomPreview(typeof(YourCustomScriptableObject))] // THIS IS VERY IMPORTANT, this is so the editor knows what this is supposed to be previewing at all
public class SkinnedMeshObjectPreviewExample : ObjectPreview {
PreviewRenderUtility m_PreviewUtility;
@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 / RaycastTargetTrigger.cs
Last active August 2, 2022 05:14
a script I give to my Unity VR classes to detect when the player is looking at something... put it on anything with a collider, and it'll know if it's being looked at or not
using UnityEngine;
using System.Collections;
using UnityEngine.VR; // we need this line here for InputTracking and VRSettings functions
// USAGE: put this on a thing you want the player to look at!
// this code will enable that thing to know if it is being looked at!
[RequireComponent (typeof(Collider)) ] // this thing needs a collider if we should look at it
public class RaycastTargetTrigger : MonoBehaviour {
@radiatoryang
radiatoryang / VertexLit-Retro3D.shader
Created May 13, 2018 18:56
yet another retro3D shader for Unity with lower vertex precision / etc... made of parts from https://github.com/dsoft20/psx_retroshader and https://github.com/keijiro/Retro3D
// mostly from https://github.com/dsoft20/psx_retroshader
// mixed with parts of https://github.com/keijiro/Retro3D
// under MIT license by Robert Yang (https://debacle.us)
Shader "Custom/VertexLit-Retro3D" {
Properties{
_MainTex("Base (RGB)", 2D) = "white" {}
_Color("Color", Color) = (0.5, 0.5, 0.5, 1)
_GeoRes("Geometric Resolution", Float) = 40
}
@radiatoryang
radiatoryang / FlxSeparateCircle.hx
Last active May 4, 2021 04:06
Terrible hack for HaxeFlixel that adds a separation (collision) function for circle-shaped hitboxes... it's a hack, so it just assumes a circular collider of radius = width/2 ... plug this into a custom FlxG.overlap collision call in your main PlayState... also I don't know how to code so sorry lol
public static function separateCircle(circle1:FlxSprite, circle2:FlxSprite):Bool
{
var totalRadius:Float = circle1.width / 2 + circle2.width / 2;
var c1 = circle1.getMidpoint(FlxPoint.weak());
var c2 = circle2.getMidpoint(FlxPoint.weak());
var distanceSquared:Float = (c1.x - c2.x) * (c1.x - c2.x) + (c1.y - c2.y) * (c1.y - c2.y);
if (distanceSquared < totalRadius * totalRadius)
{
var overlap:Float = totalRadius - Math.sqrt(distanceSquared);