This repository has been archived by the owner on Sep 21, 2022. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Created TextureCache and implemented ImageDisplayData equality
- Loading branch information
Jackson Wood
committed
Jun 11, 2019
1 parent
e1e858a
commit 8858e3c
Showing
3 changed files
with
82 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
using System.Collections.Generic; | ||
using UnityEngine; | ||
|
||
namespace ModIO.UI | ||
{ | ||
/// <summary>Manages caching of the textures required by the UI.</summary> | ||
public class TextureCache : MonoBehaviour | ||
{ | ||
// ---------[ SINGLETON ]--------- | ||
/// <summary>The singleton instance of the TextureCache.</summary> | ||
private static TextureCache _instance; | ||
/// <summary>The singleton instance of the TextureCache.</summary> | ||
public static TextureCache instance | ||
{ | ||
get | ||
{ | ||
if(TextureCache._instance == null) | ||
{ | ||
TextureCache._instance = UIUtilities.FindComponentInScene<TextureCache>(true); | ||
|
||
if(TextureCache._instance == null) | ||
{ | ||
GameObject instanceGO = new GameObject("mod.io UI Texture Cache"); | ||
TextureCache._instance = instanceGO.AddComponent<TextureCache>(); | ||
} | ||
} | ||
|
||
return TextureCache._instance; | ||
} | ||
} | ||
|
||
// ---------[ FIELDS ]--------- | ||
/// <summary>Should the cache be cleared on disable</summary> | ||
public bool clearCacheOnDisable = true; | ||
|
||
/// <summary>The texture cache holding all versions of cached images.</summary> | ||
public Dictionary<ImageDisplayData, Texture2D[]> cache = new Dictionary<ImageDisplayData, Texture2D[]>(); | ||
|
||
// ---------[ INITIALIZATION ]--------- | ||
protected virtual void OnDisable() | ||
{ | ||
if(this.clearCacheOnDisable) | ||
{ | ||
this.cache.Clear(); | ||
} | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.