/// <summary>
 /// Creates a new ContentCatalogEntry object.
 /// </summary>
 /// <param name="type">The entry type.</param>
 /// <param name="internalId">The internal id.</param>
 /// <param name="provider">The provider id.</param>
 /// <param name="keys">The collection of keys that can be used to retrieve this entry.</param>
 /// <param name="dependencies">Optional collection of keys for dependencies.</param>
 /// <param name="extraData">Optional additional data to be passed to the provider.  For example, AssetBundleProviders use this for cache and crc data.</param>
 /// <param name="allowLocalMode">Optional Allow load asset from local path (InternalId).</param>
 public ContentCatalogDataEntry(Type type, string internalId, string provider, IEnumerable <object> keys, IEnumerable <object> dependencies = null, object extraData = null, EnumLocalResourceMode allowLocalMode = EnumLocalResourceMode.Disable)
 {
     InternalId     = internalId;
     Provider       = provider;
     ResourceType   = type;
     Keys           = new List <object>(keys);
     Dependencies   = dependencies == null ? new List <object>() : new List <object>(dependencies);
     Data           = extraData;
     AllowLocalMode = allowLocalMode;
 }
 /// <summary>
 /// Construct a new ResourceLocationData object.
 /// </summary>
 /// <param name="keys">Array of keys for the location.  This must contain at least one item.</param>
 /// <param name="id">The internal id.</param>
 /// <param name="provider">The provider id.</param>
 /// <param name="t">The resource object type.</param>
 /// <param name="allowLocalMode">The mode that load asset from local file.</param>
 /// <param name="dependencies">Optional array of dependencies.</param>
 public ResourceLocationData(string[] keys, string id, Type provider, Type t, EnumLocalResourceMode allowLocalMode, string[] dependencies = null)
 {
     m_Keys         = keys;
     m_InternalId   = id;
     m_Provider     = provider == null ? "" : provider.FullName;
     m_Dependencies = dependencies == null ? new string[0] : dependencies;
     m_ResourceType = new SerializedType()
     {
         Value = t
     };
     m_AllowLocalMode = allowLocalMode;
 }
 public CompactLocation(ResourceLocationMap locator, string internalId, string providerId, object dependencyKey, object data, int depHash, string primaryKey, Type type, EnumLocalResourceMode allowLocalMode)
 {
     m_Locator            = locator;
     m_InternalId         = internalId;
     m_ProviderId         = providerId;
     m_Dependency         = dependencyKey;
     m_Data               = data;
     m_HashCode           = internalId.GetHashCode() * 31 + providerId.GetHashCode();
     m_DependencyHashCode = depHash;
     m_PrimaryKey         = primaryKey;
     m_Type               = type == null ? typeof(object) : type;
     m_AllowLocalMode     = allowLocalMode;
 }
 internal AddressableAssetEntry(string guid, string address, AddressableAssetGroup parent, bool readOnly, EnumLocalResourceMode allowLocalMode)
 {
     if (guid.Length > 0 && address.Contains("[") && address.Contains("]"))
     {
         Debug.LogErrorFormat("Address '{0}' cannot contain '[ ]'.", address);
     }
     m_GUID           = guid;
     m_Address        = address;
     m_ReadOnly       = readOnly;
     m_AllowLocalMode = allowLocalMode;
     parentGroup      = parent;
     IsInResources    = false;
     IsInSceneList    = false;
 }
示例#5
0
 /// <summary>
 /// Construct a new ResourceLocationBase.
 /// </summary>
 /// <param name="name">The name of the location.  This is usually set to the primary key, or "address" of the location.</param>
 /// <param name="id">The internal id of the location.  This is used by the IResourceProvider to identify the object to provide.  For example this may contain the file path or url of an asset.</param>
 /// <param name="providerId">The provider id.  This is set to the FullName of the type of the provder class.</param>
 /// <param name="t">The type of the object to provide.</param>
 /// <param name="allowLocalMode">The mode that load asset from local file.</param>
 /// <param name="dependencies">Locations for the dependencies of this location.</param>
 public ResourceLocationBase(string name, string id, string providerId, EnumLocalResourceMode allowLocalMode, Type t, params IResourceLocation[] dependencies)
 {
     if (string.IsNullOrEmpty(id))
     {
         throw new ArgumentNullException(nameof(id));
     }
     if (string.IsNullOrEmpty(providerId))
     {
         throw new ArgumentNullException(nameof(providerId));
     }
     m_PrimaryKey     = name;
     m_HashCode       = (name.GetHashCode() * 31 + id.GetHashCode()) * 31 + providerId.GetHashCode();
     m_Name           = name;
     m_Id             = id;
     m_ProviderId     = providerId;
     m_Dependencies   = new List <IResourceLocation>(dependencies);
     m_Type           = t == null ? typeof(object) : t;
     m_AllowLocalMode = allowLocalMode;
     ComputeDependencyHash();
 }
        /// <summary>
        /// Create IResourceLocator object
        /// </summary>
        /// <param name="providerSuffix">If specified, this value will be appeneded to all provider ids.  This is used when loading additional catalogs that need to have unique providers.</param>
        /// <returns>ResourceLocationMap, which implements the IResourceLocator interface.</returns>
        public ResourceLocationMap CreateLocator(string providerSuffix = null)
        {
            var bucketData  = Convert.FromBase64String(m_BucketDataString);
            int bucketCount = BitConverter.ToInt32(bucketData, 0);
            var buckets     = new Bucket[bucketCount];
            int bi          = 4;

            for (int i = 0; i < bucketCount; i++)
            {
                var index = SerializationUtilities.ReadInt32FromByteArray(bucketData, bi);
                bi += 4;
                var entryCount = SerializationUtilities.ReadInt32FromByteArray(bucketData, bi);
                bi += 4;
                var entryArray = new int[entryCount];
                for (int c = 0; c < entryCount; c++)
                {
                    entryArray[c] = SerializationUtilities.ReadInt32FromByteArray(bucketData, bi);
                    bi           += 4;
                }
                buckets[i] = new Bucket {
                    entries = entryArray, dataOffset = index
                };
            }
            if (!string.IsNullOrEmpty(providerSuffix))
            {
                for (int i = 0; i < m_ProviderIds.Length; i++)
                {
                    if (!m_ProviderIds[i].EndsWith(providerSuffix, StringComparison.Ordinal))
                    {
                        m_ProviderIds[i] = m_ProviderIds[i] + providerSuffix;
                    }
                }
            }
            var extraData = Convert.FromBase64String(m_ExtraDataString);

            var keyData  = Convert.FromBase64String(m_KeyDataString);
            var keyCount = BitConverter.ToInt32(keyData, 0);
            var keys     = new object[keyCount];

            for (int i = 0; i < buckets.Length; i++)
            {
                keys[i] = SerializationUtilities.ReadObjectFromByteArray(keyData, buckets[i].dataOffset);
            }

            var locator = new ResourceLocationMap(m_LocatorId, buckets.Length);

            var entryData = Convert.FromBase64String(m_EntryDataString);
            int count     = SerializationUtilities.ReadInt32FromByteArray(entryData, 0);
            var locations = new IResourceLocation[count];

            for (int i = 0; i < count; i++)
            {
                var index      = kBytesPerInt32 + i * (kBytesPerInt32 * k_EntryDataItemPerEntry);
                var internalId = SerializationUtilities.ReadInt32FromByteArray(entryData, index);
                index += kBytesPerInt32;
                var providerIndex = SerializationUtilities.ReadInt32FromByteArray(entryData, index);
                index += kBytesPerInt32;
                var dependencyKeyIndex = SerializationUtilities.ReadInt32FromByteArray(entryData, index);
                index += kBytesPerInt32;
                var depHash = SerializationUtilities.ReadInt32FromByteArray(entryData, index);
                index += kBytesPerInt32;
                var dataIndex = SerializationUtilities.ReadInt32FromByteArray(entryData, index);
                index += kBytesPerInt32;
                var primaryKey = SerializationUtilities.ReadInt32FromByteArray(entryData, index);
                index += kBytesPerInt32;
                var resourceType = SerializationUtilities.ReadInt32FromByteArray(entryData, index);
                index += kBytesPerInt32;
                EnumLocalResourceMode allowMode = (EnumLocalResourceMode)SerializationUtilities.ReadInt32FromByteArray(entryData, index);
                object data = dataIndex < 0 ? null : SerializationUtilities.ReadObjectFromByteArray(extraData, dataIndex);
                locations[i] = new CompactLocation(locator, Addressables.ResolveInternalId(ExpandInternalId(m_InternalIdPrefixes, m_InternalIds[internalId])),
                                                   m_ProviderIds[providerIndex], dependencyKeyIndex < 0 ? null : keys[dependencyKeyIndex], data, depHash, keys[primaryKey].ToString(), m_resourceTypes[resourceType].Value, allowMode);
            }

            for (int i = 0; i < buckets.Length; i++)
            {
                var bucket = buckets[i];
                var key    = keys[i];
                var locs   = new IResourceLocation[bucket.entries.Length];
                for (int b = 0; b < bucket.entries.Length; b++)
                {
                    locs[b] = locations[bucket.entries[b]];
                }
                locator.Add(key, locs);
            }

            return(locator);
        }