Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
7a7809a
Added an extension for getting all assignable classes.
RoyTheunissen Aug 25, 2023
846e9dc
Added a way to get or add an item without knowing the collection's type.
RoyTheunissen Aug 25, 2023
b99fb09
Added a non-generic way to get a collection of a type.
RoyTheunissen Aug 25, 2023
aea3f63
Created a setup for generating collection items through simple syntax.
RoyTheunissen Aug 25, 2023
133dd3e
If specified, generators will now also remove items that weren't re-g…
RoyTheunissen Aug 25, 2023
5411908
Added support for arrays in templates.
RoyTheunissen Aug 25, 2023
a185077
Added a button to generate a specific collection.
RoyTheunissen Aug 25, 2023
904192a
Small rename for clarity.
RoyTheunissen Aug 25, 2023
63880f6
Fixed incorrect whitespace.
RoyTheunissen Aug 25, 2023
7d1c121
Added some extra descriptions for clarity.
RoyTheunissen Aug 25, 2023
23ec8ce
Removed an empty case.
RoyTheunissen Aug 25, 2023
6f9c3a2
Added a way to run a specific generator instance.
RoyTheunissen Aug 25, 2023
064614f
Added the option to also generate static access immediately.
RoyTheunissen Aug 25, 2023
6be3b67
Made sure the generators are cleared for projects that don't do domai…
RoyTheunissen Aug 25, 2023
510871a
Added a way to add a new base item.
RoyTheunissen Aug 26, 2023
4467d86
Item generators can now optionally match items by index instead of name.
RoyTheunissen Aug 26, 2023
9666062
Renames / comments for clarity.
RoyTheunissen Aug 26, 2023
d760554
Certain controls are now removed for auto-generated collections.
RoyTheunissen Aug 26, 2023
6798c1f
fix: wrong property name
brunomikoski Aug 27, 2023
73ae3a0
add: custom generic collection item type for the template
brunomikoski Aug 27, 2023
b674eaa
Fixed logic for removing items that weren't re-generated.
RoyTheunissen Aug 27, 2023
fc4de6d
Dropped support for Match by Index. Not as useful as I thought.
RoyTheunissen Aug 27, 2023
4a2bded
Added a utility for renaming an item.
RoyTheunissen Aug 27, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 45 additions & 4 deletions Scripts/Editor/CustomEditors/CollectionCustomEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,39 @@ public class CollectionCustomEditor : BaseEditor<CollectionCustomEditor>
private readonly Dictionary<int, Rect> itemIndexToRect = new();
private float? reorderableListYPosition;
private Dictionary<Object, SerializedObject> collectionItemSerializedObjectCache = new();

[NonSerialized] private Type generatorType;
[NonSerialized] private IScriptableObjectCollectionGeneratorBase generator;

private bool IsAutoGenerated => generatorType != null;

protected virtual bool CanBeReorderable => true;
protected virtual bool DisplayAddButton => true;
protected virtual bool DisplayRemoveButton => true;

protected virtual bool DisplayAddButton
{
get
{
// If this is a generated collection and it's set to remove items that aren't re-generated, then it
// doesn't make sense for you to add items because they will be removed next time you generate.
if (IsAutoGenerated && generator.ShouldRemoveNonGeneratedItems)
return false;
return true;
}
}

protected virtual bool DisplayRemoveButton
{
get
{
// If this is a generated collection and it's set to remove items that aren't re-generated, then it
// doesn't make sense for you to remove items because they will be added back next time you generate.
if (IsAutoGenerated && generator.ShouldRemoveNonGeneratedItems)
return false;

return true;
}
}

protected virtual bool AllowCustomTypeCreation => true;

private static bool IsWaitingForNewTypeBeCreated
Expand All @@ -51,6 +80,10 @@ protected virtual void OnEnable()
CollectionsRegistry.Instance.ReloadCollections();

itemsSerializedProperty = serializedObject.FindProperty("items");

// Need to cache this before the reorderable list is created, because it affects how the list is displayed.
generatorType = CollectionGenerators.GetGeneratorTypeForCollection(collection.GetType());
generator = generatorType == null ? null : CollectionGenerators.GetGenerator(generatorType);

ValidateCollectionItems();

Expand Down Expand Up @@ -560,15 +593,23 @@ private void ValidateCollectionItems()

private void DrawBottomMenu()
{
using (new EditorGUILayout.HorizontalScope("Box"))
using (new EditorGUILayout.VerticalScope("Box"))
{
if (GUILayout.Button($"Generate Static Access File", EditorStyles.miniButtonRight))
if (GUILayout.Button($"Generate Static Access File", EditorStyles.miniButton))
{
EditorApplication.delayCall += () =>
{
CodeGenerationUtility.GenerateStaticCollectionScript(collection);
};
}

if (generatorType != null && GUILayout.Button($"Generate Items", GUILayout.Height(40)))
{
EditorApplication.delayCall += () =>
{
CollectionGenerators.RunGenerator(generatorType);
};
}
}
}

Expand Down
85 changes: 85 additions & 0 deletions Scripts/Editor/Extensions/SerializedPropertyExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Reflection;
using UnityEditor;
using UnityEngine;

namespace BrunoMikoski.ScriptableObjectCollections
{
Expand All @@ -23,5 +24,89 @@ public static FieldInfo GetFieldInfoFromPathByType(this SerializedProperty prope

return fieldInfo;
}

public static void SetValue(this SerializedProperty serializedProperty, object value)
{
switch (serializedProperty.propertyType)
{
case SerializedPropertyType.Integer:
serializedProperty.intValue = (int)value;
break;
case SerializedPropertyType.Boolean:
serializedProperty.boolValue = (bool)value;
break;
case SerializedPropertyType.Float:
serializedProperty.floatValue = (float)value;
break;
case SerializedPropertyType.String:
serializedProperty.stringValue = (string)value;
break;
case SerializedPropertyType.Color:
serializedProperty.colorValue = (Color)value;
break;
case SerializedPropertyType.ObjectReference:
serializedProperty.objectReferenceValue = (UnityEngine.Object)value;
break;
case SerializedPropertyType.LayerMask:
serializedProperty.intValue = (LayerMask)value;
break;
case SerializedPropertyType.Enum:
serializedProperty.intValue = (int)value;
break;
case SerializedPropertyType.Vector2:
serializedProperty.vector2Value = (Vector2)value;
break;
case SerializedPropertyType.Vector3:
serializedProperty.vector3Value = (Vector3)value;
break;
case SerializedPropertyType.Vector4:
serializedProperty.vector4Value = (Vector4)value;
break;
case SerializedPropertyType.Rect:
serializedProperty.rectValue = (Rect)value;
break;
//case SerializedPropertyType.ArraySize:
//break;
case SerializedPropertyType.Character:
serializedProperty.stringValue = ((char)value).ToString();
break;
case SerializedPropertyType.AnimationCurve:
serializedProperty.animationCurveValue = (AnimationCurve)value;
break;
case SerializedPropertyType.Bounds:
serializedProperty.boundsValue = (Bounds)value;
break;
//case SerializedPropertyType.Gradient:
//break;
case SerializedPropertyType.Quaternion:
serializedProperty.quaternionValue = (Quaternion)value;
break;
//case SerializedPropertyType.ExposedReference:
//break;
//case SerializedPropertyType.FixedBufferSize:
//break;
case SerializedPropertyType.Vector2Int:
serializedProperty.vector2IntValue = (Vector2Int)value;
break;
case SerializedPropertyType.Vector3Int:
serializedProperty.vector3IntValue = (Vector3Int)value;
break;
case SerializedPropertyType.RectInt:
serializedProperty.rectIntValue = (RectInt)value;
break;
case SerializedPropertyType.BoundsInt:
serializedProperty.boundsIntValue = (BoundsInt)value;
break;
//case SerializedPropertyType.ManagedReference:
//break;
case SerializedPropertyType.Hash128:
serializedProperty.hash128Value = (Hash128)value;
break;
default:
Debug.LogWarning(
$"Tried to copy value '{value}' from a template to an SOC item but apparently that's not supported.");
break;
}
}
}
}
8 changes: 8 additions & 0 deletions Scripts/Editor/Generators.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading