Added option to enable/disable max-height of unity-collection-view
This commit is contained in:
commit
78adbc46af
21 changed files with 265 additions and 0 deletions
70
Editor/EditorUIToolkitCustomization.cs
Normal file
70
Editor/EditorUIToolkitCustomization.cs
Normal file
|
|
@ -0,0 +1,70 @@
|
|||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UIElements;
|
||||
|
||||
namespace Module.UIToolkit.Editor
|
||||
{
|
||||
internal static class EditorUIToolkitCustomization
|
||||
{
|
||||
private static StyleSheet _ussCollectionView;
|
||||
|
||||
[InitializeOnLoadMethod]
|
||||
private static void Initialize()
|
||||
{
|
||||
EditorApplication.update -= EditorTick;
|
||||
EditorApplication.update += EditorTick;
|
||||
}
|
||||
|
||||
private static void EditorTick()
|
||||
{
|
||||
ApplyChanges();
|
||||
}
|
||||
|
||||
private static void InitializeStyleSheets()
|
||||
{
|
||||
if (_ussCollectionView == null)
|
||||
_ussCollectionView = FindStyleSheet("editor-collection-view");
|
||||
}
|
||||
|
||||
internal static void ApplyChanges()
|
||||
{
|
||||
InitializeStyleSheets();
|
||||
|
||||
var settings = Settings.Load();
|
||||
var windows = GetAllOpenEditorWindows();
|
||||
|
||||
for (var i = 0; i < windows.Length; i++)
|
||||
{
|
||||
var window = windows[i];
|
||||
var ve = window.rootVisualElement;
|
||||
|
||||
if (ve == null)
|
||||
continue;
|
||||
|
||||
if (_ussCollectionView != null)
|
||||
{
|
||||
if (settings.listViewDisableMaxHeight)
|
||||
ve.styleSheets.Add(_ussCollectionView);
|
||||
else
|
||||
ve.styleSheets.Remove(_ussCollectionView);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static StyleSheet FindStyleSheet(string name)
|
||||
{
|
||||
var guids = AssetDatabase.FindAssets($"t:{nameof(StyleSheet)} {name}");
|
||||
|
||||
if (guids.Length == 0)
|
||||
return null;
|
||||
|
||||
var path = AssetDatabase.GUIDToAssetPath(guids[0]);
|
||||
return AssetDatabase.LoadAssetAtPath<StyleSheet>(path);
|
||||
}
|
||||
|
||||
private static EditorWindow[] GetAllOpenEditorWindows()
|
||||
{
|
||||
return Resources.FindObjectsOfTypeAll<EditorWindow>();
|
||||
}
|
||||
}
|
||||
}
|
||||
2
Editor/EditorUIToolkitCustomization.cs.meta
Normal file
2
Editor/EditorUIToolkitCustomization.cs.meta
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 98c22645c5bc08b4f9da6f90d01b76ec
|
||||
16
Editor/Module.UIToolkit.Editor.asmdef
Normal file
16
Editor/Module.UIToolkit.Editor.asmdef
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
{
|
||||
"name": "Module.UIToolkit.Editor",
|
||||
"rootNamespace": "Module.UIToolkit.Editor",
|
||||
"references": [],
|
||||
"includePlatforms": [
|
||||
"Editor"
|
||||
],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": false,
|
||||
"overrideReferences": false,
|
||||
"precompiledReferences": [],
|
||||
"autoReferenced": false,
|
||||
"defineConstraints": [],
|
||||
"versionDefines": [],
|
||||
"noEngineReferences": false
|
||||
}
|
||||
7
Editor/Module.UIToolkit.Editor.asmdef.meta
Normal file
7
Editor/Module.UIToolkit.Editor.asmdef.meta
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
fileFormatVersion: 2
|
||||
guid: ba4dfb528ba3137409017f4dfbc4c8d7
|
||||
AssemblyDefinitionImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
3
Editor/Settings.meta
Normal file
3
Editor/Settings.meta
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 188e9f5b1ca5190469d4327259c28d55
|
||||
timeCreated: 1749398664
|
||||
34
Editor/Settings/Settings.cs
Normal file
34
Editor/Settings/Settings.cs
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
using System;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Module.UIToolkit.Editor
|
||||
{
|
||||
[Serializable]
|
||||
internal sealed class Settings
|
||||
{
|
||||
public bool listViewDisableMaxHeight;
|
||||
|
||||
private static Settings _settings;
|
||||
|
||||
internal static Settings Load()
|
||||
{
|
||||
if (_settings != null)
|
||||
return _settings;
|
||||
|
||||
_settings = new Settings();
|
||||
var json = EditorPrefs.GetString(nameof(Settings), string.Empty);
|
||||
|
||||
if (!string.IsNullOrEmpty(json))
|
||||
JsonUtility.FromJsonOverwrite(json, _settings);
|
||||
|
||||
return _settings;
|
||||
}
|
||||
|
||||
internal void Save()
|
||||
{
|
||||
var json = JsonUtility.ToJson(this);
|
||||
EditorPrefs.SetString(nameof(Settings), json);
|
||||
}
|
||||
}
|
||||
}
|
||||
3
Editor/Settings/Settings.cs.meta
Normal file
3
Editor/Settings/Settings.cs.meta
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 38bf3b0d567162d488a2dc66f0514dcd
|
||||
timeCreated: 1749398672
|
||||
38
Editor/Settings/SettingsProvider.cs
Normal file
38
Editor/Settings/SettingsProvider.cs
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
using System.Collections.Generic;
|
||||
using UnityEditor;
|
||||
|
||||
namespace Module.UIToolkit.Editor
|
||||
{
|
||||
internal static class SettingsProvider
|
||||
{
|
||||
[SettingsProvider]
|
||||
public static UnityEditor.SettingsProvider GetProvider()
|
||||
{
|
||||
return new UnityEditor.SettingsProvider("Module/Editor UIToolkit", SettingsScope.User)
|
||||
{
|
||||
label = "Editor UIToolkit",
|
||||
keywords = new List<string> { "UI", "Toolkit" },
|
||||
guiHandler = OnGui
|
||||
};
|
||||
}
|
||||
|
||||
private static void OnGui(string searchContext)
|
||||
{
|
||||
var settings = Settings.Load();
|
||||
|
||||
EditorGUI.BeginChangeCheck();
|
||||
EditorGUILayout.BeginVertical();
|
||||
|
||||
EditorGUILayout.LabelField("List View", EditorStyles.boldLabel);
|
||||
settings.listViewDisableMaxHeight = EditorGUILayout.Toggle("Disable Max Height", settings.listViewDisableMaxHeight);
|
||||
|
||||
EditorGUILayout.EndVertical();
|
||||
|
||||
if (!EditorGUI.EndChangeCheck())
|
||||
return;
|
||||
|
||||
settings.Save();
|
||||
EditorUIToolkitCustomization.ApplyChanges();
|
||||
}
|
||||
}
|
||||
}
|
||||
3
Editor/Settings/SettingsProvider.cs.meta
Normal file
3
Editor/Settings/SettingsProvider.cs.meta
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: cb3cf13736e25ce46a3eae1332f5cc8f
|
||||
timeCreated: 1749397903
|
||||
3
Editor/StyleSheets.meta
Normal file
3
Editor/StyleSheets.meta
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 1f126b6ba5fb4d49b319e262fb961a87
|
||||
timeCreated: 1750537625
|
||||
3
Editor/StyleSheets/editor-collection-view.uss
Normal file
3
Editor/StyleSheets/editor-collection-view.uss
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
.unity-collection-view {
|
||||
max-height: none;
|
||||
}
|
||||
11
Editor/StyleSheets/editor-collection-view.uss.meta
Normal file
11
Editor/StyleSheets/editor-collection-view.uss.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 8bf186d8caf1cd44f86f09dc65d7e37c
|
||||
ScriptedImporter:
|
||||
internalIDToNameTable: []
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
script: {fileID: 12385, guid: 0000000000000000e000000000000000, type: 0}
|
||||
disableValidation: 0
|
||||
Loading…
Add table
Add a link
Reference in a new issue