-
-
Notifications
You must be signed in to change notification settings - Fork 122
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: ODIN inspector search filter (#35)
* - add optional Odin inspector support - move Button Attribute to runtime asm.def * - add optional Odin inspector support - move Button Attribute to runtime asm.def * - add FilePath attribue for file usage improvement * - update odin Addressable Import Rule drawer * - update odin Addressable Import Rule drawer * - fix Folder Path attribute * - fix Force backslashes * - fix Force backslashes * #33 fixes * - add search filter for Odin inspector * - update addressables import serach filter * #33 - review fixes * - fix review comments * #33 * - fix odin serach filter support * - fix importer search filter * - fix ApplyChanges index * - fix duplicate class def
- Loading branch information
Showing
9 changed files
with
257 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
namespace UnityAddressableImporter.Editor.Helper | ||
{ | ||
using System; | ||
using Object = UnityEngine.Object; | ||
#if ODIN_INSPECTOR | ||
using Sirenix.OdinInspector.Editor; | ||
using Sirenix.OdinInspector; | ||
using UnityEditor; | ||
using UnityEngine; | ||
|
||
public class AddressableImporterOdinHandler : IDisposable | ||
{ | ||
private AddressableImportSettings _settings; | ||
private AddressablesImporterFilterOdinHandler _importRulesContainer; | ||
private GUIContent _searchFieldLabel; | ||
private string _searchField; | ||
|
||
public void Initialize(AddressableImportSettings target) | ||
{ | ||
_settings = target; | ||
_importRulesContainer = CreateDrawer(_settings); | ||
} | ||
|
||
public void Draw() | ||
{ | ||
DrawInspectorTree(_searchField); | ||
|
||
EditorUtility.SetDirty(_settings); | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
_settings = null; | ||
if (_importRulesContainer) { | ||
Object.DestroyImmediate(_importRulesContainer); | ||
_importRulesContainer = null; | ||
} | ||
} | ||
|
||
private AddressablesImporterFilterOdinHandler CreateDrawer(AddressableImportSettings settings) | ||
{ | ||
_importRulesContainer = ScriptableObject.CreateInstance<AddressablesImporterFilterOdinHandler>(); | ||
_importRulesContainer.Initialize(settings); | ||
return _importRulesContainer; | ||
} | ||
|
||
private void DrawInspectorTree(string filter) | ||
{ | ||
_importRulesContainer?.Draw(); | ||
} | ||
} | ||
|
||
#else | ||
|
||
public class AddressablesImporterOdinHandler : IDisposable | ||
{ | ||
public void Initialize(AddressableImportSettings target) { } | ||
|
||
public void Draw() { } | ||
|
||
public void Dispose() { } | ||
} | ||
|
||
#endif | ||
} |
2 changes: 1 addition & 1 deletion
2
...er/AddressableImporterOdinHandler.cs.meta → ...rt/AddressableImporterOdinHandler.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
163 changes: 163 additions & 0 deletions
163
Editor/OdinSupport/AddressablesImporterFilterOdinHandler.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,163 @@ | ||
namespace UnityAddressableImporter.Editor.Helper | ||
{ | ||
#if ODIN_INSPECTOR | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using Sirenix.OdinInspector; | ||
using Sirenix.OdinInspector.Editor; | ||
using UnityEditor; | ||
using UnityEngine; | ||
|
||
public class AddressablesImporterFilterOdinHandler : ScriptableObject | ||
{ | ||
private AddressableImportSettings _importSettings; | ||
private PropertyTree _drawerTree; | ||
private List<Func<AddressableImportRule, string, bool>> _filters; | ||
//private List<AddressableImportRule> _filteredRules; | ||
private bool _sourceChanged = false; | ||
|
||
[SerializeField] | ||
[HideLabel] | ||
[OnValueChanged("OnFilterChanged")] | ||
private string _searchFilter; | ||
|
||
[SerializeField] | ||
[ListDrawerSettings( | ||
HideRemoveButton = true, | ||
Expanded = true, | ||
CustomAddFunction = nameof(CustomAddFunction), | ||
OnEndListElementGUI = nameof(EndOfListItemGui), | ||
CustomRemoveElementFunction = nameof(CustomRemoveElementFunction), | ||
CustomRemoveIndexFunction = nameof(CustomRemoveIndexFunction), | ||
ShowPaging = true | ||
)] | ||
private List<AddressableImportRule> rules = new List<AddressableImportRule>(); | ||
|
||
public void Initialize(AddressableImportSettings importSettings) | ||
{ | ||
_importSettings = importSettings; | ||
_drawerTree = PropertyTree.Create(this); | ||
|
||
_filters = new List<Func<AddressableImportRule, string, bool>>() { | ||
ValidateAddressableGroupName, | ||
ValidateRulePath, | ||
ValidateLabelsPath, | ||
}; | ||
|
||
_drawerTree.OnPropertyValueChanged += (property, index) => EditorUtility.SetDirty(_importSettings); | ||
} | ||
|
||
public void Draw() | ||
{ | ||
try { | ||
FilterRules(_searchFilter); | ||
_drawerTree.Draw(); | ||
ApplyChanges(); | ||
} | ||
catch (Exception e) { | ||
Debug.LogError(e); | ||
} | ||
|
||
} | ||
|
||
[Button] | ||
public void Save() => _importSettings.Save(); | ||
|
||
[Button] | ||
public void Documentation() => _importSettings.Documentation(); | ||
|
||
[Button] | ||
public void CleanEmptyGroup() => _importSettings.CleanEmptyGroup(); | ||
|
||
#region private methods | ||
|
||
private void OnFilterChanged() | ||
{ | ||
|
||
} | ||
|
||
private bool ValidateRule(AddressableImportRule rule,string filter) | ||
{ | ||
return string.IsNullOrEmpty(filter) || _filters.Any(x => x(rule,filter)); | ||
} | ||
|
||
private bool ValidateAddressableGroupName(AddressableImportRule rule, string filter) | ||
{ | ||
return rule.groupName.IndexOf(filter, StringComparison.OrdinalIgnoreCase) >= 0; | ||
} | ||
|
||
private bool ValidateRulePath(AddressableImportRule rule, string filter) | ||
{ | ||
return rule.path.IndexOf(filter, StringComparison.OrdinalIgnoreCase) >= 0; | ||
} | ||
|
||
private bool ValidateLabelsPath(AddressableImportRule rule, string filter) | ||
{ | ||
return rule.labels.Any(x => x.IndexOf(filter, StringComparison.OrdinalIgnoreCase) >= 0); | ||
} | ||
|
||
private void FilterRules(string filter) | ||
{ | ||
rules = new List<AddressableImportRule>(); | ||
var filteredRules = _importSettings.rules. | ||
Where(x => ValidateRule(x, filter)); | ||
rules.AddRange(filteredRules); | ||
} | ||
|
||
private void ApplyChanges() | ||
{ | ||
_drawerTree.ApplyChanges(); | ||
|
||
for (var i = 0; i < rules.Count; i++) { | ||
var rule = rules[i]; | ||
var index = _importSettings.rules.IndexOf(rule); | ||
if(index < 0) continue; | ||
_importSettings.rules[index] = rules[i]; | ||
} | ||
|
||
} | ||
|
||
private void CustomAddFunction() | ||
{ | ||
_importSettings.rules.Add(new AddressableImportRule()); | ||
_sourceChanged = true; | ||
} | ||
|
||
private void CustomRemoveIndexFunction(int index) | ||
{ | ||
var removeResult = _importSettings.rules.Remove(rules[index]); | ||
_sourceChanged = true; | ||
} | ||
|
||
private void CustomRemoveElementFunction(AddressableImportRule item) | ||
{ | ||
var index = rules.IndexOf(item); | ||
CustomRemoveIndexFunction(index); | ||
} | ||
|
||
private void EndOfListItemGui(int item) | ||
{ | ||
if (GUILayout.Button("remove")) { | ||
CustomRemoveIndexFunction(item); | ||
} | ||
} | ||
|
||
private void OnDisable() | ||
{ | ||
if (_drawerTree == null) return; | ||
_drawerTree.OnPropertyValueChanged -= OnPropertyChanged; | ||
_drawerTree.Dispose(); | ||
} | ||
|
||
private void OnPropertyChanged(InspectorProperty property, int index) | ||
{ | ||
if (_importSettings == null) return; | ||
EditorUtility.SetDirty(_importSettings); | ||
} | ||
|
||
#endregion | ||
} | ||
#endif | ||
} |
3 changes: 3 additions & 0 deletions
3
Editor/OdinSupport/AddressablesImporterFilterOdinHandler.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.