___________________________________________________________________________________
Why did I create CodeSmile AssetDatabase?
___________________________________________________________________________________
Write fail-safe, readable, concise, efficient asset scripts in less time.
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 and version-dependent behaviours 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 terrible 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.
That is what CodeSmile AssetDatabase provides.
___________________________________________________________________________________
Main Features
___________________________________________________________________________________
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).
NOTE: 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!
___________________________________________________________________________________
Example Code Snippets
___________________________________________________________________________________
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! ;)
Example 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;`
Path examples:
- `var path = new Asset.Path(@"C:\MyPrjcts\Foo\Assets\Bar\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.
For completeness sake:
- `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 ms
Description sourced from the Unity Asset Store listing.