コード例 #1
0
 public CompactLocation(ResourceLocationMap locator, string internalId, string providerId, object dependencyKey, object data, int depHash)
 {
     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;
 }
コード例 #2
0
 public CompactLocation(ResourceLocationMap locator, string internalId, string providerId, object dependencyKey, object data, int depHash, string primaryKey, Type type)
 {
     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;
 }
コード例 #3
0
        /// <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))
                    {
                        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);
            List <IResourceLocation> locations = new List <IResourceLocation>(count);

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

            for (int i = 0; i < buckets.Length; i++)
            {
                var bucket = buckets[i];
                var key    = keys[i];
                var locs   = new List <IResourceLocation>(bucket.entries.Length);
                foreach (var index in bucket.entries)
                {
                    locs.Add(locations[index]);
                }
                locator.Add(key, locs);
            }
            return(locator);
        }
コード例 #4
0
        /// <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);
        }