From 20bb7ae6ab091f6d2545dbc66ce6082ca048e167 Mon Sep 17 00:00:00 2001 From: Unity Technologies <@unity.com> Date: Mon, 15 Jul 2019 00:00:00 +0200 Subject: [PATCH] com.unity.addressables@1.1.5 ## [1.1.5] - 2019-07-15 - Fixed scenario where scene unload destroys instantiated objects in different scenes. - Cleaned up SetDirty logic to remove excessive dirtying of assets. --- CHANGELOG.md | 4 ++ .../GUI/AddressableAssetSettingsInspector.cs | 2 +- .../AddressableAssetsSettingsGroupTreeView.cs | 46 +++++++++++----- Editor/GUI/AssetInspectorGUI.cs | 14 +++-- Editor/GUI/ContentUpdatePreviewWindow.cs | 8 ++- .../HostingServices/HostingServicesManager.cs | 4 +- .../Settings/AddressableAssetBuildSettings.cs | 11 +++- Editor/Settings/AddressableAssetEntry.cs | 2 +- Editor/Settings/AddressableAssetGroup.cs | 29 +++++----- .../Settings/AddressableAssetGroupSchema.cs | 2 +- .../Settings/AddressableAssetGroupTemplate.cs | 2 +- .../AddressableAssetProfileSettings.cs | 2 +- Editor/Settings/AddressableAssetSettings.cs | 55 ++++++++++--------- Editor/Settings/AddressableAssetUtility.cs | 4 +- Runtime/AddressablesImpl.cs | 2 +- Runtime/ResourceManager/ResourceManager.cs | 15 ++++- .../AddressablesIntegrationTestsImpl.cs | 32 +++++++++++ package.json | 6 +- 18 files changed, 163 insertions(+), 77 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8b199276..4d70a0ac 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ All notable changes to this package will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). +## [1.1.5] - 2019-07-15 + - Fixed scenario where scene unload destroys instantiated objects in different scenes. + - Cleaned up SetDirty logic to remove excessive dirtying of assets. + ## [1.1.4-preview] - 2019-06-19 - Fixed an issue where Editor only types were being added to the build. diff --git a/Editor/GUI/AddressableAssetSettingsInspector.cs b/Editor/GUI/AddressableAssetSettingsInspector.cs index a8987bf4..887b2e1b 100644 --- a/Editor/GUI/AddressableAssetSettingsInspector.cs +++ b/Editor/GUI/AddressableAssetSettingsInspector.cs @@ -175,7 +175,7 @@ public override void OnInspectorGUI() { var profile = m_AasTarget.profileSettings.profiles[m_CurrentProfileIndex]; profile.profileName = newName; - m_AasTarget.SetDirty(AddressableAssetSettings.ModificationEvent.ProfileModified, profile.id, true); + m_AasTarget.SetDirty(AddressableAssetSettings.ModificationEvent.ProfileModified, profile.id, true, true); } } } diff --git a/Editor/GUI/AddressableAssetsSettingsGroupTreeView.cs b/Editor/GUI/AddressableAssetsSettingsGroupTreeView.cs index a72478b6..f0db524a 100644 --- a/Editor/GUI/AddressableAssetsSettingsGroupTreeView.cs +++ b/Editor/GUI/AddressableAssetsSettingsGroupTreeView.cs @@ -852,7 +852,7 @@ protected void RemoveGroup(object context) if (EditorUtility.DisplayDialog("Delete selected groups?", "Are you sure you want to delete the selected groups?\n\nYou cannot undo this action.", "Yes", "No")) { List selectedNodes = context as List; - if (selectedNodes == null) + if (selectedNodes == null || selectedNodes.Count < 1) return; var groups = new List(); foreach (var item in selectedNodes) @@ -860,23 +860,26 @@ protected void RemoveGroup(object context) m_Editor.settings.RemoveGroupInternal(item.group, true, false); groups.Add(item.group); } - m_Editor.settings.SetDirty(AddressableAssetSettings.ModificationEvent.GroupRemoved, groups, true); + m_Editor.settings.SetDirty(AddressableAssetSettings.ModificationEvent.GroupRemoved, groups, true, true); } } protected void SimplifyAddresses(object context) { List selectedNodes = context as List; - if (selectedNodes == null) + if (selectedNodes == null || selectedNodes.Count < 1) return; var entries = new List(); - + HashSet modifiedGroups = new HashSet(); foreach (var item in selectedNodes) { item.entry.SetAddress(Path.GetFileNameWithoutExtension(item.entry.address), false); entries.Add(item.entry); + modifiedGroups.Add(item.entry.parentGroup); } - m_Editor.settings.SetDirty(AddressableAssetSettings.ModificationEvent.EntryMoved, entries, true); + foreach (var g in modifiedGroups) + g.SetDirty(AddressableAssetSettings.ModificationEvent.EntryModified, entries, false, true); + m_Editor.settings.SetDirty(AddressableAssetSettings.ModificationEvent.EntryModified, entries, true, false); } protected void RemoveEntry(object context) @@ -884,18 +887,22 @@ protected void RemoveEntry(object context) if (EditorUtility.DisplayDialog("Delete selected entries?", "Are you sure you want to delete the selected entries?\n\nYou cannot undo this action.", "Yes", "No")) { List selectedNodes = context as List; - if (selectedNodes == null) + if (selectedNodes == null || selectedNodes.Count < 1) return; var entries = new List(); + HashSet modifiedGroups = new HashSet(); foreach (var item in selectedNodes) { if (item.entry != null) { m_Editor.settings.RemoveAssetEntry(item.entry.guid, false); entries.Add(item.entry); + modifiedGroups.Add(item.entry.parentGroup); } } - m_Editor.settings.SetDirty(AddressableAssetSettings.ModificationEvent.EntryRemoved, entries, true); + foreach (var g in modifiedGroups) + g.SetDirty(AddressableAssetSettings.ModificationEvent.EntryModified, entries, false, true); + m_Editor.settings.SetDirty(AddressableAssetSettings.ModificationEvent.EntryRemoved, entries, true, false); } } @@ -1036,13 +1043,17 @@ protected override DragAndDropVisualMode HandleDragAndDrop(DragAndDropArgs args) if (canMarkNonResources) { var entries = new List(); + var modifiedGroups = new HashSet(); foreach (var p in nonResourcePaths) { - entries.Add(m_Editor.settings.CreateOrMoveEntry(AssetDatabase.AssetPathToGUID(p), parent, false, false)); + var e = m_Editor.settings.CreateOrMoveEntry(AssetDatabase.AssetPathToGUID(p), parent, false, false); + entries.Add(e); + modifiedGroups.Add(e.parentGroup); } - m_Editor.settings.SetDirty(AddressableAssetSettings.ModificationEvent.EntryMoved, entries, true); + foreach (var g in modifiedGroups) + g.SetDirty(AddressableAssetSettings.ModificationEvent.EntryMoved, entries, false, true); + m_Editor.settings.SetDirty(AddressableAssetSettings.ModificationEvent.EntryMoved, entries, true, false); } - } } } @@ -1072,7 +1083,7 @@ protected override DragAndDropVisualMode HandleDragAndDrop(DragAndDropArgs args) else m_Editor.settings.groups.Insert(args.insertAtIndex, group); - m_Editor.settings.SetDirty(AddressableAssetSettings.ModificationEvent.GroupMoved, m_Editor.settings.groups, true); + m_Editor.settings.SetDirty(AddressableAssetSettings.ModificationEvent.GroupMoved, m_Editor.settings.groups, true, true); Reload(); } else @@ -1092,11 +1103,16 @@ protected override DragAndDropVisualMode HandleDragAndDrop(DragAndDropArgs args) else { var entries = new List(); + var modifiedGroups = new HashSet(); foreach (var node in draggedNodes) - entries.Add(m_Editor.settings.CreateOrMoveEntry(node.entry.guid, parent, false, - false)); - m_Editor.settings.SetDirty(AddressableAssetSettings.ModificationEvent.EntryMoved, - entries, true); + { + var e = m_Editor.settings.CreateOrMoveEntry(node.entry.guid, parent, false, false); + entries.Add(e); + modifiedGroups.Add(e.parentGroup); + } + foreach (var g in modifiedGroups) + g.SetDirty(AddressableAssetSettings.ModificationEvent.EntryMoved, entries, false, true); + m_Editor.settings.SetDirty(AddressableAssetSettings.ModificationEvent.EntryMoved, entries, true, false); } } } diff --git a/Editor/GUI/AssetInspectorGUI.cs b/Editor/GUI/AssetInspectorGUI.cs index e2f55b82..0c3d5ecc 100644 --- a/Editor/GUI/AssetInspectorGUI.cs +++ b/Editor/GUI/AssetInspectorGUI.cs @@ -29,7 +29,7 @@ static void SetAaEntry(AddressableAssetSettings aaSettings, Object[] targets, bo //if (create || EditorUtility.DisplayDialog("Remove Addressable Asset Entries", "Do you want to remove Addressable Asset entries for " + targets.Length + " items?", "Yes", "Cancel")) { var entriesAdded = new List(); - + var modifiedGroups = new HashSet(); foreach (var t in targets) { if (AddressableAssetUtility.GetPathAndGUIDFromTarget(t, out path, ref guid)) @@ -37,9 +37,13 @@ static void SetAaEntry(AddressableAssetSettings aaSettings, Object[] targets, bo if (create) { if (AddressableAssetUtility.IsInResources(path)) - AddressableAssetUtility.SafeMoveResourcesToGroup(aaSettings, aaSettings.DefaultGroup, new List {path}); + AddressableAssetUtility.SafeMoveResourcesToGroup(aaSettings, aaSettings.DefaultGroup, new List { path }); else - entriesAdded.Add(aaSettings.CreateOrMoveEntry(guid, aaSettings.DefaultGroup, false, false)); + { + var e = aaSettings.CreateOrMoveEntry(guid, aaSettings.DefaultGroup, false, false); + entriesAdded.Add(e); + modifiedGroups.Add(e.parentGroup); + } } else aaSettings.RemoveAssetEntry(guid); @@ -48,7 +52,9 @@ static void SetAaEntry(AddressableAssetSettings aaSettings, Object[] targets, bo if (create) { - aaSettings.SetDirty(AddressableAssetSettings.ModificationEvent.EntryMoved, entriesAdded, true); + foreach (var g in modifiedGroups) + g.SetDirty(AddressableAssetSettings.ModificationEvent.EntryMoved, entriesAdded, false, true); + aaSettings.SetDirty(AddressableAssetSettings.ModificationEvent.EntryMoved, entriesAdded, true, false); } } } diff --git a/Editor/GUI/ContentUpdatePreviewWindow.cs b/Editor/GUI/ContentUpdatePreviewWindow.cs index eadc8130..f1d191d9 100644 --- a/Editor/GUI/ContentUpdatePreviewWindow.cs +++ b/Editor/GUI/ContentUpdatePreviewWindow.cs @@ -10,7 +10,13 @@ namespace UnityEditor.AddressableAssets.GUI { class ContentUpdatePreviewWindow : EditorWindow { - internal static bool PrepareForContentUpdate(AddressableAssetSettings settings, string buildPath) + /// + /// Opens ContentUpdatePreviewWindow. + /// + /// + /// + /// True if successful; false if otherwise (failed to get modified entries). + public static bool PrepareForContentUpdate(AddressableAssetSettings settings, string buildPath) { var modifiedEntries = ContentUpdateScript.GatherModifiedEntries(settings, buildPath); if (modifiedEntries == null) diff --git a/Editor/HostingServices/HostingServicesManager.cs b/Editor/HostingServices/HostingServicesManager.cs index 4f875282..7337c4e0 100644 --- a/Editor/HostingServices/HostingServicesManager.cs +++ b/Editor/HostingServices/HostingServicesManager.cs @@ -233,7 +233,7 @@ public IHostingService AddHostingService(Type serviceType, string name) m_Settings.profileSettings.RegisterProfileStringEvaluationFunc(svc.EvaluateProfileString); m_HostingServiceInfoMap.Add(svc, info); - m_Settings.SetDirty(AddressableAssetSettings.ModificationEvent.HostingServicesManagerModified, this, true); + m_Settings.SetDirty(AddressableAssetSettings.ModificationEvent.HostingServicesManagerModified, this, true, true); m_NextInstanceId++; return svc; @@ -252,7 +252,7 @@ public void RemoveHostingService(IHostingService svc) svc.StopHostingService(); m_Settings.profileSettings.UnregisterProfileStringEvaluationFunc(svc.EvaluateProfileString); m_HostingServiceInfoMap.Remove(svc); - m_Settings.SetDirty(AddressableAssetSettings.ModificationEvent.HostingServicesManagerModified, this, true); + m_Settings.SetDirty(AddressableAssetSettings.ModificationEvent.HostingServicesManagerModified, this, true, true); } /// diff --git a/Editor/Settings/AddressableAssetBuildSettings.cs b/Editor/Settings/AddressableAssetBuildSettings.cs index e4c2d2d3..00a37cb7 100644 --- a/Editor/Settings/AddressableAssetBuildSettings.cs +++ b/Editor/Settings/AddressableAssetBuildSettings.cs @@ -59,7 +59,14 @@ public bool cleanupStreamingAssetsAfterBuilds public bool LogResourceManagerExceptions { get { return m_LogResourceManagerExceptions; } - set { m_LogResourceManagerExceptions = value; } + set + { + if (m_LogResourceManagerExceptions != value) + { + m_LogResourceManagerExceptions = value; + SetDirty(); + } + } } /// @@ -88,7 +95,7 @@ internal void SerializeForHash(BinaryFormatter formatter, Stream stream) void SetDirty() { if (m_Settings != null) - m_Settings.SetDirty(AddressableAssetSettings.ModificationEvent.BuildSettingsChanged, this, true); + m_Settings.SetDirty(AddressableAssetSettings.ModificationEvent.BuildSettingsChanged, this, true, false); } internal void OnAfterDeserialize(AddressableAssetSettings settings) { diff --git a/Editor/Settings/AddressableAssetEntry.cs b/Editor/Settings/AddressableAssetEntry.cs index 5d0c9e62..5a60830e 100644 --- a/Editor/Settings/AddressableAssetEntry.cs +++ b/Editor/Settings/AddressableAssetEntry.cs @@ -225,7 +225,7 @@ internal void SerializeForHash(BinaryFormatter formatter, Stream stream) internal void SetDirty(AddressableAssetSettings.ModificationEvent e, object o, bool postEvent) { if (parentGroup != null) - parentGroup.SetDirty(e, o, postEvent); + parentGroup.SetDirty(e, o, postEvent, true); } /// diff --git a/Editor/Settings/AddressableAssetGroup.cs b/Editor/Settings/AddressableAssetGroup.cs index daad8314..971b3101 100644 --- a/Editor/Settings/AddressableAssetGroup.cs +++ b/Editor/Settings/AddressableAssetGroup.cs @@ -88,7 +88,7 @@ public virtual string Name //this isn't a valid asset, which means it wasn't persisted, so just set the object name to the desired display name. name = m_GroupName; } - SetDirty(AddressableAssetSettings.ModificationEvent.GroupRenamed, this, true); + SetDirty(AddressableAssetSettings.ModificationEvent.GroupRenamed, this, true, true); } } } @@ -132,7 +132,7 @@ public AddressableAssetGroupSchema AddSchema(AddressableAssetGroupSchema schema, if (added != null) { added.Group = this; - SetDirty(AddressableAssetSettings.ModificationEvent.GroupSchemaAdded, this, postEvent); + SetDirty(AddressableAssetSettings.ModificationEvent.GroupSchemaAdded, this, postEvent, true); } return added; } @@ -149,7 +149,7 @@ public AddressableAssetGroupSchema AddSchema(Type type, bool postEvent = true) if (added != null) { added.Group = this; - SetDirty(AddressableAssetSettings.ModificationEvent.GroupSchemaAdded, this, postEvent); + SetDirty(AddressableAssetSettings.ModificationEvent.GroupSchemaAdded, this, postEvent, true); } return added; } @@ -176,7 +176,7 @@ public bool RemoveSchema(Type type, bool postEvent = true) if (!m_SchemaSet.RemoveSchema(type)) return false; - SetDirty(AddressableAssetSettings.ModificationEvent.GroupSchemaRemoved, this, postEvent); + SetDirty(AddressableAssetSettings.ModificationEvent.GroupSchemaRemoved, this, postEvent, true); return true; } @@ -229,7 +229,7 @@ public bool HasSchema() public void ClearSchemas(bool deleteAssets, bool postEvent = true) { m_SchemaSet.ClearSchemas(deleteAssets); - SetDirty(AddressableAssetSettings.ModificationEvent.GroupRemoved, this, postEvent); + SetDirty(AddressableAssetSettings.ModificationEvent.GroupRemoved, this, postEvent, true); } /// @@ -409,8 +409,8 @@ internal void DedupeEnteries() removeEntries.Add(e); } } - - RemoveAssetEntries(removeEntries); + if(removeEntries.Count > 0) + RemoveAssetEntries(removeEntries); } internal void Initialize(AddressableAssetSettings settings, string groupName, string guid, bool readOnly) @@ -440,7 +440,7 @@ internal void AddAssetEntry(AddressableAssetEntry e, bool postEvent = true) e.IsSubAsset = false; e.parentGroup = this; m_EntryMap[e.guid] = e; - SetDirty(AddressableAssetSettings.ModificationEvent.EntryAdded, e, postEvent); + SetDirty(AddressableAssetSettings.ModificationEvent.EntryAdded, e, postEvent, true); } /// @@ -461,13 +461,14 @@ public virtual AddressableAssetEntry GetAssetEntry(string guid) /// The event type that is changed. /// The object data that corresponds to the event. /// If true, the event is propagated to callbacks. - public void SetDirty(AddressableAssetSettings.ModificationEvent modificationEvent, object eventData, bool postEvent) + /// If true, the group asset will be marked as dirty. + public void SetDirty(AddressableAssetSettings.ModificationEvent modificationEvent, object eventData, bool postEvent, bool groupModified = false) { if (Settings != null) { - if (Settings.IsPersisted && this != null) + if (groupModified && Settings.IsPersisted && this != null) EditorUtility.SetDirty(this); - Settings.SetDirty(modificationEvent, eventData, postEvent); + Settings.SetDirty(modificationEvent, eventData, postEvent, false); } } @@ -480,7 +481,7 @@ public void RemoveAssetEntry(AddressableAssetEntry entry, bool postEvent = true) { m_EntryMap.Remove(entry.guid); entry.parentGroup = null; - SetDirty(AddressableAssetSettings.ModificationEvent.EntryRemoved, entry, postEvent); + SetDirty(AddressableAssetSettings.ModificationEvent.EntryRemoved, entry, postEvent, true); } internal void RemoveAssetEntries(IEnumerable removeEntries, bool postEvent = true) @@ -490,8 +491,8 @@ internal void RemoveAssetEntries(IEnumerable removeEntrie m_EntryMap.Remove(entry.guid); entry.parentGroup = null; } - - SetDirty(AddressableAssetSettings.ModificationEvent.EntryRemoved, removeEntries.ToArray(), postEvent); + if(removeEntries.Count() > 0) + SetDirty(AddressableAssetSettings.ModificationEvent.EntryRemoved, removeEntries.ToArray(), postEvent, true); } /// diff --git a/Editor/Settings/AddressableAssetGroupSchema.cs b/Editor/Settings/AddressableAssetGroupSchema.cs index 83decfe8..3d65bbb3 100644 --- a/Editor/Settings/AddressableAssetGroupSchema.cs +++ b/Editor/Settings/AddressableAssetGroupSchema.cs @@ -70,7 +70,7 @@ protected void SetDirty(bool postEvent) if (m_Group.Settings != null && m_Group.Settings.IsPersisted) EditorUtility.SetDirty(this); if (m_Group != null) - m_Group.SetDirty(AddressableAssetSettings.ModificationEvent.GroupSchemaModified, this, postEvent); + m_Group.SetDirty(AddressableAssetSettings.ModificationEvent.GroupSchemaModified, this, postEvent, false); } } } diff --git a/Editor/Settings/AddressableAssetGroupTemplate.cs b/Editor/Settings/AddressableAssetGroupTemplate.cs index 78c9fefe..ecb31efd 100644 --- a/Editor/Settings/AddressableAssetGroupTemplate.cs +++ b/Editor/Settings/AddressableAssetGroupTemplate.cs @@ -210,7 +210,7 @@ public void SetDirty(AddressableAssetSettings.ModificationEvent modificationEven { if (Settings.IsPersisted && this != null) EditorUtility.SetDirty(this); - Settings.SetDirty(modificationEvent, eventData, postEvent); + Settings.SetDirty(modificationEvent, eventData, postEvent, false); } } } diff --git a/Editor/Settings/AddressableAssetProfileSettings.cs b/Editor/Settings/AddressableAssetProfileSettings.cs index b8b29996..32d800b4 100644 --- a/Editor/Settings/AddressableAssetProfileSettings.cs +++ b/Editor/Settings/AddressableAssetProfileSettings.cs @@ -505,7 +505,7 @@ public HashSet GetAllVariableIds() public void SetDirty(AddressableAssetSettings.ModificationEvent modificationEvent, object eventData, bool postEvent) { if (m_Settings != null) - m_Settings.SetDirty(modificationEvent, eventData, postEvent); + m_Settings.SetDirty(modificationEvent, eventData, postEvent, true); } internal bool ValidateNewVariableName(string name) diff --git a/Editor/Settings/AddressableAssetSettings.cs b/Editor/Settings/AddressableAssetSettings.cs index cc7ac64e..38f849c6 100644 --- a/Editor/Settings/AddressableAssetSettings.cs +++ b/Editor/Settings/AddressableAssetSettings.cs @@ -88,7 +88,8 @@ public enum ModificationEvent ActivePlayModeScriptChanged, BatchModification, // <-- posted object will be null. HostingServicesManagerModified, - GroupMoved + GroupMoved, + CertificateHandlerChanged } /// @@ -356,7 +357,7 @@ public bool RemoveSchemaTemplate(int index, bool postEvent = true) } var s = m_SchemaTemplates[index]; m_SchemaTemplates.RemoveAt(index); - SetDirty(ModificationEvent.GroupSchemaRemoved, s, postEvent); + SetDirty(ModificationEvent.GroupSchemaRemoved, s, postEvent, true); return true; } @@ -410,7 +411,7 @@ public bool AddGroupTemplateObject(IGroupTemplate templateObject, bool postEvent } m_GroupTemplateObjects.Add(so); - SetDirty(ModificationEvent.GroupTemplateAdded, so, postEvent); + SetDirty(ModificationEvent.GroupTemplateAdded, so, postEvent, true); return true; } @@ -426,7 +427,7 @@ public bool RemoveGroupTemplateObject(int index, bool postEvent = true) return false; var so = m_GroupTemplateObjects[index]; m_GroupTemplateObjects.RemoveAt(index); - SetDirty(ModificationEvent.GroupTemplateRemoved, so, postEvent); + SetDirty(ModificationEvent.GroupTemplateRemoved, so, postEvent, true); return true; } @@ -454,7 +455,7 @@ public bool SetGroupTemplateObjectAtIndex(int index, IGroupTemplate initObject, } m_GroupTemplateObjects[index] = so; - SetDirty(ModificationEvent.GroupTemplateAdded, so, postEvent); + SetDirty(ModificationEvent.GroupTemplateAdded, so, postEvent, true); return true; } @@ -508,7 +509,7 @@ public bool AddInitializationObject(IObjectInitializationDataProvider initObject } m_InitializationObjects.Add(so); - SetDirty(ModificationEvent.InitializationObjectAdded, so, postEvent); + SetDirty(ModificationEvent.InitializationObjectAdded, so, postEvent, true); return true; } @@ -524,7 +525,7 @@ public bool RemoveInitializationObject(int index, bool postEvent = true) return false; var so = m_InitializationObjects[index]; m_InitializationObjects.RemoveAt(index); - SetDirty(ModificationEvent.InitializationObjectRemoved, so, postEvent); + SetDirty(ModificationEvent.InitializationObjectRemoved, so, postEvent, true); return true; } @@ -552,7 +553,7 @@ public bool SetInitializationObjectAtIndex(int index, IObjectInitializationDataP } m_InitializationObjects[index] = so; - SetDirty(ModificationEvent.InitializationObjectAdded, so, postEvent); + SetDirty(ModificationEvent.InitializationObjectAdded, so, postEvent, true); return true; } @@ -573,6 +574,7 @@ public Type CertificateHandlerType set { m_CertificateHandlerType.Value = value; + SetDirty(ModificationEvent.CertificateHandlerChanged, value, true, true); } } @@ -627,7 +629,7 @@ public bool AddDataBuilder(IDataBuilder builder, bool postEvent = true) } m_DataBuilders.Add(so); - SetDirty(ModificationEvent.DataBuilderAdded, so, postEvent); + SetDirty(ModificationEvent.DataBuilderAdded, so, postEvent, true); return true; } @@ -643,7 +645,7 @@ public bool RemoveDataBuilder(int index, bool postEvent = true) return false; var so = m_DataBuilders[index]; m_DataBuilders.RemoveAt(index); - SetDirty(ModificationEvent.DataBuilderRemoved, so, postEvent); + SetDirty(ModificationEvent.DataBuilderRemoved, so, postEvent, true); return true; } @@ -671,7 +673,7 @@ public bool SetDataBuilderAtIndex(int index, IDataBuilder builder, bool postEven } m_DataBuilders[index] = so; - SetDirty(ModificationEvent.DataBuilderAdded, so, postEvent); + SetDirty(ModificationEvent.DataBuilderAdded, so, postEvent, true); return true; } @@ -709,7 +711,7 @@ public int ActivePlayerDataBuilderIndex set { m_ActivePlayerDataBuilderIndex = value; - SetDirty(ModificationEvent.ActiveBuildScriptChanged, ActivePlayerDataBuilder, true); + SetDirty(ModificationEvent.ActiveBuildScriptChanged, ActivePlayerDataBuilder, true, true); } } @@ -725,7 +727,7 @@ public int ActivePlayModeDataBuilderIndex set { m_ActivePlayModeDataBuilderIndex = value; - SetDirty(ModificationEvent.ActivePlayModeScriptChanged, ActivePlayModeDataBuilder, true); + SetDirty(ModificationEvent.ActivePlayModeScriptChanged, ActivePlayModeDataBuilder, true, true); } } @@ -738,7 +740,7 @@ public int ActivePlayModeDataBuilderIndex public void AddLabel(string label, bool postEvent = true) { m_LabelTable.AddLabelName(label); - SetDirty(ModificationEvent.LabelAdded, label, postEvent); + SetDirty(ModificationEvent.LabelAdded, label, postEvent, true); } /// @@ -749,7 +751,7 @@ public void AddLabel(string label, bool postEvent = true) public void RemoveLabel(string label, bool postEvent = true) { m_LabelTable.RemoveLabelName(label); - SetDirty(ModificationEvent.LabelRemoved, label, postEvent); + SetDirty(ModificationEvent.LabelRemoved, label, postEvent, true); } [FormerlySerializedAs("m_activeProfileId")] @@ -773,7 +775,7 @@ public string activeProfileId if (oldVal != value) { - SetDirty(ModificationEvent.ActiveProfileSet, value, true); + SetDirty(ModificationEvent.ActiveProfileSet, value, true, true); } } } @@ -827,7 +829,7 @@ public bool RemoveAssetEntry(string guid, bool postEvent = true) { if (entry.parentGroup != null) entry.parentGroup.RemoveAssetEntry(entry, postEvent); - SetDirty(ModificationEvent.EntryRemoved, entry, postEvent); + SetDirty(ModificationEvent.EntryRemoved, entry, postEvent, false); return true; } return false; @@ -1128,7 +1130,7 @@ AddressableAssetEntry CreateEntry(string guid, string address, AddressableAssetG { var entry = new AddressableAssetEntry(guid, address, parent, readOnly); if (!readOnly) - SetDirty(ModificationEvent.EntryCreated, entry, postEvent); + SetDirty(ModificationEvent.EntryCreated, entry, postEvent, true); return entry; } @@ -1138,7 +1140,8 @@ AddressableAssetEntry CreateEntry(string guid, string address, AddressableAssetG /// The event type that is changed. /// The object data that corresponds to the event. /// If true, the event is propagated to callbacks. - public void SetDirty(ModificationEvent modificationEvent, object eventData, bool postEvent) + /// If true, the settings asset will be marked as dirty. + public void SetDirty(ModificationEvent modificationEvent, object eventData, bool postEvent, bool settingsModified = false) { if (modificationEvent == ModificationEvent.ProfileRemoved && eventData as string == activeProfileId) activeProfileId = null; @@ -1156,7 +1159,7 @@ public void SetDirty(ModificationEvent modificationEvent, object eventData, bool if (unityObj != null && !string.IsNullOrEmpty(AssetDatabase.GetAssetPath(unityObj))) EditorUtility.SetDirty(unityObj); - if (IsPersisted) + if (settingsModified && IsPersisted) EditorUtility.SetDirty(this); } @@ -1225,7 +1228,7 @@ internal void MoveAssetsFromResources(Dictionary guidToNewPath, } AssetDatabase.StopAssetEditing(); AssetDatabase.Refresh(); - SetDirty(ModificationEvent.EntryMoved, entries, true); + SetDirty(ModificationEvent.EntryMoved, entries, true, true); } /// @@ -1245,7 +1248,7 @@ public void MoveEntries(List entries, AddressableAssetGro MoveEntry(entry, targetParent, readOnly, false); } - SetDirty(ModificationEvent.EntryMoved, entries, postEvent); + SetDirty(ModificationEvent.EntryMoved, entries, postEvent, false); } } @@ -1367,7 +1370,7 @@ public AddressableAssetGroup CreateGroup(string groupName, bool setAsDefaultGrou if (setAsDefaultGroup) DefaultGroup = group; - SetDirty(ModificationEvent.GroupAdded, group, postEvent); + SetDirty(ModificationEvent.GroupAdded, group, postEvent, true); return group; } @@ -1425,7 +1428,7 @@ internal void RemoveGroupInternal(AddressableAssetGroup g, bool deleteAsset, boo { g.ClearSchemas(true); groups.Remove(g); - SetDirty(ModificationEvent.GroupRemoved, g, postEvent); + SetDirty(ModificationEvent.GroupRemoved, g, postEvent, true); if (deleteAsset) { string guidOfGroup; @@ -1448,7 +1451,7 @@ internal void SetLabelValueForEntries(List entries, strin foreach (var e in entries) e.SetLabel(label, value, false); - SetDirty(ModificationEvent.EntryModified, entries, postEvent); + SetDirty(ModificationEvent.EntryModified, entries, postEvent, true); } internal void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths) @@ -1550,7 +1553,7 @@ internal void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAs } if (modified) - aa.SetDirty(ModificationEvent.BatchModification, null, true); + aa.SetDirty(ModificationEvent.BatchModification, null, true, true); } bool CheckForGroupDataDeletion(string str) diff --git a/Editor/Settings/AddressableAssetUtility.cs b/Editor/Settings/AddressableAssetUtility.cs index 85697158..940e551e 100644 --- a/Editor/Settings/AddressableAssetUtility.cs +++ b/Editor/Settings/AddressableAssetUtility.cs @@ -81,7 +81,9 @@ internal static void ConvertAssetBundlesToAddressables() imp.SetAssetBundleNameAndVariant(string.Empty, string.Empty); } } - settings.SetDirty(AddressableAssetSettings.ModificationEvent.BatchModification, null, true); + + if(fullCount > 0) + settings.SetDirty(AddressableAssetSettings.ModificationEvent.BatchModification, null, true, true); EditorUtility.ClearProgressBar(); AssetDatabase.RemoveUnusedAssetBundleNames(); } diff --git a/Runtime/AddressablesImpl.cs b/Runtime/AddressablesImpl.cs index f87a031e..f51dd7ae 100644 --- a/Runtime/AddressablesImpl.cs +++ b/Runtime/AddressablesImpl.cs @@ -82,7 +82,7 @@ private void OnSceneUnloaded(Scene scene) break; } } - m_ResourceManager.CleanupSceneInstances(); + m_ResourceManager.CleanupSceneInstances(scene); } public string StreamingAssetsSubFolder diff --git a/Runtime/ResourceManager/ResourceManager.cs b/Runtime/ResourceManager/ResourceManager.cs index f5d98d85..5c41b6e8 100644 --- a/Runtime/ResourceManager/ResourceManager.cs +++ b/Runtime/ResourceManager/ResourceManager.cs @@ -505,6 +505,8 @@ class InstanceOperation : AsyncOperationBase IInstanceProvider m_instanceProvider; GameObject m_instance; ResourceManager m_RM; + Scene m_scene; + public void Init(ResourceManager rm, IInstanceProvider instanceProvider, InstantiationParameters instantiationParams, AsyncOperationHandle dependency) { m_RM = rm; @@ -527,6 +529,8 @@ protected override string DebugName } } + public Scene InstanceScene() => m_scene; + protected override void Destroy() { m_instanceProvider.ReleaseInstance(m_RM, m_instance); @@ -538,6 +542,8 @@ protected override void Execute() if (m_dependency.Status == AsyncOperationStatus.Succeeded) { m_instance = m_instanceProvider.ProvideInstance(m_RM, m_dependency, m_instantiationParams); + if(m_instance != null) + m_scene = m_instance.scene; Complete(m_instance, true, null); } else @@ -602,13 +608,16 @@ public AsyncOperationHandle ProvideInstance(IInstanceProvider provid m_TrackedInstanceOperations.Add(baseOp); return StartOperation(baseOp, depOp); } - - public void CleanupSceneInstances() + /// + /// Cleans up ref counting on any instances that were in a newly closed scene. + /// + /// The scene that was closed + public void CleanupSceneInstances(Scene scene) { List handlesToRelease = null; foreach (var h in m_TrackedInstanceOperations) { - if (h.Result == null) + if (h.Result == null && scene == h.InstanceScene()) { if (handlesToRelease == null) handlesToRelease = new List(); diff --git a/Tests/Runtime/AddressablesIntegrationTestsImpl.cs b/Tests/Runtime/AddressablesIntegrationTestsImpl.cs index 44e84c1e..46e563f2 100644 --- a/Tests/Runtime/AddressablesIntegrationTestsImpl.cs +++ b/Tests/Runtime/AddressablesIntegrationTestsImpl.cs @@ -713,6 +713,38 @@ public IEnumerator WhenSceneUnloadedNotUsingAddressables_InstanitatedObjectsAreC yield return null; } + [UnityTest] + public IEnumerator WhenSceneUnloaded_InstantiatedObjectsInOtherScenesAreNotCleanedUp() + { + //Setup + yield return Init(); + + var op = m_Addressables.LoadSceneAsync(m_SceneKeysList[0], LoadSceneMode.Additive); + yield return op; + Assert.AreEqual(AsyncOperationStatus.Succeeded, op.Status); + + var activeScene = m_Addressables.LoadSceneAsync(m_SceneKeysList[1], LoadSceneMode.Additive); + yield return activeScene; + SceneManager.SetActiveScene(activeScene.Result.Scene); + Assert.AreEqual(AsyncOperationStatus.Succeeded, activeScene.Status); + + //Test + AsyncOperationHandle inst = default(AsyncOperationHandle); + var unloadOp = m_Addressables.UnloadSceneAsync(op); + unloadOp.Completed += i => + { + inst = m_Addressables.InstantiateAsync(m_PrefabKeysList[0]); + }; + yield return unloadOp; + yield return inst; + Assert.AreEqual(AsyncOperationStatus.Succeeded, inst.Status); + + Assert.NotNull(GameObject.Find(inst.Result.name)); + + //Cleanup + var unloadActiveScene = m_Addressables.UnloadSceneAsync(activeScene); + yield return unloadActiveScene; + } #endif } } \ No newline at end of file diff --git a/package.json b/package.json index e5a8dc2d..28621340 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "com.unity.addressables", "displayName": "Addressables", - "version": "1.1.4-preview", + "version": "1.1.5", "unity": "2018.3", "description": "The Addressable Asset System allows the developer to ask for an asset via its address. Once an asset (e.g. a prefab) is marked \"addressable\", it generates an address which can be called from anywhere. Wherever the asset resides (local or remote), the system will locate it and its dependencies, then return it.\n\nUse 'Window->Asset Management->Addressables' to begin working with the system.\n\nAddressables use asynchronous loading to support loading from any location with any collection of dependencies. Whether you have been using direct references, traditional asset bundles, or Resource folders, addressables provide a simpler way to make your game more dynamic. Addressables simultaneously opens up the world of asset bundles while managing all the complexity.", "keywords": [ @@ -13,11 +13,11 @@ ], "category": "", "dependencies": { - "com.unity.scriptablebuildpipeline": "1.5.0-preview" + "com.unity.scriptablebuildpipeline": "1.5.1" }, "repository": { "type": "git", "url": "git@github.cds.internal.unity3d.com:unity/Addressables.git", - "revision": "56c089b5af3365306e2d136d00259872bfbf0d1f" + "revision": "b76a987946490d87202d74272f097d8e0cc858ba" } }