Skip to content

Conversation

@IkeikeP
Copy link
Contributor

@IkeikeP IkeikeP commented May 9, 2022

Hey as discussed, here are the proposed changes to add references to collections.
Essentially it is now possible to convert all items in a collection to references. These references are stored inside Addressables.
Screenshot 2022-05-09 at 17 51 16
It is then possible to add references or items to the collection by using the add (plus) button:
Screenshot 2022-05-09 at 18 45 44
For the sake of simplicity, I'll provide examples using the names of the Weapons collection shown in the screenshots.
The conversion process entails several steps:

  • Marks every ScriptableObjectCollectionItem of the collection as Addressable. An Addressable group is created (or reused) for this scenario.
  • Creates new item base class type (WeaponBase).
  • Creates a new reference class type (WeaponReference) as inherits the new item base class (WeaponBase).
    • This reference class contains a reference object that only contains a GUID to the target item.
  • Swaps the the base class (ScriptableObjectCollectionItem) of the item class ( WeaponBase) for the new base class ( WeaponBase). This step does not fully regenerate the class, it just finds and replaces the base class type.
  • Updates the collection class (WeaponCollection) swapping the type argument of the generic collection class (previously Weapon) for the new base class (WeaponBase).
    • This also does not fully regenerate the class. (if the developers wrote code in the collection class it won't be overridden)
  • Creates scriptable object items of the reference class. These SOs are created in a new directory named "References" next to the Item collection directory.
  • Regenerates the static class code.
    Once the process is complete, developers can use the Load util method provided for each item on the static class (example LoadAK47()) to load the item.

Some advantages of the reference system:

[+]Unified solution that can be applied to any collection the same way
[+]The only thing getting into the resources are GUIDs
[+]Automatically sets the required assets as addressables in a isolated group
[+]More control, can partially load/unload collections

Additionally, this PR includes fixes to the core system that I've stumbled upon testing the references feature.

Keep in mind this is the first iteration and more improvements are possible in the horizon. (For example, better editor UI to manipulate references in the collection)

Also as you asked, I've updated the wiki. But this update is only in my fork (Not possible to create a PR to the wiki repo nor I have permissions to push commits to it)

@brunomikoski
Copy link
Owner

Awesome! I will get the branch and do some local tests with it, but overall looks really good!

Copy link
Owner

@brunomikoski brunomikoski left a comment

Choose a reason for hiding this comment

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

Some questions and small code code format issues

@IkeikeP IkeikeP force-pushed the feature/add_references branch 2 times, most recently from 5ec3c84 to bfceda8 Compare May 10, 2022 15:49
@IkeikeP IkeikeP requested a review from brunomikoski May 10, 2022 15:51
@IkeikeP IkeikeP force-pushed the feature/add_references branch from 6f87aaa to 80964bd Compare May 12, 2022 16:46
@IkeikeP IkeikeP force-pushed the feature/add_references branch from 80964bd to f759b52 Compare May 13, 2022 14:22
@IkeikeP
Copy link
Contributor Author

IkeikeP commented May 13, 2022

Thank you for the review, glad you liked it!
All the comments have been addressed. I have also made some minor improvements and fixes which were mostly code styling related.

@brunomikoski brunomikoski merged commit 702bc03 into brunomikoski:master Jul 11, 2022
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.

2 participants