Skip to content

Instantly share code, notes, and snippets.

View nobnak's full-sized avatar

Nakata Nobuyuki (仲田将之) nobnak

  • teamLab
  • Tokyo, Japan
View GitHub Profile
@nobnak
nobnak / TimeZoneDatabase.cs
Last active September 15, 2015 07:34
Time zone converter for Unity (Windows)
using System.Collections.Generic;
using Microsoft.Win32;
using System.Runtime.InteropServices;
using System;
using System.Text;
namespace WorldClock {
public static class TimeZoneDatabase {
public const string KERNEL32 = "kernel32.dll";
public const string REGISTRY = @"SOFTWARE\Microsoft\Windows NT\CurrentVersion\Time Zones";
@nobnak
nobnak / Quaternion.cginc
Last active April 16, 2021 09:21
Quaternion Calculation for Unity
#ifndef __QUATERNION__
#define __QUATERNION__
#define HALF_DEG2RAD 8.72664625e-3
float4 quaternion(float3 normalizedAxis, float degree) {
float rad = degree * HALF_DEG2RAD;
return float4(normalizedAxis * sin(rad), cos(rad));
}
float4 qmul(float4 a, float4 b) {
@nobnak
nobnak / ScriptableObjectUtil.cs
Created September 16, 2015 09:23
Editor Script for ScriptableObject Creation for Unity
using UnityEngine;
using UnityEditor;
using System.Collections;
using System.IO;
namespace LayerComposer {
public static class ScriptableObjectUtil {
public static void Create<T>(string path) where T : ScriptableObject {
var data = ScriptableObject.CreateInstance<T>();
@nobnak
nobnak / LensShift.cs
Last active July 26, 2022 07:06
Camera Lens Shift func. for Unity
using UnityEngine;
using System.Collections;
namespace Gist {
public static class LensShift {
public static void Frustum(this Camera cam, out float left, out float right, out float bottom, out float top, out float near, out float far) {
near = cam.nearClipPlane;
far = cam.farClipPlane;
@nobnak
nobnak / UVWorld.cs
Last active August 17, 2023 08:40
UV -> World Position (For Unity)
public class UVWorld : MonoBehaviour {
Mesh _mesh;
Vector3[] _vertices;
int[] _triangles;
Vector2[] _uvs;
Vector3[] _normals;
Triangle2D[] _uvTris;
void Awake() {
_mesh = GetComponent<MeshFilter>().sharedMesh;
@nobnak
nobnak / AutoHideCursor.cs
Created February 15, 2016 10:22
Auto Hide Cursor for Unity
using UnityEngine;
using System.Collections;
namespace nobnak.Blending {
public class AutoHideCursor : MonoBehaviour {
public float hideAfterSeconds = 3f;
public float thresholdInPixels = 3f;
float _lastTime;
@nobnak
nobnak / Depth.cginc
Created February 27, 2016 05:58
Depth Buffer -> Linear Eye Depth for Unity
#ifndef __DEPTH_CGINC__
#define __DEPTH_CGINC__
float Z2EyeDepth(float z) {
return unity_OrthoParams.w < 0.5
? LinearEyeDepth(z)
: ((_ProjectionParams.z - _ProjectionParams.y) * z + _ProjectionParams.y);
}
#endif
using UnityEngine;
using System.Collections;
namespace Gist {
/*
* A speed-improved simplex noise algorithm for 2D, 3D and 4D in Java.
*
* Based on example code by Stefan Gustavson (stegu@itn.liu.se).
* Optimisations by Peter Eastman (peastman@drizzle.stanford.edu).
* Better rank ordering method by Stefan Gustavson in 2012.
@nobnak
nobnak / ParallelFor.cs
Last active April 14, 2018 15:03
Parallel.For for Unity
using System.Collections.Generic;
using System.Threading;
namespace Gist {
public static class Parallel {
static AutoResetEvent[] _resets;
public static void For(int fromInclusive, int toExclusive, System.Action<int> body) {
var numThreads = 2 * System.Environment.ProcessorCount;
@nobnak
nobnak / BoxMuller.cs
Last active March 8, 2016 08:28
Gaussian Sampling for Unity
using UnityEngine;
using System.Collections;
namespace Gist {
public static class BoxMuller {
public const float TWO_PI = 2f * Mathf.PI;
public static Vector2 Gaussian() {
var u1 = Random.value;