using System; using System.Collections.Generic; namespace UnityEngine.Localization.Metadata { /// /// Interface to indicate that the class contains Metadata. /// public interface IMetadataCollection { /// /// All Metadata entries contained in this collection. /// IList MetadataEntries { get; } /// /// Returns the first Metadata of type TObject or null if one does not exist. /// /// A type that implements /// TObject GetMetadata() where TObject : IMetadata; /// /// Populates list with all Metadata`s that are of type TObject. /// /// List to add the found types to. /// A type that implements void GetMetadatas(IList foundItems) where TObject : IMetadata; /// /// Returns a list of all Metadata`s that are of type TObject. /// /// A type that implements /// IList GetMetadatas() where TObject : IMetadata; /// /// Add the Metadata to the collection. /// PreloadAssetTableMetadata /// void AddMetadata(IMetadata md); /// /// Removes the Metadata if it is in the collection. /// /// /// True if the collection contained the Metadata. bool RemoveMetadata(IMetadata md); /// /// Returns true if the collection contains the Metadata. /// /// /// bool Contains(IMetadata md); } /// /// Holds a collection of that can be serialized. /// [Serializable] public class MetadataCollection : IMetadataCollection { [SerializeReference] List m_Items = new List(); /// /// /// public IList MetadataEntries => m_Items; /// /// Does the collection contain any Metadata? /// public bool HasData => MetadataEntries != null && MetadataEntries.Count > 0; /// /// Returns true if any metadata of type TObject contains this entry. /// /// /// public bool HasMetadata() where TObject : IMetadata { return GetMetadata() != null; } /// /// /// /// /// public TObject GetMetadata() where TObject : IMetadata { foreach (var md in m_Items) { if (md is TObject obj) { return obj; } } return default(TObject); } /// /// /// /// List that will be populated with the metadata that was found. /// public void GetMetadatas(IList foundItems) where TObject : IMetadata { foundItems.Clear(); foreach (var md in m_Items) { if (md is TObject obj) { foundItems.Add(obj); } } } /// /// /// /// /// public IList GetMetadatas() where TObject : IMetadata { var foundItems = new List(); GetMetadatas(foundItems); return foundItems; } /// /// /// /// public void AddMetadata(IMetadata md) { MetadataEntries.Add(md); } /// /// /// /// /// public bool RemoveMetadata(IMetadata md) { return m_Items.Remove(md); } /// /// /// /// /// public bool Contains(IMetadata md) { return m_Items.Contains(md); } } }