using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

/// <summary>
/// 视角控制器
/// 角色跟随 / 小地图移动
/// </summary>
public class BattleCameraParent : MonoBehaviour 
{
/*
	protected bool m_BeginMapMoveEnd = false;

	public Vector3 farDir = new Vector3(-1,0,-.25f);

	protected Vector3 m_CamBeginPos;
	protected Vector3 m_CamBeginRot;
*/

	public Camera cam;
	public float followY = 0;

	protected virtual void Awake()
	{
		if (cam == null)
			cam = GetComponentInChildren<Camera>();

		/*m_CamBeginPos = cam.transform.localPosition;
		m_CamBeginRot = cam.transform.localRotation.eulerAngles;*/
	}

	protected virtual void Start()
	{
		
	}

	public void SetRolePosition (Vector3 position)
    {
        /*if (m_InGameStartMove)
        {
            m_RolePostion = position;
            return;
        }*/

		//this.transform.localPosition = position;
        this.SetTargetPos(position);
        
	}


	private Vector3 m_TargetStartPos;
	private Vector3 m_TargetPos = Vector3.zero;

	private float m_CurSmoothTime = 0f;
	
/*	/// <summary>
	/// 当前正在使用的曲线
	/// </summary>
	public AnimationCurve lerpCurve;
	/// <summary>
	/// 当前正在使用的时间
	/// </summary>
	/// 
	public float lerpTimeDuration = 0.2f;*/

	private void SetTargetPos (Vector3 targetPos)
	{
		if (followY > 0.000001f)
		{
			//GameDebug.LogError($"followY:{followY}");
			targetPos.y *= followY;
		}
		else
		{
			targetPos.y = transform.localPosition.y;
		}
		m_TargetPos = targetPos;
		/*if ((m_TargetPos - targetPos).sqrMagnitude > 0.001f)
		{
            m_CurSmoothTime = 0;
            m_TargetStartPos = this.transform.localPosition;
			m_TargetPos = targetPos;
		}*/
	}

	public float lerpSpeed = .5f;
	void LerpToTargetPos ()
	{
		this.transform.localPosition = Vector3.Lerp(this.transform.localPosition,m_TargetPos,lerpSpeed);
		
        /*m_CurSmoothTime += Time.deltaTime;
		if (m_CurSmoothTime > lerpTimeDuration)
		{
			this.transform.localPosition = m_TargetPos;
		}
		else
		{
			this.transform.localPosition = m_TargetStartPos + (m_TargetPos - m_TargetStartPos) * lerpCurve.Evaluate(m_CurSmoothTime / lerpTimeDuration);
		}*/
	}

	protected virtual void Update ()
    {
	    this.LerpToTargetPos();
    }

}
