Skip to main content

HashedGeneralValue<T>

An abstract class in Alta.Values, Alta.

Base for game data assets (items, stats, recipes, materials and so on) that have a numeric hash. Assets are loaded lazily from Resources under the paths in HashedPathAttribute, or the type name if none.

Constructors​

MemberWhat it is
protected HashedGeneralValue()Use ScriptableObject.CreateInstance instead of new; Unity loads the saved ones from assets.

Fields​

MemberWhat it is
protected static readonly Logger loggerShared NLog logger for every hashed value of this type. Logs missing hashes and names.
5 private and internal fields
MemberWhat it is
private static bool isFailPrivate: set when a lookup fails with no items loaded. While set, CheckItems stops trying to load.
private static bool isInResourceLoadingPrivate: true while LoadAll is calling Resources.LoadAll, so ValidateHashes does not recurse.
private static Dictionary<uint, T> itemsPrivate: every loaded asset of the type, by hash.
private static Dictionary<string, T> itemsByNamePrivate: name lookup used by Get(string), built on first use.
private static string[] pathsPrivate: cached result of GetAssetPaths.

Properties​

MemberWhat it is
static IEnumerable<T> All { get; }Every loaded asset of this type. Loads them on first use.
static int Count { get; }How many assets of this type are loaded. Loads them on first use.
override Type Type { get; }The concrete asset type T.

Methods​

MemberWhat it is
static void CheckItems()Loads all assets of this type from Resources into the hash table if not already loaded. Called by the getters, so you rarely need it.
static T Get(uint hash)Finds an asset by hash (0 gives null) or by name. The name lookup strips spaces but does not lowercase your input, and names are stored lowercased, so pass lowercase.
static T Get(string name, bool isLogging = true)Finds an asset by hash (0 gives null) or by name. The name lookup strips spaces but does not lowercase your input, and names are stored lowercased, so pass lowercase.
void ValidateForTutorialInEditor()Empty in this build.
void ValidateHashes()Checks this asset's hash is valid and unique and registers it in the hash table. Mostly an editor tool.
protected static IReadOnlyCollection<TSubType> GetItems<TSubType>()Protected: all loaded assets that are of a given subtype.
protected virtual void OnValidate()Virtual Unity validation hook, empty in the base.
3 private and internal methods
MemberWhat it is
private static Dictionary<string, T> BuildNameDictionary()Private: builds the name lookup from all loaded assets, with names lowercased and spaces removed. Logs duplicate names.
private static IEnumerable<string> GetAssetPaths()Private: the Resources folders to load from, from HashedPathAttribute or else the type's name. Cached in paths.
private static IEnumerable<T> LoadAll()Private: loads every asset of the type from its Resources folders, with isInResourceLoading set while it runs.

Used in​

Members of other types that take, return or hold a HashedGeneralValue&lt;T>: