using System.Collections; 
 | 
using System.Collections.Generic; 
 | 
using UnityEngine; 
 | 
  
 | 
public class RenderTextureCreator : MonoBehaviour  
 | 
{ 
 | 
    [SerializeField] Vector2 m_Size; 
 | 
    [SerializeField] Camera m_TargetCamera; 
 | 
    [SerializeField] bool m_Reuse = false; 
 | 
  
 | 
    static Dictionary<Vector2, RenderTexture> m_RenderTexDict = new Dictionary<Vector2, RenderTexture>(); 
 | 
  
 | 
    private void Awake()  
 | 
    {  
 | 
        if (m_TargetCamera != null && m_TargetCamera.targetTexture == null)  
 | 
        {  
 | 
            RenderTexture rt;  
 | 
            if (m_Reuse && GetRenderTexture(m_Size, out rt))  
 | 
            {  
 | 
                m_TargetCamera.targetTexture = rt;  
 | 
                return;  
 | 
            }  
 | 
  
 | 
            rt = new RenderTexture(Mathf.RoundToInt(m_Size.x), Mathf.RoundToInt(m_Size.y), 16);  
 | 
            switch (Application.platform)  
 | 
            {  
 | 
                case RuntimePlatform.OSXEditor:  
 | 
                case RuntimePlatform.WindowsEditor:  
 | 
                case RuntimePlatform.WindowsPlayer:  
 | 
                    rt.format = RenderTextureFormat.ARGB32;  
 | 
                    break;  
 | 
                default:  
 | 
                    rt.format = RenderTextureFormat.ARGB4444;  
 | 
                    break;  
 | 
            }  
 | 
  
 | 
            rt.useMipMap = false;  
 | 
            rt.wrapMode = TextureWrapMode.Clamp;  
 | 
            rt.filterMode = FilterMode.Bilinear;  
 | 
  
 | 
            m_TargetCamera.targetTexture = rt;  
 | 
  
 | 
            if (!m_RenderTexDict.ContainsKey(m_Size))  
 | 
            {  
 | 
                m_RenderTexDict.Add(m_Size, rt);  
 | 
            }  
 | 
        }  
 | 
  
 | 
    } 
 | 
  
 | 
    public static bool GetRenderTexture(Vector2 _Size, out RenderTexture _tex)  
 | 
    {  
 | 
        return m_RenderTexDict.TryGetValue(_Size, out _tex);  
 | 
    } 
 | 
  
 | 
} 
 |