public static RenderTexture Get(Pawn pawn, Vector2 size, Vector3 cameraOffset = default(Vector3), float cameraZoom = 1f) { Dictionary <Pawn, CachedPortrait> dictionary = PortraitsCache.GetOrCreateCachedPortraitsWithParams(size, cameraOffset, cameraZoom).CachedPortraits; CachedPortrait cachedPortrait = default(CachedPortrait); if (dictionary.TryGetValue(pawn, out cachedPortrait)) { if (!cachedPortrait.RenderTexture.IsCreated()) { cachedPortrait.RenderTexture.Create(); PortraitsCache.RenderPortrait(pawn, cachedPortrait.RenderTexture, cameraOffset, cameraZoom); } else if (cachedPortrait.Dirty) { PortraitsCache.RenderPortrait(pawn, cachedPortrait.RenderTexture, cameraOffset, cameraZoom); } dictionary.Remove(pawn); dictionary.Add(pawn, new CachedPortrait(cachedPortrait.RenderTexture, false, Time.time)); return(cachedPortrait.RenderTexture); } RenderTexture renderTexture = PortraitsCache.NewRenderTexture(size); PortraitsCache.RenderPortrait(pawn, renderTexture, cameraOffset, cameraZoom); dictionary.Add(pawn, new CachedPortrait(renderTexture, false, Time.time)); return(renderTexture); }
public static void SetDirty(Pawn pawn) { for (int i = 0; i < PortraitsCache.cachedPortraits.Count; i++) { Dictionary <Pawn, CachedPortrait> dictionary = PortraitsCache.cachedPortraits[i].CachedPortraits; CachedPortrait cachedPortrait = default(CachedPortrait); if (dictionary.TryGetValue(pawn, out cachedPortrait) && !cachedPortrait.Dirty) { dictionary.Remove(pawn); dictionary.Add(pawn, new CachedPortrait(cachedPortrait.RenderTexture, true, cachedPortrait.LastUseTime)); } } }
private static void SetAnimatedPortraitsDirty() { for (int i = 0; i < cachedPortraits.Count; i++) { Dictionary <Pawn, CachedPortrait> dictionary = cachedPortraits[i].CachedPortraits; toSetDirty.Clear(); foreach (KeyValuePair <Pawn, CachedPortrait> item in dictionary) { if (IsAnimated(item.Key) && !item.Value.Dirty) { toSetDirty.Add(item.Key); } } for (int j = 0; j < toSetDirty.Count; j++) { CachedPortrait cachedPortrait = dictionary[toSetDirty[j]]; dictionary.Remove(toSetDirty[j]); dictionary.Add(toSetDirty[j], new CachedPortrait(cachedPortrait.RenderTexture, dirty: true, cachedPortrait.LastUseTime)); } toSetDirty.Clear(); } }