2013년 6월 1일 토요일

Unity3D Unlit/Transparent (Alpha) Shader

Shader "Unlit/Transparent (Alpha)"
{
 Properties
 {
   _Alpha("Alpha", Range(0,1)) = 1
  _MainTex("Texture", 2D) = ""
 }
 
 SubShader
 {
     Tags {Queue = Transparent}
     ZWrite Off
     Lighting off
     Cull Back
     Blend SrcAlpha OneMinusSrcAlpha
     
        Pass
        {
         SetTexture[_MainTex]
         {
          ConstantColor(1, 1, 1, [_Alpha])
          Combine texture, texture * constant
         }
        }
 }
}

2013년 2월 27일 수요일

C# Using delegate event

 public delegate void EventHandler();
 public event EventHandler LoadCompleted = null;

2012년 12월 29일 토요일

CMake Could not create named generator Visual Studio

If you already installed Cygwin with cmake package, cmake command will execute in cygwin which does not support Visual Studio.

In this case, modify cmake command to full path of cmake like "C:\Program Files (x86)\CMake 2.8\bin\cmake.exe".

2012년 12월 23일 일요일

Unity3D Rotate GameObject with mouse

using UnityEngine;
using System.Collections;

public class RotateWithMouse : MonoBehaviour {
 
 public float sensitivityX = 15.0f;
 public float sensitivityY = 15.0f;
 private Transform cameraTm;
 
 public bool down = false;

 // Use this for initialization
 void Start ()
 {
  cameraTm = Camera.mainCamera.transform;
 }
 
 // Update is called once per frame
 void Update () {
  if( Input.GetMouseButtonDown( 0 ) )
   down = true;
  else if( Input.GetMouseButtonUp( 0 ) )
   down = false;
  
  if( down )
  {
   float rotationX = Input.GetAxis("Mouse X") * sensitivityX;
   float rotationY = Input.GetAxis("Mouse Y") * sensitivityY;
   transform.RotateAroundLocal( cameraTm.up, -Mathf.Deg2Rad * rotationX );
   transform.RotateAroundLocal( cameraTm.right, Mathf.Deg2Rad * rotationY );
  }
 }
}

2012년 10월 22일 월요일

Android likes a post on Facebook

public void onClick(View v) {

    Bundle params = new Bundle();
    params.putString("post_id", mPostId);
    params.putString(Facebook.TOKEN, mFacebook.getAccessToken());
                
    mAsyncRunner.request("/"+mPostId+"/likes", params, "POST", new LikeListener(), null);
}
public class LikeListener extends BaseRequestListener
{
    public void onComplete(final String response, final Object state)
    {
        public void run()
        {
            mText.setText("Liked!");
        }
    }
}

2012년 7월 20일 금요일

Unity3D Billboard

using UnityEngine;
using System.Collections;

public class Billboard : MonoBehaviour
{
 // Update is called once per frame
 void LateUpdate () {
  // Billboard
  transform.rotation = Camera.main.transform.rotation;
 }
}

2012년 6월 1일 금요일

Unity3D Rotate transform to vector direction

Vector3 direction;
transform.rotation = Quaternion.FromToRotation(Vector3.forward, direction);
or
Vector3 direction;
transform.forward = direction;