using System; using UnityEngine; namespace Ubisoft.Hotel.Package.Editor { public class PackageSuite : PackagePropertyComposite { public static PackageSuite CreateInstanceWithParams(string name) { PackageSuite returnValue = CreateInstance(); returnValue.name = name; return returnValue; } public delegate PackageProperty CreatePackagePropertyDelegate(EPlatform platform, string name, Type t, PackageSuiteSetup packageSuiteSetup); [SerializeField] private UnityEngine.Object m_parent; [SerializeField] private PackageSuiteSetup m_packageSuiteSetup; public PackageSuiteSetup PackageSuiteSetup { get { return m_packageSuiteSetup; } set { m_packageSuiteSetup = value; } } protected override void ExtendedSerialize(UnityEngine.Object parent) { m_parent = parent; base.ExtendedSerialize(parent); } public void ApplyPackageSuiteSetup(EPlatform platform, CreatePackagePropertyDelegate createPackageFunc) { if (PackageSuiteSetup != null && PackageSuiteSetup.Types != null) { int propertyIndex; PackageProperty property; bool refreshObject = false; // Check if any setup property has changed int count = PackageSuiteSetup.Types.Count; for (int i = 0; i < count && !refreshObject; ++i) { refreshObject = PackageSuiteSetup.HasChangedProperty(PackageSuiteSetup.Types[i]); } if (refreshObject) { // Renew all properties because a property might affect others foreach (Type type in PackageSuiteSetup.Types) { // Delete the former property property = PackageSuiteSetup.GetProperty(type); if (property != null) { propertyIndex = IndexOfProperty(property); RemoveProperty(property); property.Destroy(); refreshObject = true; } else { propertyIndex = -1; } // Create the new property property = createPackageFunc(platform, Name, type, PackageSuiteSetup); if (property != null) { // The new property is meant to occupy the same position as the former one in the property list if (propertyIndex == -1) { AddProperty(property); } else { InsertProperty(propertyIndex, property); } if (m_parent != null) { property.Serialize(m_parent); } } // Register the new property to the setup PackageSuiteSetup.RegisterProperty(type, PackageSuiteSetup.GetSelectedValueByType(type), property); } HtAssetDatabase.RefreshObject(m_parent); } } } } }