diff --git a/Assets/SmartAddresser/Editor/Core/Tools/Addresser/LayoutRuleEditor/LayoutRuleEditorPresenter.cs b/Assets/SmartAddresser/Editor/Core/Tools/Addresser/LayoutRuleEditor/LayoutRuleEditorPresenter.cs index eab6c5d..bdd85ab 100644 --- a/Assets/SmartAddresser/Editor/Core/Tools/Addresser/LayoutRuleEditor/LayoutRuleEditorPresenter.cs +++ b/Assets/SmartAddresser/Editor/Core/Tools/Addresser/LayoutRuleEditor/LayoutRuleEditorPresenter.cs @@ -17,6 +17,7 @@ using UnityEditor; using UnityEditor.AddressableAssets; using UnityEditor.AddressableAssets.Settings; +using UnityEditor.AddressableAssets.Settings.GroupSchemas; using UnityEngine; namespace SmartAddresser.Editor.Core.Tools.Addresser.LayoutRuleEditor @@ -110,7 +111,16 @@ private void SetupActiveView(LayoutRuleData data) _editingData.Value = data; _assetSaveService.SetAsset(data); - if (data.LayoutRule.SyncAddressRulesWithAddressableAssetGroups(addressableAssetSettings.groups)) + var groups = addressableAssetSettings.groups; + +#if AAS_SORT_ORDER + var orderSettings = AddressableAssetGroupSortSettings.GetSettings(addressableAssetSettings); + groups = addressableAssetSettings.groups + .OrderBy(g => Array.IndexOf(orderSettings.sortOrder, g.Guid)) + .ToList(); +#endif + + if (data.LayoutRule.SyncAddressRulesWithAddressableAssetGroups(groups)) _assetSaveService.MarkAsDirty(); _addressRuleEditorPresenter.SetupView(data.LayoutRule.AddressRules); @@ -132,11 +142,12 @@ object obj ) { if (e == AddressableAssetSettings.ModificationEvent.GroupAdded - || e == AddressableAssetSettings.ModificationEvent.GroupMoved || e == AddressableAssetSettings.ModificationEvent.GroupRemoved || e == AddressableAssetSettings.ModificationEvent.GroupRenamed) // If the addressable asset group is changed, reload. SetupActiveView(_editingData.Value); + else if (e == AddressableAssetSettings.ModificationEvent.GroupMoved) + EditorApplication.delayCall += () => SetupActiveView(_editingData.Value); } public void CleanupView() diff --git a/Assets/SmartAddresser/Editor/Core/Tools/Addresser/LayoutViewer/LayoutViewerPresenter.cs b/Assets/SmartAddresser/Editor/Core/Tools/Addresser/LayoutViewer/LayoutViewerPresenter.cs index 214aa95..93bb4c9 100644 --- a/Assets/SmartAddresser/Editor/Core/Tools/Addresser/LayoutViewer/LayoutViewerPresenter.cs +++ b/Assets/SmartAddresser/Editor/Core/Tools/Addresser/LayoutViewer/LayoutViewerPresenter.cs @@ -9,6 +9,8 @@ using SmartAddresser.Editor.Foundation.TinyRx; using SmartAddresser.Editor.Foundation.TinyRx.ObservableProperty; using UnityEditor; +using UnityEditor.AddressableAssets; +using UnityEditor.AddressableAssets.Settings.GroupSchemas; using UnityEngine; using UnityEngine.Assertions; @@ -47,13 +49,6 @@ public void Dispose() _editingData.Dispose(); } - private void AddGroupView(Group group, bool reload = true) - { - _view.TreeView.AddGroup(group); - if (reload) - _view.TreeView.Reload(); - } - public void SetupView(ILayoutRuleDataRepository dataRepository) { _setupViewDisposables.Clear(); @@ -84,9 +79,7 @@ private void SetupActiveView(LayoutRuleData data) layout.Validate(false, validationSettings.DuplicateAddresses, validationSettings.DuplicateAssetPaths, validationSettings.EntryHasMultipleVersions); _layout = layout; - foreach (var group in layout.Groups) - AddGroupView(group); - _view.TreeView.Reload(); + ApplyGroupsToTreeView(); _view.ActiveMode.Value = LayoutViewerView.Mode.Viewer; _view.ActiveAssetName.Value = data.name; @@ -185,15 +178,39 @@ void OnRefreshButtonClicked() validationSettings.EntryHasMultipleVersions); _layout = layout; - _view.TreeView.ClearItems(); - foreach (var group in layout.Groups) - AddGroupView(group); - _view.TreeView.Reload(); + ApplyGroupsToTreeView(); } #endregion } + public void ApplyGroupsToTreeView() + { + _view.TreeView.ClearItems(); + + if (_layout == null) + { + return; + } + +#if AAS_SORT_ORDER + var addressableAssetSettings = AddressableAssetSettingsDefaultObject.Settings; + var orderSettings = AddressableAssetGroupSortSettings.GetSettings(addressableAssetSettings); + foreach (var group in _layout.Groups.OrderBy(g => + Array.IndexOf(orderSettings.sortOrder, g.AddressableGroup.Guid))) + { + _view.TreeView.AddGroup(group); + } +#else + foreach (var group in _layout.Groups) + { + _view.TreeView.AddGroup(group); + } +#endif + + _view.TreeView.Reload(); + } + private void CleanupViewEventHandlers() { _view.TreeView.OnSelectionChanged -= OnTreeViewSelectionChanged; diff --git a/Assets/SmartAddresser/Editor/Core/Tools/Addresser/LayoutViewer/LayoutViewerWindow.cs b/Assets/SmartAddresser/Editor/Core/Tools/Addresser/LayoutViewer/LayoutViewerWindow.cs index cad426a..2baf5e3 100644 --- a/Assets/SmartAddresser/Editor/Core/Tools/Addresser/LayoutViewer/LayoutViewerWindow.cs +++ b/Assets/SmartAddresser/Editor/Core/Tools/Addresser/LayoutViewer/LayoutViewerWindow.cs @@ -5,6 +5,8 @@ using SmartAddresser.Editor.Foundation.EditorSplitView; using SmartAddresser.Editor.Foundation.TinyRx; using UnityEditor; +using UnityEditor.AddressableAssets; +using UnityEditor.AddressableAssets.Settings; using UnityEngine; namespace SmartAddresser.Editor.Core.Tools.Addresser.LayoutViewer @@ -21,14 +23,28 @@ internal sealed class LayoutViewerWindow : EditorWindow private LayoutViewerPresenter _presenter; private LayoutViewerView _view; + private AddressableAssetSettings _addressableAssetSettings; + private void OnEnable() { minSize = new Vector2(600, 200); Setup(); + + _addressableAssetSettings = AddressableAssetSettingsDefaultObject.Settings; + if (_addressableAssetSettings) + { + _addressableAssetSettings.OnModification += OnAddressableAssetSettingsModified; + } } private void OnDisable() { + if (_addressableAssetSettings) + { + _addressableAssetSettings.OnModification -= OnAddressableAssetSettingsModified; + _addressableAssetSettings = null; + } + _presenter?.Dispose(); _view?.Dispose(); } @@ -66,5 +82,17 @@ public static void Open() { GetWindow(WindowName); } + + private void OnAddressableAssetSettingsModified( + AddressableAssetSettings settings, + AddressableAssetSettings.ModificationEvent e, + object obj) + { + // AssetGroupの並び順反映 + if (e == AddressableAssetSettings.ModificationEvent.GroupMoved) + { + EditorApplication.delayCall += () => _presenter.ApplyGroupsToTreeView(); + } + } } } diff --git a/Assets/SmartAddresser/Editor/SmartAddresser.Editor.asmdef b/Assets/SmartAddresser/Editor/SmartAddresser.Editor.asmdef index 9d68cc3..8da1389 100644 --- a/Assets/SmartAddresser/Editor/SmartAddresser.Editor.asmdef +++ b/Assets/SmartAddresser/Editor/SmartAddresser.Editor.asmdef @@ -15,6 +15,17 @@ "precompiledReferences": [], "autoReferenced": true, "defineConstraints": [], - "versionDefines": [], + "versionDefines": [ + { + "name": "com.unity.addressables", + "expression": "[1.23.1,2.0.0)", + "define": "AAS_SORT_ORDER" + }, + { + "name": "com.unity.addressables", + "expression": "2.3.7", + "define": "AAS_SORT_ORDER" + } + ], "noEngineReferences": false } \ No newline at end of file