using System.Collections.Generic; using UnityEditor; using UnityEngine; namespace Ubisoft.Hotel.Package.Editor { public class AssetBuildProperty : PackageProperty { public static AssetBuildProperty CreateInstanceWithParams(string name) { AssetBuildProperty returnValue = CreateInstance(); returnValue.name = name; return returnValue; } [SerializeField] private List m_order; [SerializeField] private HashSet m_gitIgnorePaths; public List Order { get { return m_order; } private set { m_order = value; } } public HashSet GitIgnorePaths { get { return m_gitIgnorePaths; } private set { m_gitIgnorePaths = value; } } public void Clear() { if (Order != null) { Order.Clear(); } if (GitIgnorePaths != null) { GitIgnorePaths.Clear(); } } /// /// Place an order to copy the file or directory described by srcUnityPath into dstUnityPath /// Examples: /// 1)AddOrderItem("src_file", "dst_file") will search for the file '/Hotel/Assets//src_file'. /// If it's not found then it will search for '/Hotel/Assets/src_file' and it will copy the file found into '/Assets/dst_file' /// /// 2)AddOrderItem("src_directory/src_file", "dst_directory/dst_file") will search for the file '/Hotel/Assets//src_directory/src_file'. /// If it's not found then it will search for '/Hotel/Assets/src_directory/src_file' and it will copy the file found into '/Assets/dst_directory/dst_file.txt' /// /// 3)AddOrderItem("src_directory", "dst_directory") will search for the directory '/Hotel/Assets//src_directory'. /// If it's not found then it will search for '/Hotel/Assets/src_directory' and it will copy the directory found into '/Assets/dst_directory' /// /// /// 4)AddOrderItem("src_file", "") will search for the file '/Hotel/Assets//src_file'. /// If it's not found then it will search for '/Hotel/Assets/src_file' and it will copy the content of the directory found into '/Assets/src_file' /// /// /// 5)AddOrderItem("src_directory", "") will search for the directory '/Hotel/Assets//src_directory'. /// If it's not found then it will search for '/Hotel/Assets/src_directory' and it will copy the content of the directory found into '/Assets' /// /// /// Source path inside 'Hotel/Assets/[]' directory. is the selected build target (iOS, Android). /// Use '/' as a directory separator char regardless your dev platform /// Destination path inside 'Assets' directory. Use '/' as a directory separator char regardless your dev platform. /// Use "" if you want the file or directory to be copied into 'Assets' directory /// When true a symbolyc link between source and destination is created. Source needs to be a folder, symbolic links /// don't working with files. Use this option if consumers need to make modifications over files inside destination folder. /// Example: Android plugin configuration. /// Otherwise use false, which copies source over destination. This option is safer and prevents Unity from printing out /// a warning message, but consumers shouldn't modify any files in destination folder. /// Example: Firebase configuration file. /// When true'Hotel/Assets/[]' directory. is the selected build target (iOS, Android) /// will be used as the root path for srcUnityPath, otherwise project root will be used instead. public void AddOrderItem(string srcUnityPath, string dstUnityPath = "", bool useSymLink = false, bool useHotelAssetsRootPath = true) { if (Order == null) { Order = new List(); } AssetManager.OrderItem orderItem = GetOrderItemBySrcPath(srcUnityPath); if (orderItem == null) { orderItem = new AssetManager.OrderItem(srcUnityPath, dstUnityPath, useSymLink, useHotelAssetsRootPath); Order.Add(orderItem); } else { string message = $"Two destination paths are defined for source path {Debug.FormatTextInUserContext(srcUnityPath)}:"; message += $"{Debug.FormatTextInUserContext(orderItem.DstUnityPath)} and {Debug.FormatTextInUserContext(dstUnityPath)}."; message += "We're keeping the second one"; Log(message, ELogLevel.Warning); } } /// /// Add the unity path passed in to the list of paths that are added to .gitignore. /// /// Unity path to add to the list of paths in .gitignore. public void AddOrderPathToGitIgnore(string unityPath) { if (GitIgnorePaths == null) { GitIgnorePaths = new HashSet(); } GitIgnorePaths.Add(unityPath); } public void AddPathsToGitIgnore(HashSet pathsToGitIgnore) { if (GitIgnorePaths != null && pathsToGitIgnore != null) { pathsToGitIgnore.AddRange(GitIgnorePaths); } } private AssetManager.OrderItem GetOrderItemBySrcPath(string srcPath) { AssetManager.OrderItem returnValue = null; if (Order != null) { int count = Order.Count; for (int i = 0; i < count && returnValue == null; ++i) { if (Order[i].SrcUnityPath == srcPath) { returnValue = Order[i]; } } } return returnValue; } public override void Apply(BuildSuite buildSuite) { buildSuite.OrderProperty(this); } public void Join(AssetBuildProperty p) { if (p != null) { if (p.Order != null) { foreach (AssetManager.OrderItem orderItem in p.Order) { if (orderItem != null) { AddOrderItem(orderItem.SrcUnityPath, orderItem.DstUnityPath, orderItem.UseSymLink, orderItem.UseHotelAssetsRootPath); } } } if (p.GitIgnorePaths != null) { foreach (string path in p.GitIgnorePaths) { AddOrderPathToGitIgnore(path); } } } } public void PreBuild(EPlatform platform) { AssetManager.Unapply(); AssetManager.Apply(Order, platform); } public void PostBuild() { } } }