본문 바로가기
NOTE/SaveSource

[Source Save] TouchCameraMove.cs

by DevAthena 2016. 10. 31.
using System;
using System.Collections.Generic;
using UnityEngine;
 
class TouchCameraMove : SingleTon<TouchCameraMove>
{
    public  GameObject   Target;
 
    public  float        dragX;
    public  const int    dir         = -1;
    public  float        speed       = 1f;   // 속도
    public  float        distance    = 2f;     // 거리
    public  float        height      = 3f;     // 높이
    public  float        dampTrace   = 20f;    // 감도
    public  float        maxZoom     = 100f;
    public  float        minZoom     = 30f;
    public  bool         setZoom;
 
    private TouchCameraMove() { }
 
    #region TouchCamera
    public void TouchCamera()
    {
        
        Target                  = GameObject.FindGameObjectWithTag("Player");
 
        Camera.main.transform.parent   = Target.transform;
        Camera.main.transform.localPosition = new Vector3(0f, 6f, -8f);
        Camera.main.transform.localEulerAngles = new Vector3(27f, 0f, 0f);
        dragX = 0;
 
        CoroutineManager.Instance.Register(TouchCameraMoving());
    }
    #endregion
 
    #region TouchCameraMoving
    private IEnumerator<CoroutinePhase> TouchCameraMoving()
    {
        while (true)
        {
            if (InputTouchManager.Instance.GetIsDrag)
            { 
                dragX = InputTouchManager.Instance.GetDragXY.x;
                Camera.main.transform.RotateAround(Target.transform.position, new Vector3(010), dragX * Time.deltaTime);
            }
            else if(InputTouchManager.Instance.GetIsZoom)
            {
                float zoomDgree = InputTouchManager.Instance.GetZoomDgree;
                if(Camera.main.orthographic)
                {
                    Camera.main.orthographicSize += zoomDgree * speed;
                    Camera.main.orthographicSize = Mathf.Max(Camera.main.orthographicSize, 0.1f);
                }
                else
                {
                    Camera.main.fieldOfView += zoomDgree * speed;
                    Camera.main.fieldOfView = Mathf.Clamp(Camera.main.fieldOfView, minZoom, maxZoom);
                }
            }
            if(InputTouchManager.Instance.GetIsDoubleTap)
            {
                CoroutineManager.Instance.Register(DoubleTapZoom());
            }
            yield return null;
        }
    }
    #endregion
 
    #region DoubleTapZoom
    private IEnumerator<CoroutinePhase> DoubleTapZoom()
    {
        while (InputTouchManager.Instance.GetIsDoubleTap)
        {
            if (setZoom)
            {
                if (Camera.main.fieldOfView <= maxZoom)
                {
                    Camera.main.fieldOfView += Time.deltaTime * 10f;
                }
                else
                {
                    setZoom = !setZoom;
                    InputTouchManager.Instance.DoubleTapUsed();
                    break;
                }
            }
            else
            {
                if (Camera.main.fieldOfView >= minZoom)
                {
                    Camera.main.fieldOfView -= Time.deltaTime * 10f;
                }
                else
                {
                    setZoom = !setZoom;
                    InputTouchManager.Instance.DoubleTapUsed();
                    break;
                }
            }
            yield return null;
        }        
    }
    #endregion
}
 
 
cs


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

[SaveSource] WebcamTexture  (0) 2016.11.02
[Source Save] MobileSensorManager.cs  (0) 2016.11.01
[Source Save] InputTouchManager.cs  (0) 2016.10.27
[SaveSource] Drag Script  (0) 2016.10.14
[SaveSource] Touch Pinch Zoom  (0) 2016.10.14