Exemplo n.º 1
0
        private static void CreateAddressableSettings(bool localMode, int releaseChannel)
        {
            AddressableAssetSettings settings = AddressableAssetSettingsDefaultObject.GetSettings(true);

            settings.ActivePlayModeDataBuilderIndex = localMode ? 0 : 2;
            settings.BuildRemoteCatalog             = true;
            settings.DisableCatalogUpdateOnStartup  = true;
            settings.ContiguousBundles             = true;
            settings.IgnoreUnsupportedFilesInBuild = true;
            settings.ShaderBundleNaming            = ShaderBundleNaming.Custom;

            // don't include built-in data, causes shader issues
            settings.groups.ForEach(g =>
            {
                PlayerDataGroupSchema schema = g.GetSchema <PlayerDataGroupSchema>();
                if (schema != null)
                {
                    schema.IncludeBuildSettingsScenes = false;
                    schema.IncludeResourcesFolders    = false;
                }
            });

            // setup profiles
            AddressableAssetProfileSettings profile = settings.profileSettings;

            // activate and (re)group assets
            foreach (string dir in GetWorldPaths())
            {
                string worldName = Path.GetFileName(dir);
                bool   isBase    = worldName == "Base";

                // create one profile per world
                string profileId = profile.GetProfileId(worldName);
                if (string.IsNullOrEmpty(profileId))
                {
                    profileId = profile.AddProfile(worldName, settings.activeProfileId);
                }

                string guid = AssetDatabase.AssetPathToGUID($"Assets/Worlds/{worldName}");

                // create group if non-existent
                AddressableAssetGroup group = settings.groups.FirstOrDefault(g => g.name == worldName);
                if (group == null)
                {
                    group = CreateAssetGroup <BundledAssetGroupSchema>(settings, worldName);
                }
                if (group.CanBeSetAsDefault())
                {
                    settings.DefaultGroup = group;                            // default group ensures there is no accidental local default group resulting in local paths being baked into addressable for shaders
                }
                // set correct path
                AddressableAssetEntry entry = settings.CreateOrMoveEntry(guid, group);
                entry.SetAddress($"Worlds/{worldName}");

                // set variables
                string localRoot    = Application.dataPath + $"/../traVRsal/{worldName}/[BuildTarget]";
                string remoteTarget = null;
                switch (releaseChannel)
                {
                case 0:
                    remoteTarget = AWSUtil.S3CDNRoot_Live;
                    break;

                case 1:
                    remoteTarget = AWSUtil.S3CDNRoot_Beta;
                    break;

                case 2:
                    remoteTarget = AWSUtil.S3CDNRoot_Alpha;
                    break;
                }
                profile.SetValue(profileId, AddressableAssetSettings.kLocalBuildPath, localRoot);
                profile.SetValue(profileId, AddressableAssetSettings.kLocalLoadPath, localRoot);
                profile.SetValue(profileId, AddressableAssetSettings.kRemoteBuildPath, $"ServerData/Worlds/{worldName}/[BuildTarget]");
                profile.SetValue(profileId, AddressableAssetSettings.kRemoteLoadPath, $"{remoteTarget}Worlds/{worldName}/[BuildTarget]");

                // ensure correct group settings
                BundledAssetGroupSchema groupSchema = group.GetSchema <BundledAssetGroupSchema>();
                groupSchema.UseAssetBundleCache = true;
                groupSchema.UseAssetBundleCrc   = false;
                groupSchema.IncludeInBuild      = isBase;
                groupSchema.RetryCount          = 3;
                groupSchema.BundleNaming        = BundledAssetGroupSchema.BundleNamingStyle.NoHash; // hash to disambiguate identically named files yields same error messages, e.g. standard shaders
                groupSchema.BundleMode          = BundledAssetGroupSchema.BundlePackingMode.PackTogether;
                groupSchema.Compression         = BundledAssetGroupSchema.BundleCompressionMode.LZ4;
                groupSchema.BuildPath.SetVariableByName(settings, localMode ? AddressableAssetSettings.kLocalBuildPath : AddressableAssetSettings.kRemoteBuildPath);
                groupSchema.LoadPath.SetVariableByName(settings, localMode ? AddressableAssetSettings.kLocalLoadPath : AddressableAssetSettings.kRemoteLoadPath);
            }
        }