Пример #1
0
        internal void CreateCatalogEntriesInternal(List <ContentCatalogDataEntry> entries, bool isBundled, string providerType, IEnumerable <object> dependencies, object extraData, Dictionary <GUID, AssetLoadInfo> depInfo, HashSet <Type> providerTypes, bool includeAddress, bool includeGUID, bool includeLabels, HashSet <string> assetsInBundle)
        {
            if (string.IsNullOrEmpty(AssetPath))
            {
                return;
            }

            string        assetPath = GetAssetLoadPath(isBundled, assetsInBundle);
            List <object> keyList   = CreateKeyList(includeAddress, includeGUID, includeLabels);

            if (keyList.Count == 0)
            {
                return;
            }

            //The asset may have previously been invalid. Since then, it may have been re-imported.
            //This can occur in particular when using ScriptedImporters with complex, multi-step behavior.
            //Double-check the type here in case the asset has been imported correctly after we cached its type.
            if (MainAssetType == typeof(DefaultAsset))
            {
                m_cachedMainAssetType = null;
            }

            Type mainType = AddressableAssetUtility.MapEditorTypeToRuntimeType(MainAssetType, false);

            if ((mainType == null || mainType == typeof(DefaultAsset)) && !IsInResources)
            {
                var t = MainAssetType;
                Debug.LogWarningFormat("Type {0} is in editor assembly {1}.  Asset location with internal id {2} will be stripped.", t.Name, t.Assembly.FullName, assetPath);
                return;
            }

            Type runtimeProvider = GetRuntimeProviderType(providerType, mainType);

            if (runtimeProvider != null)
            {
                providerTypes.Add(runtimeProvider);
            }

            if (!IsScene)
            {
                ObjectIdentifier[] ids = depInfo != null ? depInfo[new GUID(guid)].includedObjects.ToArray() :
                                         ContentBuildInterface.GetPlayerObjectIdentifiersInAsset(new GUID(guid), EditorUserBuildSettings.activeBuildTarget);
                foreach (var t in GatherSubObjectTypes(ids, guid))
                {
                    entries.Add(new ContentCatalogDataEntry(t, assetPath, providerType, keyList, dependencies, extraData));
                }
            }
            else if (mainType != null && mainType != typeof(DefaultAsset))
            {
                entries.Add(new ContentCatalogDataEntry(mainType, assetPath, providerType, keyList, dependencies, extraData));
            }
        }
Пример #2
0
        internal void CreateCatalogEntriesInternal(List <ContentCatalogDataEntry> entries, bool isBundled, string providerType, IEnumerable <object> dependencies, object extraData, Dictionary <GUID, AssetLoadInfo> depInfo)
        {
            if (string.IsNullOrEmpty(AssetPath))
            {
                return;
            }

            string        assetPath = GetAssetLoadPath(isBundled);
            List <object> keyList   = CreateKeyList();
            Type          mainType  = AddressableAssetUtility.MapEditorTypeToRuntimeType(MainAssetType, false);

            if (mainType == null && !IsInResources)
            {
                var t = MainAssetType;
                Debug.LogWarningFormat("Type {0} is in editor assembly {1}.  Asset location with internal id {2} will be stripped.", t.Name, t.Assembly.FullName, assetPath);
                return;
            }

            if (mainType != null)
            {
                entries.Add(new ContentCatalogDataEntry(mainType, assetPath, providerType, keyList, dependencies, extraData));
            }

            if (!IsScene)
            {
                ObjectIdentifier[] ids = depInfo != null ? depInfo[new GUID(guid)].includedObjects.ToArray() :
                                         ContentBuildInterface.GetPlayerObjectIdentifiersInAsset(new GUID(guid), EditorUserBuildSettings.activeBuildTarget);

                if (ids.Length > 1)
                {
                    Type []        typesForObjs = ContentBuildInterface.GetTypeForObjects(ids);
                    HashSet <Type> typesSeen    = new HashSet <Type>();
                    typesSeen.Add(mainType);
                    foreach (var objType in typesForObjs)
                    {
                        if (typeof(Component).IsAssignableFrom(objType))
                        {
                            continue;
                        }
                        Type rtType = AddressableAssetUtility.MapEditorTypeToRuntimeType(objType, false);
                        if (rtType != null && !typesSeen.Contains(rtType))
                        {
                            entries.Add(new ContentCatalogDataEntry(rtType, assetPath, providerType, keyList, dependencies, extraData));
                            typesSeen.Add(rtType);
                        }
                    }
                }
            }
        }
Пример #3
0
        internal void CreateCatalogEntriesInternal(List <ContentCatalogDataEntry> entries, bool isBundled, string providerType, IEnumerable <object> dependencies, object extraData, Dictionary <GUID, AssetLoadInfo> depInfo, HashSet <Type> providerTypes, bool includeAddress, bool includeGUID, bool includeLabels, HashSet <string> assetsInBundle)
        {
            if (string.IsNullOrEmpty(AssetPath))
            {
                return;
            }

            string        assetPath = GetAssetLoadPath(isBundled, assetsInBundle);
            List <object> keyList   = CreateKeyList(includeAddress, includeGUID, includeLabels);

            if (keyList.Count == 0)
            {
                return;
            }

            Type mainType = AddressableAssetUtility.MapEditorTypeToRuntimeType(MainAssetType, false);

            if (mainType == null && !IsInResources)
            {
                var t = MainAssetType;
                Debug.LogWarningFormat("Type {0} is in editor assembly {1}.  Asset location with internal id {2} will be stripped.", t.Name, t.Assembly.FullName, assetPath);
                return;
            }

            Type runtimeProvider = GetRuntimeProviderType(providerType, mainType);

            if (runtimeProvider != null)
            {
                providerTypes.Add(runtimeProvider);
            }

            if (!IsScene)
            {
                ObjectIdentifier[] ids = depInfo != null ? depInfo[new GUID(guid)].includedObjects.ToArray() :
                                         ContentBuildInterface.GetPlayerObjectIdentifiersInAsset(new GUID(guid), EditorUserBuildSettings.activeBuildTarget);
                foreach (var t in GatherSubObjectTypes(ids, guid))
                {
                    entries.Add(new ContentCatalogDataEntry(t, assetPath, providerType, keyList, dependencies, extraData));
                }
            }
            else if (mainType != null)
            {
                entries.Add(new ContentCatalogDataEntry(mainType, assetPath, providerType, keyList, dependencies, extraData));
            }
        }
Пример #4
0
        static void GatherEntryLocations(AddressableAssetEntry entry, Type type, IList <IResourceLocation> locations, AddressableAssetTree assetTree)
        {
            if (!string.IsNullOrEmpty(entry.address) && entry.address.Contains("[") && entry.address.Contains("]"))
            {
                Debug.LogErrorFormat("Address '{0}' cannot contain '[ ]'.", entry.address);
                return;
            }
            using (new AddressablesFileEnumerationScope(assetTree))
            {
                entry.GatherAllAssets(null, true, true, false, e =>
                {
                    if (e.IsScene)
                    {
                        if (type == null || type == typeof(SceneInstance) || AddressableAssetUtility.MapEditorTypeToRuntimeType(e.MainAssetType, false) == type)
                        {
                            locations.Add(new ResourceLocationBase(e.address, e.AssetPath, typeof(SceneProvider).FullName, typeof(SceneInstance)));
                        }
                    }
                    else if (type == null || type.IsAssignableFrom(e.MainAssetType))
                    {
                        locations.Add(new ResourceLocationBase(e.address, e.AssetPath, typeof(AssetDatabaseProvider).FullName, e.MainAssetType));
                        return(true);
                    }
                    else
                    {
                        ObjectIdentifier[] ids = ContentBuildInterface.GetPlayerObjectIdentifiersInAsset(new GUID(e.guid), EditorUserBuildSettings.activeBuildTarget);
                        if (ids.Length > 1)
                        {
                            foreach (var t in AddressableAssetEntry.GatherSubObjectTypes(ids, e.guid))
                            {
                                if (type.IsAssignableFrom(t))
                                {
                                    locations.Add(new ResourceLocationBase(e.address, e.AssetPath, typeof(AssetDatabaseProvider).FullName, t));
                                }
                            }

                            return(true);
                        }
                    }
                    return(false);
                });
            }
        }
Пример #5
0
 internal static void AddLocations(IList <IResourceLocation> locations, Type type, string keyStr, string internalId)
 {
     if (!string.IsNullOrEmpty(internalId) && !string.IsNullOrEmpty(AssetDatabase.AssetPathToGUID(internalId)))
     {
         if (type == m_SpriteType && AssetDatabase.GetMainAssetTypeAtPath(internalId) == m_SpriteAtlasType)
         {
             locations.Add(new ResourceLocationBase(keyStr, internalId, typeof(AssetDatabaseProvider).FullName, m_SpriteAtlasType));
         }
         else
         {
             foreach (var obj in AssetDatabaseProvider.LoadAssetsWithSubAssets(internalId))
             {
                 var rtt = AddressableAssetUtility.MapEditorTypeToRuntimeType(obj.GetType(), false);
                 if (type.IsAssignableFrom(rtt))
                 {
                     locations.Add(new ResourceLocationBase(keyStr, internalId, typeof(AssetDatabaseProvider).FullName, rtt));
                 }
             }
         }
     }
 }
Пример #6
0
        static internal IEnumerable <Type> GatherSubObjectTypes(ObjectIdentifier[] ids, string guid)
        {
            if (ids.Length > 0)
            {
                Type[]         typesForObjs = ContentBuildInterface.GetTypeForObjects(ids);
                HashSet <Type> typesSeen    = new HashSet <Type>();
                foreach (var objType in typesForObjs)
                {
                    if (typeof(Component).IsAssignableFrom(objType))
                    {
                        continue;
                    }
                    Type rtType = AddressableAssetUtility.MapEditorTypeToRuntimeType(objType, false);
                    if (rtType != null && !typesSeen.Contains(rtType))
                    {
                        yield return(rtType);

                        typesSeen.Add(rtType);
                    }
                }
            }
        }