using System.Collections.Generic;
using System.IO;
using UnityEngine;
using UnityEditor;
namespace Ubisoft.Hotel.Addressables.Core.Editor
{
///
/// Class used to store settings to taylor Addressables build process.
///
public class AddressablesBuildSettings : ScriptableObject
{
public static readonly string AddressablesDirectory = "Assets/Hotel/Editor/Assets/Addressables";
public static readonly string RootDirectory = $"{AddressablesDirectory}/Build";
public static readonly string FileName = "AddressablesBuildSettings";
public static readonly string Path = $"{RootDirectory}/{FileName}.asset";
public static AddressablesBuildSettings GetSettings(bool create)
{
var settings = AssetDatabase.LoadAssetAtPath(Path);
if (create && settings == null)
{
settings = CreateInstance();
if (!AssetDatabase.IsValidFolder(RootDirectory))
{
_ = Directory.CreateDirectory(RootDirectory);
}
AssetDatabase.CreateAsset(settings, Path);
settings = AssetDatabase.LoadAssetAtPath(Path);
settings.Reset();
AssetDatabase.SaveAssets();
}
return settings;
}
///
/// When enabled remote asset bundles are stored in the store CDN.
/// When disabled remote asset bundles need to be stored to a CDN that is handled by the game.
///
[SerializeField]
private bool m_useStoreCdn;
///
/// When enabled all addressables group will be included in the build, typically to be able
/// to share a build without having to upload remote (FastFollow and OnDemand) asset bundles.
///
[SerializeField]
private bool m_useAllInstallTime;
///
/// List of group names to exclude from build.
///
[SerializeField]
private List m_groupNamesToExcludeFromBuild;
///
/// List of group labels to exclude from build.
///
[SerializeField]
private List m_groupLabelsToExcludeFromBuild;
///
/// Id of the host remote bucket to upload remote asset bundles to.
///
[SerializeField]
private string m_hostRemoteBucketId;
///
/// Path to the folder where remote asset bundles must be stored after built. This folder will be used
/// as source when remote asset bundles are pushed to the CDN when app CDN is enabled.
///
[SerializeField]
private string m_hostRemoteBuildPath;
///
/// Remote host to load remote asset bundles from.
///
[SerializeField]
private string m_hostRemoteLoadPath;
///
/// Suffix to add to remote host url root, typically composed of "bucketid/brahc_name/platform".
///
[SerializeField]
private string m_hostRemoteUrlSuffix;
public bool UseStoreCdn
{
get { return m_useStoreCdn; }
set { m_useStoreCdn = value; }
}
public bool UseAllInstallTime
{
get { return m_useAllInstallTime; }
set { m_useAllInstallTime = value; }
}
private List GroupNamesToExcludeFromBuild
{
get { return m_groupNamesToExcludeFromBuild; }
set { m_groupNamesToExcludeFromBuild = value; }
}
private List GroupLabelsToExcludeFromBuild
{
get { return m_groupLabelsToExcludeFromBuild; }
set { m_groupLabelsToExcludeFromBuild = value; }
}
public void ExcludeGroupNamesFromBuild(List groupNames)
{
if (groupNames != null)
{
foreach (string groupName in groupNames)
{
if (GroupNamesToExcludeFromBuild == null || !GroupNamesToExcludeFromBuild.Contains(groupName))
{
if (GroupNamesToExcludeFromBuild == null)
{
GroupNamesToExcludeFromBuild = new List();
}
GroupNamesToExcludeFromBuild.Add(groupName);
}
}
}
}
public void ExcludeGroupLabelsFromBuild(List groupLabels)
{
if (groupLabels != null)
{
foreach (string groupLabel in groupLabels)
{
if (GroupLabelsToExcludeFromBuild == null || !GroupLabelsToExcludeFromBuild.Contains(groupLabel))
{
if (GroupLabelsToExcludeFromBuild == null)
{
GroupLabelsToExcludeFromBuild = new List();
}
GroupLabelsToExcludeFromBuild.Add(groupLabel);
}
}
}
}
public string HostRemoteBuildPath
{
get { return m_hostRemoteBuildPath; }
set { m_hostRemoteBuildPath = value; }
}
public string HostRemoteLoadPath
{
get { return m_hostRemoteLoadPath; }
set { m_hostRemoteLoadPath = value; }
}
public string HostRemoteUrlSuffix
{
get { return m_hostRemoteUrlSuffix; }
set { m_hostRemoteUrlSuffix = value; }
}
public string HostRemoteBucketId
{
get { return m_hostRemoteBucketId; }
set { m_hostRemoteBucketId = value; }
}
public bool IsGroupNameExcludedFromBuild(string groupName)
{
return GroupNamesToExcludeFromBuild != null && GroupNamesToExcludeFromBuild.Contains(groupName);
}
public bool IsGroupLabelExcludedFromBuild(string groupLabel)
{
return GroupLabelsToExcludeFromBuild != null && GroupLabelsToExcludeFromBuild.Contains(groupLabel);
}
public void Reset()
{
UseStoreCdn = false;
UseAllInstallTime = false;
HostRemoteBucketId = null;
HostRemoteBuildPath = null;
HostRemoteLoadPath = null;
HostRemoteUrlSuffix = null;
if (GroupNamesToExcludeFromBuild != null)
{
GroupNamesToExcludeFromBuild.Clear();
}
if (GroupLabelsToExcludeFromBuild != null)
{
GroupLabelsToExcludeFromBuild.Clear();
}
}
}
}