본문 바로가기
NOTE/SaveSource

[Source Save] GyhroCameraMove.cs

by DevAthena 2016. 11. 9.
using System.Collections.Generic;
using UnityEngine;
 
class GyroCameraMove : SingleTon<GyroCameraMove>
{
    private     bool            gyroSupported;
    private     Gyroscope       gyro;
    private     Quaternion      rotFix;
    private     Transform       worldObj;
    private     GameObject      mCam;
    private     GameObject      camParent;
    private     float           startY;
 
    private GyroCameraMove() { }
 
    public void GyroCamera()
    {
        gyroSupported = SystemInfo.supportsGyroscope;
 
        mCam = GameObject.FindGameObjectWithTag("MainCamera");
        camParent = new GameObject("camParent");
        camParent.transform.position = mCam.transform.position;
        mCam.transform.parent = camParent.transform;
 
        if(gyroSupported)
        {
            gyro = Input.gyro;
            gyro.enabled = true;
 
            camParent.transform.rotation = Quaternion.Euler(90f, 180f, 0f);
            rotFix = new Quaternion(0010);
            CoroutineManager.Instance.Register(GyroCameraMoving());
        }
        else
        {
            Log.Info("AR - 자이로카메라 활성화 실패");
        }        
    }
 
    private IEnumerator<CoroutinePhase> GyroCameraMoving()
    {
        while(true)
        {
            mCam.transform.localRotation = gyro.attitude * rotFix;
            yield return null;
        }
    }
}
 
cs


'NOTE > SaveSource' 카테고리의 다른 글

[SaveSource] Unity Editor Study  (0) 2016.11.17
[SaveSource] 만보기소스(펌)  (0) 2016.11.09
[SaveSource] WebcamTexture  (0) 2016.11.02
[Source Save] MobileSensorManager.cs  (0) 2016.11.01
[Source Save] TouchCameraMove.cs  (0) 2016.10.31