Skip to content

Instantly share code, notes, and snippets.

View radiatoryang's full-sized avatar

Robert Yang radiatoryang

View GitHub Profile
@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 / 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);
@radiatoryang
radiatoryang / AxisInput.cs
Created November 13, 2020 18:52
Unity C# input code demos for Studio 1, Fall 2020 at NYU Game Center
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class AxisInput : MonoBehaviour
{
void Update()
{
// Input Axis is a virtual joystick... unlike GetKey, it returns -1.0 - +1.0
// e.g. holding your joystick to the left: -1.0f
@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 / 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 / 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 / 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 / Cat.cs
Last active March 31, 2016 19:28
Cat and Mouse lab base
using UnityEngine;
using System.Collections;
public class Cat : MonoBehaviour {
// declare a public variable, of type Transform, called "mouse"
public Transform mouse;
bool shouldIPlayASound = false;
@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
@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 {