Skip to content

Instantly share code, notes, and snippets.

@inoook
inoook / gist:2923076
Created June 13, 2012 09:34
Unity3d での実行順
void Awake () {
//Debug.Log("Awake");
}
void OnEnable () {
//Debug.Log("OnEnable");
}
// Use this for initialization
void Start () {
@inoook
inoook / gist:11241692
Last active August 29, 2015 14:00
GetComponentを上位の階層に対して。SendMessageUpwardsのかわりに。
public static T GetComponentUpward<T>(GameObject gObj) where T: Component
{
T comp = gObj.GetComponent<T>();
if(comp != null){
return comp;
}else{
Transform parentTrans = gObj.transform.parent;
if( parentTrans != null){
return GetComponentUpward<T>(parentTrans.gameObject);
}else{
void DrawCross(Vector3 pos)
{
float size = 0.20f;
Debug.DrawLine(pos - new Vector3(0,0,size), pos + new Vector3(0,0,size), Color.red);
Debug.DrawLine(pos - new Vector3(size,0,0), pos + new Vector3(size,0,0), Color.red);
}
Vector3 p0 = new Vector3(-1,0,0);
Vector3 p1 = new Vector3(1,0,0);
Vector3 p2 = new Vector3(0,-1,0);
Vector3 p3 = new Vector3(0,1,0);
Gizmos.DrawLine(p0, p1);
Gizmos.DrawLine(p2, p3);
Vector3 pt = getCrossPoint(p0, p2, p1, p3);
Gizmos.DrawWireSphere( pt, 0.1f);
// http://imagingsolution.blog107.fc2.com/blog-entry-137.html
@inoook
inoook / RollPitchYawFromQuaternion.cs
Last active December 22, 2015 11:13
RollPitchYawFromQuaternion.cs
// http://answers.unity3d.com/questions/416169/finding-pitchrollyaw-from-quaternions.html
Quaternion q = shipTrans.localRotation;
float x = q.x;
float y = q.y;
float z = q.z;
float w = q.w;
float _pitch = Mathf.Atan2(2*x*w - 2*y*z, 1 - 2*x*x - 2*z*z) * Mathf.Rad2Deg;
float _yaw = Mathf.Atan2(2*y*w - 2*x*z, 1 - 2*y*y - 2*z*z) * Mathf.Rad2Deg;
float _roll = Mathf.Asin(2*x*y + 2*z*w) * Mathf.Rad2Deg;
// http://forum.unity3d.com/threads/what-is-the-unity-5-3-equivalent-of-the-old-particlesystem-emissionrate.373106/
public static class ParticleSystemExtension
{
public static void EnableEmission(this ParticleSystem particleSystem, bool enabled)
{
var emission = particleSystem.emission;
emission.enabled = enabled;
}
public static float GetEmissionRate(this ParticleSystem particleSystem)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
#if UNITY_EDITOR
using UnityEditor;
#endif
[ExecuteInEditMode]
public class EditorTemplate : MonoBehaviour {
public enum MONITOR_MODE
{
IDLE = 0, LIVE, REPLAY
}
public static MONITOR_MODE IntToMONITOR_MODE(int id)
{
return (MONITOR_MODE)( ( System.Enum.GetValues( typeof(MONITOR_MODE) ) ).GetValue(id) );
}
public static int MONITOR_MODE_ToInt(MONITOR_MODE mode)
{
// https://www.dropbox.com/s/em7iqkax0771qb0/Unity%E9%81%93%E5%A0%B4%E3%82%B9%E3%83%9A%E3%82%B7%E3%83%A3%E3%83%AB%E5%8D%9A%E5%A4%9A-yasuhara.pdf?dl=0
差分 = 目標の値 x 現在の値^-1
Quaternion delta = target_rot * Quaternion.Inverse(current_rot);
--
this.transform.rotation = originalRotation * addRotation;
float a = 11.11f;//減速加速度
float stopDistance = Mathf.Abs( (targetSpeed * targetSpeed - currentSpeed * currentSpeed) / (2 * a) );