コード例 #1
0
        public void ReleaseRenderTexture(RenderTexture renderTexture, bool destroy)
        {
            int i     = 0;
            int count = this.renderTextures.Count;

            while (i < count)
            {
                RenderTextureItem renderTextureItem = this.renderTextures[i];
                if (renderTextureItem.RenderTexture == renderTexture)
                {
                    renderTextureItem.RenderTexture.DiscardContents();
                    if (destroy)
                    {
                        renderTextureItem.RenderTexture.Release();
                        UnityEngine.Object.Destroy(renderTextureItem.RenderTexture);
                        this.renderTextures.RemoveAt(i);
                    }
                    else
                    {
                        renderTextureItem.InUse = false;
                    }
                    break;
                }
                i++;
            }
        }
コード例 #2
0
        public RenderTexture GetRenderTexture(int width, int height)
        {
            RenderTexture            renderTexture = null;
            List <RenderTextureItem> list          = new List <RenderTextureItem>();

            for (int i = this.renderTextures.Count - 1; i >= 0; i--)
            {
                RenderTextureItem renderTextureItem = this.renderTextures[i];
                if (!renderTextureItem.InUse)
                {
                    if (renderTextureItem.Width != width || renderTextureItem.Height != height)
                    {
                        list.Add(renderTextureItem);
                    }
                    else if (renderTexture == null)
                    {
                        renderTextureItem.InUse = true;
                        renderTexture           = renderTextureItem.RenderTexture;
                    }
                }
            }
            int count = list.Count;

            for (int j = 0; j < count; j++)
            {
                RenderTextureItem renderTextureItem2 = list[j];
                this.renderTextures.Remove(renderTextureItem2);
                renderTextureItem2.RenderTexture.DiscardContents();
                renderTextureItem2.RenderTexture.Release();
                UnityEngine.Object.Destroy(renderTextureItem2.RenderTexture);
            }
            list.Clear();
            if (renderTexture == null)
            {
                int depth = 16;
                renderTexture = new RenderTexture(width, height, depth);
                renderTexture.autoGenerateMips = false;
                renderTexture.filterMode       = FilterMode.Point;
                RenderTextureItem renderTextureItem3 = new RenderTextureItem(renderTexture, width, height);
                renderTextureItem3.InUse = true;
                this.renderTextures.Add(renderTextureItem3);
            }
            return(renderTexture);
        }