yyl
2025-05-15 d341a47ed9bbb740f2ccb9d6d42fd74d5a1c6b5d
Main/Utility/RenderTextureCreator.cs
File was renamed from Utility/RenderTextureCreator.cs
@@ -2,7 +2,7 @@
using System.Collections.Generic;
using UnityEngine;
public class RenderTextureCreator : MonoBehaviour
public class RenderTextureCreator : MonoBehaviour
{
    [SerializeField] Vector2 m_Size;
    [SerializeField] Camera m_TargetCamera;
@@ -10,47 +10,47 @@
    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);
            }
        }
    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);
    public static bool GetRenderTexture(Vector2 _Size, out RenderTexture _tex)
    {
        return m_RenderTexDict.TryGetValue(_Size, out _tex);
    }
}