Texture.updateCount

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Submission failed

For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

public uint updateCount;

Description

This counter is incremented when the texture is updated.

Note: If you perform an update from the GPU side, you should increment the counter yourself. (For instance, when blitting into a RenderTexture). (see 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(Texture texture) { 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, Texture texture) { /* copy pixels in cache */ } int GetNextIndex() { return -1; /* Get next index to use in the cache */ } }
对文档有任何疑问,请移步至开发者社区提问,我们将尽快为您解答