Skip to content

Commit 1b2fc9a

Browse files
authored
Merge pull request #45 from brunomikoski/feature/bugfix_and_qol
Feature/bugfix and qol
2 parents f2f273c + 23bd03a commit 1b2fc9a

9 files changed

Lines changed: 73 additions & 16 deletions

CHANGELOG.MD

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,15 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7+
## [1.3.1]
8+
### Added
9+
- Added basic copy/paste functionality between colelctables
10+
11+
### Changed
12+
- Removed multiple `AssetDatabase.SaveAssets();` to improve general performance when adding / removing objects
13+
- Fixed indirect reference issues with the new Advanced Dropdown search
14+
- Removed static `.Values` from the Colletion, was redundant and error prone
15+
716
## [1.3.0]
817
### Added
918
- Advanced dropdown for better searching on big collections;
@@ -158,6 +167,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
158167

159168
### [Unreleased]
160169

170+
[1.3.1]: https://github.com/badawe/ScriptableObjectCollection/releases/tag/v1.3.1
161171
[1.3.0]: https://github.com/badawe/ScriptableObjectCollection/releases/tag/v1.3.0
162172
[1.2.9]: https://github.com/badawe/ScriptableObjectCollection/releases/tag/v1.2.9
163173
[1.2.8]: https://github.com/badawe/ScriptableObjectCollection/releases/tag/v1.2.8

Scripts/Editor/CollectableScriptableObjectPropertyDrawer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ private void Initialize(SerializedProperty property)
148148
else
149149
collectableType = fieldInfo.FieldType;
150150

151-
if (!CollectionsRegistry.Instance.TryGetCollectionForType(collectableType,
151+
if (!CollectionsRegistry.Instance.TryGetCollectionFromCollectableType(collectableType,
152152
out ScriptableObjectCollection resultCollection))
153153
{
154154
optionsAttribute.DrawType = DrawType.AsReference;
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
using UnityEditor;
2+
3+
namespace BrunoMikoski.ScriptableObjectCollections
4+
{
5+
public static class CopyCollectableUtils
6+
{
7+
private static CollectableScriptableObject source;
8+
9+
public static void SetSource(CollectableScriptableObject targetSource)
10+
{
11+
source = targetSource;
12+
}
13+
14+
public static bool CanPasteToTarget(CollectableScriptableObject target)
15+
{
16+
if (source == null)
17+
return false;
18+
19+
return target.GetType() == source.GetType();
20+
}
21+
22+
public static void ApplySourceToStart(CollectableScriptableObject target)
23+
{
24+
if (source == null)
25+
return;
26+
27+
Undo.RecordObject(target, "Paste Changes");
28+
EditorUtility.CopySerializedManagedFieldsOnly(source, target);
29+
EditorUtility.SetDirty(target);
30+
}
31+
32+
}
33+
}

Scripts/Editor/CopyCollectableUtils.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/CreateNewCollectableType.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ private void OnGUI()
7676
}
7777
else
7878
{
79-
if (CollectionsRegistry.Instance.TryGetCollectionForType(targetType,
79+
if (CollectionsRegistry.Instance.TryGetCollectionFromCollectableType(targetType,
8080
out ScriptableObjectCollection collection))
8181
{
8282
MonoScript scriptObj = MonoScript.FromScriptableObject(collection);

Scripts/Editor/ScriptableObjectCollectionCustomEditor.cs

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -173,11 +173,7 @@ private void CheckForNullItemsOrType()
173173
continue;
174174

175175
if (item.objectReferenceValue == null || item.objectReferenceInstanceIDValue == 0)
176-
{
177-
Debug.LogError($"Removing item at position {i} since it has a null script",
178-
serializedObject.context);
179176
continue;
180-
}
181177

182178
validItems.Add(item.objectReferenceValue as CollectableScriptableObject);
183179
needToRewrite = true;
@@ -282,7 +278,7 @@ public static void AfterStaticAssemblyReload()
282278

283279
Type targetType = Type.GetType($"{lastCollectionFullName}, {assemblyName}");
284280

285-
if (CollectionsRegistry.Instance.TryGetCollectionForType(targetType,
281+
if (CollectionsRegistry.Instance.TryGetCollectionFromCollectableType(targetType,
286282
out ScriptableObjectCollection collection))
287283
{
288284
Selection.activeObject = null;
@@ -386,6 +382,22 @@ private void DrawItem(int index)
386382
filteredSerializedList[index].ApplyModifiedProperties();
387383
}
388384
}
385+
386+
using (new EditorGUILayout.HorizontalScope())
387+
{
388+
if (GUILayout.Button("Copy", EditorStyles.toolbarButton))
389+
{
390+
CopyCollectableUtils.SetSource(collectionItem);
391+
}
392+
393+
using (new EditorGUI.DisabledScope(!CopyCollectableUtils.CanPasteToTarget(collectionItem)))
394+
{
395+
if (GUILayout.Button("Paste", EditorStyles.toolbarButton))
396+
{
397+
CopyCollectableUtils.ApplySourceToStart(collectionItem);
398+
}
399+
}
400+
}
389401
EditorGUI.indentLevel--;
390402
}
391403
}

Scripts/Runtime/CollectionsRegistry.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ public bool TryGetCollectionOfType<T>(out T resultCollection) where T: Scriptabl
115115
}
116116

117117

118-
public bool TryGetCollectionForType(Type targetType,
118+
public bool TryGetCollectionFromCollectableType(Type targetType,
119119
out ScriptableObjectCollection scriptableObjectCollection)
120120
{
121121
for (int i = 0; i < collections.Count; i++)
@@ -133,9 +133,9 @@ public bool TryGetCollectionForType(Type targetType,
133133
return false;
134134
}
135135

136-
public bool TryGetCollectionForType<TargetType>(out ScriptableObjectCollection<TargetType> scriptableObjectCollection) where TargetType : CollectableScriptableObject
136+
public bool TryGetCollectionFromCollectableType<TargetType>(out ScriptableObjectCollection<TargetType> scriptableObjectCollection) where TargetType : CollectableScriptableObject
137137
{
138-
if (TryGetCollectionForType(typeof(TargetType), out ScriptableObjectCollection resultCollection))
138+
if (TryGetCollectionFromCollectableType(typeof(TargetType), out ScriptableObjectCollection resultCollection))
139139
{
140140
scriptableObjectCollection = (ScriptableObjectCollection<TargetType>) resultCollection;
141141
return true;

Scripts/Runtime/ScriptableObjectCollection.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,7 @@ public CollectableScriptableObject AddNew(Type collectionType, string assetName
161161

162162
this.Add(item);
163163
UnityEditor.AssetDatabase.CreateAsset(item, newFileName);
164-
UnityEditor.AssetDatabase.SaveAssets();
165-
UnityEditor.AssetDatabase.Refresh();
164+
ObjectUtility.SetDirty(this);
166165
isReadyOnlyListDirty = true;
167166
return item;
168167
}

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "com.brunomikoski.scriptableobjectcollection",
33
"displayName": "Scriptable Object Collection",
4-
"version": "1.3.0",
4+
"version": "1.3.1",
55
"unity": "2018.4",
66
"description": "Scriptable Object Collection",
77
"keywords": [
@@ -10,12 +10,12 @@
1010
"code generation"
1111
],
1212
"category": "editor extensions",
13-
"homepage": "https://github.com/badawe/ScriptableObjectCollection",
13+
"homepage": "https://github.com/brunomikoski/ScriptableObjectCollection",
1414
"repository": {
1515
"type": "git",
16-
"url": "https://github.com/badawe/ScriptableObjectCollection.git"
16+
"url": "https://github.com/brunomikoski/ScriptableObjectCollection.git"
1717
},
18-
"bugs": "https://github.com/badawe/ScriptableObjectCollection/issues",
18+
"bugs": "https://github.com/brunomikoski/ScriptableObjectCollection/issues",
1919
"author": {
2020
"name": "Bruno Mikoski",
2121
"url": "https://www.brunomikoski.com"

0 commit comments

Comments
 (0)