changed directory structure

This commit is contained in:
Sebastian Bularca
2026-04-02 07:22:33 +02:00
parent 101a7ae81a
commit 81b8eadaf1
323 changed files with 5 additions and 5 deletions

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 10b0c99dadaea0e42b49e323700f2eb9
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,15 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace AYellowpaper.SerializedCollections.KeysGenerators
{
[KeyListGenerator("Populate Enum", typeof(System.Enum), false)]
public class EnumGenerator : KeyListGenerator
{
public override IEnumerable GetKeys(System.Type type)
{
return System.Enum.GetValues(type);
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: d639de5d36bbeea4496c97cc3f1f4e81
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,24 @@
using System;
using System.Collections;
using UnityEngine;
namespace AYellowpaper.SerializedCollections.KeysGenerators
{
[KeyListGenerator("Int Range", typeof(int))]
public class IntRangeGenerator : KeyListGenerator
{
[SerializeField]
private int _startValue = 1;
[SerializeField]
private int _endValue = 10;
public override IEnumerable GetKeys(Type type)
{
int dir = Math.Sign(_endValue - _startValue);
dir = dir == 0 ? 1 : dir;
for (int i = _startValue; i != _endValue; i += dir)
yield return i;
yield return _endValue;
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: a4203f3a582fa874fb035633bd9892b4
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,26 @@
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace AYellowpaper.SerializedCollections.KeysGenerators
{
[KeyListGenerator("Int Stepping", typeof(int))]
public class IntSteppingGenerator : KeyListGenerator
{
[SerializeField]
private int _startIndex = 0;
[SerializeField]
private int _stepDistance = 10;
[SerializeField, Min(0)]
private int _stepCount = 1;
public override IEnumerable GetKeys(Type type)
{
for (int i = 0; i <= _stepCount; i++)
{
yield return _startIndex + i * _stepDistance;
}
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 99302d4ff0ae27b4898ced57890ed32d
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,11 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace AYellowpaper.SerializedCollections.KeysGenerators
{
public abstract class KeyListGenerator : ScriptableObject
{
public abstract IEnumerable GetKeys(System.Type type);
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 08149f25a1b9c5e48a224a7c4d31a154
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,19 @@
using System;
namespace AYellowpaper.SerializedCollections.KeysGenerators
{
[AttributeUsage(AttributeTargets.Class)]
public class KeyListGeneratorAttribute : Attribute
{
public readonly string Name;
public readonly Type TargetType;
public readonly bool NeedsWindow;
public KeyListGeneratorAttribute(string name, Type targetType, bool needsWindow = true)
{
Name = name;
TargetType = targetType;
NeedsWindow = needsWindow;
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 0f6065c936425ab478ecc8a8cf30d38f
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,36 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using UnityEditor;
using UnityEngine;
namespace AYellowpaper.SerializedCollections.KeysGenerators
{
public static class KeyListGeneratorCache
{
private static List<KeyListGeneratorData> _populators;
private static Dictionary<Type, List<KeyListGeneratorData>> _populatorsByType;
static KeyListGeneratorCache()
{
_populators = new List<KeyListGeneratorData>();
_populatorsByType = new Dictionary<Type, List<KeyListGeneratorData>>();
var populatorTypes = TypeCache.GetTypesDerivedFrom<KeyListGenerator>();
foreach (var populatorType in populatorTypes.Where(x => !x.IsAbstract))
{
var attributes = populatorType.GetCustomAttributes<KeyListGeneratorAttribute>();
foreach (var attribute in attributes)
_populators.Add(new KeyListGeneratorData(attribute.Name, attribute.TargetType, populatorType, attribute.NeedsWindow));
}
}
public static IReadOnlyList<KeyListGeneratorData> GetPopulatorsForType(Type type)
{
if (!_populatorsByType.ContainsKey(type))
_populatorsByType.Add(type, new List<KeyListGeneratorData>(_populators.Where(x => x.TargetType.IsAssignableFrom(type))));
return _populatorsByType[type];
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 7936217ae19613d4bb5e46e73a4a587c
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,20 @@
using System;
namespace AYellowpaper.SerializedCollections.KeysGenerators
{
public class KeyListGeneratorData
{
public string Name { get; set; }
public Type TargetType { get; set; }
public Type GeneratorType { get; set; }
public bool NeedsWindow { get; set; }
public KeyListGeneratorData(string name, Type targetType, Type populatorType, bool needsWindow)
{
Name = name;
TargetType = targetType;
GeneratorType = populatorType;
NeedsWindow = needsWindow;
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 8992145ced672cd46a425fb2590b80bb
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,26 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
namespace AYellowpaper.SerializedCollections.KeysGenerators
{
[CustomEditor(typeof(KeyListGenerator), true)]
public class KeyListGeneratorEditor : UnityEditor.Editor
{
public override void OnInspectorGUI()
{
var iterator = serializedObject.GetIterator();
if (iterator.Next(true))
{
// skip script name
iterator.NextVisible(true);
while (iterator.NextVisible(true))
{
EditorGUILayout.PropertyField(iterator);
}
}
serializedObject.ApplyModifiedProperties();
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 211518bea98ede643af247b6295984bd
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,182 @@
using System;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
using UnityEngine.UIElements;
namespace AYellowpaper.SerializedCollections.KeysGenerators
{
public class KeyListGeneratorSelectorWindow : EditorWindow
{
[SerializeField]
private int _selectedIndex;
[SerializeField]
private ModificationType _modificationType;
private KeyListGenerator _generator;
private UnityEditor.Editor _editor;
private List<KeyListGeneratorData> _generatorsData;
private Type _targetType;
private int _undoStart;
private Dictionary<Type, KeyListGenerator> _keysGenerators = new Dictionary<Type, KeyListGenerator>();
private string _detailsText;
public event Action<KeyListGenerator, ModificationType> OnApply;
private void OnEnable()
{
VisualTreeAsset document = AssetDatabase.LoadAssetAtPath<VisualTreeAsset>("Assets/Plugins/SerializedCollections/Editor/Assets/KeysGeneratorSelectorWindow.uxml");
var element = document.CloneTree();
element.style.height = new StyleLength(new Length(100, LengthUnit.Percent));
rootVisualElement.Add(element);
}
public void Initialize(IEnumerable<KeyListGeneratorData> generatorsData, Type type)
{
_targetType = type;
_selectedIndex = 0;
_modificationType = ModificationType.Add;
_undoStart = Undo.GetCurrentGroup();
_generatorsData = new List<KeyListGeneratorData>(generatorsData);
SetGeneratorIndex(0);
Undo.undoRedoPerformed += HandleUndoCallback;
rootVisualElement.Q<Button>(className: "sc-close-button").clicked += Close;
rootVisualElement.Q<RadioButton>(name = "add-modification").userData = ModificationType.Add;
rootVisualElement.Q<RadioButton>(name = "remove-modification").userData = ModificationType.Remove;
rootVisualElement.Q<RadioButton>(name = "confine-modification").userData = ModificationType.Confine;
var modificationToggles = rootVisualElement.Query<RadioButton>(className: "sc-modification-toggle");
modificationToggles.ForEach(InitializeModificationToggle);
rootVisualElement.Q<IMGUIContainer>(name = "imgui-inspector").onGUIHandler = EditorGUIHandler;
rootVisualElement.Q<Button>(name = "apply-button").clicked += ApplyButtonClicked;
var generatorsContent = rootVisualElement.Q<ScrollView>(name = "generators-content");
var radioButtonGroup = new RadioButtonGroup();
radioButtonGroup.name = "generators-group";
radioButtonGroup.AddToClassList("sc-radio-button-group");
generatorsContent.Add(radioButtonGroup);
for (int i = 0; i < _generatorsData.Count; i++)
{
var generatorData = _generatorsData[i];
var radioButton = new RadioButton(generatorData.Name);
radioButton.value = i == 0;
radioButton.AddToClassList("sc-text-toggle");
radioButton.AddToClassList("sc-generator-toggle");
radioButton.userData = i;
radioButton.RegisterValueChangedCallback(OnGeneratorClicked);
radioButtonGroup.Add(radioButton);
}
}
private void ApplyButtonClicked()
{
OnApply?.Invoke(_editor.target as KeyListGenerator, _modificationType);
OnApply = null;
Close();
}
private void EditorGUIHandler()
{
EditorGUI.BeginChangeCheck();
_editor.OnInspectorGUI();
if (EditorGUI.EndChangeCheck())
{
UpdateDetailsText();
}
}
private void InitializeModificationToggle(RadioButton obj)
{
if ((ModificationType)obj.userData == _modificationType)
obj.value = true;
obj.RegisterValueChangedCallback(OnModificationToggleClicked);
}
private void OnModificationToggleClicked(ChangeEvent<bool> evt)
{
if (!evt.newValue)
return;
var modificationType = (ModificationType)((VisualElement)evt.target).userData;
_modificationType = modificationType;
}
private void UpdateDetailsText()
{
var enumerable = _generator.GetKeys(_targetType);
int count = 0;
var enumerator = enumerable.GetEnumerator();
while (enumerator.MoveNext())
{
count++;
if (count > 100)
{
_detailsText = "over 100 Elements";
return;
}
}
_detailsText = $"{count} Elements";
rootVisualElement.Q<Label>(name = "generated-count-label").text = _detailsText;
}
private void OnDestroy()
{
Undo.undoRedoPerformed -= HandleUndoCallback;
Undo.RevertAllDownToGroup(_undoStart);
foreach (var keyGenerator in _keysGenerators)
DestroyImmediate(keyGenerator.Value);
}
private void OnGeneratorClicked(ChangeEvent<bool> evt)
{
if (!evt.newValue)
return;
SetGeneratorIndex((int)(evt.target as VisualElement).userData);
}
private void HandleUndoCallback()
{
UpdateGeneratorAndEditorIfNeeded();
Repaint();
}
private void SetGeneratorIndex(int index)
{
Undo.RecordObject(this, "Change Window");
_selectedIndex = index;
UpdateGeneratorAndEditorIfNeeded();
}
private void UpdateGeneratorAndEditorIfNeeded()
{
var targetType = _generatorsData[_selectedIndex].GeneratorType;
if (_generator != null && _generator.GetType() == targetType)
return;
_generator = GetOrCreateKeysGenerator(targetType);
if (_editor != null)
DestroyImmediate(_editor);
_editor = UnityEditor.Editor.CreateEditor(_generator);
UpdateDetailsText();
}
private KeyListGenerator GetOrCreateKeysGenerator(Type type)
{
if (!_keysGenerators.ContainsKey(type))
{
var so = (KeyListGenerator)CreateInstance(type);
so.hideFlags = HideFlags.DontSave;
_keysGenerators.Add(type, so);
}
return _keysGenerators[type];
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: df07fe6d161e3334083f837a066dd949
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,10 @@
namespace AYellowpaper.SerializedCollections
{
public enum ModificationType
{
None,
Add,
Remove,
Confine,
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: fc2030edc0a04b74a8642773bd8c98fd
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: