CodeSmile AssetDatabase 1.9
Unity's AssetDatabase in enjoyable, consistent, concise, convenient, comprehensible, safe, documented form.
|
Imagine Unity's AssetDatabase were self-explanatory, enjoyable to use, consistent in design and behaviour, well documented, prevents disasters, and results in concise code.
Click the image to watch the video:
The AssetDatabase is heavily fragmented into verbosely named, losely related static methods with inconsistent signatures and varying side-effects. It's functional, but it's design is fundamentally broken (absent), leading to terrible code written against it.
Developers commonly employ a trial-and-error approach. Trivial tasks take much longer than estimated. Edge-cases remain to be discovered later. There is a real risk of data loss due to a simple mistake. Cargo-cult and copy-pasta programming needlessly degrade editor performance.
That's what most editor tools are based on, unfortunately.
You'll find such bad examples even in popular Asset Store tools used by big game studios!
A clean start with a consistent API is the best way to solve these issues, speed up development of editor tools, ensure scripts will not fail for users or other editor platforms.
Write fail-safe, readable, concise, efficient asset scripts in less time. That is what CodeSmile AssetDatabase provides.
The main class is CodeSmileEditor.Asset
which provides a static API but it's also instantiable.
The Asset instance provides access to asset-specific operations and alleviates you from managing separate state (eg asset path, GUID, sub assets, etc).
The CodeSmileEditor.Asset.Path
handles asset paths, ensures they are relative and compatible across editor platforms, validates correctness in regards to file system and assets, and provides all path operations and representations (.meta, full path, etc).
Unity's AssetDatabase and existing scripts using it are NOT altered or affected in any way.
BONUS: Asset Inspector - view and inspect every (!) detail of selected assets. It also serves as a showcase for CodeSmile AssetDatabase.
There's a whole lot more so be sure to explore and discover!
Load and Create assets:
Asset asset = "Assets/Folder/Data.asset";
var asset = new Asset(bytes, "Assets/Folder/Data.asset");
var obj = Asset.File.Create(str, "Assets/Folder/Data.asset");
var obj = Asset.File.CreateAsNew(bytes, "Assets/Folder/Data.asset");
Notice the hands-free, does-what-you-need approach.
What's not noticable here is that any non-existing folder in the path is automatically created. Countless asset scripts fail the first time an actual user runs it. I know YOU know it! You read this far! ;)
Other file operations:
asset.ForceSave();
var assetDupe = asset.Duplicate();
assetDupe.Delete();
var copy = asset.SaveAsNew("Assets/Elsewhere/Dada.asset");
Type conversion:
var obj = asset.MainObject;
var levelData = asset.GetMain<LevelData>();
var levelData = (LevelData)asset;
Asset.Path examples:
var path = new Asset.Path(@"C:\MyProjects\FudniteClone\Assets\my.asset");
path.CreateFolders();
var absolutePath = path.FullPath;
Performance:
Asset.File.BatchEditing(() => { /* mass file IO */ });
Asset.File.Import(paths);
Work with Sub-Assets:
asset.AddSubAsset(subData);
var subAssets = asset.SubAssets;
You'll commonly get or set dependencies, importers, labels, paths, asset bundles, etc. via instance properties.
Complete:
asset.ExportPackage("I:/leveldata.unitypackage");
asset.ActiveImporter = typeof(MyDataImporter);
Asset.Database.ImportAll();
// Hint: this is "Refresh()"You'll also find Cache Server, Version Control, etc. in well-defined, logical places.
Error Handling:
var msg = Asset.GetLastErrorMessage();
Exceptions are also thrown for malformed input to make the API more resilient and reliable, rather than calls silently failing or printing unhelpful console logs.
The API documentation is more complete with more details and caveats mentioned than Unity's. Of course you'll find these snippets right in your IDE as tooltips.
The Transition Guide helps experienced developers find what each AssetDatabase method maps to in the CodeSmileEditor.Asset class.
If there's anything out of the ordinary, report an issue or contact me. I also have a Discord channel.
You can get the most up-to-date version on the CodeSmile AssetDatabase GitHub repository.
This software is a Unity Package Manager 'npm package' available on GitHub (GPL License) or the Unity Asset Store (UAS EULA).
https://github.com/CodeSmile-0000011110110111/de.codesmile.editor.assetdatabase.git
This software is dual-licensed.
The free GitHub version is distributed under the GNU General Public License v3.0 (GPL 3.0). The main implication is that any work you publish that uses this software requires the entire work to be published as open source software under the same GPL 3.0 license.
The paid version is available on the Unity Asset Store (UAS) and licensed under the Asset Store EULA. Users who purchased this software can, at any time, also download the software from GitHub and use it under the terms and conditions of the Asset Store EULA.
I care. A lot.
I work obsessively.
I follow best practices.
I like to share knowledge.
I'm also deeply honest. And I trust you.
I support you.
Very welcome!
If you wish to license this software under different terms, for example to create Asset Store tools, please contact me!
I'm available for consultation, tutoring best practices, sharing my experience and other contract work.
If you like this asset and want to support my work please favorite, rate and review this asset! It helps a lot to bubble up in the search algorithm.