protected override string ProcessGroup(AddressableAssetGroup assetGroup, AddressableAssetsBuildContext aaContext)
    {
        var errorString = string.Empty;

        PlayerDataGroupSchema playerSchema = assetGroup.GetSchema <PlayerDataGroupSchema>();

        if (playerSchema != null)
        {
            m_legacy = CreateLocationsForPlayerData(playerSchema, assetGroup, aaContext.locations);
            return(errorString);
        }

        var allEntries = new List <AddressableAssetEntry>();

        foreach (var a in assetGroup.entries)
        {
            a.GatherAllAssets(allEntries, true, true);
        }

        var typeName = typeof(SyncAssetDatabaseProvider).FullName;

        foreach (var a in allEntries)
        {
            aaContext.locations.Add(new ContentCatalogDataEntry(a.GetAssetLoadPath(true), typeName, a.CreateKeyList()));
        }

        return(errorString);
    }
    public void WhenAssetHasDependencyOnBundle_AssetLocationIncludesRecursiveBundleDependencies()
    {
        GenerateLocationListsTask.Input input = GenerateDefaultInput();

        AddressableAssetGroup groupX = CreateGroupMappedToBundle(input, "X");
        AddressableAssetGroup groupY = CreateGroupMappedToBundle(input, "Y");
        AddressableAssetGroup groupZ = CreateGroupMappedToBundle(input, "Z");
        AddressableAssetGroup groupW = CreateGroupMappedToBundle(input, "W");

        CreateAddressablePrefab(input, "p1", groupX, "fileX", "fileY");
        CreateAddressablePrefab(input, "p2", groupY, "fileY");
        CreateAddressablePrefab(input, "p3", groupY, "fileY", "fileZ");
        CreateAddressablePrefab(input, "p4", groupZ, "fileZ");
        CreateAddressablePrefab(input, "p5", groupZ, "fileZ", "fileW");
        CreateAddressablePrefab(input, "p6", groupW, "fileW");

        input.AddressableAssetEntries = BuildAddressableAssetEntryList(input.Settings);
        GenerateLocationListsTask.Output output = GenerateLocationListsTask.RunInternal(input);

        AssertLocationDependencies(output, "p1", "bundleX", "bundleY", "bundleZ", "bundleW");
        AssertLocationDependencies(output, "p2", "bundleY", "bundleZ", "bundleW");
        AssertLocationDependencies(output, "p3", "bundleY", "bundleZ", "bundleW");
        AssertLocationDependencies(output, "p4", "bundleZ", "bundleW");
        AssertLocationDependencies(output, "p5", "bundleZ", "bundleW");
        AssertLocationDependencies(output, "p6", "bundleW");
    }
    public void WhenIncludeLabelsOptionChanged_LocationsKeysAreSetCorrectly()
    {
        GenerateLocationListsTask.Input input  = GenerateDefaultInput();
        AddressableAssetGroup           groupX = CreateGroupMappedToBundle(input, "X");
        var schema = groupX.GetSchema <BundledAssetGroupSchema>();
        var guid   = CreateAddressablePrefab(input, "p1", groupX, "fileX");

        groupX.GetAssetEntry(guid).SetLabel("LABEL1", true, true, true);
        input.AddressableAssetEntries = BuildAddressableAssetEntryList(input.Settings);

        schema.IncludeLabelsInCatalog = true;
        foreach (var l in GenerateLocationListsTask.RunInternal(input).Locations)
        {
            if (l.Provider == typeof(BundledAssetProvider).FullName)
            {
                CollectionAssert.Contains(l.Keys, "LABEL1");
            }
        }

        schema.IncludeLabelsInCatalog = false;
        foreach (var l in GenerateLocationListsTask.RunInternal(input).Locations)
        {
            if (l.Provider == typeof(BundledAssetProvider).FullName)
            {
                CollectionAssert.DoesNotContain(l.Keys, "LABEL1");
            }
        }
    }
    public void WhenIncludeGUIDInCatalog_SetFalse_GUIDSNotIncluded()
    {
        GenerateLocationListsTask.Input input  = GenerateDefaultInput();
        AddressableAssetGroup           groupX = CreateGroupMappedToBundle(input, "X");
        var schema = groupX.GetSchema <BundledAssetGroupSchema>();
        var guid   = CreateAddressablePrefab(input, "p1", groupX, "fileX");

        input.AddressableAssetEntries = BuildAddressableAssetEntryList(input.Settings);
        schema.IncludeGUIDInCatalog   = true;
        foreach (var l in GenerateLocationListsTask.RunInternal(input).Locations)
        {
            if (l.Provider == typeof(BundledAssetProvider).FullName)
            {
                CollectionAssert.Contains(l.Keys, guid);
            }
        }

        schema.IncludeGUIDInCatalog = false;
        foreach (var l in GenerateLocationListsTask.RunInternal(input).Locations)
        {
            if (l.Provider == typeof(BundledAssetProvider).FullName)
            {
                CollectionAssert.DoesNotContain(l.Keys, guid);
            }
        }
    }
        public void AddPostCatalogUpdates_AddsCallbackToUpdateBundleLocation_WhenNamingSchemaIsSetToFilenameOnly()
        {
            //Setup
            AddressableAssetGroup group = Settings.CreateGroup("TestAddPostCatalogUpdate", false, false, false,
                                                               new List <AddressableAssetGroupSchema>(), typeof(BundledAssetGroupSchema));

            group.GetSchema <BundledAssetGroupSchema>().BundleNaming = BundledAssetGroupSchema.BundleNamingStyle.NoHash;
            List <Action>           callbacks = new List <Action>();
            string                  targetBundlePathHashed         = "LocalPathToFile/testbundle_123456.bundle";
            string                  targetBundleInternalIdHashed   = "{runtime_val}/testbundle_123456.bundle";
            string                  targetBundleInternalIdUnHashed = "{runtime_val}/testbundle.bundle";
            ContentCatalogDataEntry dataEntry = new ContentCatalogDataEntry(typeof(ContentCatalogData), targetBundleInternalIdHashed, typeof(BundledAssetProvider).FullName, new List <object>());

            m_BuildScript.AddPostCatalogUpdatesInternal(group, callbacks, dataEntry, targetBundlePathHashed);

            //Assert setup
            Assert.AreEqual(1, callbacks.Count);
            Assert.AreEqual(targetBundleInternalIdHashed, dataEntry.InternalId);

            //Test
            callbacks[0].Invoke();

            //Assert
            Assert.AreEqual(targetBundleInternalIdUnHashed, dataEntry.InternalId);

            //Cleanup
            Settings.RemoveGroup(group);
        }
示例#6
0
        public void RemoveEntries_InvokesModificationNotification()
        {
            AddressableAssetGroup group1 = Settings.CreateGroup("group1", false, false, true, null, new Type[] {});

            List <AddressableAssetEntry> entries = new List <AddressableAssetEntry>();

            for (int i = 0; i < 10; i++)
            {
                group1.AddAssetEntry(new AddressableAssetEntry("000" + i.ToString(), "unknown" + i.ToString(), group1, false));
            }


            List <AddressableAssetEntry> callbackEntries = new List <AddressableAssetEntry>();
            Action <AddressableAssetSettings, AddressableAssetSettings.ModificationEvent, object> callback = (x, y, z) => callbackEntries.AddRange((AddressableAssetEntry[])z);

            AddressableAssetSettings.OnModificationGlobal += callback;

            group1.RemoveAssetEntries(entries.ToArray());

            for (int i = 0; i < entries.Count; i++)
            {
                Assert.AreEqual(entries[i], callbackEntries[i]);
            }

            //Cleanup
            AddressableAssetSettings.OnModificationGlobal -= callback;
            Settings.RemoveGroup(group1);
        }
示例#7
0
    private static void SetGroupsSetting(AddressableAssetGroup group,
                                         bool UseAssetBundleCache,
                                         bool UseAssetBundleCrc,
                                         BundledAssetGroupSchema.BundleNamingStyle BundleNaming,
                                         string BuildPath,
                                         string LoadPath,
                                         bool StaticContent)
    {
        BundledAssetGroupSchema bundledAssetGroupSchema = group.GetSchema <BundledAssetGroupSchema>();

        if (bundledAssetGroupSchema == null)
        {
            bundledAssetGroupSchema = group.AddSchema <BundledAssetGroupSchema>();
        }
        //bundledAssetGroupSchema.IncludeInBuild = true;
        bundledAssetGroupSchema.UseAssetBundleCache = UseAssetBundleCache;
        bundledAssetGroupSchema.UseAssetBundleCrc   = UseAssetBundleCrc;
        bundledAssetGroupSchema.BundleNaming        = BundleNaming;
        bundledAssetGroupSchema.BuildPath.SetVariableByName(group.Settings, BuildPath);
        bundledAssetGroupSchema.LoadPath.SetVariableByName(group.Settings, LoadPath);
        bundledAssetGroupSchema.SetAssetBundleProviderType(typeof(AssetBundleEncryptProvider));
        EditorUtility.SetDirty(bundledAssetGroupSchema);


        ContentUpdateGroupSchema contentUpdateGroupSchema = group.GetSchema <ContentUpdateGroupSchema>();

        if (contentUpdateGroupSchema == null)
        {
            contentUpdateGroupSchema = group.AddSchema <ContentUpdateGroupSchema>();
        }
        contentUpdateGroupSchema.StaticContent = StaticContent;
        EditorUtility.SetDirty(contentUpdateGroupSchema);
    }
        public void WhenLoadPathUsesHttp_AndInsecureHttpNotAllowed_BuildLogsWarning()
        {
#if UNITY_2022_1_OR_NEWER
            InsecureHttpOption oldHttpOption = PlayerSettings.insecureHttpOption;
            PlayerSettings.insecureHttpOption = InsecureHttpOption.NotAllowed;

            string remoteLoadPathId  = Settings.profileSettings.GetProfileDataByName(AddressableAssetSettings.kRemoteLoadPath).Id;
            string oldRemoteLoadPath = Settings.profileSettings.GetValueById(Settings.activeProfileId, remoteLoadPathId);
            Settings.profileSettings.SetValue(Settings.activeProfileId, AddressableAssetSettings.kRemoteLoadPath, "http://insecureconnection/");

            AddressableAssetGroup assetGroup = Settings.CreateGroup("InsecureConnections", false, false, false, null, typeof(BundledAssetGroupSchema));
            assetGroup.GetSchema <BundledAssetGroupSchema>().BuildPath.SetVariableById(Settings, Settings.profileSettings.GetProfileDataByName(AddressableAssetSettings.kRemoteBuildPath).Id);
            assetGroup.GetSchema <BundledAssetGroupSchema>().LoadPath.SetVariableById(Settings, Settings.profileSettings.GetProfileDataByName(AddressableAssetSettings.kRemoteLoadPath).Id);

            string assetPath = Path.Combine(TestFolder, "insecureConnectionsTest.prefab");
            PrefabUtility.SaveAsPrefabAsset(new GameObject(), assetPath);
            Settings.CreateOrMoveEntry(AssetDatabase.AssetPathToGUID(assetPath), assetGroup, false, false);

            var             context = new AddressablesDataBuilderInput(Settings);
            BuildScriptBase db      = (BuildScriptBase)Settings.DataBuilders.Find(x => x.GetType() == typeof(BuildScriptPackedMode));
            db.BuildData <AddressablesPlayerBuildResult>(context);
            LogAssert.Expect(LogType.Warning, $"Addressable group {assetGroup.Name} uses insecure http for its load path.  To allow http connections for UnityWebRequests, change your settings in Edit > Project Settings > Player > Other Settings > Configuration > Allow downloads over HTTP.");

            Settings.RemoveGroup(assetGroup);
            Settings.profileSettings.SetValue(Settings.activeProfileId, AddressableAssetSettings.kRemoteLoadPath, oldRemoteLoadPath);
            AssetDatabase.DeleteAsset(assetPath);
            PlayerSettings.insecureHttpOption = oldHttpOption;
#else
            Assert.Ignore($"Skipping test {nameof(WhenLoadPathUsesHttp_AndInsecureHttpNotAllowed_BuildLogsWarning)}.");
#endif
        }
示例#9
0
        public void ContentUpdateScenes_PackedTogetherByLabel_MarksAllScenesModifiedWithSharedLabel()
        {
            AddressableAssetGroup group = Settings.CreateGroup("SceneGroup", false, false, false, null, typeof(BundledAssetGroupSchema));

            group.GetSchema <BundledAssetGroupSchema>().BundleMode = BundledAssetGroupSchema.BundlePackingMode.PackTogetherByLabel;

            AddressableAssetEntry scene1 = new AddressableAssetEntry(m_SceneGuids[0], "scene1", group, false);
            AddressableAssetEntry scene2 = new AddressableAssetEntry(m_SceneGuids[1], "scene2", group, false);
            AddressableAssetEntry scene3 = new AddressableAssetEntry(m_SceneGuids[2], "scene3", group, false);

            group.AddAssetEntry(scene1, false);
            group.AddAssetEntry(scene2, false);
            group.AddAssetEntry(scene3, false);

            scene1.SetLabel("label", true);
            scene3.SetLabel("label", true);

            List <AddressableAssetEntry> modifedEnteries = new List <AddressableAssetEntry>()
            {
                scene1
            };

            ContentUpdateScript.AddAllDependentScenesFromModifiedEnteries(modifedEnteries);

            Assert.AreEqual(2, modifedEnteries.Count);
            Assert.AreEqual(scene1, modifedEnteries[0]);
            Assert.AreEqual(scene3, modifedEnteries[1]);

            Settings.RemoveGroup(group);
        }
示例#10
0
        public void ContentUpdateScenes_PackedSeperately_MarksNoAdditionalScenes()
        {
            AddressableAssetGroup group = Settings.CreateGroup("SceneGroup", false, false, false, null, typeof(BundledAssetGroupSchema));

            group.GetSchema <BundledAssetGroupSchema>().BundleMode = BundledAssetGroupSchema.BundlePackingMode.PackSeparately;

            AddressableAssetEntry scene1 = new AddressableAssetEntry(m_SceneGuids[0], "scene1", group, false);
            AddressableAssetEntry scene2 = new AddressableAssetEntry(m_SceneGuids[1], "scene2", group, false);
            AddressableAssetEntry scene3 = new AddressableAssetEntry(m_SceneGuids[2], "scene3", group, false);

            group.AddAssetEntry(scene1, false);
            group.AddAssetEntry(scene2, false);
            group.AddAssetEntry(scene3, false);

            List <AddressableAssetEntry> modifedEnteries = new List <AddressableAssetEntry>()
            {
                scene1
            };

            ContentUpdateScript.AddAllDependentScenesFromModifiedEnteries(modifedEnteries);

            Assert.AreEqual(1, modifedEnteries.Count);
            Assert.AreEqual(scene1, modifedEnteries[0]);

            Settings.RemoveGroup(group);
        }
        internal override void Setup(AddressableAssetSettings settings, string tempAssetFolder)
        {
            AddressableAssetGroup regGroup = settings.CreateGroup("localNoUWRGroup", false, false, true,
                                                                  new List <AddressableAssetGroupSchema>(), typeof(BundledAssetGroupSchema));

            regGroup.GetSchema <BundledAssetGroupSchema>().BundleNaming = BundledAssetGroupSchema.BundleNamingStyle.OnlyHash;

            AddressableAssetGroup forceUWRGroup = settings.CreateGroup("ForceUWRGroup", false, false, true,
                                                                       new List <AddressableAssetGroupSchema>(), typeof(BundledAssetGroupSchema));

            forceUWRGroup.GetSchema <BundledAssetGroupSchema>().UseUnityWebRequestForLocalBundles = true;
            forceUWRGroup.GetSchema <BundledAssetGroupSchema>().BundleMode   = BundledAssetGroupSchema.BundlePackingMode.PackSeparately;
            forceUWRGroup.GetSchema <BundledAssetGroupSchema>().BundleNaming = BundledAssetGroupSchema.BundleNamingStyle.OnlyHash;

            settings.MaxConcurrentWebRequests = kMaxConcurrentRequests;

            for (int i = 0; i < kForceUWRBundleCount; i++)
            {
                string s    = GetForceUWRAddrName(i);
                string guid = CreatePrefab(tempAssetFolder + $"/{s}.prefab");
                AddressableAssetEntry entry = settings.CreateOrMoveEntry(guid, forceUWRGroup);
                entry.address = s;
            }

            {
                string guid = CreatePrefab(tempAssetFolder + $"/testprefab.prefab");
                AddressableAssetEntry entry = settings.CreateOrMoveEntry(guid, regGroup);
                entry.address = "testprefab";
            }
        }
示例#12
0
        protected virtual string ConstructAssetBundleName(AddressableAssetGroup assetGroup, BundledAssetGroupSchema schema, BundleDetails info, string assetBundleName)
        {
            string groupName = assetGroup.Name.Replace(" ", "").Replace('\\', '/').Replace("//", "/").ToLower();

            assetBundleName = groupName + "_" + assetBundleName;
            return(BuildUtility.GetNameWithHashNaming(schema.BundleNaming, info.Hash.ToString(), assetBundleName));
        }
        public void DedupeEntries_WhenGroupsHaveOverlappingAssetEntries_RemovesEntries()
        {
            const string          guid    = "0000";
            const string          address = "not/a/real/address";
            AddressableAssetGroup group1  = Settings.CreateGroup("group1", false, false, true, null, new Type[] {});
            AddressableAssetGroup group2  = Settings.CreateGroup("group2", false, false, true, null, new Type[] {});

            //We're making 2 identical enteries.  This is to simulate each group having it's own copy of an AA Entry that references the same object.
            //If we use the same object the call to AddAssetEntry won't give us the state we're looking for.
            AddressableAssetEntry entry  = new AddressableAssetEntry(guid, address, group1, false);
            AddressableAssetEntry entry2 = new AddressableAssetEntry(guid, address, group2, false);

            group1.AddAssetEntry(entry);
            group2.AddAssetEntry(entry2);

            //Ensuring our setup is correct
            Assert.IsNotNull(group1.GetAssetEntry(guid));
            Assert.IsNotNull(group2.GetAssetEntry(guid));

            group1.DedupeEnteries(); //We setup our entry with group1 so it should retain its reference
            group2.DedupeEnteries(); //The entry was added to group2 afterwards and should lose its reference

            Assert.IsNotNull(group1.GetAssetEntry(guid));
            Assert.IsNull(group2.GetAssetEntry(guid));

            //Cleanup
            Settings.RemoveGroup(group1);
            Settings.RemoveGroup(group2);
        }
        /// <inheritdoc />
        protected override string ProcessGroup(AddressableAssetGroup assetGroup, AddressableAssetsBuildContext aaContext)
        {
            var errorString = string.Empty;
            PlayerDataGroupSchema playerSchema = assetGroup.GetSchema <PlayerDataGroupSchema>();

            if (playerSchema != null)
            {
                m_NeedsLegacyProvider = CreateLocationsForPlayerData(playerSchema, assetGroup, aaContext.locations);
                return(errorString);
            }

            var allEntries = new List <AddressableAssetEntry>();

            foreach (var a in assetGroup.entries)
            {
                a.GatherAllAssets(allEntries, true, true);
            }

            var providerType = typeof(AssetDatabaseProvider).FullName;

            foreach (var a in allEntries)
            {
                a.CreateCatalogEntries(aaContext.locations, false, providerType, null, null);
            }

            return(errorString);
        }
        /// <summary>
        /// Set default values taken from the assigned group.
        /// </summary>
        /// <param name="group">The group this schema has been added to.</param>
        protected override void OnSetGroup(AddressableAssetGroup group)
        {
            //this can happen during the load of the addressables asset
            if (group.Settings != null)
            {
                if (BuildPath == null || string.IsNullOrEmpty(BuildPath.GetValue(group.Settings)))
                {
                    m_BuildPath = new ProfileValueReference();
                    BuildPath.SetVariableByName(group.Settings, AddressableAssetSettings.kLocalBuildPath);
                }

                if (LoadPath == null || string.IsNullOrEmpty(LoadPath.GetValue(group.Settings)))
                {
                    m_LoadPath = new ProfileValueReference();
                    LoadPath.SetVariableByName(group.Settings, AddressableAssetSettings.kLocalLoadPath);
                }
            }

            if (m_AssetBundleProviderType.Value == null)
            {
                m_AssetBundleProviderType.Value = typeof(AssetBundleProvider);
            }
            if (m_BundledAssetProviderType.Value == null)
            {
                m_BundledAssetProviderType.Value = typeof(BundledAssetProvider);
            }
        }
示例#16
0
        /// <inheritdoc />
        protected override string ProcessGroup(AddressableAssetGroup assetGroup, AddressableAssetsBuildContext aaContext)
        {
            float index = 0.0f;

            foreach (var entry in assetGroup.entries)
            {
                if (entry.AssetPath == AddressableAssetEntry.ResourcesPath || entry.AssetPath == AddressableAssetEntry.EditorSceneListPath)
                {
                    GatherAssetsForFolder(entry, aaContext);
                }
                else if (File.Exists(entry.AssetPath) || Directory.Exists(entry.AssetPath))
                {
                    FileAttributes file = File.GetAttributes(entry.AssetPath);
                    if (file.HasFlag(FileAttributes.Directory))
                    {
                        GatherAssetsForFolder(entry, aaContext);
                    }
                    else
                    {
                        entry.CreateCatalogEntries(aaContext.locations, false, typeof(AssetDatabaseProvider).FullName,
                                                   null, null, aaContext.providerTypes);
                    }
                }
                else
                {
                    UnityEngine.Debug.LogError("File not found: " + entry.AssetPath);
                }

                index++;
            }

            return(string.Empty);
        }
示例#17
0
        /// <inheritdoc />
        protected override string ProcessGroup(AddressableAssetGroup assetGroup, AddressableAssetsBuildContext aaContext)
        {
            foreach (var entry in assetGroup.entries)
            {
                if (entry != null && !string.IsNullOrEmpty(entry.AssetPath))
                {
                    if (entry.AssetPath == AddressableAssetEntry.ResourcesPath || entry.AssetPath == AddressableAssetEntry.EditorSceneListPath)
                    {
                        GatherAssetsForFolder(entry, aaContext);
                    }
                    else
                    {
                        FileAttributes file = File.GetAttributes(entry.AssetPath);
                        if (file.HasFlag(FileAttributes.Directory))
                        {
                            GatherAssetsForFolder(entry, aaContext);
                        }
                        else
                        {
                            entry.CreateCatalogEntries(aaContext.locations, false, typeof(AssetDatabaseProvider).FullName,
                                                       null, null, aaContext.providerTypes);
                        }
                    }
                }
            }

            return(string.Empty);
        }
    internal static string ErrorCheckBundleSettings(BundledAssetGroupSchema schema, AddressableAssetGroup assetGroup, AddressableAssetSettings settings)
    {
        var message = string.Empty;

        //var buildPath = settings.profileSettings.GetValueById(settings.activeProfileId, schema.BuildPath.Id);
        //var loadPath = settings.profileSettings.GetValueById(settings.activeProfileId, schema.LoadPath.Id);

        //var buildLocal = buildPath.Contains("[UnityEngine.AddressableAssets.Addressables.BuildPath]");
        //var loadLocal = loadPath.Contains("{UnityEngine.AddressableAssets.Addressables.RuntimePath}");

        //if ( buildLocal && !loadLocal )
        //{
        //	message = "BuildPath for group '" + assetGroup.Name + "' is set to the dynamic-lookup version of StreamingAssets, but LoadPath is not. \n";
        //}
        //else if ( !buildLocal && loadLocal )
        //{
        //	message = "LoadPath for group " + assetGroup.Name + " is set to the dynamic-lookup version of StreamingAssets, but BuildPath is not. These paths must both use the dynamic-lookup, or both not use it. \n";
        //}

        //if ( !string.IsNullOrEmpty( message ) )
        //{
        //	message += "BuildPath: '" + buildPath + "'\n";
        //	message += "LoadPath: '" + loadPath + "'";
        //}

        return(message);
    }
示例#19
0
        internal static void CreateResourceLocationData(
            AddressableAssetGroup assetGroup,
            string bundleName,
            string bundleInternalId,
            string bundleProvider,
            string assetProvider,
            List <GUID> assetsInBundle,
            HashSet <string> bundleDependencies,
            List <ContentCatalogDataEntry> locations,
            HashSet <Type> providerTypes)
        {
            locations.Add(new ContentCatalogDataEntry(typeof(IAssetBundleResource), bundleInternalId, bundleProvider, new object[] { bundleName }));

            var assets = new List <AddressableAssetEntry>();

            assetGroup.GatherAllAssets(assets, true, true, false);
            var guidToEntry = new Dictionary <string, AddressableAssetEntry>();

            foreach (var a in assets)
            {
                guidToEntry.Add(a.guid, a);
            }
            foreach (var a in assetsInBundle)
            {
                AddressableAssetEntry entry;
                if (!guidToEntry.TryGetValue(a.ToString(), out entry))
                {
                    continue;
                }
                entry.CreateCatalogEntries(locations, true, assetProvider, bundleDependencies, null, providerTypes);
            }
        }
        /// <summary>
        /// Loops over each group, after doing some data checking.
        /// </summary>
        /// <param name="aaContext">The Addressables builderInput object to base the group processing on</param>
        /// <returns>An error string if there were any problems processing the groups</returns>
        protected virtual string ProcessAllGroups(AddressableAssetsBuildContext aaContext)
        {
            if (aaContext == null ||
                aaContext.settings == null ||
                aaContext.settings.groups == null)
            {
                return("No groups found to process in build script " + Name);
            }
            //intentionally for not foreach so groups can be added mid-loop.
            for (int index = 0; index < aaContext.settings.groups.Count; index++)
            {
                AddressableAssetGroup assetGroup = aaContext.settings.groups[index];
                if (assetGroup == null)
                {
                    continue;
                }

                EditorUtility.DisplayProgressBar($"Processing Addressable Group", assetGroup.Name, (float)index / aaContext.settings.groups.Count);
                var errorString = ProcessGroup(assetGroup, aaContext);
                if (!string.IsNullOrEmpty(errorString))
                {
                    EditorUtility.ClearProgressBar();
                    return(errorString);
                }
            }

            EditorUtility.ClearProgressBar();
            return(string.Empty);
        }
示例#21
0
        public static void DedupeEnteries(this AddressableAssetGroup group)
        {
            var type       = typeof(AddressableAssetGroup);
            var methodInfo = type.GetMethod(nameof(DedupeEnteries), BindingFlags.Instance | BindingFlags.NonPublic);

            methodInfo.Invoke(group, new object[] { });
        }
        public void WhenLoadPathUsesHttp_AndInsecureHttpAllowed_BuildSucceeds()
        {
#if UNITY_2022_1_OR_NEWER
            InsecureHttpOption oldHttpOption = PlayerSettings.insecureHttpOption;
            PlayerSettings.insecureHttpOption = InsecureHttpOption.AlwaysAllowed;

            string remoteLoadPathId  = Settings.profileSettings.GetProfileDataByName(AddressableAssetSettings.kRemoteLoadPath).Id;
            string oldRemoteLoadPath = Settings.profileSettings.GetValueById(Settings.activeProfileId, remoteLoadPathId);
            Settings.profileSettings.SetValue(Settings.activeProfileId, AddressableAssetSettings.kRemoteLoadPath, "http://insecureconnection/");

            AddressableAssetGroup assetGroup = Settings.CreateGroup("InsecureConnections", false, false, false, null, typeof(BundledAssetGroupSchema));
            assetGroup.GetSchema <BundledAssetGroupSchema>().BuildPath.SetVariableById(Settings, Settings.profileSettings.GetProfileDataByName(AddressableAssetSettings.kRemoteBuildPath).Id);
            assetGroup.GetSchema <BundledAssetGroupSchema>().LoadPath.SetVariableById(Settings, Settings.profileSettings.GetProfileDataByName(AddressableAssetSettings.kRemoteLoadPath).Id);

            string assetPath = Path.Combine(TestFolder, "insecureConnectionsTest.prefab");
            PrefabUtility.SaveAsPrefabAsset(new GameObject(), assetPath);
            Settings.CreateOrMoveEntry(AssetDatabase.AssetPathToGUID(assetPath), assetGroup, false, false);

            var             context = new AddressablesDataBuilderInput(Settings);
            BuildScriptBase db      = (BuildScriptBase)Settings.DataBuilders.Find(x => x.GetType() == typeof(BuildScriptPackedMode));
            db.BuildData <AddressablesPlayerBuildResult>(context);
            LogAssert.NoUnexpectedReceived();

            Settings.RemoveGroup(assetGroup);
            Settings.profileSettings.SetValue(Settings.activeProfileId, AddressableAssetSettings.kRemoteLoadPath, oldRemoteLoadPath);
            AssetDatabase.DeleteAsset(assetPath);
            PlayerSettings.insecureHttpOption = oldHttpOption;
#else
            Assert.Ignore($"Skipping test {nameof(WhenLoadPathUsesHttp_AndInsecureHttpAllowed_BuildSucceeds)}.");
#endif
        }
示例#23
0
    public static void AutoGroup()
    {
        //是否启用简单命名方式
        bool   simplied = false;
        string assetPath;

        string[] dirs = Directory.GetDirectories(resPath);
        foreach (var item in dirs)
        {
            DirectoryInfo         dir      = new DirectoryInfo(item);
            var                   settings = AddressableAssetSettingsDefaultObject.Settings;
            AddressableAssetGroup Group    = CreateOrGetNonStaticGroup(settings, dir.Name);
            FileSystemInfo[]      files    = dir.GetFileSystemInfos();
            foreach (var file in files)
            {
                if (file.FullName.EndsWith(".meta"))
                {
                    continue;
                }
                assetPath = "Assets" + file.FullName.Substring(Application.dataPath.Length);
                var guid  = AssetDatabase.AssetPathToGUID(assetPath);
                var entry = settings.CreateOrMoveEntry(guid, Group);
                Debug.Log(assetPath);
                entry.address = assetPath;
                if (simplied)
                {
                    entry.address = Path.GetFileNameWithoutExtension(assetPath);
                }
                //设置资源标签
                //entry.SetLabel("labelname",true,true);
            }
        }
        AssetDatabase.SaveAssets();
        AssetDatabase.Refresh();
    }
示例#24
0
        static List <AddressableAssetEntry> SetEntries(AddressableAssetSettings aaSettings, Object[] targets)
        {
            if (aaSettings.DefaultGroup.ReadOnly)
            {
                Debug.LogError("Current default group is ReadOnly.  Cannot add addressable assets to it");
                return(null);
            }

            Undo.RecordObject(aaSettings, "AddressableAssetSettings");
            string path;
            var    guid = string.Empty;

            var entriesAdded = new List <AddressableAssetEntry>();
            var result       = new List <AddressableAssetEntry>();

            var modifiedGroups = new HashSet <AddressableAssetGroup>();

            AddressableAssetGroup modified = new AddressableAssetGroup();

            Type mainAssetType;

            foreach (var o in targets)
            {
                if (AddressableAssetUtility.GetPathAndGUIDFromTarget(o, out path, ref guid, out mainAssetType))
                {
                    var entry = aaSettings.FindAssetEntry(guid);
                    if (entry == null)
                    {
                        if (AddressableAssetUtility.IsInResources(path))
                        {
                            AddressableAssetUtility.SafeMoveResourcesToGroup(aaSettings, aaSettings.DefaultGroup, new List <string> {
                                path
                            });
                        }
                        else
                        {
                            var e = aaSettings.CreateOrMoveEntry(guid, aaSettings.DefaultGroup, false, false);
                            entriesAdded.Add(e);
                            modifiedGroups.Add(e.parentGroup);
                        }
                    }
                    else
                    {
                        result.Add(entry);
                    }
                }
            }

            foreach (var g in modifiedGroups)
            {
                g.SetDirty(AddressableAssetSettings.ModificationEvent.EntryMoved, entriesAdded, false, true);
            }

            aaSettings.SetDirty(AddressableAssetSettings.ModificationEvent.EntryMoved, entriesAdded, true, false);

            result.AddRange(entriesAdded);

            return(result);
        }
示例#25
0
    AddressableAssetGroup CreateGroupMappedToBundle(GenerateLocationListsTask.Input input, string postfix)
    {
        AddressableAssetGroup group = m_Settings.CreateGroup($"testGroup{postfix}", false, false, false, null, typeof(BundledAssetGroupSchema));

        input.BundleToAssetGroup[$"bundle{postfix}"] = group.Guid;
        input.FileToBundle[$"file{postfix}"]         = $"bundle{postfix}";
        return(group);
    }
    string MakeAddressable(AddressableAssetGroup group, string guid, string address = null)
    {
        var entry = m_Settings.CreateOrMoveEntry(guid, group, false, false);

        entry.address = address == null?Path.GetFileNameWithoutExtension(entry.AssetPath) : address;

        return(guid);
    }
示例#27
0
        internal static void AddAssetsToAddressablesGroup(HashSet <string> assetsAdded, string groupName = "")
        {
            if (AddressableAssetSettingsDefaultObject.Settings == null)
            {
                AddressableAssetSettingsDefaultObject.Settings =
                    AddressableAssetSettings.Create(AddressableAssetSettingsDefaultObject.kDefaultConfigFolder,
                                                    AddressableAssetSettingsDefaultObject.kDefaultConfigAssetName, true, true);
            }

            var settings = AddressableAssetSettingsDefaultObject.Settings;

            if (settings == null)
            {
                Debug.LogWarningFormat("[Addressables] settings file not found.\nPlease go to Menu/Window/Asset Management/Addressables/Groups, then click 'Create Addressables Settings' button.");
                return;
            }

            List <AddressableAssetEntry> groupEntriesModified = new List <AddressableAssetEntry>();
            var parseGroupNames = string.IsNullOrEmpty(groupName);

            foreach (var assetPath in assetsAdded)
            {
                string guid = AssetDatabase.AssetPathToGUID(assetPath);

                string platform;
                string language;
                AkAssetUtilities.ParseAssetPath(assetPath, out platform, out language);

                if (parseGroupNames)
                {
                    if (string.IsNullOrEmpty(platform))
                    {
                        Debug.LogError($"Wwise Addressables import : could not parse platform for {assetPath}.");
                        continue;
                    }
                    groupName = $"WwiseData_{platform}";

                    if (Path.GetFileName(assetPath) == "Init.bnk")
                    {
                        groupName = $"WwiseData_{platform}_InitBank";
                    }
                }

                AddressableAssetGroup group = GetOrAddGroup(settings, groupName);

                var groupEntry = settings.CreateOrMoveEntry(guid, group);
                if (groupEntry != null)
                {
                    groupEntriesModified.Add(groupEntry);
                }
            }

            if (groupEntriesModified.Count > 0)
            {
                settings.SetDirty(AddressableAssetSettings.ModificationEvent.EntryMoved, groupEntriesModified, true);
                AssetDatabase.SaveAssets();
            }
        }
        string ProcessVariants(ProcessVariantAssetsSchema schema, AddressableAssetGroup group, AddressableAssetsBuildContext context)
        {
            var settings = context.Settings;

            var entries = new List <AddressableAssetEntry>(group.entries);

            foreach (var mainEntry in entries)
            {
                if (AssetDatabase.GetMainAssetTypeAtPath(mainEntry.AssetPath) != typeof(GameObject))
                {
                    continue;
                }

                GameObject mainAsset = AssetDatabase.LoadMainAssetAtPath(mainEntry.AssetPath) as GameObject;
                if (!schema.PreprocessCheck(mainAsset))
                {
                    continue;
                }

                string fileName      = Path.GetFileNameWithoutExtension(mainEntry.AssetPath);
                string mainAssetPath = AssetDatabase.GUIDToAssetPath(mainEntry.guid);

                string groupDirectory = Path.Combine(defaultBaseDirectory, $"{group.Name}").Replace('\\', '/');
                string newPrefabPath  = groupDirectory + '/' + Path.GetFileName(mainEntry.AssetPath).Replace(fileName, $"{fileName}_variant");
                Directory.CreateDirectory(groupDirectory);

                if (!AssetDatabase.CopyAsset(mainAssetPath, newPrefabPath))
                {
                    Debug.LogError("Failed to copy asset " + mainAssetPath);
                    continue;
                }
                if (schema.deleteVariants)
                {
                    variantsPrefabsToDelete.Add(newPrefabPath);
                }
                GameObject variant = AssetDatabase.LoadAssetAtPath <GameObject>(newPrefabPath);

                foreach (var script in schema.variantAssetsScripts)
                {
                    script.ProcessVariantAsset(variant);
                }

                //Create the Variant Entry and set it's address and labels.
                var variantEntry = settings.CreateOrMoveEntry(AssetDatabase.AssetPathToGUID(newPrefabPath), mainEntry.parentGroup, false, false);
                variantEntry.address = mainEntry.address;
                foreach (string label in mainEntry.labels)
                {
                    variantEntry.SetLabel(label, true, false, false);
                }
                variantEntriesToRemove.Add(AssetDatabase.AssetPathToGUID(newPrefabPath));
                entriesToRestore.Add(new AssetEntry {
                    address = mainEntry.address, assetGUID = mainEntry.guid, group = mainEntry.parentGroup, labels = mainEntry.labels
                });
                settings.RemoveAssetEntry(AssetDatabase.AssetPathToGUID(mainEntry.AssetPath), false);
            }

            return(string.Empty);
        }
示例#29
0
        static void SetAaEntry(AddressableAssetSettings aaSettings, Object[] targets, bool create)
        {
            if (create && aaSettings.DefaultGroup.ReadOnly)
            {
                Debug.LogError("Current default group is ReadOnly.  Cannot add addressable assets to it");
                return;
            }

            Undo.RecordObject(aaSettings, "AddressableAssetSettings");

            var targetInfos = new List <TargetInfo>();

            foreach (var t in targets)
            {
                if (AddressableAssetUtility.GetPathAndGUIDFromTarget(t, out var path, out var guid, out var mainAssetType))
                {
                    targetInfos.Add(new TargetInfo()
                    {
                        Guid = guid, Path = path, MainAssetType = mainAssetType
                    });
                }
            }

            if (!create)
            {
                targetInfos.ForEach(ti =>
                {
                    AddressableAssetGroup group = aaSettings.FindAssetEntry(ti.Guid).parentGroup;
                    aaSettings.RemoveAssetEntry(ti.Guid);
                    AddressableAssetUtility.OpenAssetIfUsingVCIntegration(group);
                });
            }
            else
            {
                var resourceTargets = targetInfos.Where(ti => AddressableAssetUtility.IsInResources(ti.Path));
                var resourcePaths   = resourceTargets.Select(t => t.Path).ToList();
                var resourceGuids   = resourceTargets.Select(t => t.Guid).ToList();
                AddressableAssetUtility.SafeMoveResourcesToGroup(aaSettings, aaSettings.DefaultGroup, resourcePaths, resourceGuids);

                var entriesAdded     = new List <AddressableAssetEntry>();
                var modifiedGroups   = new HashSet <AddressableAssetGroup>();
                var otherTargetInfos = targetInfos.Except(resourceTargets);
                foreach (var info in otherTargetInfos)
                {
                    var e = aaSettings.CreateOrMoveEntry(info.Guid, aaSettings.DefaultGroup, false, false);
                    entriesAdded.Add(e);
                    modifiedGroups.Add(e.parentGroup);
                }

                foreach (var g in modifiedGroups)
                {
                    g.SetDirty(AddressableAssetSettings.ModificationEvent.EntryMoved, entriesAdded, false, true);
                    AddressableAssetUtility.OpenAssetIfUsingVCIntegration(g);
                }

                aaSettings.SetDirty(AddressableAssetSettings.ModificationEvent.EntryMoved, entriesAdded, true, false);
            }
        }
示例#30
0
 /// <summary>
 /// Attempts to get the group using the provided <paramref name="groupName"/>.
 /// </summary>
 /// <param name="settings">Reference to the <see cref="AddressableAssetSettings"/></param>
 /// <param name="groupName">The name of the group for the search.</param>
 /// <param name="group">The <see cref="AddressableAssetGroup"/> if found. Set to <see cref="null"/> if not found.</param>
 /// <returns>True if a group is found.</returns>
 static bool TryGetGroup(AddressableAssetSettings settings, string groupName, out AddressableAssetGroup group)
 {
     if (string.IsNullOrWhiteSpace(groupName))
     {
         group = settings.DefaultGroup;
         return(true);
     }
     return(((group = settings.groups.Find(g => string.Equals(g.Name, groupName.Trim()))) == null) ? false : true);
 }