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

/// <summary>
/// 替代Camera.main
/// Camera.main内部使用FindObjectWithTag 比较消耗性能
/// 如果有特殊逻辑需要修改mainCamrea 调用Refresh
/// add by 温田 2020/9/4
/// </summary>
public static class CameraCache
{
    private static Camera s_cachedCamera;

    public static Camera main
    {
        get
        {
            if(s_cachedCamera == null)
            {
                return Refresh(Camera.main);
            }
            return s_cachedCamera;
        } 
    }

    public static Camera Refresh(Camera newMain)
    {
        return s_cachedCamera = newMain;
    }
}
