using System; using System.Collections.Generic; using UnityEngine; namespace Ubisoft.Hotel.Package.Editor { public class PackagePropertyComposite : PackageProperty { [SerializeField] private List m_properties; [NonSerialized] private UnityBuildProperty m_unitySettingsProperty; [NonSerialized] private UpmBuildProperty m_packagesSettingsProperty; protected override void ExtendedSerialize(UnityEngine.Object parent) { if (Properties != null) { foreach (PackageProperty p in Properties) { p.Serialize(parent); } } } public override void Destroy() { if (Properties != null) { // We need to make sure that all properties will be destroyed and removed from the ScriptableObject where they were attached to // We do not save assets here to boost performance because calling it once is enough and base.Destroy() will do so while (Properties.Count > 0) { HtAssetDatabase.DestroyImmediate(Properties[0], true, false); Properties.RemoveAt(0); } } base.Destroy(); } public override void Apply(BuildSuite buildSuite) { if (buildSuite != null) { if (Properties != null) { foreach (PackageProperty p in Properties) { if (p != null) { p.Apply(buildSuite); } } } } } public override void AddPackagePropertyPlayer(List list) { if (Properties != null) { foreach (PackageProperty p in Properties) { if (p != null) { p.AddPackagePropertyPlayer(list); } } } } public override void GenerateResources() { if (Properties != null) { foreach (PackageProperty p in Properties) { if (p != null) { p.GenerateResources(); } } } } public List Properties { get { return m_properties; } } public bool ContainsProperty(PackageProperty property) { return m_properties != null && property != null && m_properties.Contains(property); } public void AddProperty(PackageProperty property) { if (m_properties == null) { m_properties = new List(); } if (property == null) { Debug.EditorLogWarning($"You are attempting to add a null property to property called {Name}"); } else { m_properties.Add(property); } } protected void InsertProperty(int index, PackageProperty property) { if (m_properties != null) { m_properties.Insert(index, property); } } protected int IndexOfProperty(PackageProperty property) { return (m_properties == null) ? -1 : m_properties.IndexOf(property); } public void RemoveProperty(PackageProperty property) { if (ContainsProperty(property)) { _ = m_properties.Remove(property); } } public HashSet GetAllPropertiesOfType() { HashSet returnValue = new HashSet(); if (Properties != null) { foreach (PackageProperty p in Properties) { if (p is PackagePropertyComposite composite) { _ = returnValue.AddRange(composite.GetAllPropertiesOfType()); } else if (p is T) { _ = returnValue.Add(p); } } } return returnValue; } // // Helper methods // private UnityBuildProperty UnitySettingsProperty { get { if (m_unitySettingsProperty == null) { m_unitySettingsProperty = UnityBuildProperty.CreateInstanceWithParams($"{Name}:unity"); AddProperty(m_unitySettingsProperty); } return m_unitySettingsProperty; } } public void AddDefineSymbol(string symbol) { UnitySettingsProperty.AddDefineSymbol(symbol); } public void AddDefineSymbols(HashSet symbols) { UnitySettingsProperty.AddDefineSymbols(symbols); } public void AddPackage(string name, string version, PackageDefinition.EImplementation implementation) { if (m_packagesSettingsProperty == null) { m_packagesSettingsProperty = UpmBuildProperty.CreateInstanceWithParams($"{Name}:upm"); AddProperty(m_packagesSettingsProperty); } m_packagesSettingsProperty.AddPackage(name, version, implementation); } } }