Skip to content

Commit 27ad1af

Browse files
committed
add: more stuffs
1 parent af43b24 commit 27ad1af

13 files changed

+208
-170
lines changed

Scripts/Editor/CustomEditors/CollectionCustomEditor.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919

2020
namespace BrunoMikoski.ScriptableObjectCollections
2121
{
22-
2322
[CustomEditor(typeof(ScriptableObjectCollection), true)]
2423
public class CollectionCustomEditor : Editor
2524
{
@@ -394,6 +393,12 @@ protected virtual void OnEnable()
394393
{
395394
collection = (ScriptableObjectCollection)target;
396395

396+
if (!CollectionsRegistry.Instance.HasUniqueGUID(collection))
397+
{
398+
collection.GenerateNewGUID();
399+
collection.Clear();
400+
}
401+
397402
if (!CollectionsRegistry.Instance.IsKnowCollection(collection))
398403
CollectionsRegistry.Instance.ReloadCollections();
399404

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
using System.Collections.Generic;
2+
using UnityEditor;
3+
using UnityEngine;
4+
5+
namespace BrunoMikoski.ScriptableObjectCollections
6+
{
7+
public class MoveToCollectionWindow : EditorWindow
8+
{
9+
private List<ISOCItem> itemsToMove;
10+
private List<ScriptableObjectCollection> availableCollections;
11+
12+
public static void ShowWindow(List<ISOCItem> items, List<ScriptableObjectCollection> collections)
13+
{
14+
MoveToCollectionWindow window = GetWindow<MoveToCollectionWindow>("Move to Collection");
15+
window.itemsToMove = items;
16+
window.availableCollections = collections;
17+
window.ShowPopup();
18+
}
19+
20+
private void OnGUI()
21+
{
22+
EditorGUILayout.LabelField("Select a Collection to Move Items", EditorStyles.boldLabel);
23+
24+
if (availableCollections == null || availableCollections.Count == 0)
25+
{
26+
EditorGUILayout.LabelField("No available collections.");
27+
return;
28+
}
29+
30+
foreach (ScriptableObjectCollection collection in availableCollections)
31+
{
32+
if (GUILayout.Button(collection.name))
33+
{
34+
foreach (ISOCItem item in itemsToMove)
35+
{
36+
SOCItemUtility.MoveItem(item, collection);
37+
EditorUtility.SetDirty(collection);
38+
}
39+
40+
Close();
41+
}
42+
}
43+
}
44+
}
45+
}

Scripts/Editor/CustomEditors/MoveToCollectionWindow.cs.meta

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

Scripts/Editor/Processors/CollectionsAssetsPostProcessor.cs

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -29,30 +29,21 @@ static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAsse
2929
ScriptableObject collectionItem =
3030
AssetDatabase.LoadAssetAtPath<ScriptableObject>(importedAssetPath);
3131

32-
if (collectionItem != null)
32+
if (collectionItem == null)
3333
{
34-
if (collectionItem is ISOCItem socItem)
35-
{
36-
if (socItem.Collection == null)
37-
{
38-
continue;
39-
}
34+
continue;
35+
}
36+
37+
if (collectionItem is not ISOCItem socItem)
38+
{
39+
continue;
40+
}
4041

41-
if (!socItem.Collection.Contains(collectionItem))
42-
{
43-
if (socItem.Collection.TryGetItemByGUID(socItem.GUID, out _))
44-
{
45-
Debug.LogWarning(
46-
$"Collection already contains one item with the same GUID" +
47-
$" ({socItem.GUID}) but different name ({socItem.name}), generating new GUID");
48-
socItem.GenerateNewGUID();
49-
}
50-
51-
socItem.Collection.Add(collectionItem);
52-
Debug.Log($"{collectionItem.name} has collection assigned "
53-
+ $"{socItem.Collection} but its missing from collection list, adding it");
54-
}
55-
}
42+
if (!CollectionsRegistry.Instance.HasUniqueGUID(socItem))
43+
{
44+
socItem.GenerateNewGUID();
45+
socItem.ClearCollection();
46+
Debug.LogWarning($"Item {socItem} GUID was not unique, generating a new one and clearing the collection");
5647
}
5748
}
5849

@@ -64,6 +55,13 @@ static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAsse
6455
if (collection == null)
6556
continue;
6657

58+
if (!CollectionsRegistry.Instance.HasUniqueGUID(collection))
59+
{
60+
collection.GenerateNewGUID();
61+
collection.Clear();
62+
Debug.LogWarning($"Collection {collection} GUID was not unique, generating a new one, and clearing the items");
63+
}
64+
6765
if (!CollectionsRegistry.Instance.IsKnowCollection(collection))
6866
{
6967
RefreshRegistry();
@@ -95,4 +93,4 @@ static void OnAfterScriptsReloading()
9593
RefreshRegistryAfterRecompilation = false;
9694
}
9795
}
98-
}
96+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
using UnityEditor;
2+
using UnityEngine;
3+
4+
namespace BrunoMikoski.ScriptableObjectCollections.Picker
5+
{
6+
[CustomPropertyDrawer(typeof(CollectionReferenceLongGuidAttribute))]
7+
public class CollectionReferenceLongGuidDrawer : PropertyDrawer
8+
{
9+
public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
10+
{
11+
return EditorGUIUtility.singleLineHeight;
12+
}
13+
14+
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
15+
{
16+
LongGuid collectionGUID = (LongGuid)property.boxedValue;
17+
18+
ScriptableObjectCollection collection = null;
19+
if (collectionGUID.IsValid())
20+
{
21+
collection = CollectionsRegistry.Instance.GetCollectionByGUID(collectionGUID);
22+
}
23+
24+
EditorGUI.BeginDisabledGroup(true);
25+
EditorGUI.ObjectField(position, "Collection", collection, typeof(ScriptableObjectCollection), false);
26+
EditorGUI.EndDisabledGroup();
27+
}
28+
}
29+
}

Scripts/Editor/PropertyDrawers/CollectionReferenceLongGuidDrawer.cs.meta

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

0 commit comments

Comments
 (0)