Skip to content

Instantly share code, notes, and snippets.

View keijiro's full-sized avatar

Keijiro Takahashi keijiro

View GitHub Profile
@keijiro
keijiro / ExpEase.cs
Created April 28, 2011 23:02
Exponential easing out utility for Unity
// Example:
//
// currentPos = ExpEase.Out(currentPos, targetPos, -4.0);
//
// or
//
// ExpEase.Out2(currentPos, targetPos, -4.0); // This modifies currentPos.
//
using UnityEngine;
@keijiro
keijiro / ParticleAttractor.js
Created July 29, 2011 04:40
Particle attractor (Unity)
var target : Vector3;
var power = 5.0;
function LateUpdate () {
var particles = particleEmitter.particles;
for (var i = 0; i < particles.Length; i++) {
var rp = target - particles[i].position;
if (rp.magnitude < 0.5) {
// 近づき過ぎたパーティクルを消す。
particles[i].energy = 0.0;
} else {
@keijiro
keijiro / ClickDetector.js
Created August 19, 2011 09:23
Detect click on the outside of GUI.
var guiIsHot : boolean;
function Update() {
if (Input.GetMouseButton(0) && GUIUtility.hotControl != 0) {
guiIsHot = true;
}
if (Input.GetMouseButtonUp(0)) {
if (!guiIsHot) {
Debug.Log("Hooray!");
}
@keijiro
keijiro / MakeState1-2
Created September 9, 2011 03:28
Workaround for asset reference problem.
@MenuItem ("MyMenu/Do Something")
static function DoSomething () {
var header1 = ScriptableObject.CreateInstance.<StateHeader>();
var header2 = ScriptableObject.CreateInstance.<StateHeader>();
AssetDatabase.CreateAsset(header1, "Assets/State1Set.asset");
AssetDatabase.CreateAsset(header2, "Assets/State2Set.asset");
var state1 = ScriptableObject.CreateInstance.<State1>();
@keijiro
keijiro / Plugin.js
Created September 26, 2011 10:40
(Unity for iOS) Native plugin import in JavaScript
import System.Runtime.InteropServices;
#if UNITY_IPHONE && !UNITY_EDITOR
@DllImportAttribute("__Internal") static private function _PluginFoo(arg : int) {}
#else
static private function _PluginFoo(arg : int) {
// iOS以外での代替処理。
@keijiro
keijiro / PostprocessBuildPlayer
Created September 26, 2011 11:24
PostprocessBuildPlayer for Unity iOS: modifies Info.plist to use Facebook URL-scheme
#!/usr/bin/env python
import sys, os.path
install_path = sys.argv[1]
target_platform = sys.argv[2]
if target_platform != "iPhone": sys.exit()
info_plist_path = os.path.join(install_path, 'Info.plist')
@keijiro
keijiro / RTTest
Created October 7, 2011 00:07
Huge render texture test
var rt : RenderTexture;
function Start() {
rt = new RenderTexture(4096, 4096, 24);
camera.targetTexture = rt;
}
@keijiro
keijiro / gist:1297977
Created October 19, 2011 10:59
JavaScript (UnityScript) multidimensional array
#pragma strict
static function BoolArray(a : int, b : int, c : int) {
return new boolean[a,b,c];
}
static function IntArray (a : int, b : int, c : int) {
return new int[a,b,c];
}
var testArray = IntArray(10, 10, 10);
@keijiro
keijiro / gist:1298138
Created October 19, 2011 12:21
Associative array in JavaScript (UnityScript)
#pragma strict
var a = {"foo": {10: "bar"}};
Debug.Log((a["foo"] as Hashtable)[10]); // prints "bar"
@keijiro
keijiro / gist:1298141
Created October 19, 2011 12:22
Associative array in JavaScript (UnityScript)
#pragma strict
class StrIntArray {
private var table = new Hashtable();
function Set(key1 : String, key2 : int, value : String) {
table[key1 + "/" + key2] = value;
}
function Get(key1 : String, key2 : int) : String {