一套库,可通过将 Unity3D 脚本化对象分组到集合中,并通过代码或用户友好的方式提供便捷访问,从而提高这些对象的可用性
一套库,可通过将 Unity3D 脚本化对象分组到集合中,并通过代码或用户友好的方式提供便捷访问,从而提高这些对象的可用性
Most of the time when dealing with Scriptable Objects they all belong to some sort of collection, let's say for example all your consumables on the game? Or maybe all your weapons? Or even all your in-app purchases. Dealing with this can be quite challenging since you have to rely on proper naming of those scriptable objects, this can become a problem super fast as the project continues to grow.
The ScriptableObjectCollection exists to help you deal with scriptable objects without losing your sanity! It's a set of tools that will make your life a lot easier.
Check the FAQ with more examples and use examples.
Collection.ValuesAssets/Create/Scriptable Object Collection/New Collection ScriptableObjectCollection as a regular ScriptableObject, add any item you want there I'm having issues when deleting duplicating items It's really hard to make sure those features work perfectly with the system since it depends on to catch up the GUIDs of the collectables, ALWAYS try to use the Add New / Deleting by the inspector itself
How I can propery serialize this for Save Game or Backend data
There's a couple of ways of dealing with this, the easiest one is to use the IndirectReference when you need this data to be serialized, this will only store 2 GUIDs.
Another option is writing a proper parser using the ISerializationCallback.
Collection Registry on the Resources Folder Since the CollectionsRegistry is inside the Resources folder, every reference this has to a collection and to all the collectables will be inside the Unity Resources bundle, and if you have a lot of references for expensive stuff, this can increase your startup time significantly, there are 2 things you should keep in mind:
CollectionsRegistry.Instance.RegisterCollection(Collection); and removing it when they are not necessary anymore. How can I create a new collection
You can use the Collection Creating Wizard by right click on the project panel and going into: Assets/Create/Scriptable Object Collection/New Collection this will create 3 items and respective folder: YourCollectionName.cs YourCollectableName.cs and the Collection Scriptable Object
Use a direct reference to the item instead of the dropdown
When you add a reference to a Collectable you may choose how you want this to be displayed by adding [CollectionItemEditorOptions].
There are two Draw Types for now:
- DropDown the default option which displays all the available options in a convenient drop-down, like an enum field Unity 2018.4.0 or later versions
Add from OpenUPM | via scoped registry, recommended
This package is available on OpenUPM: https://openupm.com/packages/com.brunomikoski.scriptableobjectcollection
To add the package to your project:
Edit/Project Settings/Package ManagerName: OpenUPM
URL: https://package.openupm.com/
Scope(s): com.brunomikoskicom.brunomikoski.scriptableobjectcollectionAdd from GitHub | not recommended, no updates :(
You can also add it directly from GitHub on Unity 2019.4+. Note that you won't be able to receive updates through Package Manager this way, you'll have to update manually.
https://github.com/brunomikoski/ScriptableObjectCollection.git⚠️ Upgrading from <2.3.0 to 2.4.0 — Important Migration Notes
If you are upgrading ScriptableObjectCollection from a version prior to 2.3.0 to 2.4.0, please read this section carefully to avoid breaking changes and compile errors.
.g.cs Suffix.g.cs suffix..g.cs suffix from your project..meta file instead of in the generator/collection files..cs files (without the .g.cs suffix) during the upgrade process.If you encounter problems after upgrading:
.g.cs are deleted..meta files..g.cs.暂无开放 Issues,或尚未同步最近议题。