using System; using UnityEngine; namespace UnityEditor { /// /// Data structure to hold Name ID pair. /// [Serializable] public class SpriteNameFileIdPair : IEquatable { [SerializeField] private string m_Name; [SerializeField] private long m_FileId; [SerializeField] private GUID m_GUID; /// /// Name property. /// public string name { get { return m_Name; } set { m_Name = value; } } /// /// FileId property. This property is obsolete. Please use GetFileGUID and SetFileGUID instead. /// [Obsolete("Property obsolete. Please use GetFileGUID and SetFileGUID instead.")] public long fileId { get { return m_FileId; } set { m_FileId = value; SetFileGUID(GUID.CreateGUIDFromSInt64(m_FileId)); } } /// /// Returns the ID used for the name. /// /// GUID value. public GUID GetFileGUID() { return m_GUID; } /// /// Sets the ID used for the name. /// /// GUID value to set. public void SetFileGUID(GUID value) { if (value.Empty()) value = GUID.Generate(); m_GUID = value; } /// /// Default constructor. /// public SpriteNameFileIdPair() {} /// /// Constructor to initialize name and fileID. /// public SpriteNameFileIdPair(string name, GUID fileId) { this.name = name; SetFileGUID(fileId); } /// /// Custom hashcode generation. /// /// Int value representing the hash value. public override int GetHashCode() { return (name ?? string.Empty).GetHashCode() ^ m_GUID.GetHashCode(); } /// /// Override Equal operator. /// /// Object to compare. /// True if the same. False otherwise. public override bool Equals(object obj) { var pair = obj as SpriteNameFileIdPair; return pair != null && Equals(pair); } /// /// Override Equal operator. /// /// Object to compare. /// True if the same. False otherwise. public bool Equals(SpriteNameFileIdPair pair) { return pair != null && name == pair.name && GetFileGUID() == pair.GetFileGUID(); } } }