using System; using UnityEngine; namespace UnityEditor.Build.Pipeline.Utilities { interface ICachedData {} /// /// Stores asset information for the cache. /// [Serializable] public class CachedInfo : ICachedData { /// /// Stores the asset. /// public CacheEntry Asset { get; set; } /// /// Stores the asset dependencies. /// public CacheEntry[] Dependencies { get; set; } /// /// Stores extra data related to the asset. /// public object[] Data { get; set; } } /// /// Creates a container to store data in build cache. /// [Serializable] public struct CacheEntry : IEquatable { /// /// Options for the cache entry type. /// public enum EntryType { /// /// Indicates that the entry is an asset. /// Asset, /// /// Indicates that the entry is a file. /// File, /// /// Indicates that the entry holds general data. /// Data, /// /// Indicates that the entry is a type. /// ScriptType } internal enum InclusionType { None, Explicit, Implicit } /// /// Stores the entry hash. /// public Hash128 Hash { get; internal set; } /// /// Stores the entry guid. /// public GUID Guid { get; internal set; } /// /// Stores the entry version. /// public int Version { get; internal set; } /// /// Stores the entry type. /// public EntryType Type { get; internal set; } internal InclusionType Inclusion { get; set; } /// /// Stores the entry file name. /// public string File { get; internal set; } /// /// Stores the entry scripting type. /// public string ScriptType { get; internal set; } /// /// Determines if the entry is valid. /// /// Returns true if the entry is valid. Returns false otherwise. public bool IsValid() { return Hash.isValid && !Guid.Empty(); } /// /// Determines if the current entry instance is equal to the specified entry. /// /// The entry to compare. /// Returns true if the entries are equivalent. Returns false otherwise. public override bool Equals(object obj) { if (ReferenceEquals(null, obj)) return false; return obj is CacheEntry && Equals((CacheEntry)obj); } /// public static bool operator==(CacheEntry x, CacheEntry y) { return x.Equals(y); } /// public static bool operator!=(CacheEntry x, CacheEntry y) { return !(x == y); } /// /// Creates the hash code for the cache entry. /// /// Returns the hash code for the cache entry. public override int GetHashCode() { unchecked { var hashCode = Hash.GetHashCode(); hashCode = (hashCode * 397) ^ Guid.GetHashCode(); hashCode = (hashCode * 397) ^ Version; hashCode = (hashCode * 397) ^ (int)Type; hashCode = (hashCode * 397) ^ (int)Inclusion; hashCode = (hashCode * 397) ^ (File != null ? File.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (ScriptType != null ? ScriptType.GetHashCode() : 0); return hashCode; } } /// /// Converts the information about the cache entry to a formatted string. /// /// Returns information about the cache entry. public override string ToString() { if (Type == EntryType.File) return string.Format("({0}, {1})", File, Hash); if (Type == EntryType.ScriptType) return string.Format("({0}, {1})", ScriptType, Hash); return string.Format("({0}, {1})", Guid, Hash); } /// /// Determines if the current entry instance is equal to the specified entry. /// /// The entry to compare. /// Returns true if the entries are equivalent. Returns false otherwise. public bool Equals(CacheEntry other) { return Hash.Equals(other.Hash) && Guid.Equals(other.Guid) && Version == other.Version && Type == other.Type && Inclusion == other.Inclusion && string.Equals(File, other.File) && string.Equals(ScriptType, other.ScriptType); } } }