Skip to content

Commit

Permalink
add: more stuffs
Browse files Browse the repository at this point in the history
  • Loading branch information
brunomikoski committed Feb 19, 2025
1 parent af43b24 commit 27ad1af
Show file tree
Hide file tree
Showing 13 changed files with 208 additions and 170 deletions.
7 changes: 6 additions & 1 deletion Scripts/Editor/CustomEditors/CollectionCustomEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

namespace BrunoMikoski.ScriptableObjectCollections
{

[CustomEditor(typeof(ScriptableObjectCollection), true)]
public class CollectionCustomEditor : Editor
{
Expand Down Expand Up @@ -394,6 +393,12 @@ protected virtual void OnEnable()
{
collection = (ScriptableObjectCollection)target;

if (!CollectionsRegistry.Instance.HasUniqueGUID(collection))
{
collection.GenerateNewGUID();
collection.Clear();
}

if (!CollectionsRegistry.Instance.IsKnowCollection(collection))
CollectionsRegistry.Instance.ReloadCollections();

Expand Down
45 changes: 45 additions & 0 deletions Scripts/Editor/CustomEditors/MoveToCollectionWindow.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;

namespace BrunoMikoski.ScriptableObjectCollections
{
public class MoveToCollectionWindow : EditorWindow
{
private List<ISOCItem> itemsToMove;
private List<ScriptableObjectCollection> availableCollections;

public static void ShowWindow(List<ISOCItem> items, List<ScriptableObjectCollection> collections)
{
MoveToCollectionWindow window = GetWindow<MoveToCollectionWindow>("Move to Collection");
window.itemsToMove = items;
window.availableCollections = collections;
window.ShowPopup();
}

private void OnGUI()
{
EditorGUILayout.LabelField("Select a Collection to Move Items", EditorStyles.boldLabel);

if (availableCollections == null || availableCollections.Count == 0)
{
EditorGUILayout.LabelField("No available collections.");
return;
}

foreach (ScriptableObjectCollection collection in availableCollections)
{
if (GUILayout.Button(collection.name))
{
foreach (ISOCItem item in itemsToMove)
{
SOCItemUtility.MoveItem(item, collection);
EditorUtility.SetDirty(collection);
}

Close();
}
}
}
}
}
3 changes: 3 additions & 0 deletions Scripts/Editor/CustomEditors/MoveToCollectionWindow.cs.meta

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

44 changes: 21 additions & 23 deletions Scripts/Editor/Processors/CollectionsAssetsPostProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,30 +29,21 @@ static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAsse
ScriptableObject collectionItem =
AssetDatabase.LoadAssetAtPath<ScriptableObject>(importedAssetPath);

if (collectionItem != null)
if (collectionItem == null)
{
if (collectionItem is ISOCItem socItem)
{
if (socItem.Collection == null)
{
continue;
}
continue;
}

if (collectionItem is not ISOCItem socItem)
{
continue;
}

if (!socItem.Collection.Contains(collectionItem))
{
if (socItem.Collection.TryGetItemByGUID(socItem.GUID, out _))
{
Debug.LogWarning(
$"Collection already contains one item with the same GUID" +
$" ({socItem.GUID}) but different name ({socItem.name}), generating new GUID");
socItem.GenerateNewGUID();
}

socItem.Collection.Add(collectionItem);
Debug.Log($"{collectionItem.name} has collection assigned "
+ $"{socItem.Collection} but its missing from collection list, adding it");
}
}
if (!CollectionsRegistry.Instance.HasUniqueGUID(socItem))
{
socItem.GenerateNewGUID();
socItem.ClearCollection();
Debug.LogWarning($"Item {socItem} GUID was not unique, generating a new one and clearing the collection");
}
}

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

if (!CollectionsRegistry.Instance.HasUniqueGUID(collection))
{
collection.GenerateNewGUID();
collection.Clear();
Debug.LogWarning($"Collection {collection} GUID was not unique, generating a new one, and clearing the items");
}

if (!CollectionsRegistry.Instance.IsKnowCollection(collection))
{
RefreshRegistry();
Expand Down Expand Up @@ -95,4 +93,4 @@ static void OnAfterScriptsReloading()
RefreshRegistryAfterRecompilation = false;
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using UnityEditor;
using UnityEngine;

namespace BrunoMikoski.ScriptableObjectCollections.Picker
{
[CustomPropertyDrawer(typeof(CollectionReferenceLongGuidAttribute))]
public class CollectionReferenceLongGuidDrawer : PropertyDrawer
{
public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
{
return EditorGUIUtility.singleLineHeight;
}

public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
LongGuid collectionGUID = (LongGuid)property.boxedValue;

ScriptableObjectCollection collection = null;
if (collectionGUID.IsValid())
{
collection = CollectionsRegistry.Instance.GetCollectionByGUID(collectionGUID);
}

EditorGUI.BeginDisabledGroup(true);
EditorGUI.ObjectField(position, "Collection", collection, typeof(ScriptableObjectCollection), false);
EditorGUI.EndDisabledGroup();
}
}
}

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

Loading

0 comments on commit 27ad1af

Please sign in to comment.