Texture.updateCount

Unity · Версия 2020.3 LTS · Scripting · Texture

Texture.updateCount

public uint updateCount;

Описание

Этот счетчик увеличивается при обновлении текстуры.

Примечание. Если вы выполняете обновление на стороне графического процессора, вам следует самостоятельно увеличить значение счетчика. (Например, при переносе в RenderTexture). (см. IncrementUpdateCount).

using UnityEngine;
using System.Collections.Generic;

public class MyTextureCache
{
    struct TextureCacheMeta
    {
        internal int index;
        internal uint updateCount;
    }

    Dictionary<Texture, TextureCacheMeta> m_TextureMetas = new Dictionary<Texture, TextureCacheMeta>();
    RenderTexture m_Cache;

    public Texture cache { get { return m_Cache; } }

    public int CacheTexture(TextureTexture)
    {
        var index = -1;
        TextureCacheMeta meta;
        if (m_TextureMetas.TryGetValue(Texture, out meta))
        {
            if (meta.updateCount != Texture.updateCount)
            {
                // Texture has changed since last caching
                // So blit again into the cache Texture
                BlitTextureAt(meta.index, Texture);
                meta.updateCount = Texture.updateCount;
                m_TextureMetas[Texture] = meta;
            }
        }
        else
        {
            index = GetNextIndex();
            if (index < 0)
            {
                Debug.LogError("Invalid index");
                return -1;
            }

            m_TextureMetas[Texture] = new TextureCacheMeta
            {
                index = index,
                updateCount = Texture.updateCount
            };
        }
        return index;
    }

    void BlitTextureAt(int index, TextureTexture) { /* copy pixels in cache */ }
    int GetNextIndex() { return -1; /* Get next index to use in the cache */ }
}

Обновлено 17 ноября 2026 г.