-
Notifications
You must be signed in to change notification settings - Fork 40
Various fixes #176
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Various fixes #176
Changes from all commits
da7789b
1d9f0b5
72089b8
82b43cf
6d3d97e
c6257f2
8608bf5
c372719
f419fa8
fe9c8ef
9b94b69
c1aac39
c5a4df5
8da50d7
4484f5c
2869c2d
e45787f
31f569d
003b01e
4c83758
b106540
40df7c7
e1138eb
b43af7a
07f002c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -347,6 +347,7 @@ | |
|
|
||
| private void OnCollectionItemOrderChanged(int fromIndex, int toIndex) | ||
| { | ||
| ReloadFilteredItems(); | ||
| ScriptableObject sourceItem = filteredItems[fromIndex]; | ||
| ScriptableObject targetItem = filteredItems[toIndex]; | ||
|
|
||
|
|
@@ -735,12 +736,32 @@ | |
| false, | ||
| () => { CopyCollectionItemUtility.SetSource(scriptableObject); } | ||
| ); | ||
|
|
||
| menu.AddDisabledItem(new GUIContent("Sort Items"), false); | ||
| } | ||
| else | ||
| { | ||
| menu.AddDisabledItem( | ||
| new GUIContent("Copy Values"), | ||
| false); | ||
|
|
||
| menu.AddItem( | ||
| new GUIContent("Sort Items"), | ||
| false, | ||
| () => | ||
| { | ||
| Undo.RecordObject(collection, "Sort Items"); | ||
| List<ScriptableObject> itemsToBeSorted = new(); | ||
| foreach (int selectedIndex in collectionItemListView.selectedIndices) | ||
| { | ||
| itemsToBeSorted.Add(filteredItems[selectedIndex]); | ||
| } | ||
|
|
||
| collection.Sort(new LimitedComparer(itemsToBeSorted)); | ||
|
|
||
| ReloadFilteredItems(); | ||
| } | ||
| ); | ||
| } | ||
| if (CopyCollectionItemUtility.CanPasteToTarget(scriptableObject)) | ||
| { | ||
|
|
@@ -1085,4 +1106,48 @@ | |
| } | ||
| } | ||
| } | ||
|
|
||
| internal struct LimitedComparer : IComparer<ScriptableObject> | ||
| { | ||
| private readonly HashSet<ScriptableObjectCollectionItem> m_ItemsToBeSorted; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
| private readonly int m_FirstItemIndex; | ||
| public LimitedComparer(List<ScriptableObject> itemsToBeSorted) | ||
| { | ||
| m_ItemsToBeSorted = itemsToBeSorted.OfType<ScriptableObjectCollectionItem>().ToHashSet(); | ||
| m_FirstItemIndex = m_ItemsToBeSorted.Select(i => i.Index).Min(); | ||
| } | ||
|
|
||
| public int Compare(ScriptableObject xObject, ScriptableObject yObject) | ||
| { | ||
| if (ReferenceEquals(xObject, yObject)) return 0; | ||
| if (yObject is null) return 1; | ||
| if (xObject is null) return -1; | ||
|
|
||
| if (xObject is not ScriptableObjectCollectionItem x || yObject is not ScriptableObjectCollectionItem y) | ||
| { | ||
| return 0; // or throw an exception if you want to enforce that both are of type ScriptableObjectCollectionItem | ||
| } | ||
|
|
||
| bool toSortX = m_ItemsToBeSorted.Contains(x); | ||
| bool toSortY = m_ItemsToBeSorted.Contains(y); | ||
|
|
||
| if (toSortX && toSortY) | ||
| { | ||
| return String.Compare(x.name, y.name, StringComparison.Ordinal); | ||
| } | ||
|
|
||
| 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; | ||
| } | ||
|
Comment on lines
+1139
to
+1148
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are the comments in these if statements perhaps flipped? |
||
| // neither x nor y are in the list to sort, compare by Index | ||
| return x.Index.CompareTo(y.Index); | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -510,10 +510,13 @@ public void SetAutoSearchForCollections(bool isOn) | |
|
|
||
| public void UpdateAutoSearchForCollections() | ||
| { | ||
| for (int i = 0; i < Collections.Count; i++) | ||
| foreach (ScriptableObjectCollection collection in collections) | ||
| { | ||
| ScriptableObjectCollection collection = Collections[i]; | ||
| if (!collection.AutomaticallyLoaded) | ||
| if (!collection) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
| } | ||
| if (collection != null && !collection.AutomaticallyLoaded) | ||
| { | ||
| SetAutoSearchForCollections(true); | ||
| return; | ||
|
|
@@ -525,9 +528,12 @@ public void UpdateAutoSearchForCollections() | |
|
|
||
| public bool HasUniqueGUID(ISOCItem targetItem) | ||
| { | ||
| for (int i = 0; i < collections.Count; i++) | ||
| foreach (ScriptableObjectCollection collection in collections) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there a particular reason you've changed these There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. They're faster and I find them more readable |
||
| { | ||
| ScriptableObjectCollection collection = collections[i]; | ||
| if (!collection) | ||
| { | ||
| continue; | ||
| } | ||
| foreach (ScriptableObject scriptableObject in collection) | ||
| { | ||
| if (scriptableObject is ISOCItem socItem) | ||
|
|
@@ -543,9 +549,12 @@ public bool HasUniqueGUID(ISOCItem targetItem) | |
|
|
||
| public bool HasUniqueGUID(ScriptableObjectCollection targetCollection) | ||
| { | ||
| for (int i = 0; i < collections.Count; i++) | ||
| foreach (ScriptableObjectCollection collection in collections) | ||
| { | ||
| ScriptableObjectCollection collection = collections[i]; | ||
| if (!collection) | ||
| { | ||
| continue; | ||
| } | ||
| if (collection != targetCollection && collection.GUID == targetCollection.GUID) | ||
| return false; | ||
| } | ||
|
|
||
There was a problem hiding this comment.
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
.csfile but automatically removes it, otherwise you get compile errors and you have to manually find where it generated the code and delete the old.csfileThere was a problem hiding this comment.
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