Skip to content

Conversation

lgarczyn
Copy link

You may want to pick and chose, this is just all of the edits we made to fit our usecase, and some general fixes

  • Use TypeCache for faster retrieval of generators
  • Added sort command to order all or a selection by name
  • Fixed reordering only moving one items one row at a time (turns out the filtered view was being reordered before the event)
  • Fixed Add returning false when the item had an invalid backref to collection
  • Added whitespace to popup to prevent exploding beyond the screen
  • Stopped renaming "Asset" to "Asset1" if SOC tries to move it to the same folder
  • Added support for multiple collections sharing one Items folder
  • Fixed MoveItem causing a stack overflow

Copy link
Collaborator

@RoyTheunissen RoyTheunissen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Found some stuff that is probably worth fixing. Mostly style inconsistencies, but some functional things as well. Please have a look


// Delete any existing files that have the old deprecated extension.
string deprecatedFileName = finalFileName + ExtensionOld;
if (File.Exists(deprecatedFileName))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you remove this exactly? It is useful when migrating from an older version of SOC that it doesn't leave the old .cs file but automatically removes it, otherwise you get compile errors and you have to manually find where it generated the code and delete the old .cs file

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Our collections are in the same folder as the generated code, so this code deletes them. Not sure how we ended up with a different structure than recommended, but we have a 100+ collections now.

This wasn't meant to be sent with the pull request, but since I start the pr with master, it got updated


internal struct LimitedComparer : IComparer<ScriptableObject>
{
private readonly HashSet<ScriptableObjectCollectionItem> m_ItemsToBeSorted;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The m_ prefix is not consistent with the rest of the package. According to the style of this package this field should be called itemsToBeSorted. That goes for m_FirstItemIndex as well

{
ScriptableObjectCollection collection = Collections[i];
if (!collection.AutomaticallyLoaded)
if (!collection)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's fine to omit braces for one line statements after an if condition. It's not done 100% of the time so I wouldn't say it's a rule, just know that it's okay to do so. In cases like this where it's just a continue, I'd say it's simpler / snappier.

if (items.Contains(item))

bool contains = items.Contains(item);
bool set = socItem.Collection == this;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't find set a very clear name. How did you intend it? As "should set collection"?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's more meant as "collectionAlreadySet" and "collectionAlreadyContains"

ObjectUtility.SetDirty(this);
}

private string Desc(int index)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The method name Desc is not consistent with other method names / not that clear. Please write it out fully and with a verb, like GetDescription, which I think is what you intended here.


private string Desc(int index)
{
var item = items[index];
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use explicit types unless the type is very long and it's also very obvious what it is.

{
public static partial class TypeExtensions
{
private static bool IsList(this Type type)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method is either not named correctly or does not function as intended, it seems to check if something is an ICollection<> but that just indicates that it's a collection, not that it's a list. For example, if you called IsList or an a Dictionary it would also return true.

You should either rename this to IsCollection or make it check for IList<> instead.

{
if (baseType.IsGenericType &&
baseType.GetGenericTypeDefinition() == typeof(CollectionItemIndirectReference<>))
return baseType;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Multi-line conditions should have braces

public bool HasUniqueGUID(ISOCItem targetItem)
{
for (int i = 0; i < collections.Count; i++)
foreach (ScriptableObjectCollection collection in collections)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a particular reason you've changed these for loops to foreach loops?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They're faster and I find them more readable

Comment on lines +1139 to +1148
if (toSortX)
{
// compare y with the first item in the list to sort
return x.Index - m_FirstItemIndex;
}
if (toSortY)
{
// compare x with the first item in the list to sort
return m_FirstItemIndex - y.Index;
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are the comments in these if statements perhaps flipped?

Action onCompleteCallback = null)
{
if (item is ISOCItem)
if (item is ISOCItem iItem)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think a better name would be socItem instead of iItem

changed = true;
ObjectUtility.SetDirty(itemsFromOtherCollection.Collection);
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the indentation correct here? I'm seeing two } in a row on the same indentation

lgarczyn and others added 2 commits September 1, 2025 14:14
Co-authored-by: Roy Theunissen <roy.theunissen@live.nl>
Co-authored-by: Roy Theunissen <roy.theunissen@live.nl>
@lgarczyn
Copy link
Author

lgarczyn commented Sep 1, 2025

To be honest, I didn't really intend for this PR to be merged. It just contains a bunch of fixes to issues that you may or may not want to include. I won't have time to fit it to the repo standard until at least next week.

The most important fix by far is the ReorderableList fix

@Thundernerd
Copy link
Collaborator

@lgarczyn

To be honest, I didn't really intend for this PR to be merged. It just contains a bunch of fixes to issues that you may or may not want to include. I won't have time to fit it to the repo standard until at least next week.

The most important fix by far is the ReorderableList fix

That's totally fair and you did sorta already mention this in the description!

@lgarczyn
Copy link
Author

lgarczyn commented Sep 1, 2025

@lgarczyn

To be honest, I didn't really intend for this PR to be merged. It just contains a bunch of fixes to issues that you may or may not want to include. I won't have time to fit it to the repo standard until at least next week.

The most important fix by far is the ReorderableList fix

That's totally fair and you did sorta already mention this in the description!

Thank you, sorry for the messy code :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants