CodeSmile AssetDatabase

CodeSmile

(0)
$40
Publisher CodeSmile
File size 1.21MB
Number of files 88
Latest version 1.9.1
Latest release date 2024-02-05 04:58:04
First release date 2024-01-31 11:58:12
Supported Unity versions 2018.4.2 or higher

___________________________________________________________________________________

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 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 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.


___________________________________________________________________________________

Documentation & Support

___________________________________________________________________________________


The API documentation is complete with more details, examples, annotations and implementation notes than in Unity's manual. Your IDE will show these 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.


___________________________________________________________________________________

About me

___________________________________________________________________________________


I care. A lot.


The API has been designed to be concise, approachable, elegant, consistent, explorable, complete and whole lot more buzzwords - except they actually mean something to me.


I work obsessively.


All AssetDatabase methods are included.

The Asset Inspector window lets you inspect every detail of selected assets in the project.


I follow best practices.


Included are extensive test cases, the file I/O operations specifically have 100% test coverage. The tests also serve to instruct by example.


I like to share.


The documentation is exhaustive, well structured, and contains more information than what you'll find in Unity's manual and script reference.


I'm also deeply honest.


Admittedly, a very fringe method that returns a NativeArray has been omitted to avoid having to depend on com.unity.collections. Just so you know.


And I trust you.


You can demo the project on GitHub where it's available for free, albeit under the terms of the GNU GPL 3.0.


___________________________________________________________________________________

Support, Feeback, Inquiries

___________________________________________________________________________________


Very welcome!


Contact me if you have any issues or feature requests.

You'll also find me actively supporting users on the Unity Forums.


I'm available for consultation, tutoring best practices, sharing my experience and other contract work.


All purchases are much appreciated and are invested straight into making more assets of this kind. You also support feeding my super-cute budgies. :)


- Steffen aka CodeSmile

- Email / Website / GitHub / Discord / My Assets

Top Publisher Assets