void CreateCustomAssetPacks(AddressableAssetSettings settings, CustomAssetPackSettings customAssetPackSettings, bool resetAssetPackSchemaData)
        {
            List <CustomAssetPackEditorInfo> customAssetPacks = customAssetPackSettings.CustomAssetPacks;
            var assetPackToDataEntry      = new Dictionary <string, CustomAssetPackDataEntry>();
            var bundleIdToEditorDataEntry = new Dictionary <string, BuildProcessorDataEntry>();

            CreateBuildOutputFolders();

            foreach (AddressableAssetGroup group in settings.groups)
            {
                if (HasRequiredSchemas(settings, group))
                {
                    var assetPackSchema = group.GetSchema <PlayAssetDeliverySchema>();
                    // Reset schema data to match Custom Asset Pack Settings. This can occur when the CustomAssetPackSettings was deleted but the schema properties still use the old settings data.
                    if (resetAssetPackSchemaData || assetPackSchema.AssetPackIndex >= customAssetPacks.Count)
                    {
                        assetPackSchema.ResetAssetPackIndex();
                    }

                    CustomAssetPackEditorInfo assetPack = customAssetPacks[assetPackSchema.AssetPackIndex];
                    if (IsAssignedToCustomAssetPack(settings, group, assetPackSchema, assetPack))
                    {
                        CreateConfigFiles(group, assetPack.AssetPackName, assetPack.DeliveryType, assetPackToDataEntry, bundleIdToEditorDataEntry);
                    }
                }
            }

            // Create the bundleIdToEditorDataEntry. It contains information for relocating custom asset pack bundles when building a player.
            SerializeBuildProcessorData(bundleIdToEditorDataEntry.Values.ToList());

            // Create the CustomAssetPacksData.json file. It contains all custom asset pack information that can be used at runtime.
            SerializeCustomAssetPacksData(assetPackToDataEntry.Values.ToList());
        }
Esempio n. 2
0
        void DrawCustomAssetPackCallback(Rect rect, int index, bool isActive, bool isFocused)
        {
            float halfW = rect.width * 0.4f;
            CustomAssetPackEditorInfo currentAssetPack = m_Settings.CustomAssetPacks[index];

            EditorGUI.BeginDisabledGroup(currentAssetPack.AssetPackName == CustomAssetPackSettings.kInstallTimePackName);

            string oldName = currentAssetPack.AssetPackName;
            var    newName = EditorGUI.DelayedTextField(new Rect(rect.x, rect.y, halfW, rect.height), oldName);

            if (newName != oldName)
            {
                m_Settings.SetAssetPackName(index, newName);
            }

            DeliveryType oldType = currentAssetPack.DeliveryType;
            var          newType = (DeliveryType)EditorGUI.EnumPopup(new Rect(rect.x + halfW, rect.y, rect.width - halfW, rect.height), new GUIContent(""), oldType, IsDeliveryTypeEnabled);

            if (oldType != newType)
            {
                m_Settings.SetDeliveryType(index, newType);
            }

            EditorGUI.EndDisabledGroup();
        }
        bool IsAssignedToCustomAssetPack(AddressableAssetSettings settings, AddressableAssetGroup group, PlayAssetDeliverySchema schema, CustomAssetPackEditorInfo assetPack)
        {
            if (!schema.IncludeInAssetPack)
            {
                var    bundledSchema = group.GetSchema <BundledAssetGroupSchema>();
                string buildPath     = bundledSchema.BuildPath.GetValue(settings);
                if (BuildPathIncludedInStreamingAssets(buildPath))
                {
                    Addressables.LogWarning($"Group '{group.name}' has 'Include In Asset Pack' disabled, but its build path '{buildPath}' will be included in StreamingAssets at build time. " +
                                            $"The group will be assigned to the streaming assets pack.");
                }
                return(false);
            }
            if (assetPack.DeliveryType == DeliveryType.InstallTime)
            {
                return(false);
            }

            return(true);
        }