Skip to content

Commit ddf7ee2

Browse files
Haruma-Kclaude
andcommitted
feat: Ruleタイプに基づくAssetFilterの使用制限機能を実装
- RestrictedToRulesAttribute を追加し、特定のRuleタイプでのみ使用可能なAssetFilterを指定できるように - AddressBasedAssetFilter と AddressableAssetGroupBasedAssetFilter に制限を追加(Label、Versionルールでのみ使用可能) - AssetGroupPanelPresenter と AssetGroupCollectionPanelPresenter のコンストラクタでRuleTypeを受け取るように変更 - 各RulePresenterから適切なRuleTypeを渡すように修正 これにより、AddressRuleのGUIではAddressBasedAssetFilterとAddressableAssetGroupBasedAssetFilterが選択できなくなりました。 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 6fcee89 commit ddf7ee2

File tree

10 files changed

+89
-8
lines changed

10 files changed

+89
-8
lines changed

Assets/Development/Editor/Core/Tools/Addresser/Shared/AssetGroups/AssetGroupPanelDevelopmentWindow.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ private void OnEnable()
2626
_groupCollection.Add(new AssetGroup());
2727

2828
_view = new AssetGroupPanelView();
29-
_presenter = new AssetGroupPanelPresenter(_view, _history, _assetSaveService);
29+
// Use Address rule type for development window
30+
_presenter = new AssetGroupPanelPresenter(_view, _history, _assetSaveService, RuleType.Address);
3031
_presenter.SetupView(_groupCollection, 0);
3132
}
3233

Assets/SmartAddresser/Editor/Core/Models/Shared/AssetGroups/AssetFilterImpl/AddressBasedAssetFilter.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ namespace SmartAddresser.Editor.Core.Models.Shared.AssetGroups.AssetFilterImpl
1515
/// </summary>
1616
[Serializable]
1717
[AssetFilter("Address Filter", "Address Filter")]
18+
[RestrictedToRules(RuleType.Label, RuleType.Version)]
1819
public sealed class AddressBasedAssetFilter : AssetFilterBase
1920
{
2021
[SerializeField] private bool _matchWithFolders;

Assets/SmartAddresser/Editor/Core/Models/Shared/AssetGroups/AssetFilterImpl/AddressableAssetGroupBasedAssetFilter.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ namespace SmartAddresser.Editor.Core.Models.Shared.AssetGroups.AssetFilterImpl
1313
/// </summary>
1414
[Serializable]
1515
[AssetFilter("Addressable Group Filter", "Addressable Group Filter")]
16+
[RestrictedToRules(RuleType.Label, RuleType.Version)]
1617
public sealed class AddressableAssetGroupBasedAssetFilter : AssetFilterBase
1718
{
1819
[SerializeField]
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
using System;
2+
3+
namespace SmartAddresser.Editor.Core.Models.Shared.AssetGroups
4+
{
5+
/// <summary>
6+
/// Attribute to restrict AssetFilter usage to specific rule types.
7+
/// </summary>
8+
[AttributeUsage(AttributeTargets.Class)]
9+
public sealed class RestrictedToRulesAttribute : Attribute
10+
{
11+
/// <summary>
12+
/// Constructor.
13+
/// </summary>
14+
/// <param name="allowedRuleTypes">The rule types that are allowed to use this filter.</param>
15+
public RestrictedToRulesAttribute(params RuleType[] allowedRuleTypes)
16+
{
17+
AllowedRuleTypes = allowedRuleTypes;
18+
}
19+
20+
/// <summary>
21+
/// The rule types that are allowed to use this filter.
22+
/// </summary>
23+
public RuleType[] AllowedRuleTypes { get; }
24+
}
25+
26+
/// <summary>
27+
/// Enum representing the different rule types.
28+
/// </summary>
29+
public enum RuleType
30+
{
31+
/// <summary>
32+
/// Address rule type.
33+
/// </summary>
34+
Address,
35+
36+
/// <summary>
37+
/// Label rule type.
38+
/// </summary>
39+
Label,
40+
41+
/// <summary>
42+
/// Version rule type.
43+
/// </summary>
44+
Version
45+
}
46+
}

Assets/SmartAddresser/Editor/Core/Models/Shared/AssetGroups/RestrictedToRulesAttribute.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/SmartAddresser/Editor/Core/Tools/Addresser/LayoutRuleEditor/AddressRuleEditor/AddressRuleEditorInspectorPresenter.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using SmartAddresser.Editor.Core.Models.LayoutRules.AddressRules;
3+
using SmartAddresser.Editor.Core.Models.Shared.AssetGroups;
34
using SmartAddresser.Editor.Core.Tools.Addresser.Shared;
45
using SmartAddresser.Editor.Core.Tools.Addresser.Shared.AssetGroups;
56
using SmartAddresser.Editor.Foundation.CommandBasedUndo;
@@ -22,7 +23,7 @@ public AddressRuleEditorInspectorPresenter(AddressRuleEditorInspectorView view,
2223
{
2324
_view = view;
2425
_assetGroupCollectionPanelPresenter =
25-
new AssetGroupCollectionPanelPresenter(view.GroupCollectionView, history, saveService);
26+
new AssetGroupCollectionPanelPresenter(view.GroupCollectionView, history, saveService, RuleType.Address);
2627
_addressProviderPanelPresenter =
2728
new AddressProviderPanelPresenter(view.AddressProviderPanelView, history, saveService);
2829
}

Assets/SmartAddresser/Editor/Core/Tools/Addresser/LayoutRuleEditor/LabelRuleEditor/LabelRuleEditorInspectorPresenter.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using SmartAddresser.Editor.Core.Models.LayoutRules.LabelRules;
3+
using SmartAddresser.Editor.Core.Models.Shared.AssetGroups;
34
using SmartAddresser.Editor.Core.Tools.Addresser.Shared;
45
using SmartAddresser.Editor.Core.Tools.Addresser.Shared.AssetGroups;
56
using SmartAddresser.Editor.Foundation.CommandBasedUndo;
@@ -20,7 +21,7 @@ public LabelRuleEditorInspectorPresenter(LabelRuleEditorInspectorView view, Auto
2021
{
2122
_view = view;
2223
_assetGroupCollectionPanelPresenter =
23-
new AssetGroupCollectionPanelPresenter(view.GroupCollectionView, history, saveService);
24+
new AssetGroupCollectionPanelPresenter(view.GroupCollectionView, history, saveService, RuleType.Label);
2425
_labelProviderPanelPresenter =
2526
new LabelProviderPanelViewPresenter(view.LabelProviderPanelView, history, saveService);
2627
}

Assets/SmartAddresser/Editor/Core/Tools/Addresser/LayoutRuleEditor/VersionRuleEditor/VersionRuleEditorInspectorPresenter.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using SmartAddresser.Editor.Core.Models.LayoutRules.VersionRules;
3+
using SmartAddresser.Editor.Core.Models.Shared.AssetGroups;
34
using SmartAddresser.Editor.Core.Tools.Addresser.Shared;
45
using SmartAddresser.Editor.Core.Tools.Addresser.Shared.AssetGroups;
56
using SmartAddresser.Editor.Foundation.CommandBasedUndo;
@@ -20,7 +21,7 @@ public VersionRuleEditorInspectorPresenter(VersionRuleEditorInspectorView view,
2021
{
2122
_view = view;
2223
_assetGroupCollectionPanelPresenter =
23-
new AssetGroupCollectionPanelPresenter(view.GroupCollectionView, history, saveService);
24+
new AssetGroupCollectionPanelPresenter(view.GroupCollectionView, history, saveService, RuleType.Version);
2425
_versionProviderPanelPresenter =
2526
new VersionProviderPanelViewPresenter(view.VersionProviderPanelView, history, saveService);
2627
}

Assets/SmartAddresser/Editor/Core/Tools/Addresser/Shared/AssetGroups/AssetGroupCollectionPanelPresenter.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ internal sealed class AssetGroupCollectionPanelPresenter : IDisposable
1616
new Dictionary<string, AssetGroupPanelPresenter>();
1717

1818
private readonly AutoIncrementHistory _history;
19+
private readonly RuleType? _ruleContext;
1920
private readonly IAssetSaveService _saveService;
2021
private readonly CompositeDisposable _setupViewDisposables = new CompositeDisposable();
2122
private readonly AssetGroupCollectionPanelView _view;
@@ -24,11 +25,12 @@ internal sealed class AssetGroupCollectionPanelPresenter : IDisposable
2425
private IObservableList<AssetGroup> _groups;
2526

2627
public AssetGroupCollectionPanelPresenter(AssetGroupCollectionPanelView view, AutoIncrementHistory history,
27-
IAssetSaveService saveService)
28+
IAssetSaveService saveService, RuleType? ruleContext = null)
2829
{
2930
_view = view;
3031
_history = history;
3132
_saveService = saveService;
33+
_ruleContext = ruleContext;
3234

3335
SetupViewEventHandlers();
3436
}
@@ -78,7 +80,7 @@ public void SetupView(ObservableList<AssetGroup> groups)
7880
void AddGroupView(AssetGroup group, int index)
7981
{
8082
var groupPanelView = _view.AddGroupPanelView(group, index);
81-
var groupPanelPresenter = new AssetGroupPanelPresenter(groupPanelView, _history, _saveService);
83+
var groupPanelPresenter = new AssetGroupPanelPresenter(groupPanelView, _history, _saveService, _ruleContext);
8284
groupPanelPresenter.SetupView(_groups, index);
8385
_groupPanelPresenters.Add(group.Id, groupPanelPresenter);
8486
}

Assets/SmartAddresser/Editor/Core/Tools/Addresser/Shared/AssetGroups/AssetGroupPanelPresenter.cs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ internal sealed class AssetGroupPanelPresenter : IDisposable
2020
new Dictionary<string, AssetFilterViewPresenter>();
2121

2222
private readonly AutoIncrementHistory _history;
23+
private readonly RuleType? _ruleContext;
2324
private readonly IAssetSaveService _saveService;
2425
private readonly CompositeDisposable _setupViewDisposables = new CompositeDisposable();
2526
private readonly AssetGroupPanelView _view;
@@ -29,11 +30,12 @@ internal sealed class AssetGroupPanelPresenter : IDisposable
2930
private IList<AssetGroup> _groups;
3031

3132
public AssetGroupPanelPresenter(AssetGroupPanelView view, AutoIncrementHistory history,
32-
IAssetSaveService saveService)
33+
IAssetSaveService saveService, RuleType? ruleContext = null)
3334
{
3435
_view = view;
3536
_history = history;
3637
_saveService = saveService;
38+
_ruleContext = ruleContext;
3739

3840
SetupViewEventHandlers();
3941
}
@@ -246,6 +248,18 @@ void AddFilter()
246248
.Where(x => !typeof(AssetFilterAsset).IsAssignableFrom(x))
247249
.Where(x => x.GetCustomAttribute<IgnoreAssetFilterAttribute>() == null);
248250

251+
// Filter by rule context if set
252+
if (_ruleContext.HasValue)
253+
types = types.Where(type =>
254+
{
255+
var restrictedAttribute = type.GetCustomAttribute<RestrictedToRulesAttribute>();
256+
// If no restriction attribute, allow for all rules
257+
if (restrictedAttribute == null)
258+
return true;
259+
// If restriction attribute exists, check if current rule type is allowed
260+
return restrictedAttribute.AllowedRuleTypes.Contains(_ruleContext.Value);
261+
});
262+
249263
// Show filter selection menu.
250264
var menu = new GenericMenu();
251265
foreach (var type in types)
@@ -394,7 +408,9 @@ private ICollection<int> GetMoveDownByOptions()
394408
return Array.Empty<int>();
395409

396410
var index = _groups.IndexOf(_group);
397-
return index == _groups.Count - 1 ? Array.Empty<int>() : Enumerable.Range(1, _groups.Count - index - 1).ToArray();
411+
return index == _groups.Count - 1
412+
? Array.Empty<int>()
413+
: Enumerable.Range(1, _groups.Count - index - 1).ToArray();
398414
}
399415
}
400416
}

0 commit comments

Comments
 (0)