NOTE: This is only for mod developers who want to create custom real prefabs without needing to use asset bundles, even at runtime.
Github repository, where you can look at SynergyAPI's code and download it: https://github.com/SpecialAPI/PrefabAPI
PrefabAPI allows you to create custom prefabs with one simple method, without needing to use any asset bundles, and it even works in runtime.
If you don't know what a prefab is, you can read about prefabs here: https://docs.unity3d.com/2017.4/Documentation/Manual/Prefabs.html
To use this API, just
- Add it's files except files from Examples folder, PrefabAPI.csproj and PrefabAPI.sln, README.md, .gitignore and .gitattributes and everything from the Properties folder to your project.
- Call PrefabAPI.Init() in your module's Init()/Start() method. Oh wait. I forgot. You don't even need to do this! Every time you build a prefab, if PrefabAPI wasn't initialized already, it will automatically initialize itself!
PrefabAPI Guide
Various PrefabAPI classes
Spoiler!
PrefabBuilder
- the class you will be using to create prefabs.AssetBundleBuilder
- the class that actually builds the bytes for the asset bundles with the prefabs.ExampleModule
- an example module that shows how to use PrefabAPI's methods.UrBadAtTheGameComponent
- an example component that was used in the "cloning already existing objects" part ofExampleModule
.- Everything else - just exists. Don't touch/change it.
Creating a new object or cloning an existing ones.
Spoiler!
To create a new prefab object you will need to use PrefabBuilder.BuildObject("insert name of the object here")
. That's it. Nothing more.
If you want to clone an already existing object (if it's prefab or not doesn't matter), you can use PrefabBuilder.Clone(objectToClone)
. NOTE: UNLIKE ACTUAL OBJECT INSTANTIATION, CLONE() WILL NOT MAKE A PERFECT CLONE, SOME THINGS MAY NOT SERIALIZE CORRECTLY, BUT IT SHOULD WORK FOR THE MOST PART. (ALTHROUGH I STILL RECOMMEND TO USE CLONE() AS LITTLE AS POSSIBLE)
Credits and stuff:
- SpecialAPI (me) - brute-forcing my way trough the creation of this API (it was painful).
- All of the people that created AssetStudio (https://github.com/Perfare/AssetStudio) - creating AssetStudio (which is already a very very very helpful tool for modding gungeon) and making it open source. Without that code I would've never created this.
- Unity (the game engine) - Hating fun and being confusing mostly.
Things I want to add in the future:
- Serialization of lists.
- Runtime
TextAsset
creation.