Skip to content

Instantly share code, notes, and snippets.

View unitycoder's full-sized avatar
‏‏‎

mika unitycoder

‏‏‎
View GitHub Profile
@unitycoder
unitycoder / vrpn.cfg
Created November 24, 2015 09:36
uiva_1.02\Release\VRPN servers\Wiimote + WiiFit Balance Board - config file
# vrpn.cfg.SAMPLE for VRPN version 07.18
################################################################################
################################################################################
# This file provides comments and examples for the vrpn.cfg file that is read
# by the vrpn_server application when it starts up. This is a generic server
# application that can start up many but maybe not all servers.
#
# This has sample lines for a vrpn.cfg file. If you get a new device working,
# add a line for it here. DO NOT remove lines from this file (unless
@unitycoder
unitycoder / UIVA_Server.cfg
Created November 24, 2015 09:38
uiva_1.02\Release\UIVA_Server\ - config file
# ------------------------------------------------------------
# UIVA (Unity Indie VRPN Adapter) Configuration File
# UIVA.cfg
#
# UIVA is a middle-ware between VRPN and Unity which allows fast,
# strong, and user friendly device connection in Unity Indie via
# VRPN
#
# This configuration file specifies which devices to enable and
# their address.
@unitycoder
unitycoder / SpriteOpaqueNoTint.shader
Last active December 14, 2017 01:53
Sprites/OpaqueSnapNoTint - shader
Shader "Sprites/OpaqueSnapNoTint"
{
Properties
{
[PerRendererData] _MainTex ("Sprite Texture", 2D) = "white" {}
}
SubShader
{
Tags
@unitycoder
unitycoder / OptimizedVersions.js
Last active December 28, 2020 03:30
LudumDare34 - Vote with ArrowKeys (left = yes, right = no)
// these are just for trying to make the same code shorter
// original code
document.onkeydown=function(e){e=e||window.event;document.getElementById(e.keyCode==37?"kill-good":e.keyCode==39?"kill-bad":"sg").click();};
// optimized
document.onkeydown=function(e){document.getElementById(e.keyCode==37?"kill-good":e.keyCode==39?"kill-bad":"sg").click()}
// shorter version. Left = yes, Other keys = no
document.onkeyup=function(e){document.getElementById(e.keyCode==37?'kill-good':'kill-bad').click()}
@unitycoder
unitycoder / UITextTypeWriter.cs
Last active April 11, 2024 08:11
Type out UI text one character at a time
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
// attach to UI Text component (with the full text already there)
public class UITextTypeWriter.cs : MonoBehaviour
{
Text txt;
@unitycoder
unitycoder / ExampleClass.cs
Created December 2, 2015 23:19 — forked from shaunsales/ExampleClass.cs
Example Unity Class - How to format your code.
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class ExampleClass : MonoBehaviour // Try to name classes so other developers can infer their functionality. Abstract classes are prefixed with 'Base'
{
private enum WidgetType // Enums should end in 'Type' and can be inlined with the class if private, but generally should be relocated if public
{
None,
Circle,
@unitycoder
unitycoder / ShaderToggle.shader
Created December 3, 2015 22:29
Shader with Toggle (bool)
[MaterialToggle(_INVERT_OFF)] _Invert ("Invert", Float) = 0
..
#pragma multi_compile _INVERT_ON _INVERT_OFF
..
#if _INVERT_ON
..
#else
..
#endif
@unitycoder
unitycoder / UNITY_MATRIX_IT_MV.shader
Last active April 15, 2025 02:39
UNITY_MATRIX_IT_MV[] Vectors in Shader
UNITY_MATRIX_IT_MV[0].xyz = ???
UNITY_MATRIX_IT_MV[1].xyz = Camera Up
UNITY_MATRIX_IT_MV[2].xyz = Camera Forward
float3 forward = -normalize(UNITY_MATRIX_V._m20_m21_m22);
cameraFwd = -unity_MatrixInvV._m02_m12_m22;
float3 up = normalize(UNITY_MATRIX_V._m10_m11_m12);
float3 right = normalize(UNITY_MATRIX_V._m00_m01_m02);
float3 cameraUp = unity_CameraInvProjection[1].xyz;
@unitycoder
unitycoder / LerpColor.cs
Created December 16, 2015 18:09
Lerp Material Color inside Update Loop
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class LerpColor : MonoBehaviour {
public float lerpDuration = 2;
public Slider slider;
public Text textTime;
@unitycoder
unitycoder / atan2Approximation.cs
Last active January 20, 2019 12:45
float atan2Approximation for C# and Shader
// c#
float atan2Approximation(float y, float x) // http://http.developer.nvidia.com/Cg/atan2.html
{
float t0, t1, t2, t3, t4;
t3 = Mathf.Abs(x);
t1 = Mathf.Abs(y);
t0 = Mathf.Max(t3, t1);
t1 = Mathf.Min(t3, t1);
t3 = 1f / t0;
t3 = t1 * t3;