Version: Unity 6.7 Alpha (6000.7)
LanguageEnglish
  • C#

AssetKey.GetHashCode

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

Declaration

public int GetHashCode();

Returns

int An integer hash code derived from the address, sub-asset name, and type.

Description

Computes a hash code for this key.

Consistent with AssetKey.Equals: keys that compare equal produce the same hash code. Derived from the address, sub-asset name, and type, so a key is safe to use as a dictionary key for a load cache.

<para>Use a key as a dictionary key for loaded assets.</para>

using System.Collections.Generic;
using Unity.Localization.Providers;
using UnityEngine;

namespace Unity.Localization.Samples { public class AssetKeyHashCodeExample { public void Run() { var loaded = new Dictionary<AssetKey, Texture2D>(); var key = new AssetKey("UI/Logo", typeof(Texture2D)); loaded[key] = new Texture2D(2, 2);

Debug.Log(loaded.ContainsKey(new AssetKey("UI/Logo", typeof(Texture2D)))); // True } } }